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 |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 6 | * Copyright 2015 Intel Deutschland GmbH |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/if.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13 | #include <linux/list.h> |
| 14 | #include <linux/if_ether.h> |
| 15 | #include <linux/ieee80211.h> |
| 16 | #include <linux/nl80211.h> |
| 17 | #include <linux/rtnetlink.h> |
| 18 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 21 | #include <net/genetlink.h> |
| 22 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 23 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 24 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include "core.h" |
| 26 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 27 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 28 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 31 | struct genl_info *info, |
| 32 | struct cfg80211_crypto_settings *settings, |
| 33 | int cipher_limit); |
| 34 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 36 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 37 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 38 | struct genl_info *info); |
| 39 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | /* the netlink family */ |
| 41 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 42 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 43 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 44 | .hdrsize = 0, /* no private header */ |
| 45 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 46 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 47 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 48 | .pre_doit = nl80211_pre_doit, |
| 49 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 52 | /* multicast groups */ |
| 53 | enum nl80211_multicast_groups { |
| 54 | NL80211_MCGRP_CONFIG, |
| 55 | NL80211_MCGRP_SCAN, |
| 56 | NL80211_MCGRP_REGULATORY, |
| 57 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 58 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 59 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 60 | }; |
| 61 | |
| 62 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 63 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 64 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 65 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 66 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 67 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 68 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 69 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 70 | #endif |
| 71 | }; |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | /* returns ERR_PTR values */ |
| 74 | static struct wireless_dev * |
| 75 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 77 | struct cfg80211_registered_device *rdev; |
| 78 | struct wireless_dev *result = NULL; |
| 79 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 80 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 81 | u64 wdev_id; |
| 82 | int wiphy_idx = -1; |
| 83 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 85 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 87 | if (!have_ifidx && !have_wdev_id) |
| 88 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 89 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 90 | if (have_ifidx) |
| 91 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 92 | if (have_wdev_id) { |
| 93 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 94 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 97 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 98 | struct wireless_dev *wdev; |
| 99 | |
| 100 | if (wiphy_net(&rdev->wiphy) != netns) |
| 101 | continue; |
| 102 | |
| 103 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 104 | continue; |
| 105 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 106 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 107 | if (have_ifidx && wdev->netdev && |
| 108 | wdev->netdev->ifindex == ifidx) { |
| 109 | result = wdev; |
| 110 | break; |
| 111 | } |
| 112 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 113 | result = wdev; |
| 114 | break; |
| 115 | } |
| 116 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 117 | |
| 118 | if (result) |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | if (result) |
| 123 | return result; |
| 124 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 128 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 129 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 130 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 131 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 133 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 134 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 135 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 136 | !attrs[NL80211_ATTR_IFINDEX] && |
| 137 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 138 | return ERR_PTR(-EINVAL); |
| 139 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 141 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 142 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 143 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 144 | if (attrs[NL80211_ATTR_WDEV]) { |
| 145 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 146 | struct wireless_dev *wdev; |
| 147 | bool found = false; |
| 148 | |
| 149 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 150 | if (tmp) { |
| 151 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 152 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 153 | if (wdev->identifier != (u32)wdev_id) |
| 154 | continue; |
| 155 | found = true; |
| 156 | break; |
| 157 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 158 | |
| 159 | if (!found) |
| 160 | tmp = NULL; |
| 161 | |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | rdev = tmp; |
| 165 | } |
| 166 | } |
| 167 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 168 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 169 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 170 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 171 | if (netdev) { |
| 172 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 173 | tmp = wiphy_to_rdev( |
| 174 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 175 | else |
| 176 | tmp = NULL; |
| 177 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 178 | /* not wireless device -- return error */ |
| 179 | if (!tmp) |
| 180 | return ERR_PTR(-EINVAL); |
| 181 | |
| 182 | /* mismatch -- return error */ |
| 183 | if (rdev && tmp != rdev) |
| 184 | return ERR_PTR(-EINVAL); |
| 185 | |
| 186 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 190 | if (!rdev) |
| 191 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 192 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 193 | if (netns != wiphy_net(&rdev->wiphy)) |
| 194 | return ERR_PTR(-ENODEV); |
| 195 | |
| 196 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* |
| 200 | * This function returns a pointer to the driver |
| 201 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 202 | * |
| 203 | * The result of this can be a PTR_ERR and hence must |
| 204 | * be checked with IS_ERR() for errors. |
| 205 | */ |
| 206 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 207 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 208 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 209 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 212 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 213 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 214 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 215 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 216 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 218 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 220 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 221 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 224 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 226 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 227 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 230 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 231 | |
| 232 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 234 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 235 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 236 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 237 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 238 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 241 | .len = WLAN_MAX_KEY_LEN }, |
| 242 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 243 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 244 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 245 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 247 | |
| 248 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 249 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 250 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 251 | .len = IEEE80211_MAX_DATA_LEN }, |
| 252 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 253 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 254 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 255 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 256 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 257 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 258 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 260 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 261 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 263 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 264 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 265 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 266 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 267 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 268 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 269 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 270 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 271 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 272 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 273 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 274 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 275 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 276 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 277 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 278 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 279 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 280 | |
| 281 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 282 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 283 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 284 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 285 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 286 | |
| 287 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 288 | .len = IEEE80211_MAX_SSID_LEN }, |
| 289 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 290 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_STA_FLAGS2] = { |
| 295 | .len = sizeof(struct nl80211_sta_flag_update), |
| 296 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 298 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 299 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 300 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 301 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 302 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 305 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 306 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 307 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 308 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 311 | .len = IEEE80211_MAX_DATA_LEN }, |
| 312 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 314 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 315 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 317 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 318 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 319 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 320 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 321 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 325 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 326 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 329 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 331 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 332 | .len = IEEE80211_MAX_DATA_LEN }, |
| 333 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 334 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 335 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 336 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 337 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 338 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 342 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 343 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 345 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 346 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 347 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 348 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 349 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 350 | .len = NL80211_HT_CAPABILITY_LEN |
| 351 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 352 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 355 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 356 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 357 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 358 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 359 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 360 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 361 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 362 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 363 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 364 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 365 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 368 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 369 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 370 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 372 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 373 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 374 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 375 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 376 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 377 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 378 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 379 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 380 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 381 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 382 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 383 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 384 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 385 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 386 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 387 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 388 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 389 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 390 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 391 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 392 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 393 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 395 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 396 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 397 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 398 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 399 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 400 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 403 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame^] | 404 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 405 | }; |
| 406 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 407 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 408 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 409 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 410 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 411 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 412 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 413 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 414 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 415 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 416 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 417 | }; |
| 418 | |
| 419 | /* policy for the key default flags */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 422 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 423 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 424 | }; |
| 425 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 426 | /* policy for WoWLAN attributes */ |
| 427 | static const struct nla_policy |
| 428 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 429 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 430 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 431 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 432 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 433 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 434 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 435 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 436 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 437 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 438 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | static const struct nla_policy |
| 442 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 443 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 444 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 445 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 446 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 447 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 448 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 449 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 450 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 451 | }, |
| 452 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 453 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 454 | }, |
| 455 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 456 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 457 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 458 | }; |
| 459 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 460 | /* policy for coalesce rule attributes */ |
| 461 | static const struct nla_policy |
| 462 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 463 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 464 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 465 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 466 | }; |
| 467 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 468 | /* policy for GTK rekey offload attributes */ |
| 469 | static const struct nla_policy |
| 470 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 471 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 472 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 473 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 474 | }; |
| 475 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 476 | static const struct nla_policy |
| 477 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 478 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 479 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 480 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 481 | }; |
| 482 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 483 | static const struct nla_policy |
| 484 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 485 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 486 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 487 | }; |
| 488 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 490 | struct netlink_callback *cb, |
| 491 | struct cfg80211_registered_device **rdev, |
| 492 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 493 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 494 | int err; |
| 495 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 496 | rtnl_lock(); |
| 497 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 498 | if (!cb->args[0]) { |
| 499 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 500 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 501 | nl80211_policy); |
| 502 | if (err) |
| 503 | goto out_unlock; |
| 504 | |
| 505 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 506 | nl80211_fam.attrbuf); |
| 507 | if (IS_ERR(*wdev)) { |
| 508 | err = PTR_ERR(*wdev); |
| 509 | goto out_unlock; |
| 510 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 511 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 512 | /* 0 is the first index - add 1 to parse only once */ |
| 513 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | cb->args[1] = (*wdev)->identifier; |
| 515 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 516 | /* subtract the 1 again here */ |
| 517 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 518 | struct wireless_dev *tmp; |
| 519 | |
| 520 | if (!wiphy) { |
| 521 | err = -ENODEV; |
| 522 | goto out_unlock; |
| 523 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 524 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 525 | *wdev = NULL; |
| 526 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 527 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 528 | if (tmp->identifier == cb->args[1]) { |
| 529 | *wdev = tmp; |
| 530 | break; |
| 531 | } |
| 532 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 533 | |
| 534 | if (!*wdev) { |
| 535 | err = -ENODEV; |
| 536 | goto out_unlock; |
| 537 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 540 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 541 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 542 | rtnl_unlock(); |
| 543 | return err; |
| 544 | } |
| 545 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 546 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 547 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 548 | rtnl_unlock(); |
| 549 | } |
| 550 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 551 | /* IE validation */ |
| 552 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 553 | { |
| 554 | const u8 *pos; |
| 555 | int len; |
| 556 | |
| 557 | if (!attr) |
| 558 | return true; |
| 559 | |
| 560 | pos = nla_data(attr); |
| 561 | len = nla_len(attr); |
| 562 | |
| 563 | while (len) { |
| 564 | u8 elemlen; |
| 565 | |
| 566 | if (len < 2) |
| 567 | return false; |
| 568 | len -= 2; |
| 569 | |
| 570 | elemlen = pos[1]; |
| 571 | if (elemlen > len) |
| 572 | return false; |
| 573 | |
| 574 | len -= elemlen; |
| 575 | pos += 2 + elemlen; |
| 576 | } |
| 577 | |
| 578 | return true; |
| 579 | } |
| 580 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 581 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 582 | 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] | 583 | int flags, u8 cmd) |
| 584 | { |
| 585 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 586 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 590 | struct ieee80211_channel *chan, |
| 591 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 592 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 593 | /* Some channels must be completely excluded from the |
| 594 | * list to protect old user-space tools from breaking |
| 595 | */ |
| 596 | if (!large && chan->flags & |
| 597 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 598 | return 0; |
| 599 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 600 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 601 | chan->center_freq)) |
| 602 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 604 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 605 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 606 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 607 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 608 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 609 | goto nla_put_failure; |
| 610 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 611 | goto nla_put_failure; |
| 612 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 613 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 614 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 615 | goto nla_put_failure; |
| 616 | if (large) { |
| 617 | u32 time; |
| 618 | |
| 619 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 620 | |
| 621 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 622 | chan->dfs_state)) |
| 623 | goto nla_put_failure; |
| 624 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 625 | time)) |
| 626 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 627 | if (nla_put_u32(msg, |
| 628 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 629 | chan->dfs_cac_ms)) |
| 630 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 631 | } |
| 632 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 633 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 634 | if (large) { |
| 635 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 637 | goto nla_put_failure; |
| 638 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 639 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 640 | goto nla_put_failure; |
| 641 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 642 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 643 | goto nla_put_failure; |
| 644 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 645 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 646 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 647 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 648 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 649 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 650 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 651 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 652 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 653 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 654 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 655 | goto nla_put_failure; |
| 656 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 657 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 658 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 659 | } |
| 660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 661 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 662 | DBM_TO_MBM(chan->max_power))) |
| 663 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | |
| 667 | nla_put_failure: |
| 668 | return -ENOBUFS; |
| 669 | } |
| 670 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 671 | /* netlink command implementations */ |
| 672 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 673 | struct key_parse { |
| 674 | struct key_params p; |
| 675 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 676 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 677 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 679 | }; |
| 680 | |
| 681 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 682 | { |
| 683 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 684 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 685 | nl80211_key_policy); |
| 686 | if (err) |
| 687 | return err; |
| 688 | |
| 689 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 690 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 691 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 692 | if (k->def) { |
| 693 | k->def_uni = true; |
| 694 | k->def_multi = true; |
| 695 | } |
| 696 | if (k->defmgmt) |
| 697 | k->def_multi = true; |
| 698 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 699 | if (tb[NL80211_KEY_IDX]) |
| 700 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 701 | |
| 702 | if (tb[NL80211_KEY_DATA]) { |
| 703 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 704 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 705 | } |
| 706 | |
| 707 | if (tb[NL80211_KEY_SEQ]) { |
| 708 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 709 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 710 | } |
| 711 | |
| 712 | if (tb[NL80211_KEY_CIPHER]) |
| 713 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 714 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 715 | if (tb[NL80211_KEY_TYPE]) { |
| 716 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 717 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 718 | return -EINVAL; |
| 719 | } |
| 720 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 721 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 722 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 723 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 724 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 725 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 726 | if (err) |
| 727 | return err; |
| 728 | |
| 729 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 730 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 731 | } |
| 732 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 737 | { |
| 738 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 739 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 740 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 741 | } |
| 742 | |
| 743 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 744 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 745 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 746 | } |
| 747 | |
| 748 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 749 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 750 | |
| 751 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 752 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 753 | |
| 754 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 755 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 756 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 757 | if (k->def) { |
| 758 | k->def_uni = true; |
| 759 | k->def_multi = true; |
| 760 | } |
| 761 | if (k->defmgmt) |
| 762 | k->def_multi = true; |
| 763 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 764 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 765 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 766 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 767 | return -EINVAL; |
| 768 | } |
| 769 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 770 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 771 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 772 | int err = nla_parse_nested( |
| 773 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 774 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 775 | nl80211_key_default_policy); |
| 776 | if (err) |
| 777 | return err; |
| 778 | |
| 779 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 780 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 781 | } |
| 782 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 787 | { |
| 788 | int err; |
| 789 | |
| 790 | memset(k, 0, sizeof(*k)); |
| 791 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 792 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 793 | |
| 794 | if (info->attrs[NL80211_ATTR_KEY]) |
| 795 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 796 | else |
| 797 | err = nl80211_parse_key_old(info, k); |
| 798 | |
| 799 | if (err) |
| 800 | return err; |
| 801 | |
| 802 | if (k->def && k->defmgmt) |
| 803 | return -EINVAL; |
| 804 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 805 | if (k->defmgmt) { |
| 806 | if (k->def_uni || !k->def_multi) |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 810 | if (k->idx != -1) { |
| 811 | if (k->defmgmt) { |
| 812 | if (k->idx < 4 || k->idx > 5) |
| 813 | return -EINVAL; |
| 814 | } else if (k->def) { |
| 815 | if (k->idx < 0 || k->idx > 3) |
| 816 | return -EINVAL; |
| 817 | } else { |
| 818 | if (k->idx < 0 || k->idx > 5) |
| 819 | return -EINVAL; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | return 0; |
| 824 | } |
| 825 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 826 | static struct cfg80211_cached_keys * |
| 827 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 828 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 829 | { |
| 830 | struct key_parse parse; |
| 831 | struct nlattr *key; |
| 832 | struct cfg80211_cached_keys *result; |
| 833 | int rem, err, def = 0; |
| 834 | |
| 835 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 836 | if (!result) |
| 837 | return ERR_PTR(-ENOMEM); |
| 838 | |
| 839 | result->def = -1; |
| 840 | result->defmgmt = -1; |
| 841 | |
| 842 | nla_for_each_nested(key, keys, rem) { |
| 843 | memset(&parse, 0, sizeof(parse)); |
| 844 | parse.idx = -1; |
| 845 | |
| 846 | err = nl80211_parse_key_new(key, &parse); |
| 847 | if (err) |
| 848 | goto error; |
| 849 | err = -EINVAL; |
| 850 | if (!parse.p.key) |
| 851 | goto error; |
| 852 | if (parse.idx < 0 || parse.idx > 4) |
| 853 | goto error; |
| 854 | if (parse.def) { |
| 855 | if (def) |
| 856 | goto error; |
| 857 | def = 1; |
| 858 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 859 | if (!parse.def_uni || !parse.def_multi) |
| 860 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 861 | } else if (parse.defmgmt) |
| 862 | goto error; |
| 863 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 864 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 865 | if (err) |
| 866 | goto error; |
| 867 | result->params[parse.idx].cipher = parse.p.cipher; |
| 868 | result->params[parse.idx].key_len = parse.p.key_len; |
| 869 | result->params[parse.idx].key = result->data[parse.idx]; |
| 870 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 871 | |
| 872 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 873 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 874 | if (no_ht) |
| 875 | *no_ht = true; |
| 876 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | return result; |
| 880 | error: |
| 881 | kfree(result); |
| 882 | return ERR_PTR(err); |
| 883 | } |
| 884 | |
| 885 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 886 | { |
| 887 | ASSERT_WDEV_LOCK(wdev); |
| 888 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 889 | switch (wdev->iftype) { |
| 890 | case NL80211_IFTYPE_AP: |
| 891 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 892 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 893 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 894 | break; |
| 895 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 896 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 897 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 898 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 899 | return -ENOLINK; |
| 900 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 901 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 902 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 903 | case NL80211_IFTYPE_MONITOR: |
| 904 | case NL80211_IFTYPE_P2P_DEVICE: |
| 905 | case NL80211_IFTYPE_WDS: |
| 906 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 907 | return -EINVAL; |
| 908 | } |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 913 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 914 | struct nlattr *tb) |
| 915 | { |
| 916 | struct ieee80211_channel *chan; |
| 917 | |
| 918 | if (tb == NULL) |
| 919 | return NULL; |
| 920 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 921 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 922 | return NULL; |
| 923 | return chan; |
| 924 | } |
| 925 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 926 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 927 | { |
| 928 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 929 | int i; |
| 930 | |
| 931 | if (!nl_modes) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | i = 0; |
| 935 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 936 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 937 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 938 | ifmodes >>= 1; |
| 939 | i++; |
| 940 | } |
| 941 | |
| 942 | nla_nest_end(msg, nl_modes); |
| 943 | return 0; |
| 944 | |
| 945 | nla_put_failure: |
| 946 | return -ENOBUFS; |
| 947 | } |
| 948 | |
| 949 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 950 | struct sk_buff *msg, |
| 951 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 952 | { |
| 953 | struct nlattr *nl_combis; |
| 954 | int i, j; |
| 955 | |
| 956 | nl_combis = nla_nest_start(msg, |
| 957 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 958 | if (!nl_combis) |
| 959 | goto nla_put_failure; |
| 960 | |
| 961 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 962 | const struct ieee80211_iface_combination *c; |
| 963 | struct nlattr *nl_combi, *nl_limits; |
| 964 | |
| 965 | c = &wiphy->iface_combinations[i]; |
| 966 | |
| 967 | nl_combi = nla_nest_start(msg, i + 1); |
| 968 | if (!nl_combi) |
| 969 | goto nla_put_failure; |
| 970 | |
| 971 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 972 | if (!nl_limits) |
| 973 | goto nla_put_failure; |
| 974 | |
| 975 | for (j = 0; j < c->n_limits; j++) { |
| 976 | struct nlattr *nl_limit; |
| 977 | |
| 978 | nl_limit = nla_nest_start(msg, j + 1); |
| 979 | if (!nl_limit) |
| 980 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 981 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 982 | c->limits[j].max)) |
| 983 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 984 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 985 | c->limits[j].types)) |
| 986 | goto nla_put_failure; |
| 987 | nla_nest_end(msg, nl_limit); |
| 988 | } |
| 989 | |
| 990 | nla_nest_end(msg, nl_limits); |
| 991 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 992 | if (c->beacon_int_infra_match && |
| 993 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 994 | goto nla_put_failure; |
| 995 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 996 | c->num_different_channels) || |
| 997 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 998 | c->max_interfaces)) |
| 999 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1000 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1001 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1002 | c->radar_detect_widths) || |
| 1003 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1004 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1005 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1006 | |
| 1007 | nla_nest_end(msg, nl_combi); |
| 1008 | } |
| 1009 | |
| 1010 | nla_nest_end(msg, nl_combis); |
| 1011 | |
| 1012 | return 0; |
| 1013 | nla_put_failure: |
| 1014 | return -ENOBUFS; |
| 1015 | } |
| 1016 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1017 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1018 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1019 | struct sk_buff *msg) |
| 1020 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1021 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1022 | struct nlattr *nl_tcp; |
| 1023 | |
| 1024 | if (!tcp) |
| 1025 | return 0; |
| 1026 | |
| 1027 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1028 | if (!nl_tcp) |
| 1029 | return -ENOBUFS; |
| 1030 | |
| 1031 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1032 | tcp->data_payload_max)) |
| 1033 | return -ENOBUFS; |
| 1034 | |
| 1035 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1036 | tcp->data_payload_max)) |
| 1037 | return -ENOBUFS; |
| 1038 | |
| 1039 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1040 | return -ENOBUFS; |
| 1041 | |
| 1042 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1043 | sizeof(*tcp->tok), tcp->tok)) |
| 1044 | return -ENOBUFS; |
| 1045 | |
| 1046 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1047 | tcp->data_interval_max)) |
| 1048 | return -ENOBUFS; |
| 1049 | |
| 1050 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1051 | tcp->wake_payload_max)) |
| 1052 | return -ENOBUFS; |
| 1053 | |
| 1054 | nla_nest_end(msg, nl_tcp); |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1058 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1060 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1061 | { |
| 1062 | struct nlattr *nl_wowlan; |
| 1063 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | return 0; |
| 1066 | |
| 1067 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1068 | if (!nl_wowlan) |
| 1069 | return -ENOBUFS; |
| 1070 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1071 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1075 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1077 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1079 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1080 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1081 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1082 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1083 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1084 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1085 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1086 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1087 | return -ENOBUFS; |
| 1088 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1089 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1090 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1091 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1092 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1093 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1094 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1095 | }; |
| 1096 | |
| 1097 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1098 | sizeof(pat), &pat)) |
| 1099 | return -ENOBUFS; |
| 1100 | } |
| 1101 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1102 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1103 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1104 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1105 | return -ENOBUFS; |
| 1106 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1107 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1108 | return -ENOBUFS; |
| 1109 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1110 | nla_nest_end(msg, nl_wowlan); |
| 1111 | |
| 1112 | return 0; |
| 1113 | } |
| 1114 | #endif |
| 1115 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1116 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1117 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1118 | { |
| 1119 | struct nl80211_coalesce_rule_support rule; |
| 1120 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1121 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1122 | return 0; |
| 1123 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1124 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1125 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1126 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1127 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1128 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1129 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1130 | |
| 1131 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1132 | return -ENOBUFS; |
| 1133 | |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1137 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1138 | struct ieee80211_supported_band *sband) |
| 1139 | { |
| 1140 | struct nlattr *nl_rates, *nl_rate; |
| 1141 | struct ieee80211_rate *rate; |
| 1142 | int i; |
| 1143 | |
| 1144 | /* add HT info */ |
| 1145 | if (sband->ht_cap.ht_supported && |
| 1146 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1147 | sizeof(sband->ht_cap.mcs), |
| 1148 | &sband->ht_cap.mcs) || |
| 1149 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1150 | sband->ht_cap.cap) || |
| 1151 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1152 | sband->ht_cap.ampdu_factor) || |
| 1153 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1154 | sband->ht_cap.ampdu_density))) |
| 1155 | return -ENOBUFS; |
| 1156 | |
| 1157 | /* add VHT info */ |
| 1158 | if (sband->vht_cap.vht_supported && |
| 1159 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1160 | sizeof(sband->vht_cap.vht_mcs), |
| 1161 | &sband->vht_cap.vht_mcs) || |
| 1162 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1163 | sband->vht_cap.cap))) |
| 1164 | return -ENOBUFS; |
| 1165 | |
| 1166 | /* add bitrates */ |
| 1167 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1168 | if (!nl_rates) |
| 1169 | return -ENOBUFS; |
| 1170 | |
| 1171 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1172 | nl_rate = nla_nest_start(msg, i); |
| 1173 | if (!nl_rate) |
| 1174 | return -ENOBUFS; |
| 1175 | |
| 1176 | rate = &sband->bitrates[i]; |
| 1177 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1178 | rate->bitrate)) |
| 1179 | return -ENOBUFS; |
| 1180 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1181 | nla_put_flag(msg, |
| 1182 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1183 | return -ENOBUFS; |
| 1184 | |
| 1185 | nla_nest_end(msg, nl_rate); |
| 1186 | } |
| 1187 | |
| 1188 | nla_nest_end(msg, nl_rates); |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static int |
| 1194 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1195 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1196 | { |
| 1197 | u16 stypes; |
| 1198 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1199 | enum nl80211_iftype ift; |
| 1200 | int i; |
| 1201 | |
| 1202 | if (!mgmt_stypes) |
| 1203 | return 0; |
| 1204 | |
| 1205 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1206 | if (!nl_ifs) |
| 1207 | return -ENOBUFS; |
| 1208 | |
| 1209 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1210 | nl_ftypes = nla_nest_start(msg, ift); |
| 1211 | if (!nl_ftypes) |
| 1212 | return -ENOBUFS; |
| 1213 | i = 0; |
| 1214 | stypes = mgmt_stypes[ift].tx; |
| 1215 | while (stypes) { |
| 1216 | if ((stypes & 1) && |
| 1217 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1218 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1219 | return -ENOBUFS; |
| 1220 | stypes >>= 1; |
| 1221 | i++; |
| 1222 | } |
| 1223 | nla_nest_end(msg, nl_ftypes); |
| 1224 | } |
| 1225 | |
| 1226 | nla_nest_end(msg, nl_ifs); |
| 1227 | |
| 1228 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1229 | if (!nl_ifs) |
| 1230 | return -ENOBUFS; |
| 1231 | |
| 1232 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1233 | nl_ftypes = nla_nest_start(msg, ift); |
| 1234 | if (!nl_ftypes) |
| 1235 | return -ENOBUFS; |
| 1236 | i = 0; |
| 1237 | stypes = mgmt_stypes[ift].rx; |
| 1238 | while (stypes) { |
| 1239 | if ((stypes & 1) && |
| 1240 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1241 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1242 | return -ENOBUFS; |
| 1243 | stypes >>= 1; |
| 1244 | i++; |
| 1245 | } |
| 1246 | nla_nest_end(msg, nl_ftypes); |
| 1247 | } |
| 1248 | nla_nest_end(msg, nl_ifs); |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1253 | struct nl80211_dump_wiphy_state { |
| 1254 | s64 filter_wiphy; |
| 1255 | long start; |
| 1256 | long split_start, band_start, chan_start; |
| 1257 | bool split; |
| 1258 | }; |
| 1259 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1260 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1261 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1263 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1264 | { |
| 1265 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1266 | struct nlattr *nl_bands, *nl_band; |
| 1267 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1268 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1269 | enum ieee80211_band band; |
| 1270 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1271 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1272 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1273 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1274 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1275 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1276 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1277 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | return -ENOBUFS; |
| 1279 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1280 | if (WARN_ON(!state)) |
| 1281 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1282 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1285 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1286 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1288 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1289 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1290 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1291 | goto finish; |
| 1292 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1293 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | case 0: |
| 1295 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1304 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1307 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1308 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1310 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1312 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1314 | rdev->wiphy.max_match_sets) || |
| 1315 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1316 | rdev->wiphy.max_sched_scan_plans) || |
| 1317 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1318 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1319 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1320 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1321 | goto nla_put_failure; |
| 1322 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1323 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1325 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1326 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1328 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1331 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1332 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1334 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1335 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1336 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1337 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1338 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1340 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1341 | state->split_start++; |
| 1342 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1343 | break; |
| 1344 | case 1: |
| 1345 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1347 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1348 | goto nla_put_failure; |
| 1349 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1351 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | goto nla_put_failure; |
| 1353 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1354 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1356 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1359 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1361 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1363 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1364 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1365 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1366 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1368 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1369 | if ((rdev->wiphy.available_antennas_tx || |
| 1370 | rdev->wiphy.available_antennas_rx) && |
| 1371 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | u32 tx_ant = 0, rx_ant = 0; |
| 1373 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1374 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | if (!res) { |
| 1376 | if (nla_put_u32(msg, |
| 1377 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1378 | tx_ant) || |
| 1379 | nla_put_u32(msg, |
| 1380 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1381 | rx_ant)) |
| 1382 | goto nla_put_failure; |
| 1383 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1386 | state->split_start++; |
| 1387 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1388 | break; |
| 1389 | case 2: |
| 1390 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1391 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1393 | state->split_start++; |
| 1394 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | break; |
| 1396 | case 3: |
| 1397 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1398 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1399 | goto nla_put_failure; |
| 1400 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1401 | for (band = state->band_start; |
| 1402 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1403 | struct ieee80211_supported_band *sband; |
| 1404 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1405 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | |
| 1407 | if (!sband) |
| 1408 | continue; |
| 1409 | |
| 1410 | nl_band = nla_nest_start(msg, band); |
| 1411 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1412 | goto nla_put_failure; |
| 1413 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1414 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1415 | case 0: |
| 1416 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1417 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1418 | state->chan_start++; |
| 1419 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | break; |
| 1421 | default: |
| 1422 | /* add frequencies */ |
| 1423 | nl_freqs = nla_nest_start( |
| 1424 | msg, NL80211_BAND_ATTR_FREQS); |
| 1425 | if (!nl_freqs) |
| 1426 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1427 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1428 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | i < sband->n_channels; |
| 1430 | i++) { |
| 1431 | nl_freq = nla_nest_start(msg, i); |
| 1432 | if (!nl_freq) |
| 1433 | goto nla_put_failure; |
| 1434 | |
| 1435 | chan = &sband->channels[i]; |
| 1436 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1437 | if (nl80211_msg_put_channel( |
| 1438 | msg, chan, |
| 1439 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | goto nla_put_failure; |
| 1441 | |
| 1442 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1443 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1447 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1449 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | nla_nest_end(msg, nl_freqs); |
| 1451 | } |
| 1452 | |
| 1453 | nla_nest_end(msg, nl_band); |
| 1454 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1456 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1457 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | band--; |
| 1459 | break; |
| 1460 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1461 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1463 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1465 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1467 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1468 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1470 | if (state->band_start == 0 && state->chan_start == 0) |
| 1471 | state->split_start++; |
| 1472 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | break; |
| 1474 | case 4: |
| 1475 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1476 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1477 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | |
| 1479 | i = 0; |
| 1480 | #define CMD(op, n) \ |
| 1481 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1482 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | i++; \ |
| 1484 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1485 | goto nla_put_failure; \ |
| 1486 | } \ |
| 1487 | } while (0) |
| 1488 | |
| 1489 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1490 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1491 | CMD(add_key, NEW_KEY); |
| 1492 | CMD(start_ap, START_AP); |
| 1493 | CMD(add_station, NEW_STATION); |
| 1494 | CMD(add_mpath, NEW_MPATH); |
| 1495 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1496 | CMD(change_bss, SET_BSS); |
| 1497 | CMD(auth, AUTHENTICATE); |
| 1498 | CMD(assoc, ASSOCIATE); |
| 1499 | CMD(deauth, DEAUTHENTICATE); |
| 1500 | CMD(disassoc, DISASSOCIATE); |
| 1501 | CMD(join_ibss, JOIN_IBSS); |
| 1502 | CMD(join_mesh, JOIN_MESH); |
| 1503 | CMD(set_pmksa, SET_PMKSA); |
| 1504 | CMD(del_pmksa, DEL_PMKSA); |
| 1505 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1506 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1508 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1509 | CMD(mgmt_tx, FRAME); |
| 1510 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1511 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | i++; |
| 1513 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1514 | goto nla_put_failure; |
| 1515 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1516 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1517 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | i++; |
| 1519 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1520 | goto nla_put_failure; |
| 1521 | } |
| 1522 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1523 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1525 | CMD(tdls_oper, TDLS_OPER); |
| 1526 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1527 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1529 | CMD(probe_client, PROBE_CLIENT); |
| 1530 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1531 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1532 | i++; |
| 1533 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1534 | goto nla_put_failure; |
| 1535 | } |
| 1536 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1537 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1538 | #ifdef CONFIG_NL80211_TESTMODE |
| 1539 | CMD(testmode_cmd, TESTMODE); |
| 1540 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1541 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1542 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1543 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1544 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1545 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1546 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1547 | if (rdev->wiphy.features & |
| 1548 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1549 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1550 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1551 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1552 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1553 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1554 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1555 | i++; |
| 1556 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1557 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1560 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | i++; |
| 1562 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1563 | goto nla_put_failure; |
| 1564 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1565 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1567 | state->split_start++; |
| 1568 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | break; |
| 1570 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1571 | if (rdev->ops->remain_on_channel && |
| 1572 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | nla_put_u32(msg, |
| 1574 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1575 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1576 | goto nla_put_failure; |
| 1577 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1579 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1580 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1581 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1583 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1584 | state->split_start++; |
| 1585 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1586 | break; |
| 1587 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1588 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1591 | state->split_start++; |
| 1592 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1593 | break; |
| 1594 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1595 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | #endif |
| 1597 | case 7: |
| 1598 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1599 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1600 | goto nla_put_failure; |
| 1601 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1602 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1603 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1605 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1606 | state->split_start++; |
| 1607 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | break; |
| 1609 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1610 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1611 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1612 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | goto nla_put_failure; |
| 1614 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1615 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1616 | /* |
| 1617 | * We can only add the per-channel limit information if the |
| 1618 | * dump is split, otherwise it makes it too big. Therefore |
| 1619 | * only advertise it in that case. |
| 1620 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1622 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1623 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1624 | goto nla_put_failure; |
| 1625 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1626 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1628 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1629 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | goto nla_put_failure; |
| 1631 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1633 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1634 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1635 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1636 | goto nla_put_failure; |
| 1637 | |
| 1638 | /* |
| 1639 | * Any information below this point is only available to |
| 1640 | * applications that can deal with it being split. This |
| 1641 | * helps ensure that newly added capabilities don't break |
| 1642 | * older tools by overrunning their buffers. |
| 1643 | * |
| 1644 | * We still increment split_start so that in the split |
| 1645 | * case we'll continue with more data in the next round, |
| 1646 | * but break unconditionally so unsplit data stops here. |
| 1647 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1648 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1649 | break; |
| 1650 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1651 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1652 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1653 | rdev->wiphy.extended_capabilities_len, |
| 1654 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1655 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1656 | rdev->wiphy.extended_capabilities_len, |
| 1657 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1658 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1660 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1661 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1662 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1663 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1664 | goto nla_put_failure; |
| 1665 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1666 | state->split_start++; |
| 1667 | break; |
| 1668 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1669 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1670 | goto nla_put_failure; |
| 1671 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1672 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1673 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1674 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1675 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1676 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1677 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1678 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1680 | goto nla_put_failure; |
| 1681 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1682 | state->split_start++; |
| 1683 | break; |
| 1684 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1685 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1686 | const struct nl80211_vendor_cmd_info *info; |
| 1687 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1688 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1689 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1690 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1691 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1692 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1693 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1694 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1695 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1696 | goto nla_put_failure; |
| 1697 | } |
| 1698 | nla_nest_end(msg, nested); |
| 1699 | } |
| 1700 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1701 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1702 | const struct nl80211_vendor_cmd_info *info; |
| 1703 | struct nlattr *nested; |
| 1704 | |
| 1705 | nested = nla_nest_start(msg, |
| 1706 | NL80211_ATTR_VENDOR_EVENTS); |
| 1707 | if (!nested) |
| 1708 | goto nla_put_failure; |
| 1709 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1710 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1711 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1712 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1713 | goto nla_put_failure; |
| 1714 | } |
| 1715 | nla_nest_end(msg, nested); |
| 1716 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1717 | state->split_start++; |
| 1718 | break; |
| 1719 | case 12: |
| 1720 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1721 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1722 | rdev->wiphy.max_num_csa_counters)) |
| 1723 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1724 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1725 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1726 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1727 | goto nla_put_failure; |
| 1728 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1729 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1730 | sizeof(rdev->wiphy.ext_features), |
| 1731 | rdev->wiphy.ext_features)) |
| 1732 | goto nla_put_failure; |
| 1733 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1734 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1735 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1736 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1737 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1738 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1739 | genlmsg_end(msg, hdr); |
| 1740 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1741 | |
| 1742 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1743 | genlmsg_cancel(msg, hdr); |
| 1744 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1745 | } |
| 1746 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1747 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1748 | struct netlink_callback *cb, |
| 1749 | struct nl80211_dump_wiphy_state *state) |
| 1750 | { |
| 1751 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1752 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1753 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1754 | /* ignore parse errors for backward compatibility */ |
| 1755 | if (ret) |
| 1756 | return 0; |
| 1757 | |
| 1758 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1759 | if (tb[NL80211_ATTR_WIPHY]) |
| 1760 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1761 | if (tb[NL80211_ATTR_WDEV]) |
| 1762 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1763 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1764 | struct net_device *netdev; |
| 1765 | struct cfg80211_registered_device *rdev; |
| 1766 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1767 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1768 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1769 | if (!netdev) |
| 1770 | return -ENODEV; |
| 1771 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1772 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1773 | netdev->ieee80211_ptr->wiphy); |
| 1774 | state->filter_wiphy = rdev->wiphy_idx; |
| 1775 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1781 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1782 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1783 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1784 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1785 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1786 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1787 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1788 | if (!state) { |
| 1789 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1790 | if (!state) { |
| 1791 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1792 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1793 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1794 | state->filter_wiphy = -1; |
| 1795 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1796 | if (ret) { |
| 1797 | kfree(state); |
| 1798 | rtnl_unlock(); |
| 1799 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1800 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1801 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1802 | } |
| 1803 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1804 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1805 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1806 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1807 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1808 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1809 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1810 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1811 | continue; |
| 1812 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1813 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1814 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1815 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1816 | NETLINK_CB(cb->skb).portid, |
| 1817 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1818 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1819 | if (ret < 0) { |
| 1820 | /* |
| 1821 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1822 | * or EMSGSIZE returned), this SKB is still |
| 1823 | * empty (so it's not too big because another |
| 1824 | * wiphy dataset is already in the skb) and |
| 1825 | * we've not tried to adjust the dump allocation |
| 1826 | * yet ... then adjust the alloc size to be |
| 1827 | * bigger, and return 1 but with the empty skb. |
| 1828 | * This results in an empty message being RX'ed |
| 1829 | * in userspace, but that is ignored. |
| 1830 | * |
| 1831 | * We can then retry with the larger buffer. |
| 1832 | */ |
| 1833 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1834 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1835 | cb->min_dump_alloc < 4096) { |
| 1836 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1837 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1838 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1839 | return 1; |
| 1840 | } |
| 1841 | idx--; |
| 1842 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1843 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1844 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1845 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1846 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1847 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1848 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1849 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1850 | |
| 1851 | return skb->len; |
| 1852 | } |
| 1853 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1854 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1855 | { |
| 1856 | kfree((void *)cb->args[0]); |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1860 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1861 | { |
| 1862 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1863 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1864 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1865 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1866 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1867 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1868 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1869 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1870 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1871 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1872 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1873 | nlmsg_free(msg); |
| 1874 | return -ENOBUFS; |
| 1875 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1876 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1877 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1878 | } |
| 1879 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1880 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1881 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1882 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1883 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1884 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1885 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1886 | }; |
| 1887 | |
| 1888 | static int parse_txq_params(struct nlattr *tb[], |
| 1889 | struct ieee80211_txq_params *txq_params) |
| 1890 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1891 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1892 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1893 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1894 | return -EINVAL; |
| 1895 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1896 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1897 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1898 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1899 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1900 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1901 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1902 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1903 | return -EINVAL; |
| 1904 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1905 | return 0; |
| 1906 | } |
| 1907 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1908 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1909 | { |
| 1910 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1911 | * You can only set the channel explicitly for WDS interfaces, |
| 1912 | * all others have their channel managed via their respective |
| 1913 | * "establish a connection" command (connect, join, ...) |
| 1914 | * |
| 1915 | * For AP/GO and mesh mode, the channel can be set with the |
| 1916 | * channel userspace API, but is only stored and passed to the |
| 1917 | * low-level driver when the AP starts or the mesh is joined. |
| 1918 | * This is for backward compatibility, userspace can also give |
| 1919 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1920 | * |
| 1921 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1922 | * whatever else is going on, so they have their own special |
| 1923 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1924 | */ |
| 1925 | return !wdev || |
| 1926 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1927 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1928 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1929 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1930 | } |
| 1931 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1932 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1933 | struct genl_info *info, |
| 1934 | struct cfg80211_chan_def *chandef) |
| 1935 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1936 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1937 | |
| 1938 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1939 | return -EINVAL; |
| 1940 | |
| 1941 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1942 | |
| 1943 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1944 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1945 | chandef->center_freq1 = control_freq; |
| 1946 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1947 | |
| 1948 | /* Primary channel not allowed */ |
| 1949 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1950 | return -EINVAL; |
| 1951 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1952 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1953 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1954 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1955 | chantype = nla_get_u32( |
| 1956 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1957 | |
| 1958 | switch (chantype) { |
| 1959 | case NL80211_CHAN_NO_HT: |
| 1960 | case NL80211_CHAN_HT20: |
| 1961 | case NL80211_CHAN_HT40PLUS: |
| 1962 | case NL80211_CHAN_HT40MINUS: |
| 1963 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1964 | chantype); |
| 1965 | break; |
| 1966 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1967 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1968 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1969 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1970 | chandef->width = |
| 1971 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1972 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1973 | chandef->center_freq1 = |
| 1974 | nla_get_u32( |
| 1975 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1976 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1977 | chandef->center_freq2 = |
| 1978 | nla_get_u32( |
| 1979 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1980 | } |
| 1981 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1982 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1983 | return -EINVAL; |
| 1984 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1985 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1986 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1987 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1988 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1989 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1990 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1991 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1992 | return -EINVAL; |
| 1993 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1994 | return 0; |
| 1995 | } |
| 1996 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1997 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1998 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1999 | struct genl_info *info) |
| 2000 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2001 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2003 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2004 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2005 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2006 | if (dev) |
| 2007 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2008 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2009 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2010 | if (wdev) |
| 2011 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2012 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2013 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2014 | if (result) |
| 2015 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2016 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2017 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2018 | case NL80211_IFTYPE_AP: |
| 2019 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2020 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2021 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2022 | result = -EINVAL; |
| 2023 | break; |
| 2024 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2025 | if (wdev->beacon_interval) { |
| 2026 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2027 | !(rdev->wiphy.features & |
| 2028 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2029 | result = -EBUSY; |
| 2030 | break; |
| 2031 | } |
| 2032 | |
| 2033 | /* Only allow dynamic channel width changes */ |
| 2034 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2035 | result = -EBUSY; |
| 2036 | break; |
| 2037 | } |
| 2038 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2039 | if (result) |
| 2040 | break; |
| 2041 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2042 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2043 | result = 0; |
| 2044 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2045 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2046 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2047 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2048 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2049 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2050 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2051 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2052 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2053 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2054 | |
| 2055 | return result; |
| 2056 | } |
| 2057 | |
| 2058 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2059 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2060 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2061 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2062 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2063 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2064 | } |
| 2065 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2066 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2067 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2069 | struct net_device *dev = info->user_ptr[1]; |
| 2070 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2071 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2072 | |
| 2073 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2074 | return -EINVAL; |
| 2075 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2076 | if (netif_running(dev)) |
| 2077 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2078 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2079 | if (!rdev->ops->set_wds_peer) |
| 2080 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2081 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2082 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2083 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2084 | |
| 2085 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2086 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2090 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2091 | { |
| 2092 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2093 | struct net_device *netdev = NULL; |
| 2094 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2095 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2096 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2097 | u32 changed; |
| 2098 | u8 retry_short = 0, retry_long = 0; |
| 2099 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2100 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2101 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2102 | ASSERT_RTNL(); |
| 2103 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2104 | /* |
| 2105 | * Try to find the wiphy and netdev. Normally this |
| 2106 | * function shouldn't need the netdev, but this is |
| 2107 | * done for backward compatibility -- previously |
| 2108 | * setting the channel was done per wiphy, but now |
| 2109 | * it is per netdev. Previous userland like hostapd |
| 2110 | * also passed a netdev to set_wiphy, so that it is |
| 2111 | * possible to let that go to the right netdev! |
| 2112 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2113 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2114 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2115 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2116 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2117 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2118 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2119 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2120 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2121 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2122 | } |
| 2123 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2124 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2125 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2126 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2127 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2128 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2129 | wdev = NULL; |
| 2130 | netdev = NULL; |
| 2131 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2132 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2133 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2134 | |
| 2135 | /* |
| 2136 | * end workaround code, by now the rdev is available |
| 2137 | * and locked, and wdev may or may not be NULL. |
| 2138 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2139 | |
| 2140 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2141 | result = cfg80211_dev_rename( |
| 2142 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2143 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2144 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2145 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2146 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2147 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2148 | struct ieee80211_txq_params txq_params; |
| 2149 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2150 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2151 | if (!rdev->ops->set_txq_params) |
| 2152 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2153 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2154 | if (!netdev) |
| 2155 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2156 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2157 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2158 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2159 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2160 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2161 | if (!netif_running(netdev)) |
| 2162 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2163 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2164 | nla_for_each_nested(nl_txq_params, |
| 2165 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2166 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2167 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2168 | nla_data(nl_txq_params), |
| 2169 | nla_len(nl_txq_params), |
| 2170 | txq_params_policy); |
| 2171 | if (result) |
| 2172 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2173 | result = parse_txq_params(tb, &txq_params); |
| 2174 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2175 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2176 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2177 | result = rdev_set_txq_params(rdev, netdev, |
| 2178 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2179 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2180 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2184 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2185 | result = __nl80211_set_channel( |
| 2186 | rdev, |
| 2187 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2188 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2189 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2190 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2191 | } |
| 2192 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2193 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2194 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2195 | enum nl80211_tx_power_setting type; |
| 2196 | int idx, mbm = 0; |
| 2197 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2198 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2199 | txp_wdev = NULL; |
| 2200 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2201 | if (!rdev->ops->set_tx_power) |
| 2202 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2203 | |
| 2204 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2205 | type = nla_get_u32(info->attrs[idx]); |
| 2206 | |
| 2207 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2208 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2209 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2210 | |
| 2211 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2212 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2213 | mbm = nla_get_u32(info->attrs[idx]); |
| 2214 | } |
| 2215 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2216 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2217 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2218 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2219 | } |
| 2220 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2221 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2222 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2223 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2224 | if ((!rdev->wiphy.available_antennas_tx && |
| 2225 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2226 | !rdev->ops->set_antenna) |
| 2227 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2228 | |
| 2229 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2230 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2231 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2232 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2233 | * available antenna masks, except for the "all" mask */ |
| 2234 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2235 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2236 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2237 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2238 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2239 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2240 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2241 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2242 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2243 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2244 | } |
| 2245 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2246 | changed = 0; |
| 2247 | |
| 2248 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2249 | retry_short = nla_get_u8( |
| 2250 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2251 | if (retry_short == 0) |
| 2252 | return -EINVAL; |
| 2253 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2254 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2255 | } |
| 2256 | |
| 2257 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2258 | retry_long = nla_get_u8( |
| 2259 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2260 | if (retry_long == 0) |
| 2261 | return -EINVAL; |
| 2262 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2263 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2264 | } |
| 2265 | |
| 2266 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2267 | frag_threshold = nla_get_u32( |
| 2268 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2269 | if (frag_threshold < 256) |
| 2270 | return -EINVAL; |
| 2271 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2272 | if (frag_threshold != (u32) -1) { |
| 2273 | /* |
| 2274 | * Fragments (apart from the last one) are required to |
| 2275 | * have even length. Make the fragmentation code |
| 2276 | * simpler by stripping LSB should someone try to use |
| 2277 | * odd threshold value. |
| 2278 | */ |
| 2279 | frag_threshold &= ~0x1; |
| 2280 | } |
| 2281 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2282 | } |
| 2283 | |
| 2284 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2285 | rts_threshold = nla_get_u32( |
| 2286 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2287 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2288 | } |
| 2289 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2290 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2291 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2292 | return -EINVAL; |
| 2293 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2294 | coverage_class = nla_get_u8( |
| 2295 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2296 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2297 | } |
| 2298 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2299 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2300 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2301 | return -EOPNOTSUPP; |
| 2302 | |
| 2303 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2304 | } |
| 2305 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2306 | if (changed) { |
| 2307 | u8 old_retry_short, old_retry_long; |
| 2308 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2309 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2310 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2311 | if (!rdev->ops->set_wiphy_params) |
| 2312 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2313 | |
| 2314 | old_retry_short = rdev->wiphy.retry_short; |
| 2315 | old_retry_long = rdev->wiphy.retry_long; |
| 2316 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2317 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2318 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2319 | |
| 2320 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2321 | rdev->wiphy.retry_short = retry_short; |
| 2322 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2323 | rdev->wiphy.retry_long = retry_long; |
| 2324 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2325 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2326 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2327 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2328 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2329 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2330 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2331 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2332 | if (result) { |
| 2333 | rdev->wiphy.retry_short = old_retry_short; |
| 2334 | rdev->wiphy.retry_long = old_retry_long; |
| 2335 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2336 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2337 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2338 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2339 | } |
| 2340 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2341 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2342 | } |
| 2343 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2344 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2345 | { |
| 2346 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2347 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2348 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2349 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2350 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2351 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2352 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2353 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2354 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2355 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2356 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2357 | chandef->chan->center_freq)) |
| 2358 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2359 | switch (chandef->width) { |
| 2360 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2361 | case NL80211_CHAN_WIDTH_20: |
| 2362 | case NL80211_CHAN_WIDTH_40: |
| 2363 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2364 | cfg80211_get_chandef_type(chandef))) |
| 2365 | return -ENOBUFS; |
| 2366 | break; |
| 2367 | default: |
| 2368 | break; |
| 2369 | } |
| 2370 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2371 | return -ENOBUFS; |
| 2372 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2373 | return -ENOBUFS; |
| 2374 | if (chandef->center_freq2 && |
| 2375 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2376 | return -ENOBUFS; |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2380 | 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] | 2381 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2382 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2383 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2384 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2385 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2386 | void *hdr; |
| 2387 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2388 | if (removal) |
| 2389 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2390 | |
| 2391 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2392 | if (!hdr) |
| 2393 | return -1; |
| 2394 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2395 | if (dev && |
| 2396 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2397 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2398 | goto nla_put_failure; |
| 2399 | |
| 2400 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2401 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2402 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2403 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2404 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2405 | rdev->devlist_generation ^ |
| 2406 | (cfg80211_rdev_list_generation << 2))) |
| 2407 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2408 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2409 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2410 | int ret; |
| 2411 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2412 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2413 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2414 | if (ret == 0) { |
| 2415 | if (nl80211_send_chandef(msg, &chandef)) |
| 2416 | goto nla_put_failure; |
| 2417 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2418 | } |
| 2419 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2420 | if (rdev->ops->get_tx_power) { |
| 2421 | int dbm, ret; |
| 2422 | |
| 2423 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2424 | if (ret == 0 && |
| 2425 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2426 | DBM_TO_MBM(dbm))) |
| 2427 | goto nla_put_failure; |
| 2428 | } |
| 2429 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2430 | if (wdev->ssid_len) { |
| 2431 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2432 | goto nla_put_failure; |
| 2433 | } |
| 2434 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2435 | genlmsg_end(msg, hdr); |
| 2436 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2437 | |
| 2438 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2439 | genlmsg_cancel(msg, hdr); |
| 2440 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2444 | { |
| 2445 | int wp_idx = 0; |
| 2446 | int if_idx = 0; |
| 2447 | int wp_start = cb->args[0]; |
| 2448 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2449 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | struct wireless_dev *wdev; |
| 2451 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2452 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2453 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2454 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2455 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2456 | if (wp_idx < wp_start) { |
| 2457 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2458 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2459 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2460 | if_idx = 0; |
| 2461 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2462 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2463 | if (if_idx < if_start) { |
| 2464 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2465 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2466 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2467 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2468 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2469 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2470 | goto out; |
| 2471 | } |
| 2472 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2473 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2474 | |
| 2475 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2476 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2477 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2478 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2479 | |
| 2480 | cb->args[0] = wp_idx; |
| 2481 | cb->args[1] = if_idx; |
| 2482 | |
| 2483 | return skb->len; |
| 2484 | } |
| 2485 | |
| 2486 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2487 | { |
| 2488 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2490 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2491 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2492 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2493 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2494 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2495 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2496 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2497 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | nlmsg_free(msg); |
| 2499 | return -ENOBUFS; |
| 2500 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2501 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2502 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2503 | } |
| 2504 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2505 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2506 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2507 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2508 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2509 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2510 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2511 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2512 | }; |
| 2513 | |
| 2514 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2515 | { |
| 2516 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2517 | int flag; |
| 2518 | |
| 2519 | *mntrflags = 0; |
| 2520 | |
| 2521 | if (!nla) |
| 2522 | return -EINVAL; |
| 2523 | |
| 2524 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2525 | nla, mntr_flags_policy)) |
| 2526 | return -EINVAL; |
| 2527 | |
| 2528 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2529 | if (flags[flag]) |
| 2530 | *mntrflags |= (1<<flag); |
| 2531 | |
| 2532 | return 0; |
| 2533 | } |
| 2534 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2535 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2536 | struct net_device *netdev, u8 use_4addr, |
| 2537 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2538 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2539 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2540 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2541 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2542 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2543 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2544 | |
| 2545 | switch (iftype) { |
| 2546 | case NL80211_IFTYPE_AP_VLAN: |
| 2547 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2548 | return 0; |
| 2549 | break; |
| 2550 | case NL80211_IFTYPE_STATION: |
| 2551 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2552 | return 0; |
| 2553 | break; |
| 2554 | default: |
| 2555 | break; |
| 2556 | } |
| 2557 | |
| 2558 | return -EOPNOTSUPP; |
| 2559 | } |
| 2560 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2561 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2562 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2564 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2565 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2566 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2567 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2568 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2569 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2570 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2571 | memset(¶ms, 0, sizeof(params)); |
| 2572 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2573 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2574 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2575 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2576 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2577 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2578 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2579 | if (ntype > NL80211_IFTYPE_MAX) |
| 2580 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2581 | } |
| 2582 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2583 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2584 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2586 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2587 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2588 | if (netif_running(dev)) |
| 2589 | return -EBUSY; |
| 2590 | |
| 2591 | wdev_lock(wdev); |
| 2592 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2593 | IEEE80211_MAX_MESH_ID_LEN); |
| 2594 | wdev->mesh_id_up_len = |
| 2595 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2596 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2597 | wdev->mesh_id_up_len); |
| 2598 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2599 | } |
| 2600 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2601 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2602 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2603 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2604 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2605 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2606 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2607 | } else { |
| 2608 | params.use_4addr = -1; |
| 2609 | } |
| 2610 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2611 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2612 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2613 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2614 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2615 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2616 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2617 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2618 | |
| 2619 | flags = &_flags; |
| 2620 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2621 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2622 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2623 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2624 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2625 | return -EOPNOTSUPP; |
| 2626 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2627 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2628 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2629 | else |
| 2630 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2631 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2632 | if (!err && params.use_4addr != -1) |
| 2633 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2634 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2635 | return err; |
| 2636 | } |
| 2637 | |
| 2638 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2639 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2640 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2641 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2642 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2643 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2644 | int err; |
| 2645 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2646 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2647 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2648 | /* to avoid failing a new interface creation due to pending removal */ |
| 2649 | cfg80211_destroy_ifaces(rdev); |
| 2650 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2651 | memset(¶ms, 0, sizeof(params)); |
| 2652 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2653 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2654 | return -EINVAL; |
| 2655 | |
| 2656 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2657 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2658 | if (type > NL80211_IFTYPE_MAX) |
| 2659 | return -EINVAL; |
| 2660 | } |
| 2661 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2662 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2663 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2664 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2665 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2666 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2667 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2668 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2669 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2670 | ETH_ALEN); |
| 2671 | if (!is_valid_ether_addr(params.macaddr)) |
| 2672 | return -EADDRNOTAVAIL; |
| 2673 | } |
| 2674 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2675 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2676 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2677 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2678 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2679 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2680 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2681 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2682 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2683 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2684 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2685 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2686 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2687 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2688 | return -EOPNOTSUPP; |
| 2689 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2690 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2691 | if (!msg) |
| 2692 | return -ENOMEM; |
| 2693 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2694 | wdev = rdev_add_virtual_intf(rdev, |
| 2695 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2696 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2697 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2698 | if (WARN_ON(!wdev)) { |
| 2699 | nlmsg_free(msg); |
| 2700 | return -EPROTO; |
| 2701 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2702 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2703 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2704 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2705 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2706 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2707 | wdev->owner_nlportid = info->snd_portid; |
| 2708 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2709 | switch (type) { |
| 2710 | case NL80211_IFTYPE_MESH_POINT: |
| 2711 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2712 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2713 | wdev_lock(wdev); |
| 2714 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2715 | IEEE80211_MAX_MESH_ID_LEN); |
| 2716 | wdev->mesh_id_up_len = |
| 2717 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2718 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2719 | wdev->mesh_id_up_len); |
| 2720 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2721 | break; |
| 2722 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2723 | /* |
| 2724 | * P2P Device doesn't have a netdev, so doesn't go |
| 2725 | * through the netdev notifier and must be added here |
| 2726 | */ |
| 2727 | mutex_init(&wdev->mtx); |
| 2728 | INIT_LIST_HEAD(&wdev->event_list); |
| 2729 | spin_lock_init(&wdev->event_lock); |
| 2730 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2731 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2732 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2733 | wdev->identifier = ++rdev->wdev_id; |
| 2734 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2735 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2736 | break; |
| 2737 | default: |
| 2738 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2739 | } |
| 2740 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2741 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2742 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2743 | nlmsg_free(msg); |
| 2744 | return -ENOBUFS; |
| 2745 | } |
| 2746 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2747 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2748 | if (event) { |
| 2749 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2750 | rdev, wdev, false) < 0) { |
| 2751 | nlmsg_free(event); |
| 2752 | goto out; |
| 2753 | } |
| 2754 | |
| 2755 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2756 | event, 0, NL80211_MCGRP_CONFIG, |
| 2757 | GFP_KERNEL); |
| 2758 | } |
| 2759 | |
| 2760 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2761 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2765 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2767 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2768 | struct sk_buff *msg; |
| 2769 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2770 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2771 | if (!rdev->ops->del_virtual_intf) |
| 2772 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2773 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2775 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2776 | nlmsg_free(msg); |
| 2777 | msg = NULL; |
| 2778 | } |
| 2779 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2780 | /* |
| 2781 | * If we remove a wireless device without a netdev then clear |
| 2782 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2783 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2784 | * since the wdev has been freed, unlike with a netdev where |
| 2785 | * we need the dev_put() for the netdev to really be freed. |
| 2786 | */ |
| 2787 | if (!wdev->netdev) |
| 2788 | info->user_ptr[1] = NULL; |
| 2789 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2790 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2791 | if (status >= 0 && msg) |
| 2792 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2793 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2794 | GFP_KERNEL); |
| 2795 | else |
| 2796 | nlmsg_free(msg); |
| 2797 | |
| 2798 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2799 | } |
| 2800 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2801 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2802 | { |
| 2803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2804 | struct net_device *dev = info->user_ptr[1]; |
| 2805 | u16 noack_map; |
| 2806 | |
| 2807 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2808 | return -EINVAL; |
| 2809 | |
| 2810 | if (!rdev->ops->set_noack_map) |
| 2811 | return -EOPNOTSUPP; |
| 2812 | |
| 2813 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2814 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2815 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | struct get_key_cookie { |
| 2819 | struct sk_buff *msg; |
| 2820 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2821 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | }; |
| 2823 | |
| 2824 | static void get_key_callback(void *c, struct key_params *params) |
| 2825 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2826 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2827 | struct get_key_cookie *cookie = c; |
| 2828 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2829 | if ((params->key && |
| 2830 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2831 | params->key_len, params->key)) || |
| 2832 | (params->seq && |
| 2833 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2834 | params->seq_len, params->seq)) || |
| 2835 | (params->cipher && |
| 2836 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2837 | params->cipher))) |
| 2838 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2839 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2840 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2841 | if (!key) |
| 2842 | goto nla_put_failure; |
| 2843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2844 | if ((params->key && |
| 2845 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2846 | params->key_len, params->key)) || |
| 2847 | (params->seq && |
| 2848 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2849 | params->seq_len, params->seq)) || |
| 2850 | (params->cipher && |
| 2851 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2852 | params->cipher))) |
| 2853 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2854 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2855 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2856 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2857 | |
| 2858 | nla_nest_end(cookie->msg, key); |
| 2859 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2860 | return; |
| 2861 | nla_put_failure: |
| 2862 | cookie->error = 1; |
| 2863 | } |
| 2864 | |
| 2865 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2866 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2868 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2869 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2870 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2871 | const u8 *mac_addr = NULL; |
| 2872 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | struct get_key_cookie cookie = { |
| 2874 | .error = 0, |
| 2875 | }; |
| 2876 | void *hdr; |
| 2877 | struct sk_buff *msg; |
| 2878 | |
| 2879 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2880 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2881 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2882 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2883 | return -EINVAL; |
| 2884 | |
| 2885 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2886 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2887 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2888 | pairwise = !!mac_addr; |
| 2889 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2890 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2891 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2892 | return -EINVAL; |
| 2893 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2894 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2895 | return -EINVAL; |
| 2896 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2897 | } |
| 2898 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2899 | if (!rdev->ops->get_key) |
| 2900 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2901 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 2902 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2903 | return -ENOENT; |
| 2904 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2905 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2906 | if (!msg) |
| 2907 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2908 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2909 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2910 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2911 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2912 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2913 | |
| 2914 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2915 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2917 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2918 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2919 | goto nla_put_failure; |
| 2920 | if (mac_addr && |
| 2921 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2922 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2923 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2924 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2925 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2926 | |
| 2927 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2928 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | |
| 2930 | if (cookie.error) |
| 2931 | goto nla_put_failure; |
| 2932 | |
| 2933 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2934 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2935 | |
| 2936 | nla_put_failure: |
| 2937 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2938 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2939 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2940 | return err; |
| 2941 | } |
| 2942 | |
| 2943 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2944 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2946 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2947 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2948 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2949 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2950 | err = nl80211_parse_key(info, &key); |
| 2951 | if (err) |
| 2952 | return err; |
| 2953 | |
| 2954 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2955 | return -EINVAL; |
| 2956 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2957 | /* only support setting default key */ |
| 2958 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2959 | return -EINVAL; |
| 2960 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2961 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2962 | |
| 2963 | if (key.def) { |
| 2964 | if (!rdev->ops->set_default_key) { |
| 2965 | err = -EOPNOTSUPP; |
| 2966 | goto out; |
| 2967 | } |
| 2968 | |
| 2969 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2970 | if (err) |
| 2971 | goto out; |
| 2972 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2973 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2974 | key.def_uni, key.def_multi); |
| 2975 | |
| 2976 | if (err) |
| 2977 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2978 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2979 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2980 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2981 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2982 | } else { |
| 2983 | if (key.def_uni || !key.def_multi) { |
| 2984 | err = -EINVAL; |
| 2985 | goto out; |
| 2986 | } |
| 2987 | |
| 2988 | if (!rdev->ops->set_default_mgmt_key) { |
| 2989 | err = -EOPNOTSUPP; |
| 2990 | goto out; |
| 2991 | } |
| 2992 | |
| 2993 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2994 | if (err) |
| 2995 | goto out; |
| 2996 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2997 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2998 | if (err) |
| 2999 | goto out; |
| 3000 | |
| 3001 | #ifdef CONFIG_CFG80211_WEXT |
| 3002 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3003 | #endif |
| 3004 | } |
| 3005 | |
| 3006 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3007 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3008 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3009 | return err; |
| 3010 | } |
| 3011 | |
| 3012 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3013 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3015 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3017 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3018 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3019 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3020 | err = nl80211_parse_key(info, &key); |
| 3021 | if (err) |
| 3022 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3023 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3024 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3025 | return -EINVAL; |
| 3026 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3027 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3028 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3029 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3030 | if (key.type == -1) { |
| 3031 | if (mac_addr) |
| 3032 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3033 | else |
| 3034 | key.type = NL80211_KEYTYPE_GROUP; |
| 3035 | } |
| 3036 | |
| 3037 | /* for now */ |
| 3038 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3039 | key.type != NL80211_KEYTYPE_GROUP) |
| 3040 | return -EINVAL; |
| 3041 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3042 | if (!rdev->ops->add_key) |
| 3043 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3044 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3045 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3046 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3047 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3048 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3049 | |
| 3050 | wdev_lock(dev->ieee80211_ptr); |
| 3051 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3052 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3053 | err = rdev_add_key(rdev, dev, key.idx, |
| 3054 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3055 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3056 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3057 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3058 | return err; |
| 3059 | } |
| 3060 | |
| 3061 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3062 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3064 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3065 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3066 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3067 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3068 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3069 | err = nl80211_parse_key(info, &key); |
| 3070 | if (err) |
| 3071 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3072 | |
| 3073 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3074 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3075 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3076 | if (key.type == -1) { |
| 3077 | if (mac_addr) |
| 3078 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3079 | else |
| 3080 | key.type = NL80211_KEYTYPE_GROUP; |
| 3081 | } |
| 3082 | |
| 3083 | /* for now */ |
| 3084 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3085 | key.type != NL80211_KEYTYPE_GROUP) |
| 3086 | return -EINVAL; |
| 3087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3088 | if (!rdev->ops->del_key) |
| 3089 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3090 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3091 | wdev_lock(dev->ieee80211_ptr); |
| 3092 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3093 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3094 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3095 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3096 | err = -ENOENT; |
| 3097 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3098 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3099 | err = rdev_del_key(rdev, dev, key.idx, |
| 3100 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3101 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3102 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3103 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3104 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3105 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3106 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3107 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3108 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3109 | } |
| 3110 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3111 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3112 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3113 | return err; |
| 3114 | } |
| 3115 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3116 | /* This function returns an error or the number of nested attributes */ |
| 3117 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3118 | { |
| 3119 | struct nlattr *attr; |
| 3120 | int n_entries = 0, tmp; |
| 3121 | |
| 3122 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3123 | if (nla_len(attr) != ETH_ALEN) |
| 3124 | return -EINVAL; |
| 3125 | |
| 3126 | n_entries++; |
| 3127 | } |
| 3128 | |
| 3129 | return n_entries; |
| 3130 | } |
| 3131 | |
| 3132 | /* |
| 3133 | * This function parses ACL information and allocates memory for ACL data. |
| 3134 | * On successful return, the calling function is responsible to free the |
| 3135 | * ACL buffer returned by this function. |
| 3136 | */ |
| 3137 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3138 | struct genl_info *info) |
| 3139 | { |
| 3140 | enum nl80211_acl_policy acl_policy; |
| 3141 | struct nlattr *attr; |
| 3142 | struct cfg80211_acl_data *acl; |
| 3143 | int i = 0, n_entries, tmp; |
| 3144 | |
| 3145 | if (!wiphy->max_acl_mac_addrs) |
| 3146 | return ERR_PTR(-EOPNOTSUPP); |
| 3147 | |
| 3148 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3149 | return ERR_PTR(-EINVAL); |
| 3150 | |
| 3151 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3152 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3153 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3154 | return ERR_PTR(-EINVAL); |
| 3155 | |
| 3156 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3157 | return ERR_PTR(-EINVAL); |
| 3158 | |
| 3159 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3160 | if (n_entries < 0) |
| 3161 | return ERR_PTR(n_entries); |
| 3162 | |
| 3163 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3164 | return ERR_PTR(-ENOTSUPP); |
| 3165 | |
| 3166 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3167 | GFP_KERNEL); |
| 3168 | if (!acl) |
| 3169 | return ERR_PTR(-ENOMEM); |
| 3170 | |
| 3171 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3172 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3173 | i++; |
| 3174 | } |
| 3175 | |
| 3176 | acl->n_acl_entries = n_entries; |
| 3177 | acl->acl_policy = acl_policy; |
| 3178 | |
| 3179 | return acl; |
| 3180 | } |
| 3181 | |
| 3182 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3183 | { |
| 3184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3185 | struct net_device *dev = info->user_ptr[1]; |
| 3186 | struct cfg80211_acl_data *acl; |
| 3187 | int err; |
| 3188 | |
| 3189 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3190 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3191 | return -EOPNOTSUPP; |
| 3192 | |
| 3193 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3194 | return -EINVAL; |
| 3195 | |
| 3196 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3197 | if (IS_ERR(acl)) |
| 3198 | return PTR_ERR(acl); |
| 3199 | |
| 3200 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3201 | |
| 3202 | kfree(acl); |
| 3203 | |
| 3204 | return err; |
| 3205 | } |
| 3206 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3207 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3208 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3209 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3210 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3211 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3212 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3213 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3214 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3215 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3216 | return -EINVAL; |
| 3217 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3218 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3219 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3220 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3221 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3222 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3223 | if (!bcn->head_len) |
| 3224 | return -EINVAL; |
| 3225 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3226 | } |
| 3227 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3228 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3229 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3230 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3231 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3232 | } |
| 3233 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3234 | if (!haveinfo) |
| 3235 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3236 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3237 | if (attrs[NL80211_ATTR_IE]) { |
| 3238 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3239 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3240 | } |
| 3241 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3242 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3243 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3244 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3245 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3246 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3247 | } |
| 3248 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3249 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3250 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3251 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3252 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3253 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3254 | } |
| 3255 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3256 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3257 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3258 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3259 | } |
| 3260 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3261 | return 0; |
| 3262 | } |
| 3263 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3264 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3265 | struct cfg80211_ap_settings *params) |
| 3266 | { |
| 3267 | struct wireless_dev *wdev; |
| 3268 | bool ret = false; |
| 3269 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3270 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3271 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3272 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3273 | continue; |
| 3274 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3275 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3276 | continue; |
| 3277 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3278 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3279 | ret = true; |
| 3280 | break; |
| 3281 | } |
| 3282 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3283 | return ret; |
| 3284 | } |
| 3285 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3286 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3287 | enum nl80211_auth_type auth_type, |
| 3288 | enum nl80211_commands cmd) |
| 3289 | { |
| 3290 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3291 | return false; |
| 3292 | |
| 3293 | switch (cmd) { |
| 3294 | case NL80211_CMD_AUTHENTICATE: |
| 3295 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3296 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3297 | return false; |
| 3298 | return true; |
| 3299 | case NL80211_CMD_CONNECT: |
| 3300 | case NL80211_CMD_START_AP: |
| 3301 | /* SAE not supported yet */ |
| 3302 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3303 | return false; |
| 3304 | return true; |
| 3305 | default: |
| 3306 | return false; |
| 3307 | } |
| 3308 | } |
| 3309 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3310 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3311 | { |
| 3312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3313 | struct net_device *dev = info->user_ptr[1]; |
| 3314 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3315 | struct cfg80211_ap_settings params; |
| 3316 | int err; |
| 3317 | |
| 3318 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3319 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3320 | return -EOPNOTSUPP; |
| 3321 | |
| 3322 | if (!rdev->ops->start_ap) |
| 3323 | return -EOPNOTSUPP; |
| 3324 | |
| 3325 | if (wdev->beacon_interval) |
| 3326 | return -EALREADY; |
| 3327 | |
| 3328 | memset(¶ms, 0, sizeof(params)); |
| 3329 | |
| 3330 | /* these are required for START_AP */ |
| 3331 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3332 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3333 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3334 | return -EINVAL; |
| 3335 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3336 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3337 | if (err) |
| 3338 | return err; |
| 3339 | |
| 3340 | params.beacon_interval = |
| 3341 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3342 | params.dtim_period = |
| 3343 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3344 | |
| 3345 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3346 | if (err) |
| 3347 | return err; |
| 3348 | |
| 3349 | /* |
| 3350 | * In theory, some of these attributes should be required here |
| 3351 | * but since they were not used when the command was originally |
| 3352 | * added, keep them optional for old user space programs to let |
| 3353 | * them continue to work with drivers that do not need the |
| 3354 | * additional information -- drivers must check! |
| 3355 | */ |
| 3356 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3357 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3358 | params.ssid_len = |
| 3359 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3360 | if (params.ssid_len == 0 || |
| 3361 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3362 | return -EINVAL; |
| 3363 | } |
| 3364 | |
| 3365 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3366 | params.hidden_ssid = nla_get_u32( |
| 3367 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3368 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3369 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3370 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3371 | return -EINVAL; |
| 3372 | } |
| 3373 | |
| 3374 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3375 | |
| 3376 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3377 | params.auth_type = nla_get_u32( |
| 3378 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3379 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3380 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3381 | return -EINVAL; |
| 3382 | } else |
| 3383 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3384 | |
| 3385 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3386 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3387 | if (err) |
| 3388 | return err; |
| 3389 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3390 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3391 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3392 | return -EOPNOTSUPP; |
| 3393 | params.inactivity_timeout = nla_get_u16( |
| 3394 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3395 | } |
| 3396 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3397 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3398 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3399 | return -EINVAL; |
| 3400 | params.p2p_ctwindow = |
| 3401 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3402 | if (params.p2p_ctwindow > 127) |
| 3403 | return -EINVAL; |
| 3404 | if (params.p2p_ctwindow != 0 && |
| 3405 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3406 | return -EINVAL; |
| 3407 | } |
| 3408 | |
| 3409 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3410 | u8 tmp; |
| 3411 | |
| 3412 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3413 | return -EINVAL; |
| 3414 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3415 | if (tmp > 1) |
| 3416 | return -EINVAL; |
| 3417 | params.p2p_opp_ps = tmp; |
| 3418 | if (params.p2p_opp_ps != 0 && |
| 3419 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3420 | return -EINVAL; |
| 3421 | } |
| 3422 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3423 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3424 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3425 | if (err) |
| 3426 | return err; |
| 3427 | } else if (wdev->preset_chandef.chan) { |
| 3428 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3429 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3430 | return -EINVAL; |
| 3431 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3432 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3433 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3434 | return -EINVAL; |
| 3435 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3436 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3437 | params.smps_mode = |
| 3438 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3439 | switch (params.smps_mode) { |
| 3440 | case NL80211_SMPS_OFF: |
| 3441 | break; |
| 3442 | case NL80211_SMPS_STATIC: |
| 3443 | if (!(rdev->wiphy.features & |
| 3444 | NL80211_FEATURE_STATIC_SMPS)) |
| 3445 | return -EINVAL; |
| 3446 | break; |
| 3447 | case NL80211_SMPS_DYNAMIC: |
| 3448 | if (!(rdev->wiphy.features & |
| 3449 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3450 | return -EINVAL; |
| 3451 | break; |
| 3452 | default: |
| 3453 | return -EINVAL; |
| 3454 | } |
| 3455 | } else { |
| 3456 | params.smps_mode = NL80211_SMPS_OFF; |
| 3457 | } |
| 3458 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3459 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3460 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3461 | if (IS_ERR(params.acl)) |
| 3462 | return PTR_ERR(params.acl); |
| 3463 | } |
| 3464 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame^] | 3465 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3466 | if (params.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) |
| 3467 | return -EOPNOTSUPP; |
| 3468 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3469 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3470 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3471 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3472 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3473 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3474 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3475 | wdev->ssid_len = params.ssid_len; |
| 3476 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3477 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3478 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3479 | |
| 3480 | kfree(params.acl); |
| 3481 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3482 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3483 | } |
| 3484 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3485 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3486 | { |
| 3487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3488 | struct net_device *dev = info->user_ptr[1]; |
| 3489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3490 | struct cfg80211_beacon_data params; |
| 3491 | int err; |
| 3492 | |
| 3493 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3495 | return -EOPNOTSUPP; |
| 3496 | |
| 3497 | if (!rdev->ops->change_beacon) |
| 3498 | return -EOPNOTSUPP; |
| 3499 | |
| 3500 | if (!wdev->beacon_interval) |
| 3501 | return -EINVAL; |
| 3502 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3503 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3504 | if (err) |
| 3505 | return err; |
| 3506 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3507 | wdev_lock(wdev); |
| 3508 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3509 | wdev_unlock(wdev); |
| 3510 | |
| 3511 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | 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] | 3515 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3516 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3517 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3518 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3519 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3520 | } |
| 3521 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3522 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3523 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3524 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3525 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3526 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3527 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3528 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3529 | }; |
| 3530 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3531 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3532 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3533 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3534 | { |
| 3535 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3536 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3537 | int flag; |
| 3538 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3539 | /* |
| 3540 | * Try parsing the new attribute first so userspace |
| 3541 | * can specify both for older kernels. |
| 3542 | */ |
| 3543 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3544 | if (nla) { |
| 3545 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3546 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3547 | sta_flags = nla_data(nla); |
| 3548 | params->sta_flags_mask = sta_flags->mask; |
| 3549 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3550 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3551 | if ((params->sta_flags_mask | |
| 3552 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3553 | return -EINVAL; |
| 3554 | return 0; |
| 3555 | } |
| 3556 | |
| 3557 | /* if present, parse the old attribute */ |
| 3558 | |
| 3559 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3560 | if (!nla) |
| 3561 | return 0; |
| 3562 | |
| 3563 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3564 | nla, sta_flags_policy)) |
| 3565 | return -EINVAL; |
| 3566 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3567 | /* |
| 3568 | * Only allow certain flags for interface types so that |
| 3569 | * other attributes are silently ignored. Remember that |
| 3570 | * this is backward compatibility code with old userspace |
| 3571 | * and shouldn't be hit in other cases anyway. |
| 3572 | */ |
| 3573 | switch (iftype) { |
| 3574 | case NL80211_IFTYPE_AP: |
| 3575 | case NL80211_IFTYPE_AP_VLAN: |
| 3576 | case NL80211_IFTYPE_P2P_GO: |
| 3577 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3578 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3579 | BIT(NL80211_STA_FLAG_WME) | |
| 3580 | BIT(NL80211_STA_FLAG_MFP); |
| 3581 | break; |
| 3582 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3583 | case NL80211_IFTYPE_STATION: |
| 3584 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3585 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3586 | break; |
| 3587 | case NL80211_IFTYPE_MESH_POINT: |
| 3588 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3589 | BIT(NL80211_STA_FLAG_MFP) | |
| 3590 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3591 | default: |
| 3592 | return -EINVAL; |
| 3593 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3594 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3595 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3596 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3597 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3598 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3599 | /* no longer support new API additions in old API */ |
| 3600 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3601 | return -EINVAL; |
| 3602 | } |
| 3603 | } |
| 3604 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3605 | return 0; |
| 3606 | } |
| 3607 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3608 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3609 | int attr) |
| 3610 | { |
| 3611 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3612 | u32 bitrate; |
| 3613 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3614 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3615 | |
| 3616 | rate = nla_nest_start(msg, attr); |
| 3617 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3618 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3619 | |
| 3620 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3621 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3622 | /* report 16-bit bitrate only if we can */ |
| 3623 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3624 | if (bitrate > 0 && |
| 3625 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3626 | return false; |
| 3627 | if (bitrate_compat > 0 && |
| 3628 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3629 | return false; |
| 3630 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3631 | switch (info->bw) { |
| 3632 | case RATE_INFO_BW_5: |
| 3633 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3634 | break; |
| 3635 | case RATE_INFO_BW_10: |
| 3636 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3637 | break; |
| 3638 | default: |
| 3639 | WARN_ON(1); |
| 3640 | /* fall through */ |
| 3641 | case RATE_INFO_BW_20: |
| 3642 | rate_flg = 0; |
| 3643 | break; |
| 3644 | case RATE_INFO_BW_40: |
| 3645 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3646 | break; |
| 3647 | case RATE_INFO_BW_80: |
| 3648 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3649 | break; |
| 3650 | case RATE_INFO_BW_160: |
| 3651 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3652 | break; |
| 3653 | } |
| 3654 | |
| 3655 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3656 | return false; |
| 3657 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3658 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3659 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3660 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3661 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3662 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3663 | return false; |
| 3664 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3665 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3666 | return false; |
| 3667 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3668 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3669 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3670 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3671 | return false; |
| 3672 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3673 | |
| 3674 | nla_nest_end(msg, rate); |
| 3675 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3676 | } |
| 3677 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3678 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3679 | int id) |
| 3680 | { |
| 3681 | void *attr; |
| 3682 | int i = 0; |
| 3683 | |
| 3684 | if (!mask) |
| 3685 | return true; |
| 3686 | |
| 3687 | attr = nla_nest_start(msg, id); |
| 3688 | if (!attr) |
| 3689 | return false; |
| 3690 | |
| 3691 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3692 | if (!(mask & BIT(i))) |
| 3693 | continue; |
| 3694 | |
| 3695 | if (nla_put_u8(msg, i, signal[i])) |
| 3696 | return false; |
| 3697 | } |
| 3698 | |
| 3699 | nla_nest_end(msg, attr); |
| 3700 | |
| 3701 | return true; |
| 3702 | } |
| 3703 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3704 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3705 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3706 | struct cfg80211_registered_device *rdev, |
| 3707 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3708 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3709 | { |
| 3710 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3711 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3712 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3713 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3714 | if (!hdr) |
| 3715 | return -1; |
| 3716 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3717 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3718 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3719 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3720 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3721 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3722 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3723 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3724 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3725 | |
| 3726 | #define PUT_SINFO(attr, memb, type) do { \ |
| 3727 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ |
| 3728 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3729 | sinfo->memb)) \ |
| 3730 | goto nla_put_failure; \ |
| 3731 | } while (0) |
| 3732 | |
| 3733 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3734 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3735 | |
| 3736 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3737 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3738 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3739 | (u32)sinfo->rx_bytes)) |
| 3740 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3741 | |
| 3742 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3743 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3744 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3745 | (u32)sinfo->tx_bytes)) |
| 3746 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3747 | |
| 3748 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); |
| 3749 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); |
| 3750 | PUT_SINFO(LLID, llid, u16); |
| 3751 | PUT_SINFO(PLID, plid, u16); |
| 3752 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
| 3753 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3754 | switch (rdev->wiphy.signal_type) { |
| 3755 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3756 | PUT_SINFO(SIGNAL, signal, u8); |
| 3757 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3758 | break; |
| 3759 | default: |
| 3760 | break; |
| 3761 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3762 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3763 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3764 | sinfo->chain_signal, |
| 3765 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3766 | goto nla_put_failure; |
| 3767 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3768 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3769 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3770 | sinfo->chain_signal_avg, |
| 3771 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3772 | goto nla_put_failure; |
| 3773 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3774 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3775 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3776 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3777 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3778 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3779 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3780 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3781 | NL80211_STA_INFO_RX_BITRATE)) |
| 3782 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3783 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3784 | |
| 3785 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3786 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3787 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3788 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3789 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3790 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3791 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3792 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3793 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3794 | |
| 3795 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3796 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3797 | if (!bss_param) |
| 3798 | goto nla_put_failure; |
| 3799 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3800 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3801 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3802 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3803 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3804 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3805 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3806 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3807 | sinfo->bss_param.dtim_period) || |
| 3808 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3809 | sinfo->bss_param.beacon_interval)) |
| 3810 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3811 | |
| 3812 | nla_nest_end(msg, bss_param); |
| 3813 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3814 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3815 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3816 | sizeof(struct nl80211_sta_flag_update), |
| 3817 | &sinfo->sta_flags)) |
| 3818 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3819 | |
| 3820 | PUT_SINFO(T_OFFSET, t_offset, u64); |
| 3821 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3822 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
| 3823 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3824 | |
| 3825 | #undef PUT_SINFO |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3826 | |
| 3827 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3828 | struct nlattr *tidsattr; |
| 3829 | int tid; |
| 3830 | |
| 3831 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3832 | if (!tidsattr) |
| 3833 | goto nla_put_failure; |
| 3834 | |
| 3835 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3836 | struct cfg80211_tid_stats *tidstats; |
| 3837 | struct nlattr *tidattr; |
| 3838 | |
| 3839 | tidstats = &sinfo->pertid[tid]; |
| 3840 | |
| 3841 | if (!tidstats->filled) |
| 3842 | continue; |
| 3843 | |
| 3844 | tidattr = nla_nest_start(msg, tid + 1); |
| 3845 | if (!tidattr) |
| 3846 | goto nla_put_failure; |
| 3847 | |
| 3848 | #define PUT_TIDVAL(attr, memb, type) do { \ |
| 3849 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
| 3850 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ |
| 3851 | tidstats->memb)) \ |
| 3852 | goto nla_put_failure; \ |
| 3853 | } while (0) |
| 3854 | |
| 3855 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); |
| 3856 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); |
| 3857 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); |
| 3858 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); |
| 3859 | |
| 3860 | #undef PUT_TIDVAL |
| 3861 | nla_nest_end(msg, tidattr); |
| 3862 | } |
| 3863 | |
| 3864 | nla_nest_end(msg, tidsattr); |
| 3865 | } |
| 3866 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3867 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3868 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3869 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3870 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3871 | sinfo->assoc_req_ies)) |
| 3872 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3873 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3874 | genlmsg_end(msg, hdr); |
| 3875 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3876 | |
| 3877 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3878 | genlmsg_cancel(msg, hdr); |
| 3879 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3880 | } |
| 3881 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3882 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3883 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3884 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3885 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3886 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3887 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3888 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3889 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3890 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3891 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3892 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3893 | if (err) |
| 3894 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3895 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3896 | if (!wdev->netdev) { |
| 3897 | err = -EINVAL; |
| 3898 | goto out_err; |
| 3899 | } |
| 3900 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3901 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3902 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3903 | goto out_err; |
| 3904 | } |
| 3905 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3906 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3907 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3908 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3909 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3910 | if (err == -ENOENT) |
| 3911 | break; |
| 3912 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3913 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3914 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3915 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3916 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3917 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3918 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3919 | &sinfo) < 0) |
| 3920 | goto out; |
| 3921 | |
| 3922 | sta_idx++; |
| 3923 | } |
| 3924 | |
| 3925 | |
| 3926 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3927 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3928 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3929 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3930 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3931 | |
| 3932 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3933 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3934 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3935 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3936 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3938 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3939 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3940 | struct sk_buff *msg; |
| 3941 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3942 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3943 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3944 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3945 | |
| 3946 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3947 | return -EINVAL; |
| 3948 | |
| 3949 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3950 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3951 | if (!rdev->ops->get_station) |
| 3952 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3953 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3954 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3955 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3956 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3957 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3959 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3960 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3961 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3962 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 3963 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3964 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3965 | nlmsg_free(msg); |
| 3966 | return -ENOBUFS; |
| 3967 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3969 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3970 | } |
| 3971 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3972 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3973 | struct station_parameters *params, |
| 3974 | enum cfg80211_station_type statype) |
| 3975 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3976 | if (params->listen_interval != -1 && |
| 3977 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3978 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3979 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3980 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3981 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 3982 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3983 | return -EINVAL; |
| 3984 | |
| 3985 | /* When you run into this, adjust the code below for the new flag */ |
| 3986 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3987 | |
| 3988 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3989 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3990 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3991 | /* |
| 3992 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3993 | * code doesn't have the bug of including TDLS in the |
| 3994 | * mask everywhere. |
| 3995 | */ |
| 3996 | if (params->sta_flags_mask & |
| 3997 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3998 | BIT(NL80211_STA_FLAG_MFP) | |
| 3999 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4000 | return -EINVAL; |
| 4001 | break; |
| 4002 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4003 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4004 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4005 | return -EINVAL; |
| 4006 | /* ignore since it can't change */ |
| 4007 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4008 | break; |
| 4009 | default: |
| 4010 | /* disallow mesh-specific things */ |
| 4011 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4012 | return -EINVAL; |
| 4013 | if (params->local_pm) |
| 4014 | return -EINVAL; |
| 4015 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4016 | return -EINVAL; |
| 4017 | } |
| 4018 | |
| 4019 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4020 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4021 | /* TDLS can't be set, ... */ |
| 4022 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4023 | return -EINVAL; |
| 4024 | /* |
| 4025 | * ... but don't bother the driver with it. This works around |
| 4026 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4027 | * TLDS_PEER flag in the mask even for AP mode. |
| 4028 | */ |
| 4029 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4030 | } |
| 4031 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4032 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4033 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4034 | /* reject other things that can't change */ |
| 4035 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4036 | return -EINVAL; |
| 4037 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4038 | return -EINVAL; |
| 4039 | if (params->supported_rates) |
| 4040 | return -EINVAL; |
| 4041 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4042 | return -EINVAL; |
| 4043 | } |
| 4044 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4045 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4046 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4047 | if (params->vlan) |
| 4048 | return -EINVAL; |
| 4049 | } |
| 4050 | |
| 4051 | switch (statype) { |
| 4052 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4053 | /* Use this only for authorizing/unauthorizing a station */ |
| 4054 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4055 | return -EOPNOTSUPP; |
| 4056 | break; |
| 4057 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4058 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4059 | /* accept only the listed bits */ |
| 4060 | if (params->sta_flags_mask & |
| 4061 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4062 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4063 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4064 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4065 | BIT(NL80211_STA_FLAG_WME) | |
| 4066 | BIT(NL80211_STA_FLAG_MFP))) |
| 4067 | return -EINVAL; |
| 4068 | |
| 4069 | /* but authenticated/associated only if driver handles it */ |
| 4070 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4071 | params->sta_flags_mask & |
| 4072 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4073 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4074 | return -EINVAL; |
| 4075 | break; |
| 4076 | case CFG80211_STA_IBSS: |
| 4077 | case CFG80211_STA_AP_STA: |
| 4078 | /* reject any changes other than AUTHORIZED */ |
| 4079 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4080 | return -EINVAL; |
| 4081 | break; |
| 4082 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4083 | /* reject any changes other than AUTHORIZED or WME */ |
| 4084 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4085 | BIT(NL80211_STA_FLAG_WME))) |
| 4086 | return -EINVAL; |
| 4087 | /* force (at least) rates when authorizing */ |
| 4088 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4089 | !params->supported_rates) |
| 4090 | return -EINVAL; |
| 4091 | break; |
| 4092 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4093 | /* reject any changes */ |
| 4094 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4095 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4096 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4097 | return -EINVAL; |
| 4098 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4099 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4100 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4101 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4102 | return -EINVAL; |
| 4103 | break; |
| 4104 | } |
| 4105 | |
| 4106 | return 0; |
| 4107 | } |
| 4108 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4109 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4110 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4111 | * 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] | 4112 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4113 | static struct net_device *get_vlan(struct genl_info *info, |
| 4114 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4115 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4116 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4117 | struct net_device *v; |
| 4118 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4119 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4120 | if (!vlanattr) |
| 4121 | return NULL; |
| 4122 | |
| 4123 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4124 | if (!v) |
| 4125 | return ERR_PTR(-ENODEV); |
| 4126 | |
| 4127 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4128 | ret = -EINVAL; |
| 4129 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4130 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4131 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4132 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4133 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4134 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4135 | ret = -EINVAL; |
| 4136 | goto error; |
| 4137 | } |
| 4138 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4139 | if (!netif_running(v)) { |
| 4140 | ret = -ENETDOWN; |
| 4141 | goto error; |
| 4142 | } |
| 4143 | |
| 4144 | return v; |
| 4145 | error: |
| 4146 | dev_put(v); |
| 4147 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4148 | } |
| 4149 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4150 | static const struct nla_policy |
| 4151 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4152 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4153 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4154 | }; |
| 4155 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4156 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4157 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4158 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4159 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4160 | struct nlattr *nla; |
| 4161 | int err; |
| 4162 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4163 | /* parse WME attributes if present */ |
| 4164 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4165 | return 0; |
| 4166 | |
| 4167 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4168 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4169 | nl80211_sta_wme_policy); |
| 4170 | if (err) |
| 4171 | return err; |
| 4172 | |
| 4173 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4174 | params->uapsd_queues = nla_get_u8( |
| 4175 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4176 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4177 | return -EINVAL; |
| 4178 | |
| 4179 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4180 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4181 | |
| 4182 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4183 | return -EINVAL; |
| 4184 | |
| 4185 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4186 | |
| 4187 | return 0; |
| 4188 | } |
| 4189 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4190 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4191 | struct station_parameters *params) |
| 4192 | { |
| 4193 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4194 | params->supported_channels = |
| 4195 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4196 | params->supported_channels_len = |
| 4197 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4198 | /* |
| 4199 | * Need to include at least one (first channel, number of |
| 4200 | * channels) tuple for each subband, and must have proper |
| 4201 | * tuples for the rest of the data as well. |
| 4202 | */ |
| 4203 | if (params->supported_channels_len < 2) |
| 4204 | return -EINVAL; |
| 4205 | if (params->supported_channels_len % 2) |
| 4206 | return -EINVAL; |
| 4207 | } |
| 4208 | |
| 4209 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4210 | params->supported_oper_classes = |
| 4211 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4212 | params->supported_oper_classes_len = |
| 4213 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4214 | /* |
| 4215 | * The value of the Length field of the Supported Operating |
| 4216 | * Classes element is between 2 and 253. |
| 4217 | */ |
| 4218 | if (params->supported_oper_classes_len < 2 || |
| 4219 | params->supported_oper_classes_len > 253) |
| 4220 | return -EINVAL; |
| 4221 | } |
| 4222 | return 0; |
| 4223 | } |
| 4224 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4225 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4226 | struct station_parameters *params) |
| 4227 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4228 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4229 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4230 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4231 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4232 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4233 | params->ht_capa = |
| 4234 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4235 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4236 | params->vht_capa = |
| 4237 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4238 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4239 | err = nl80211_parse_sta_channel_info(info, params); |
| 4240 | if (err) |
| 4241 | return err; |
| 4242 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4243 | return nl80211_parse_sta_wme(info, params); |
| 4244 | } |
| 4245 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4246 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4247 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4250 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4251 | u8 *mac_addr; |
| 4252 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4253 | |
| 4254 | memset(¶ms, 0, sizeof(params)); |
| 4255 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4256 | if (!rdev->ops->change_station) |
| 4257 | return -EOPNOTSUPP; |
| 4258 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4259 | /* |
| 4260 | * AID and listen_interval properties can be set only for unassociated |
| 4261 | * station. Include these parameters here and will check them in |
| 4262 | * cfg80211_check_station_change(). |
| 4263 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4264 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4265 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4266 | |
| 4267 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4268 | params.listen_interval = |
| 4269 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4270 | else |
| 4271 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4272 | |
| 4273 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4274 | return -EINVAL; |
| 4275 | |
| 4276 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4277 | |
| 4278 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4279 | params.supported_rates = |
| 4280 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4281 | params.supported_rates_len = |
| 4282 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4283 | } |
| 4284 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4285 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4286 | params.capability = |
| 4287 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4288 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4289 | } |
| 4290 | |
| 4291 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4292 | params.ext_capab = |
| 4293 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4294 | params.ext_capab_len = |
| 4295 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4296 | } |
| 4297 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4298 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4299 | return -EINVAL; |
| 4300 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4301 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4302 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4303 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4304 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4305 | return -EINVAL; |
| 4306 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4307 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4308 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4309 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4310 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4311 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4312 | return -EINVAL; |
| 4313 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4314 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4315 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4316 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4317 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4318 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4319 | |
| 4320 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4321 | pm > NL80211_MESH_POWER_MAX) |
| 4322 | return -EINVAL; |
| 4323 | |
| 4324 | params.local_pm = pm; |
| 4325 | } |
| 4326 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4327 | /* Include parameters for TDLS peer (will check later) */ |
| 4328 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4329 | if (err) |
| 4330 | return err; |
| 4331 | |
| 4332 | params.vlan = get_vlan(info, rdev); |
| 4333 | if (IS_ERR(params.vlan)) |
| 4334 | return PTR_ERR(params.vlan); |
| 4335 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4336 | switch (dev->ieee80211_ptr->iftype) { |
| 4337 | case NL80211_IFTYPE_AP: |
| 4338 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4339 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4340 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4341 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4342 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4343 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4344 | break; |
| 4345 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4346 | err = -EOPNOTSUPP; |
| 4347 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4348 | } |
| 4349 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4350 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4351 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4352 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4353 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4354 | if (params.vlan) |
| 4355 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4356 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4357 | return err; |
| 4358 | } |
| 4359 | |
| 4360 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4363 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4364 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4365 | struct station_parameters params; |
| 4366 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4367 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4368 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4369 | |
| 4370 | memset(¶ms, 0, sizeof(params)); |
| 4371 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4372 | if (!rdev->ops->add_station) |
| 4373 | return -EOPNOTSUPP; |
| 4374 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4375 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4376 | return -EINVAL; |
| 4377 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4378 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4379 | return -EINVAL; |
| 4380 | |
| 4381 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4382 | return -EINVAL; |
| 4383 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4384 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4385 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4386 | return -EINVAL; |
| 4387 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4388 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4389 | params.supported_rates = |
| 4390 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4391 | params.supported_rates_len = |
| 4392 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4393 | params.listen_interval = |
| 4394 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4395 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4396 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4397 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4398 | else |
| 4399 | 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] | 4400 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4401 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4402 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4403 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4404 | params.capability = |
| 4405 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4406 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4407 | } |
| 4408 | |
| 4409 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4410 | params.ext_capab = |
| 4411 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4412 | params.ext_capab_len = |
| 4413 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4414 | } |
| 4415 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4416 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4417 | params.ht_capa = |
| 4418 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4419 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4420 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4421 | params.vht_capa = |
| 4422 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4423 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4424 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4425 | params.opmode_notif_used = true; |
| 4426 | params.opmode_notif = |
| 4427 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4428 | } |
| 4429 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4430 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4431 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4432 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4433 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4434 | return -EINVAL; |
| 4435 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4436 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4437 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4438 | if (err) |
| 4439 | return err; |
| 4440 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4441 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4442 | if (err) |
| 4443 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4444 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4445 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4446 | return -EINVAL; |
| 4447 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4448 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4449 | * as userspace might just pass through the capabilities from the IEs |
| 4450 | * directly, rather than enforcing this restriction and returning an |
| 4451 | * error in this case. |
| 4452 | */ |
| 4453 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4454 | params.ht_capa = NULL; |
| 4455 | params.vht_capa = NULL; |
| 4456 | } |
| 4457 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4458 | /* When you run into this, adjust the code below for the new flag */ |
| 4459 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4460 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4461 | switch (dev->ieee80211_ptr->iftype) { |
| 4462 | case NL80211_IFTYPE_AP: |
| 4463 | case NL80211_IFTYPE_AP_VLAN: |
| 4464 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4465 | /* ignore WME attributes if iface/sta is not capable */ |
| 4466 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4467 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4468 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4469 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4470 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4471 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4472 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4473 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4474 | /* but don't bother the driver with it */ |
| 4475 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4476 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4477 | /* allow authenticated/associated only if driver handles it */ |
| 4478 | if (!(rdev->wiphy.features & |
| 4479 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4480 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4481 | return -EINVAL; |
| 4482 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4483 | /* Older userspace, or userspace wanting to be compatible with |
| 4484 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 4485 | * and assoc flags in the mask, but assumes the station will be |
| 4486 | * added as associated anyway since this was the required driver |
| 4487 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 4488 | * introduced. |
| 4489 | * In order to not bother drivers with this quirk in the API |
| 4490 | * set the flags in both the mask and set for new stations in |
| 4491 | * this case. |
| 4492 | */ |
| 4493 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 4494 | params.sta_flags_mask |= auth_assoc; |
| 4495 | params.sta_flags_set |= auth_assoc; |
| 4496 | } |
| 4497 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4498 | /* must be last in here for error handling */ |
| 4499 | params.vlan = get_vlan(info, rdev); |
| 4500 | if (IS_ERR(params.vlan)) |
| 4501 | return PTR_ERR(params.vlan); |
| 4502 | break; |
| 4503 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4504 | /* ignore uAPSD data */ |
| 4505 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4506 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4507 | /* associated is disallowed */ |
| 4508 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4509 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4510 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4511 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4512 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4513 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4514 | break; |
| 4515 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4516 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4517 | /* ignore uAPSD data */ |
| 4518 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4519 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4520 | /* these are disallowed */ |
| 4521 | if (params.sta_flags_mask & |
| 4522 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4523 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4524 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4525 | /* Only TDLS peers can be added */ |
| 4526 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4527 | return -EINVAL; |
| 4528 | /* Can only add if TDLS ... */ |
| 4529 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4530 | return -EOPNOTSUPP; |
| 4531 | /* ... with external setup is supported */ |
| 4532 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4533 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4534 | /* |
| 4535 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4536 | * as authorized, but it shouldn't yet be. |
| 4537 | */ |
| 4538 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4539 | break; |
| 4540 | default: |
| 4541 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4542 | } |
| 4543 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4544 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4545 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4546 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4547 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4548 | if (params.vlan) |
| 4549 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4550 | return err; |
| 4551 | } |
| 4552 | |
| 4553 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4554 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4556 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4557 | struct station_del_parameters params; |
| 4558 | |
| 4559 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4560 | |
| 4561 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4562 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4563 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4564 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4565 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4566 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4567 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4568 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | if (!rdev->ops->del_station) |
| 4571 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4572 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4573 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4574 | params.subtype = |
| 4575 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4576 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4577 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4578 | return -EINVAL; |
| 4579 | } else { |
| 4580 | /* Default to Deauthentication frame */ |
| 4581 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4582 | } |
| 4583 | |
| 4584 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4585 | params.reason_code = |
| 4586 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4587 | if (params.reason_code == 0) |
| 4588 | return -EINVAL; /* 0 is reserved */ |
| 4589 | } else { |
| 4590 | /* Default to reason code 2 */ |
| 4591 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4592 | } |
| 4593 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4594 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4595 | } |
| 4596 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4597 | 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] | 4598 | int flags, struct net_device *dev, |
| 4599 | u8 *dst, u8 *next_hop, |
| 4600 | struct mpath_info *pinfo) |
| 4601 | { |
| 4602 | void *hdr; |
| 4603 | struct nlattr *pinfoattr; |
| 4604 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4605 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4606 | if (!hdr) |
| 4607 | return -1; |
| 4608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4609 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4610 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4611 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4612 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4613 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4614 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4615 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4616 | if (!pinfoattr) |
| 4617 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4618 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4619 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4620 | pinfo->frame_qlen)) |
| 4621 | goto nla_put_failure; |
| 4622 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4623 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4624 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4625 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4626 | pinfo->metric)) || |
| 4627 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4628 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4629 | pinfo->exptime)) || |
| 4630 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4631 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4632 | pinfo->flags)) || |
| 4633 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4634 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4635 | pinfo->discovery_timeout)) || |
| 4636 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4637 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4638 | pinfo->discovery_retries))) |
| 4639 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4640 | |
| 4641 | nla_nest_end(msg, pinfoattr); |
| 4642 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4643 | genlmsg_end(msg, hdr); |
| 4644 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4645 | |
| 4646 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4647 | genlmsg_cancel(msg, hdr); |
| 4648 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4652 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4653 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4654 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4655 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4656 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4657 | u8 dst[ETH_ALEN]; |
| 4658 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4659 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4660 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4661 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4662 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4663 | if (err) |
| 4664 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4665 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4666 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4667 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4668 | goto out_err; |
| 4669 | } |
| 4670 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4671 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4672 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4673 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4674 | } |
| 4675 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4676 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4677 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4678 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4679 | if (err == -ENOENT) |
| 4680 | break; |
| 4681 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4682 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4683 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4684 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4685 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4686 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4687 | &pinfo) < 0) |
| 4688 | goto out; |
| 4689 | |
| 4690 | path_idx++; |
| 4691 | } |
| 4692 | |
| 4693 | |
| 4694 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4695 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4696 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4697 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4698 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4699 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4703 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4705 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4706 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4707 | struct mpath_info pinfo; |
| 4708 | struct sk_buff *msg; |
| 4709 | u8 *dst = NULL; |
| 4710 | u8 next_hop[ETH_ALEN]; |
| 4711 | |
| 4712 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4713 | |
| 4714 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4715 | return -EINVAL; |
| 4716 | |
| 4717 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | if (!rdev->ops->get_mpath) |
| 4720 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4722 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4723 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4724 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4725 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4726 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4727 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4728 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4730 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4731 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4732 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4733 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4734 | dev, dst, next_hop, &pinfo) < 0) { |
| 4735 | nlmsg_free(msg); |
| 4736 | return -ENOBUFS; |
| 4737 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4738 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4739 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4743 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4745 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4746 | u8 *dst = NULL; |
| 4747 | u8 *next_hop = NULL; |
| 4748 | |
| 4749 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4750 | return -EINVAL; |
| 4751 | |
| 4752 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4753 | return -EINVAL; |
| 4754 | |
| 4755 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4756 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4758 | if (!rdev->ops->change_mpath) |
| 4759 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4762 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4763 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4764 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4765 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4767 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4768 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4770 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4771 | u8 *dst = NULL; |
| 4772 | u8 *next_hop = NULL; |
| 4773 | |
| 4774 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4775 | return -EINVAL; |
| 4776 | |
| 4777 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4778 | return -EINVAL; |
| 4779 | |
| 4780 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4781 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4782 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4783 | if (!rdev->ops->add_mpath) |
| 4784 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4786 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4787 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4788 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4789 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4795 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4796 | u8 *dst = NULL; |
| 4797 | |
| 4798 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4799 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4800 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4801 | if (!rdev->ops->del_mpath) |
| 4802 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4803 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4804 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4807 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4808 | { |
| 4809 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4810 | int err; |
| 4811 | struct net_device *dev = info->user_ptr[1]; |
| 4812 | struct mpath_info pinfo; |
| 4813 | struct sk_buff *msg; |
| 4814 | u8 *dst = NULL; |
| 4815 | u8 mpp[ETH_ALEN]; |
| 4816 | |
| 4817 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4818 | |
| 4819 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4820 | return -EINVAL; |
| 4821 | |
| 4822 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4823 | |
| 4824 | if (!rdev->ops->get_mpp) |
| 4825 | return -EOPNOTSUPP; |
| 4826 | |
| 4827 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4828 | return -EOPNOTSUPP; |
| 4829 | |
| 4830 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4831 | if (err) |
| 4832 | return err; |
| 4833 | |
| 4834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4835 | if (!msg) |
| 4836 | return -ENOMEM; |
| 4837 | |
| 4838 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4839 | dev, dst, mpp, &pinfo) < 0) { |
| 4840 | nlmsg_free(msg); |
| 4841 | return -ENOBUFS; |
| 4842 | } |
| 4843 | |
| 4844 | return genlmsg_reply(msg, info); |
| 4845 | } |
| 4846 | |
| 4847 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4848 | struct netlink_callback *cb) |
| 4849 | { |
| 4850 | struct mpath_info pinfo; |
| 4851 | struct cfg80211_registered_device *rdev; |
| 4852 | struct wireless_dev *wdev; |
| 4853 | u8 dst[ETH_ALEN]; |
| 4854 | u8 mpp[ETH_ALEN]; |
| 4855 | int path_idx = cb->args[2]; |
| 4856 | int err; |
| 4857 | |
| 4858 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4859 | if (err) |
| 4860 | return err; |
| 4861 | |
| 4862 | if (!rdev->ops->dump_mpp) { |
| 4863 | err = -EOPNOTSUPP; |
| 4864 | goto out_err; |
| 4865 | } |
| 4866 | |
| 4867 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4868 | err = -EOPNOTSUPP; |
| 4869 | goto out_err; |
| 4870 | } |
| 4871 | |
| 4872 | while (1) { |
| 4873 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4874 | mpp, &pinfo); |
| 4875 | if (err == -ENOENT) |
| 4876 | break; |
| 4877 | if (err) |
| 4878 | goto out_err; |
| 4879 | |
| 4880 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4881 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4882 | wdev->netdev, dst, mpp, |
| 4883 | &pinfo) < 0) |
| 4884 | goto out; |
| 4885 | |
| 4886 | path_idx++; |
| 4887 | } |
| 4888 | |
| 4889 | out: |
| 4890 | cb->args[2] = path_idx; |
| 4891 | err = skb->len; |
| 4892 | out_err: |
| 4893 | nl80211_finish_wdev_dump(rdev); |
| 4894 | return err; |
| 4895 | } |
| 4896 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4897 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4898 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4899 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4900 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4901 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4902 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4903 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4904 | |
| 4905 | memset(¶ms, 0, sizeof(params)); |
| 4906 | /* default to not changing parameters */ |
| 4907 | params.use_cts_prot = -1; |
| 4908 | params.use_short_preamble = -1; |
| 4909 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4910 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4911 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4912 | params.p2p_ctwindow = -1; |
| 4913 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4914 | |
| 4915 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4916 | params.use_cts_prot = |
| 4917 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4918 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4919 | params.use_short_preamble = |
| 4920 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4921 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4922 | params.use_short_slot_time = |
| 4923 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4924 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4925 | params.basic_rates = |
| 4926 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4927 | params.basic_rates_len = |
| 4928 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4929 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4930 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4931 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4932 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4933 | params.ht_opmode = |
| 4934 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4935 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4936 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4937 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4938 | return -EINVAL; |
| 4939 | params.p2p_ctwindow = |
| 4940 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4941 | if (params.p2p_ctwindow < 0) |
| 4942 | return -EINVAL; |
| 4943 | if (params.p2p_ctwindow != 0 && |
| 4944 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4945 | return -EINVAL; |
| 4946 | } |
| 4947 | |
| 4948 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4949 | u8 tmp; |
| 4950 | |
| 4951 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4952 | return -EINVAL; |
| 4953 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4954 | if (tmp > 1) |
| 4955 | return -EINVAL; |
| 4956 | params.p2p_opp_ps = tmp; |
| 4957 | if (params.p2p_opp_ps && |
| 4958 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4959 | return -EINVAL; |
| 4960 | } |
| 4961 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4962 | if (!rdev->ops->change_bss) |
| 4963 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4964 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4965 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4967 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4968 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4969 | wdev_lock(wdev); |
| 4970 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4971 | wdev_unlock(wdev); |
| 4972 | |
| 4973 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4974 | } |
| 4975 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4976 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4977 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4978 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4979 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4980 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4981 | u32 owner_nlportid; |
| 4982 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4983 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4984 | /* |
| 4985 | * You should only get this when cfg80211 hasn't yet initialized |
| 4986 | * completely when built-in to the kernel right between the time |
| 4987 | * window between nl80211_init() and regulatory_init(), if that is |
| 4988 | * even possible. |
| 4989 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4990 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4991 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4992 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4993 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4994 | user_reg_hint_type = |
| 4995 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4996 | else |
| 4997 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4998 | |
| 4999 | switch (user_reg_hint_type) { |
| 5000 | case NL80211_USER_REG_HINT_USER: |
| 5001 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5002 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5003 | return -EINVAL; |
| 5004 | |
| 5005 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5006 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5007 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5008 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5009 | owner_nlportid = info->snd_portid; |
| 5010 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5011 | } else { |
| 5012 | owner_nlportid = 0; |
| 5013 | is_indoor = true; |
| 5014 | } |
| 5015 | |
| 5016 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5017 | default: |
| 5018 | return -EINVAL; |
| 5019 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5022 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5023 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5024 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5026 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5027 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5028 | struct mesh_config cur_params; |
| 5029 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5030 | void *hdr; |
| 5031 | struct nlattr *pinfoattr; |
| 5032 | struct sk_buff *msg; |
| 5033 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5034 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5035 | return -EOPNOTSUPP; |
| 5036 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5037 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5038 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5039 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5040 | wdev_lock(wdev); |
| 5041 | /* If not connected, get default parameters */ |
| 5042 | if (!wdev->mesh_id_len) |
| 5043 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5044 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5045 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5046 | wdev_unlock(wdev); |
| 5047 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5048 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5049 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5050 | |
| 5051 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5053 | if (!msg) |
| 5054 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5055 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5056 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5057 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5058 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5059 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5060 | if (!pinfoattr) |
| 5061 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5062 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5063 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5064 | cur_params.dot11MeshRetryTimeout) || |
| 5065 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5066 | cur_params.dot11MeshConfirmTimeout) || |
| 5067 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5068 | cur_params.dot11MeshHoldingTimeout) || |
| 5069 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5070 | cur_params.dot11MeshMaxPeerLinks) || |
| 5071 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5072 | cur_params.dot11MeshMaxRetries) || |
| 5073 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5074 | cur_params.dot11MeshTTL) || |
| 5075 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5076 | cur_params.element_ttl) || |
| 5077 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5078 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5079 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5080 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5081 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5082 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5083 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5084 | cur_params.path_refresh_time) || |
| 5085 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5086 | cur_params.min_discovery_timeout) || |
| 5087 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5088 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5089 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5090 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5091 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5092 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5093 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5094 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5095 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5096 | cur_params.dot11MeshHWMPRootMode) || |
| 5097 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5098 | cur_params.dot11MeshHWMPRannInterval) || |
| 5099 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5100 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5101 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5102 | cur_params.dot11MeshForwarding) || |
| 5103 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5104 | cur_params.rssi_threshold) || |
| 5105 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5106 | cur_params.ht_opmode) || |
| 5107 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5108 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5109 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5110 | cur_params.dot11MeshHWMProotInterval) || |
| 5111 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5112 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5113 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5114 | cur_params.power_mode) || |
| 5115 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5116 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5117 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5118 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5119 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5120 | nla_nest_end(msg, pinfoattr); |
| 5121 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5122 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5123 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5124 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5125 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5126 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5127 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5128 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5131 | 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] | 5132 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5133 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5134 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5135 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5136 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5137 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5138 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5139 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5140 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5141 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5142 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5143 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5144 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5145 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5146 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5147 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5148 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5149 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5150 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5151 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5152 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5153 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5154 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5155 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5156 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5157 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5158 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5159 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5160 | }; |
| 5161 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5162 | static const struct nla_policy |
| 5163 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5164 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5165 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5166 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5167 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5168 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5169 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5170 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5171 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5172 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5173 | }; |
| 5174 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5175 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5176 | struct mesh_config *cfg, |
| 5177 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5178 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5179 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5180 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5181 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5182 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5183 | do { \ |
| 5184 | if (tb[attr]) { \ |
| 5185 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5186 | return -EINVAL; \ |
| 5187 | cfg->param = fn(tb[attr]); \ |
| 5188 | mask |= (1 << (attr - 1)); \ |
| 5189 | } \ |
| 5190 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5191 | |
| 5192 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5193 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5194 | return -EINVAL; |
| 5195 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5196 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5197 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5198 | return -EINVAL; |
| 5199 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5200 | /* This makes sure that there aren't more than 32 mesh config |
| 5201 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5202 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5203 | |
| 5204 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5205 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5206 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5207 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5209 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5210 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5211 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5212 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5213 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5214 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5215 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5216 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5217 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5218 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5219 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5221 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5222 | 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] | 5223 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5224 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5225 | 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] | 5226 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5227 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5229 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5230 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5231 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5233 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5234 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5235 | 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] | 5236 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5237 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5238 | 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] | 5239 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5240 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5242 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5243 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5244 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5245 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5246 | 1, 65535, mask, |
| 5247 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5248 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5249 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5250 | 1, 65535, mask, |
| 5251 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5252 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5253 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5254 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5255 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5256 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5257 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5258 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5259 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5260 | nla_get_u8); |
| 5261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5262 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5263 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5265 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5266 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5267 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5268 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5269 | mask, NL80211_MESHCONF_FORWARDING, |
| 5270 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5271 | 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] | 5272 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5273 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5275 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5276 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5278 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5279 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5280 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5282 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5283 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5284 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5285 | dot11MeshHWMPconfirmationInterval, |
| 5286 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5287 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5288 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5289 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5290 | NL80211_MESH_POWER_ACTIVE, |
| 5291 | NL80211_MESH_POWER_MAX, |
| 5292 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5293 | nla_get_u32); |
| 5294 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5295 | 0, 65535, mask, |
| 5296 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5297 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5298 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5299 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5300 | if (mask_out) |
| 5301 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5302 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5303 | return 0; |
| 5304 | |
| 5305 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5306 | } |
| 5307 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5308 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5309 | struct mesh_setup *setup) |
| 5310 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5312 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5313 | |
| 5314 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5315 | return -EINVAL; |
| 5316 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5317 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5318 | nl80211_mesh_setup_params_policy)) |
| 5319 | return -EINVAL; |
| 5320 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5321 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5322 | setup->sync_method = |
| 5323 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5324 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5325 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5326 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5327 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5328 | setup->path_sel_proto = |
| 5329 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5330 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5331 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5332 | |
| 5333 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5334 | setup->path_metric = |
| 5335 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5336 | IEEE80211_PATH_METRIC_VENDOR : |
| 5337 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5338 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5339 | |
| 5340 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5341 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5342 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5343 | if (!is_valid_ie_attr(ieattr)) |
| 5344 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5345 | setup->ie = nla_data(ieattr); |
| 5346 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5347 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5348 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5349 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5350 | return -EINVAL; |
| 5351 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5352 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5353 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5354 | if (setup->is_secure) |
| 5355 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5356 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5357 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5358 | if (!setup->user_mpm) |
| 5359 | return -EINVAL; |
| 5360 | setup->auth_id = |
| 5361 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5362 | } |
| 5363 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5364 | return 0; |
| 5365 | } |
| 5366 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5367 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5368 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5369 | { |
| 5370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5373 | struct mesh_config cfg; |
| 5374 | u32 mask; |
| 5375 | int err; |
| 5376 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5377 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5378 | return -EOPNOTSUPP; |
| 5379 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5380 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5381 | return -EOPNOTSUPP; |
| 5382 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5383 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5384 | if (err) |
| 5385 | return err; |
| 5386 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5387 | wdev_lock(wdev); |
| 5388 | if (!wdev->mesh_id_len) |
| 5389 | err = -ENOLINK; |
| 5390 | |
| 5391 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5392 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5393 | |
| 5394 | wdev_unlock(wdev); |
| 5395 | |
| 5396 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5399 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5400 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5401 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5402 | struct nlattr *nl_reg_rules; |
| 5403 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5404 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5405 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5406 | (regdom->dfs_region && |
| 5407 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5408 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5409 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5410 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5411 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5412 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5413 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5414 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5415 | struct nlattr *nl_reg_rule; |
| 5416 | const struct ieee80211_reg_rule *reg_rule; |
| 5417 | const struct ieee80211_freq_range *freq_range; |
| 5418 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5419 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5420 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5421 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5422 | freq_range = ®_rule->freq_range; |
| 5423 | power_rule = ®_rule->power_rule; |
| 5424 | |
| 5425 | nl_reg_rule = nla_nest_start(msg, i); |
| 5426 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5427 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5428 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5429 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5430 | if (!max_bandwidth_khz) |
| 5431 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5432 | reg_rule); |
| 5433 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5434 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5435 | reg_rule->flags) || |
| 5436 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5437 | freq_range->start_freq_khz) || |
| 5438 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5439 | freq_range->end_freq_khz) || |
| 5440 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5441 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5442 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5443 | power_rule->max_antenna_gain) || |
| 5444 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5445 | power_rule->max_eirp) || |
| 5446 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5447 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5448 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5449 | |
| 5450 | nla_nest_end(msg, nl_reg_rule); |
| 5451 | } |
| 5452 | |
| 5453 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5454 | return 0; |
| 5455 | |
| 5456 | nla_put_failure: |
| 5457 | return -EMSGSIZE; |
| 5458 | } |
| 5459 | |
| 5460 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5461 | { |
| 5462 | const struct ieee80211_regdomain *regdom = NULL; |
| 5463 | struct cfg80211_registered_device *rdev; |
| 5464 | struct wiphy *wiphy = NULL; |
| 5465 | struct sk_buff *msg; |
| 5466 | void *hdr; |
| 5467 | |
| 5468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5469 | if (!msg) |
| 5470 | return -ENOBUFS; |
| 5471 | |
| 5472 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5473 | NL80211_CMD_GET_REG); |
| 5474 | if (!hdr) |
| 5475 | goto put_failure; |
| 5476 | |
| 5477 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5478 | bool self_managed; |
| 5479 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5480 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5481 | if (IS_ERR(rdev)) { |
| 5482 | nlmsg_free(msg); |
| 5483 | return PTR_ERR(rdev); |
| 5484 | } |
| 5485 | |
| 5486 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5487 | self_managed = wiphy->regulatory_flags & |
| 5488 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5489 | regdom = get_wiphy_regdom(wiphy); |
| 5490 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5491 | /* a self-managed-reg device must have a private regdom */ |
| 5492 | if (WARN_ON(!regdom && self_managed)) { |
| 5493 | nlmsg_free(msg); |
| 5494 | return -EINVAL; |
| 5495 | } |
| 5496 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5497 | if (regdom && |
| 5498 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5499 | goto nla_put_failure; |
| 5500 | } |
| 5501 | |
| 5502 | if (!wiphy && reg_last_request_cell_base() && |
| 5503 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5504 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5505 | goto nla_put_failure; |
| 5506 | |
| 5507 | rcu_read_lock(); |
| 5508 | |
| 5509 | if (!regdom) |
| 5510 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5511 | |
| 5512 | if (nl80211_put_regdom(regdom, msg)) |
| 5513 | goto nla_put_failure_rcu; |
| 5514 | |
| 5515 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5516 | |
| 5517 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5518 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5519 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5520 | nla_put_failure_rcu: |
| 5521 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5522 | nla_put_failure: |
| 5523 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5524 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5525 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5526 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5527 | } |
| 5528 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5529 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5530 | u32 seq, int flags, struct wiphy *wiphy, |
| 5531 | const struct ieee80211_regdomain *regdom) |
| 5532 | { |
| 5533 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5534 | NL80211_CMD_GET_REG); |
| 5535 | |
| 5536 | if (!hdr) |
| 5537 | return -1; |
| 5538 | |
| 5539 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5540 | |
| 5541 | if (nl80211_put_regdom(regdom, msg)) |
| 5542 | goto nla_put_failure; |
| 5543 | |
| 5544 | if (!wiphy && reg_last_request_cell_base() && |
| 5545 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5546 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5547 | goto nla_put_failure; |
| 5548 | |
| 5549 | if (wiphy && |
| 5550 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5551 | goto nla_put_failure; |
| 5552 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5553 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5554 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5555 | goto nla_put_failure; |
| 5556 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5557 | genlmsg_end(msg, hdr); |
| 5558 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5559 | |
| 5560 | nla_put_failure: |
| 5561 | genlmsg_cancel(msg, hdr); |
| 5562 | return -EMSGSIZE; |
| 5563 | } |
| 5564 | |
| 5565 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5566 | struct netlink_callback *cb) |
| 5567 | { |
| 5568 | const struct ieee80211_regdomain *regdom = NULL; |
| 5569 | struct cfg80211_registered_device *rdev; |
| 5570 | int err, reg_idx, start = cb->args[2]; |
| 5571 | |
| 5572 | rtnl_lock(); |
| 5573 | |
| 5574 | if (cfg80211_regdomain && start == 0) { |
| 5575 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5576 | NLM_F_MULTI, NULL, |
| 5577 | rtnl_dereference(cfg80211_regdomain)); |
| 5578 | if (err < 0) |
| 5579 | goto out_err; |
| 5580 | } |
| 5581 | |
| 5582 | /* the global regdom is idx 0 */ |
| 5583 | reg_idx = 1; |
| 5584 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5585 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5586 | if (!regdom) |
| 5587 | continue; |
| 5588 | |
| 5589 | if (++reg_idx <= start) |
| 5590 | continue; |
| 5591 | |
| 5592 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5593 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5594 | if (err < 0) { |
| 5595 | reg_idx--; |
| 5596 | break; |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | cb->args[2] = reg_idx; |
| 5601 | err = skb->len; |
| 5602 | out_err: |
| 5603 | rtnl_unlock(); |
| 5604 | return err; |
| 5605 | } |
| 5606 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5607 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 5608 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 5609 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5610 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5611 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5612 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5613 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5614 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5615 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 5616 | }; |
| 5617 | |
| 5618 | static int parse_reg_rule(struct nlattr *tb[], |
| 5619 | struct ieee80211_reg_rule *reg_rule) |
| 5620 | { |
| 5621 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 5622 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 5623 | |
| 5624 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 5625 | return -EINVAL; |
| 5626 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 5627 | return -EINVAL; |
| 5628 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 5629 | return -EINVAL; |
| 5630 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 5631 | return -EINVAL; |
| 5632 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 5633 | return -EINVAL; |
| 5634 | |
| 5635 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 5636 | |
| 5637 | freq_range->start_freq_khz = |
| 5638 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 5639 | freq_range->end_freq_khz = |
| 5640 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 5641 | freq_range->max_bandwidth_khz = |
| 5642 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 5643 | |
| 5644 | power_rule->max_eirp = |
| 5645 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 5646 | |
| 5647 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 5648 | power_rule->max_antenna_gain = |
| 5649 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 5650 | |
| 5651 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 5652 | reg_rule->dfs_cac_ms = |
| 5653 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 5654 | |
| 5655 | return 0; |
| 5656 | } |
| 5657 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5658 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5659 | { |
| 5660 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5661 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5662 | char *alpha2; |
| 5663 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5664 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5665 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5666 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5667 | |
| 5668 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5669 | return -EINVAL; |
| 5670 | |
| 5671 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5672 | return -EINVAL; |
| 5673 | |
| 5674 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5675 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5676 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5677 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5678 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5679 | 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] | 5680 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5681 | num_rules++; |
| 5682 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5683 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5686 | if (!reg_is_valid_request(alpha2)) |
| 5687 | return -EINVAL; |
| 5688 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5689 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5690 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5691 | |
| 5692 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5693 | if (!rd) |
| 5694 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5695 | |
| 5696 | rd->n_reg_rules = num_rules; |
| 5697 | rd->alpha2[0] = alpha2[0]; |
| 5698 | rd->alpha2[1] = alpha2[1]; |
| 5699 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5700 | /* |
| 5701 | * Disable DFS master mode if the DFS region was |
| 5702 | * not supported or known on this kernel. |
| 5703 | */ |
| 5704 | if (reg_supported_dfs_region(dfs_region)) |
| 5705 | rd->dfs_region = dfs_region; |
| 5706 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5707 | 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] | 5708 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5709 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5710 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5711 | reg_rule_policy); |
| 5712 | if (r) |
| 5713 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5714 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5715 | if (r) |
| 5716 | goto bad_reg; |
| 5717 | |
| 5718 | rule_idx++; |
| 5719 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5720 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5721 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5722 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5723 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 5726 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5727 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5728 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5729 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5730 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5731 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5732 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5733 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5734 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5735 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5736 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5737 | { |
| 5738 | struct nlattr *attr1, *attr2; |
| 5739 | int n_channels = 0, tmp1, tmp2; |
| 5740 | |
| 5741 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5742 | n_channels++; |
| 5743 | /* |
| 5744 | * Some hardware has a limited channel list for |
| 5745 | * scanning, and it is pretty much nonsensical |
| 5746 | * to scan for a channel twice, so disallow that |
| 5747 | * and don't require drivers to check that the |
| 5748 | * channel list they get isn't longer than what |
| 5749 | * they can scan, as long as they can scan all |
| 5750 | * the channels they registered at once. |
| 5751 | */ |
| 5752 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5753 | if (attr1 != attr2 && |
| 5754 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5755 | return 0; |
| 5756 | } |
| 5757 | |
| 5758 | return n_channels; |
| 5759 | } |
| 5760 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5761 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5762 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5763 | { |
| 5764 | int i; |
| 5765 | |
| 5766 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 5767 | eth_zero_addr(mac_addr); |
| 5768 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5769 | mac_addr[0] = 0x2; |
| 5770 | mac_addr_mask[0] = 0x3; |
| 5771 | |
| 5772 | return 0; |
| 5773 | } |
| 5774 | |
| 5775 | /* need both or none */ |
| 5776 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5777 | return -EINVAL; |
| 5778 | |
| 5779 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5780 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5781 | |
| 5782 | /* don't allow or configure an mcast address */ |
| 5783 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5784 | is_multicast_ether_addr(mac_addr)) |
| 5785 | return -EINVAL; |
| 5786 | |
| 5787 | /* |
| 5788 | * allow users to pass a MAC address that has bits set outside |
| 5789 | * of the mask, but don't bother drivers with having to deal |
| 5790 | * with such bits |
| 5791 | */ |
| 5792 | for (i = 0; i < ETH_ALEN; i++) |
| 5793 | mac_addr[i] &= mac_addr_mask[i]; |
| 5794 | |
| 5795 | return 0; |
| 5796 | } |
| 5797 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5798 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5799 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5801 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5803 | struct nlattr *attr; |
| 5804 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5805 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5806 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5807 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5808 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5809 | return -EINVAL; |
| 5810 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5811 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5812 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5813 | if (!rdev->ops->scan) |
| 5814 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5815 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5816 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5817 | err = -EBUSY; |
| 5818 | goto unlock; |
| 5819 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5820 | |
| 5821 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5822 | n_channels = validate_scan_freqs( |
| 5823 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5824 | if (!n_channels) { |
| 5825 | err = -EINVAL; |
| 5826 | goto unlock; |
| 5827 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5828 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5829 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5833 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5834 | n_ssids++; |
| 5835 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5836 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5837 | err = -EINVAL; |
| 5838 | goto unlock; |
| 5839 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5840 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5841 | if (info->attrs[NL80211_ATTR_IE]) |
| 5842 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5843 | else |
| 5844 | ie_len = 0; |
| 5845 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5846 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5847 | err = -EINVAL; |
| 5848 | goto unlock; |
| 5849 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5850 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5851 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5852 | + sizeof(*request->ssids) * n_ssids |
| 5853 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5854 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5855 | if (!request) { |
| 5856 | err = -ENOMEM; |
| 5857 | goto unlock; |
| 5858 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5859 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5860 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5861 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5863 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5864 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5865 | request->ie = (void *)(request->ssids + n_ssids); |
| 5866 | else |
| 5867 | request->ie = (void *)(request->channels + n_channels); |
| 5868 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5869 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5870 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5871 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5872 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5873 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5874 | struct ieee80211_channel *chan; |
| 5875 | |
| 5876 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5877 | |
| 5878 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5879 | err = -EINVAL; |
| 5880 | goto out_free; |
| 5881 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5882 | |
| 5883 | /* ignore disabled channels */ |
| 5884 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5885 | continue; |
| 5886 | |
| 5887 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5888 | i++; |
| 5889 | } |
| 5890 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5891 | enum ieee80211_band band; |
| 5892 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5893 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5894 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5895 | int j; |
| 5896 | if (!wiphy->bands[band]) |
| 5897 | continue; |
| 5898 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5899 | struct ieee80211_channel *chan; |
| 5900 | |
| 5901 | chan = &wiphy->bands[band]->channels[j]; |
| 5902 | |
| 5903 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5904 | continue; |
| 5905 | |
| 5906 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5907 | i++; |
| 5908 | } |
| 5909 | } |
| 5910 | } |
| 5911 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5912 | if (!i) { |
| 5913 | err = -EINVAL; |
| 5914 | goto out_free; |
| 5915 | } |
| 5916 | |
| 5917 | request->n_channels = i; |
| 5918 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5919 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5920 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5921 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5922 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5923 | err = -EINVAL; |
| 5924 | goto out_free; |
| 5925 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5926 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5927 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5928 | i++; |
| 5929 | } |
| 5930 | } |
| 5931 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5932 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5933 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5934 | memcpy((void *)request->ie, |
| 5935 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5936 | request->ie_len); |
| 5937 | } |
| 5938 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5939 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5940 | if (wiphy->bands[i]) |
| 5941 | request->rates[i] = |
| 5942 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5943 | |
| 5944 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5945 | nla_for_each_nested(attr, |
| 5946 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5947 | tmp) { |
| 5948 | enum ieee80211_band band = nla_type(attr); |
| 5949 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5950 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5951 | err = -EINVAL; |
| 5952 | goto out_free; |
| 5953 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5954 | |
| 5955 | if (!wiphy->bands[band]) |
| 5956 | continue; |
| 5957 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5958 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5959 | nla_data(attr), |
| 5960 | nla_len(attr), |
| 5961 | &request->rates[band]); |
| 5962 | if (err) |
| 5963 | goto out_free; |
| 5964 | } |
| 5965 | } |
| 5966 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5967 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5968 | request->flags = nla_get_u32( |
| 5969 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5970 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5971 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5972 | err = -EOPNOTSUPP; |
| 5973 | goto out_free; |
| 5974 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5975 | |
| 5976 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5977 | if (!(wiphy->features & |
| 5978 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5979 | err = -EOPNOTSUPP; |
| 5980 | goto out_free; |
| 5981 | } |
| 5982 | |
| 5983 | if (wdev->current_bss) { |
| 5984 | err = -EOPNOTSUPP; |
| 5985 | goto out_free; |
| 5986 | } |
| 5987 | |
| 5988 | err = nl80211_parse_random_mac(info->attrs, |
| 5989 | request->mac_addr, |
| 5990 | request->mac_addr_mask); |
| 5991 | if (err) |
| 5992 | goto out_free; |
| 5993 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5994 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5995 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5996 | request->no_cck = |
| 5997 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5998 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5999 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6000 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6001 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6002 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6003 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6004 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6005 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6006 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6007 | nl80211_send_scan_start(rdev, wdev); |
| 6008 | if (wdev->netdev) |
| 6009 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6010 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6011 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6012 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6013 | kfree(request); |
| 6014 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6015 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6016 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6017 | return err; |
| 6018 | } |
| 6019 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6020 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6021 | { |
| 6022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6023 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6024 | |
| 6025 | if (!rdev->ops->abort_scan) |
| 6026 | return -EOPNOTSUPP; |
| 6027 | |
| 6028 | if (rdev->scan_msg) |
| 6029 | return 0; |
| 6030 | |
| 6031 | if (!rdev->scan_req) |
| 6032 | return -ENOENT; |
| 6033 | |
| 6034 | rdev_abort_scan(rdev, wdev); |
| 6035 | return 0; |
| 6036 | } |
| 6037 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6038 | static int |
| 6039 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6040 | struct cfg80211_sched_scan_request *request, |
| 6041 | struct nlattr **attrs) |
| 6042 | { |
| 6043 | int tmp, err, i = 0; |
| 6044 | struct nlattr *attr; |
| 6045 | |
| 6046 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6047 | u32 interval; |
| 6048 | |
| 6049 | /* |
| 6050 | * If scan plans are not specified, |
| 6051 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6052 | * case one scan plan will be set with the specified scan |
| 6053 | * interval and infinite number of iterations. |
| 6054 | */ |
| 6055 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6056 | return -EINVAL; |
| 6057 | |
| 6058 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6059 | if (!interval) |
| 6060 | return -EINVAL; |
| 6061 | |
| 6062 | request->scan_plans[0].interval = |
| 6063 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6064 | if (!request->scan_plans[0].interval) |
| 6065 | return -EINVAL; |
| 6066 | |
| 6067 | if (request->scan_plans[0].interval > |
| 6068 | wiphy->max_sched_scan_plan_interval) |
| 6069 | request->scan_plans[0].interval = |
| 6070 | wiphy->max_sched_scan_plan_interval; |
| 6071 | |
| 6072 | return 0; |
| 6073 | } |
| 6074 | |
| 6075 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6076 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6077 | |
| 6078 | if (WARN_ON(i >= n_plans)) |
| 6079 | return -EINVAL; |
| 6080 | |
| 6081 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6082 | nla_data(attr), nla_len(attr), |
| 6083 | nl80211_plan_policy); |
| 6084 | if (err) |
| 6085 | return err; |
| 6086 | |
| 6087 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6088 | return -EINVAL; |
| 6089 | |
| 6090 | request->scan_plans[i].interval = |
| 6091 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6092 | if (!request->scan_plans[i].interval || |
| 6093 | request->scan_plans[i].interval > |
| 6094 | wiphy->max_sched_scan_plan_interval) |
| 6095 | return -EINVAL; |
| 6096 | |
| 6097 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6098 | request->scan_plans[i].iterations = |
| 6099 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6100 | if (!request->scan_plans[i].iterations || |
| 6101 | (request->scan_plans[i].iterations > |
| 6102 | wiphy->max_sched_scan_plan_iterations)) |
| 6103 | return -EINVAL; |
| 6104 | } else if (i < n_plans - 1) { |
| 6105 | /* |
| 6106 | * All scan plans but the last one must specify |
| 6107 | * a finite number of iterations |
| 6108 | */ |
| 6109 | return -EINVAL; |
| 6110 | } |
| 6111 | |
| 6112 | i++; |
| 6113 | } |
| 6114 | |
| 6115 | /* |
| 6116 | * The last scan plan must not specify the number of |
| 6117 | * iterations, it is supposed to run infinitely |
| 6118 | */ |
| 6119 | if (request->scan_plans[n_plans - 1].iterations) |
| 6120 | return -EINVAL; |
| 6121 | |
| 6122 | return 0; |
| 6123 | } |
| 6124 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6125 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6126 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6127 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6128 | { |
| 6129 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6130 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6131 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6132 | enum ieee80211_band band; |
| 6133 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6134 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6135 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6136 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6137 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6138 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6139 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6140 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6141 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6142 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6143 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6144 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6145 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6146 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6147 | } |
| 6148 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6149 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6150 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6151 | tmp) |
| 6152 | n_ssids++; |
| 6153 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6154 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6155 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6156 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6157 | /* |
| 6158 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6159 | * the old implementation, matchsets containing only the RSSI attribute |
| 6160 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6161 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6162 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6163 | * older userspace that treated a matchset with only the RSSI as the |
| 6164 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6165 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6166 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6167 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6168 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6169 | tmp) { |
| 6170 | struct nlattr *rssi; |
| 6171 | |
| 6172 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6173 | nla_data(attr), nla_len(attr), |
| 6174 | nl80211_match_policy); |
| 6175 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6176 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6177 | /* add other standalone attributes here */ |
| 6178 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6179 | n_match_sets++; |
| 6180 | continue; |
| 6181 | } |
| 6182 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6183 | if (rssi) |
| 6184 | default_match_rssi = nla_get_s32(rssi); |
| 6185 | } |
| 6186 | } |
| 6187 | |
| 6188 | /* However, if there's no other matchset, add the RSSI one */ |
| 6189 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6190 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6191 | |
| 6192 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6193 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6194 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6195 | if (attrs[NL80211_ATTR_IE]) |
| 6196 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6197 | else |
| 6198 | ie_len = 0; |
| 6199 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6200 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6201 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6202 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6203 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6204 | /* |
| 6205 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6206 | * each scan plan already specifies its own interval |
| 6207 | */ |
| 6208 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6209 | return ERR_PTR(-EINVAL); |
| 6210 | |
| 6211 | nla_for_each_nested(attr, |
| 6212 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6213 | n_plans++; |
| 6214 | } else { |
| 6215 | /* |
| 6216 | * The scan interval attribute is kept for backward |
| 6217 | * compatibility. If no scan plans are specified and sched scan |
| 6218 | * interval is specified, one scan plan will be set with this |
| 6219 | * scan interval and infinite number of iterations. |
| 6220 | */ |
| 6221 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6222 | return ERR_PTR(-EINVAL); |
| 6223 | |
| 6224 | n_plans = 1; |
| 6225 | } |
| 6226 | |
| 6227 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6228 | return ERR_PTR(-EINVAL); |
| 6229 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6230 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6231 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6232 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6233 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6234 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6235 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6236 | if (!request) |
| 6237 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6238 | |
| 6239 | if (n_ssids) |
| 6240 | request->ssids = (void *)&request->channels[n_channels]; |
| 6241 | request->n_ssids = n_ssids; |
| 6242 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6243 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6244 | request->ie = (void *)(request->ssids + n_ssids); |
| 6245 | else |
| 6246 | request->ie = (void *)(request->channels + n_channels); |
| 6247 | } |
| 6248 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6249 | if (n_match_sets) { |
| 6250 | if (request->ie) |
| 6251 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6252 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6253 | request->match_sets = |
| 6254 | (void *)(request->ssids + n_ssids); |
| 6255 | else |
| 6256 | request->match_sets = |
| 6257 | (void *)(request->channels + n_channels); |
| 6258 | } |
| 6259 | request->n_match_sets = n_match_sets; |
| 6260 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6261 | if (n_match_sets) |
| 6262 | request->scan_plans = (void *)(request->match_sets + |
| 6263 | n_match_sets); |
| 6264 | else if (request->ie) |
| 6265 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6266 | else if (n_ssids) |
| 6267 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6268 | else |
| 6269 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6270 | |
| 6271 | request->n_scan_plans = n_plans; |
| 6272 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6273 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6274 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6275 | /* user specified, bail out if channel not found */ |
| 6276 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6277 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6278 | tmp) { |
| 6279 | struct ieee80211_channel *chan; |
| 6280 | |
| 6281 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6282 | |
| 6283 | if (!chan) { |
| 6284 | err = -EINVAL; |
| 6285 | goto out_free; |
| 6286 | } |
| 6287 | |
| 6288 | /* ignore disabled channels */ |
| 6289 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6290 | continue; |
| 6291 | |
| 6292 | request->channels[i] = chan; |
| 6293 | i++; |
| 6294 | } |
| 6295 | } else { |
| 6296 | /* all channels */ |
| 6297 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6298 | int j; |
| 6299 | if (!wiphy->bands[band]) |
| 6300 | continue; |
| 6301 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6302 | struct ieee80211_channel *chan; |
| 6303 | |
| 6304 | chan = &wiphy->bands[band]->channels[j]; |
| 6305 | |
| 6306 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6307 | continue; |
| 6308 | |
| 6309 | request->channels[i] = chan; |
| 6310 | i++; |
| 6311 | } |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | if (!i) { |
| 6316 | err = -EINVAL; |
| 6317 | goto out_free; |
| 6318 | } |
| 6319 | |
| 6320 | request->n_channels = i; |
| 6321 | |
| 6322 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6323 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6324 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6325 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6326 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6327 | err = -EINVAL; |
| 6328 | goto out_free; |
| 6329 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6330 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6331 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6332 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6333 | i++; |
| 6334 | } |
| 6335 | } |
| 6336 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6337 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6338 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6339 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6340 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6341 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6342 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6343 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6344 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6345 | nla_data(attr), nla_len(attr), |
| 6346 | nl80211_match_policy); |
| 6347 | if (err) |
| 6348 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6349 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6350 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6351 | if (WARN_ON(i >= n_match_sets)) { |
| 6352 | /* this indicates a programming error, |
| 6353 | * the loop above should have verified |
| 6354 | * things properly |
| 6355 | */ |
| 6356 | err = -EINVAL; |
| 6357 | goto out_free; |
| 6358 | } |
| 6359 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6360 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6361 | err = -EINVAL; |
| 6362 | goto out_free; |
| 6363 | } |
| 6364 | memcpy(request->match_sets[i].ssid.ssid, |
| 6365 | nla_data(ssid), nla_len(ssid)); |
| 6366 | request->match_sets[i].ssid.ssid_len = |
| 6367 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6368 | /* special attribute - old implemenation w/a */ |
| 6369 | request->match_sets[i].rssi_thold = |
| 6370 | default_match_rssi; |
| 6371 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6372 | if (rssi) |
| 6373 | request->match_sets[i].rssi_thold = |
| 6374 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6375 | } |
| 6376 | i++; |
| 6377 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6378 | |
| 6379 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6380 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6381 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6382 | |
| 6383 | request->min_rssi_thold = INT_MAX; |
| 6384 | for (i = 0; i < n_match_sets; i++) |
| 6385 | request->min_rssi_thold = |
| 6386 | min(request->match_sets[i].rssi_thold, |
| 6387 | request->min_rssi_thold); |
| 6388 | } else { |
| 6389 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6390 | } |
| 6391 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6392 | if (ie_len) { |
| 6393 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6394 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6395 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6396 | request->ie_len); |
| 6397 | } |
| 6398 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6399 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6400 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6401 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6402 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6403 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6404 | err = -EOPNOTSUPP; |
| 6405 | goto out_free; |
| 6406 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6407 | |
| 6408 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6409 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6410 | |
| 6411 | if (!wdev) /* must be net-detect */ |
| 6412 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6413 | |
| 6414 | if (!(wiphy->features & flg)) { |
| 6415 | err = -EOPNOTSUPP; |
| 6416 | goto out_free; |
| 6417 | } |
| 6418 | |
| 6419 | if (wdev && wdev->current_bss) { |
| 6420 | err = -EOPNOTSUPP; |
| 6421 | goto out_free; |
| 6422 | } |
| 6423 | |
| 6424 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6425 | request->mac_addr_mask); |
| 6426 | if (err) |
| 6427 | goto out_free; |
| 6428 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6429 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6430 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6431 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6432 | request->delay = |
| 6433 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6434 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6435 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 6436 | if (err) |
| 6437 | goto out_free; |
| 6438 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6439 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6440 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6441 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6442 | |
| 6443 | out_free: |
| 6444 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6445 | return ERR_PTR(err); |
| 6446 | } |
| 6447 | |
| 6448 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6449 | struct genl_info *info) |
| 6450 | { |
| 6451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6452 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6453 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6454 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6455 | int err; |
| 6456 | |
| 6457 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6458 | !rdev->ops->sched_scan_start) |
| 6459 | return -EOPNOTSUPP; |
| 6460 | |
| 6461 | if (rdev->sched_scan_req) |
| 6462 | return -EINPROGRESS; |
| 6463 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6464 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6465 | info->attrs); |
| 6466 | |
| 6467 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6468 | if (err) |
| 6469 | goto out_err; |
| 6470 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6471 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6472 | if (err) |
| 6473 | goto out_free; |
| 6474 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6475 | sched_scan_req->dev = dev; |
| 6476 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6477 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6478 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6479 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6480 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6481 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6482 | |
| 6483 | nl80211_send_sched_scan(rdev, dev, |
| 6484 | NL80211_CMD_START_SCHED_SCAN); |
| 6485 | return 0; |
| 6486 | |
| 6487 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6488 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6489 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6490 | return err; |
| 6491 | } |
| 6492 | |
| 6493 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6494 | struct genl_info *info) |
| 6495 | { |
| 6496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6497 | |
| 6498 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6499 | !rdev->ops->sched_scan_stop) |
| 6500 | return -EOPNOTSUPP; |
| 6501 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6502 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6503 | } |
| 6504 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6505 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6506 | struct genl_info *info) |
| 6507 | { |
| 6508 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6509 | struct net_device *dev = info->user_ptr[1]; |
| 6510 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6511 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6512 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6513 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6514 | int err; |
| 6515 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6516 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6517 | if (dfs_region == NL80211_DFS_UNSET) |
| 6518 | return -EINVAL; |
| 6519 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6520 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6521 | if (err) |
| 6522 | return err; |
| 6523 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6524 | if (netif_carrier_ok(dev)) |
| 6525 | return -EBUSY; |
| 6526 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6527 | if (wdev->cac_started) |
| 6528 | return -EBUSY; |
| 6529 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6530 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6531 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6532 | if (err < 0) |
| 6533 | return err; |
| 6534 | |
| 6535 | if (err == 0) |
| 6536 | return -EINVAL; |
| 6537 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6538 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6539 | return -EINVAL; |
| 6540 | |
| 6541 | if (!rdev->ops->start_radar_detection) |
| 6542 | return -EOPNOTSUPP; |
| 6543 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6544 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6545 | if (WARN_ON(!cac_time_ms)) |
| 6546 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6547 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 6548 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6549 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6550 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6551 | wdev->cac_started = true; |
| 6552 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6553 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6554 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6555 | return err; |
| 6556 | } |
| 6557 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6558 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6559 | { |
| 6560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6561 | struct net_device *dev = info->user_ptr[1]; |
| 6562 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6563 | struct cfg80211_csa_settings params; |
| 6564 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6565 | * function is called under RTNL lock, so this should not be a problem. |
| 6566 | */ |
| 6567 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6568 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6569 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6570 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6571 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6572 | |
| 6573 | if (!rdev->ops->channel_switch || |
| 6574 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6575 | return -EOPNOTSUPP; |
| 6576 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6577 | switch (dev->ieee80211_ptr->iftype) { |
| 6578 | case NL80211_IFTYPE_AP: |
| 6579 | case NL80211_IFTYPE_P2P_GO: |
| 6580 | need_new_beacon = true; |
| 6581 | |
| 6582 | /* useless if AP is not running */ |
| 6583 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6584 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6585 | break; |
| 6586 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6587 | if (!wdev->ssid_len) |
| 6588 | return -ENOTCONN; |
| 6589 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6590 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6591 | if (!wdev->mesh_id_len) |
| 6592 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6593 | break; |
| 6594 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6595 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6596 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6597 | |
| 6598 | memset(¶ms, 0, sizeof(params)); |
| 6599 | |
| 6600 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6601 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6602 | return -EINVAL; |
| 6603 | |
| 6604 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6605 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6606 | return -EINVAL; |
| 6607 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6608 | /* Even though the attribute is u32, the specification says |
| 6609 | * u8, so let's make sure we don't overflow. |
| 6610 | */ |
| 6611 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6612 | if (cs_count > 255) |
| 6613 | return -EINVAL; |
| 6614 | |
| 6615 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6616 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6617 | if (!need_new_beacon) |
| 6618 | goto skip_beacons; |
| 6619 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6620 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6621 | if (err) |
| 6622 | return err; |
| 6623 | |
| 6624 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6625 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6626 | nl80211_policy); |
| 6627 | if (err) |
| 6628 | return err; |
| 6629 | |
| 6630 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6631 | if (err) |
| 6632 | return err; |
| 6633 | |
| 6634 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6635 | return -EINVAL; |
| 6636 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6637 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6638 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6639 | return -EINVAL; |
| 6640 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6641 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6642 | if (rdev->wiphy.max_num_csa_counters && |
| 6643 | (params.n_counter_offsets_beacon > |
| 6644 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6645 | return -EINVAL; |
| 6646 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6647 | params.counter_offsets_beacon = |
| 6648 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6649 | |
| 6650 | /* sanity checks - counters should fit and be the same */ |
| 6651 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6652 | u16 offset = params.counter_offsets_beacon[i]; |
| 6653 | |
| 6654 | if (offset >= params.beacon_csa.tail_len) |
| 6655 | return -EINVAL; |
| 6656 | |
| 6657 | if (params.beacon_csa.tail[offset] != params.count) |
| 6658 | return -EINVAL; |
| 6659 | } |
| 6660 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6661 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6662 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6663 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6664 | return -EINVAL; |
| 6665 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6666 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6667 | if (rdev->wiphy.max_num_csa_counters && |
| 6668 | (params.n_counter_offsets_beacon > |
| 6669 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6670 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6671 | |
| 6672 | params.counter_offsets_presp = |
| 6673 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6674 | |
| 6675 | /* sanity checks - counters should fit and be the same */ |
| 6676 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6677 | u16 offset = params.counter_offsets_presp[i]; |
| 6678 | |
| 6679 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6680 | return -EINVAL; |
| 6681 | |
| 6682 | if (params.beacon_csa.probe_resp[offset] != |
| 6683 | params.count) |
| 6684 | return -EINVAL; |
| 6685 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6686 | } |
| 6687 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6688 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6689 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6690 | if (err) |
| 6691 | return err; |
| 6692 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 6693 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 6694 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6695 | return -EINVAL; |
| 6696 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6697 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6698 | ¶ms.chandef, |
| 6699 | wdev->iftype); |
| 6700 | if (err < 0) |
| 6701 | return err; |
| 6702 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6703 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6704 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6705 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6706 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6707 | params.block_tx = true; |
| 6708 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6709 | wdev_lock(wdev); |
| 6710 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6711 | wdev_unlock(wdev); |
| 6712 | |
| 6713 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6714 | } |
| 6715 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6716 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6717 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6718 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6719 | struct wireless_dev *wdev, |
| 6720 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6721 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6722 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6723 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6724 | void *hdr; |
| 6725 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6726 | |
| 6727 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6728 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6729 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6730 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6731 | if (!hdr) |
| 6732 | return -1; |
| 6733 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6734 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6735 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6736 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6737 | goto nla_put_failure; |
| 6738 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6739 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6740 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6741 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6742 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6743 | |
| 6744 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6745 | if (!bss) |
| 6746 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6747 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6748 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6749 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6750 | |
| 6751 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6752 | /* indicate whether we have probe response data or not */ |
| 6753 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6754 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6755 | goto fail_unlock_rcu; |
| 6756 | |
| 6757 | /* this pointer prefers to be pointed to probe response data |
| 6758 | * but is always valid |
| 6759 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6760 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6761 | if (ies) { |
| 6762 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6763 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6764 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6765 | ies->len, ies->data)) |
| 6766 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6767 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6768 | |
| 6769 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6770 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6771 | if (ies && ies->from_beacon) { |
| 6772 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6773 | goto fail_unlock_rcu; |
| 6774 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6775 | ies->len, ies->data)) |
| 6776 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6777 | } |
| 6778 | rcu_read_unlock(); |
| 6779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6780 | if (res->beacon_interval && |
| 6781 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6782 | goto nla_put_failure; |
| 6783 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6784 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6785 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6786 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6787 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6788 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6789 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 6790 | if (intbss->ts_boottime && |
| 6791 | nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 6792 | intbss->ts_boottime)) |
| 6793 | goto nla_put_failure; |
| 6794 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6795 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6796 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6797 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6798 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6799 | break; |
| 6800 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6801 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6802 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6803 | break; |
| 6804 | default: |
| 6805 | break; |
| 6806 | } |
| 6807 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6808 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6809 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6810 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6811 | if (intbss == wdev->current_bss && |
| 6812 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6813 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6814 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6815 | break; |
| 6816 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6817 | if (intbss == wdev->current_bss && |
| 6818 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6819 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6820 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6821 | break; |
| 6822 | default: |
| 6823 | break; |
| 6824 | } |
| 6825 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6826 | nla_nest_end(msg, bss); |
| 6827 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6828 | genlmsg_end(msg, hdr); |
| 6829 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6830 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6831 | fail_unlock_rcu: |
| 6832 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6833 | nla_put_failure: |
| 6834 | genlmsg_cancel(msg, hdr); |
| 6835 | return -EMSGSIZE; |
| 6836 | } |
| 6837 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6838 | 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] | 6839 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6840 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6841 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6842 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6843 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6844 | int err; |
| 6845 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6846 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6847 | if (err) |
| 6848 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6849 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6850 | wdev_lock(wdev); |
| 6851 | spin_lock_bh(&rdev->bss_lock); |
| 6852 | cfg80211_bss_expire(rdev); |
| 6853 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6854 | cb->seq = rdev->bss_generation; |
| 6855 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6856 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6857 | if (++idx <= start) |
| 6858 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6859 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6860 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6861 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6862 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6863 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6864 | } |
| 6865 | } |
| 6866 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6867 | spin_unlock_bh(&rdev->bss_lock); |
| 6868 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6869 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6870 | cb->args[2] = idx; |
| 6871 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6872 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6873 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6874 | } |
| 6875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6876 | 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] | 6877 | int flags, struct net_device *dev, |
| 6878 | bool allow_radio_stats, |
| 6879 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6880 | { |
| 6881 | void *hdr; |
| 6882 | struct nlattr *infoattr; |
| 6883 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6884 | /* skip radio stats if userspace didn't request them */ |
| 6885 | if (!survey->channel && !allow_radio_stats) |
| 6886 | return 0; |
| 6887 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6888 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6889 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6890 | if (!hdr) |
| 6891 | return -ENOMEM; |
| 6892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6893 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6894 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6895 | |
| 6896 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6897 | if (!infoattr) |
| 6898 | goto nla_put_failure; |
| 6899 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6900 | if (survey->channel && |
| 6901 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6902 | survey->channel->center_freq)) |
| 6903 | goto nla_put_failure; |
| 6904 | |
| 6905 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6906 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6907 | goto nla_put_failure; |
| 6908 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6909 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6910 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6911 | if ((survey->filled & SURVEY_INFO_TIME) && |
| 6912 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, |
| 6913 | survey->time)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6914 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6915 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
| 6916 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 6917 | survey->time_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6918 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6919 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
| 6920 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 6921 | survey->time_ext_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6922 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6923 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
| 6924 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 6925 | survey->time_rx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6926 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6927 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
| 6928 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 6929 | survey->time_tx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6930 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 6931 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
| 6932 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 6933 | survey->time_scan)) |
| 6934 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6935 | |
| 6936 | nla_nest_end(msg, infoattr); |
| 6937 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6938 | genlmsg_end(msg, hdr); |
| 6939 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6940 | |
| 6941 | nla_put_failure: |
| 6942 | genlmsg_cancel(msg, hdr); |
| 6943 | return -EMSGSIZE; |
| 6944 | } |
| 6945 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6946 | 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] | 6947 | { |
| 6948 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6949 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6950 | struct wireless_dev *wdev; |
| 6951 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6952 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6953 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6954 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6955 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6956 | if (res) |
| 6957 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6958 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6959 | /* prepare_wdev_dump parsed the attributes */ |
| 6960 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 6961 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6962 | if (!wdev->netdev) { |
| 6963 | res = -EINVAL; |
| 6964 | goto out_err; |
| 6965 | } |
| 6966 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6967 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6968 | res = -EOPNOTSUPP; |
| 6969 | goto out_err; |
| 6970 | } |
| 6971 | |
| 6972 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6973 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6974 | if (res == -ENOENT) |
| 6975 | break; |
| 6976 | if (res) |
| 6977 | goto out_err; |
| 6978 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6979 | /* don't send disabled channels, but do send non-channel data */ |
| 6980 | if (survey.channel && |
| 6981 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6982 | survey_idx++; |
| 6983 | continue; |
| 6984 | } |
| 6985 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6986 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6987 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6988 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6989 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6990 | goto out; |
| 6991 | survey_idx++; |
| 6992 | } |
| 6993 | |
| 6994 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6995 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6996 | res = skb->len; |
| 6997 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6998 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6999 | return res; |
| 7000 | } |
| 7001 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7002 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7003 | { |
| 7004 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7005 | NL80211_WPA_VERSION_2)); |
| 7006 | } |
| 7007 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7008 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7009 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7011 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7012 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7013 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 7014 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7015 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7016 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7017 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7018 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7019 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7020 | return -EINVAL; |
| 7021 | |
| 7022 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7023 | return -EINVAL; |
| 7024 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7025 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7026 | return -EINVAL; |
| 7027 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7028 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7029 | return -EINVAL; |
| 7030 | |
| 7031 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7032 | return -EINVAL; |
| 7033 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7034 | err = nl80211_parse_key(info, &key); |
| 7035 | if (err) |
| 7036 | return err; |
| 7037 | |
| 7038 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7039 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7040 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7041 | if (!key.p.key || !key.p.key_len) |
| 7042 | return -EINVAL; |
| 7043 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7044 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7045 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7046 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7047 | return -EINVAL; |
| 7048 | if (key.idx > 4) |
| 7049 | return -EINVAL; |
| 7050 | } else { |
| 7051 | key.p.key_len = 0; |
| 7052 | key.p.key = NULL; |
| 7053 | } |
| 7054 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7055 | if (key.idx >= 0) { |
| 7056 | int i; |
| 7057 | bool ok = false; |
| 7058 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7059 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7060 | ok = true; |
| 7061 | break; |
| 7062 | } |
| 7063 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7064 | if (!ok) |
| 7065 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7066 | } |
| 7067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7068 | if (!rdev->ops->auth) |
| 7069 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7070 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7071 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7073 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7074 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7075 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7076 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7077 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7078 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7079 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7080 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7081 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7082 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7083 | |
| 7084 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7085 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7086 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7087 | } |
| 7088 | |
| 7089 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7090 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7091 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7092 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7093 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7094 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7095 | return -EINVAL; |
| 7096 | |
| 7097 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7098 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7099 | return -EINVAL; |
| 7100 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7101 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7102 | /* need to include at least Auth Transaction and Status Code */ |
| 7103 | if (sae_data_len < 4) |
| 7104 | return -EINVAL; |
| 7105 | } |
| 7106 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7107 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7108 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7109 | /* |
| 7110 | * Since we no longer track auth state, ignore |
| 7111 | * requests to only change local state. |
| 7112 | */ |
| 7113 | if (local_state_change) |
| 7114 | return 0; |
| 7115 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7116 | wdev_lock(dev->ieee80211_ptr); |
| 7117 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7118 | ssid, ssid_len, ie, ie_len, |
| 7119 | key.p.key, key.p.key_len, key.idx, |
| 7120 | sae_data, sae_data_len); |
| 7121 | wdev_unlock(dev->ieee80211_ptr); |
| 7122 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7123 | } |
| 7124 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7125 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7126 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7127 | struct cfg80211_crypto_settings *settings, |
| 7128 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7129 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7130 | memset(settings, 0, sizeof(*settings)); |
| 7131 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7132 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7133 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7134 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7135 | u16 proto; |
| 7136 | proto = nla_get_u16( |
| 7137 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7138 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7139 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7140 | proto != ETH_P_PAE) |
| 7141 | return -EINVAL; |
| 7142 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7143 | settings->control_port_no_encrypt = true; |
| 7144 | } else |
| 7145 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7146 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7147 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7148 | void *data; |
| 7149 | int len, i; |
| 7150 | |
| 7151 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7152 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7153 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7154 | |
| 7155 | if (len % sizeof(u32)) |
| 7156 | return -EINVAL; |
| 7157 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7158 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7159 | return -EINVAL; |
| 7160 | |
| 7161 | memcpy(settings->ciphers_pairwise, data, len); |
| 7162 | |
| 7163 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7164 | if (!cfg80211_supported_cipher_suite( |
| 7165 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7166 | settings->ciphers_pairwise[i])) |
| 7167 | return -EINVAL; |
| 7168 | } |
| 7169 | |
| 7170 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7171 | settings->cipher_group = |
| 7172 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7173 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7174 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7175 | return -EINVAL; |
| 7176 | } |
| 7177 | |
| 7178 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7179 | settings->wpa_versions = |
| 7180 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7181 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7182 | return -EINVAL; |
| 7183 | } |
| 7184 | |
| 7185 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7186 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7187 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7188 | |
| 7189 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7190 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7191 | settings->n_akm_suites = len / sizeof(u32); |
| 7192 | |
| 7193 | if (len % sizeof(u32)) |
| 7194 | return -EINVAL; |
| 7195 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7196 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7197 | return -EINVAL; |
| 7198 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7199 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | return 0; |
| 7203 | } |
| 7204 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7205 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7206 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7208 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7209 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7210 | struct cfg80211_assoc_request req = {}; |
| 7211 | const u8 *bssid, *ssid; |
| 7212 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7213 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7214 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7215 | return -EINVAL; |
| 7216 | |
| 7217 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7218 | !info->attrs[NL80211_ATTR_SSID] || |
| 7219 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7220 | return -EINVAL; |
| 7221 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7222 | if (!rdev->ops->assoc) |
| 7223 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7224 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7225 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7226 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7227 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7228 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7229 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7230 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7231 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7232 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7233 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7234 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7235 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7236 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7237 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7238 | |
| 7239 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7240 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7241 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7242 | } |
| 7243 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7244 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7245 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7246 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7247 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7248 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7249 | else if (mfp != NL80211_MFP_NO) |
| 7250 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7251 | } |
| 7252 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7253 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7254 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7255 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7256 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7257 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7258 | |
| 7259 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7260 | memcpy(&req.ht_capa_mask, |
| 7261 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7262 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7263 | |
| 7264 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7265 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7266 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7267 | memcpy(&req.ht_capa, |
| 7268 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7269 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7270 | } |
| 7271 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7272 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7273 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7274 | |
| 7275 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7276 | memcpy(&req.vht_capa_mask, |
| 7277 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7278 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7279 | |
| 7280 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7281 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7282 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7283 | memcpy(&req.vht_capa, |
| 7284 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7285 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7286 | } |
| 7287 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7288 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7289 | if (!(rdev->wiphy.features & |
| 7290 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7291 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7292 | return -EINVAL; |
| 7293 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7294 | } |
| 7295 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7296 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7297 | if (!err) { |
| 7298 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7299 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7300 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7301 | wdev_unlock(dev->ieee80211_ptr); |
| 7302 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7303 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7304 | return err; |
| 7305 | } |
| 7306 | |
| 7307 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7308 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7310 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7311 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7312 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7313 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7314 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7315 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7316 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7317 | return -EINVAL; |
| 7318 | |
| 7319 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7320 | return -EINVAL; |
| 7321 | |
| 7322 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7323 | return -EINVAL; |
| 7324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7325 | if (!rdev->ops->deauth) |
| 7326 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7327 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7328 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7329 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7330 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7331 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7332 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7333 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7334 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7335 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7336 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7337 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7338 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7339 | |
| 7340 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7341 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7342 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7343 | } |
| 7344 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7345 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7346 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7347 | wdev_lock(dev->ieee80211_ptr); |
| 7348 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7349 | local_state_change); |
| 7350 | wdev_unlock(dev->ieee80211_ptr); |
| 7351 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7352 | } |
| 7353 | |
| 7354 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7357 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7358 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7359 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7360 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7361 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7362 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7363 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7364 | return -EINVAL; |
| 7365 | |
| 7366 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7367 | return -EINVAL; |
| 7368 | |
| 7369 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7370 | return -EINVAL; |
| 7371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | if (!rdev->ops->disassoc) |
| 7373 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7374 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7375 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7376 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7377 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7378 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7379 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7380 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7381 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7382 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7383 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7384 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7385 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7386 | |
| 7387 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7388 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7389 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7390 | } |
| 7391 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7392 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7393 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7394 | wdev_lock(dev->ieee80211_ptr); |
| 7395 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7396 | local_state_change); |
| 7397 | wdev_unlock(dev->ieee80211_ptr); |
| 7398 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7399 | } |
| 7400 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7401 | static bool |
| 7402 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7403 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7404 | int rateval) |
| 7405 | { |
| 7406 | struct wiphy *wiphy = &rdev->wiphy; |
| 7407 | bool found = false; |
| 7408 | int band, i; |
| 7409 | |
| 7410 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7411 | struct ieee80211_supported_band *sband; |
| 7412 | |
| 7413 | sband = wiphy->bands[band]; |
| 7414 | if (!sband) |
| 7415 | continue; |
| 7416 | |
| 7417 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7418 | if (sband->bitrates[i].bitrate == rateval) { |
| 7419 | mcast_rate[band] = i + 1; |
| 7420 | found = true; |
| 7421 | break; |
| 7422 | } |
| 7423 | } |
| 7424 | } |
| 7425 | |
| 7426 | return found; |
| 7427 | } |
| 7428 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7429 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7430 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7432 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7433 | struct cfg80211_ibss_params ibss; |
| 7434 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7435 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7436 | int err; |
| 7437 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7438 | memset(&ibss, 0, sizeof(ibss)); |
| 7439 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7440 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7441 | return -EINVAL; |
| 7442 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7443 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7444 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7445 | return -EINVAL; |
| 7446 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7447 | ibss.beacon_interval = 100; |
| 7448 | |
| 7449 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7450 | ibss.beacon_interval = |
| 7451 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7452 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7453 | return -EINVAL; |
| 7454 | } |
| 7455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7456 | if (!rdev->ops->join_ibss) |
| 7457 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7459 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7460 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7461 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7462 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7463 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7464 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7465 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7466 | |
| 7467 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7468 | return -EINVAL; |
| 7469 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7470 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7471 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7472 | |
| 7473 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7474 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7475 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7476 | } |
| 7477 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7478 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7479 | if (err) |
| 7480 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7481 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7482 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7483 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7484 | return -EINVAL; |
| 7485 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7486 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7487 | case NL80211_CHAN_WIDTH_5: |
| 7488 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7489 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7490 | break; |
| 7491 | case NL80211_CHAN_WIDTH_20: |
| 7492 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7493 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7494 | return -EINVAL; |
| 7495 | break; |
| 7496 | case NL80211_CHAN_WIDTH_80: |
| 7497 | case NL80211_CHAN_WIDTH_80P80: |
| 7498 | case NL80211_CHAN_WIDTH_160: |
| 7499 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7500 | return -EINVAL; |
| 7501 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7502 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7503 | return -EINVAL; |
| 7504 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7505 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7506 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7507 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7508 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7509 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7510 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7511 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7512 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7513 | u8 *rates = |
| 7514 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7515 | int n_rates = |
| 7516 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7517 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7518 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7519 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7520 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7521 | &ibss.basic_rates); |
| 7522 | if (err) |
| 7523 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7524 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7525 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7526 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7527 | memcpy(&ibss.ht_capa_mask, |
| 7528 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7529 | sizeof(ibss.ht_capa_mask)); |
| 7530 | |
| 7531 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7532 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7533 | return -EINVAL; |
| 7534 | memcpy(&ibss.ht_capa, |
| 7535 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7536 | sizeof(ibss.ht_capa)); |
| 7537 | } |
| 7538 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7539 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7540 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7541 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7542 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7544 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7545 | bool no_ht = false; |
| 7546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7547 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7548 | info->attrs[NL80211_ATTR_KEYS], |
| 7549 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7550 | if (IS_ERR(connkeys)) |
| 7551 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7552 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7553 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7554 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7555 | kfree(connkeys); |
| 7556 | return -EINVAL; |
| 7557 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7558 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7559 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7560 | ibss.control_port = |
| 7561 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7562 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7563 | ibss.userspace_handles_dfs = |
| 7564 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7566 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7567 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7568 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7569 | return err; |
| 7570 | } |
| 7571 | |
| 7572 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7573 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7575 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7577 | if (!rdev->ops->leave_ibss) |
| 7578 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7580 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7581 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7582 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7583 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7584 | } |
| 7585 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7586 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7587 | { |
| 7588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7589 | struct net_device *dev = info->user_ptr[1]; |
| 7590 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7591 | u32 nla_rate; |
| 7592 | int err; |
| 7593 | |
| 7594 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7595 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7596 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7597 | return -EOPNOTSUPP; |
| 7598 | |
| 7599 | if (!rdev->ops->set_mcast_rate) |
| 7600 | return -EOPNOTSUPP; |
| 7601 | |
| 7602 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7603 | |
| 7604 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7605 | return -EINVAL; |
| 7606 | |
| 7607 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7608 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7609 | return -EINVAL; |
| 7610 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7611 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7612 | |
| 7613 | return err; |
| 7614 | } |
| 7615 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7616 | static struct sk_buff * |
| 7617 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7618 | struct wireless_dev *wdev, int approxlen, |
| 7619 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7620 | enum nl80211_attrs attr, |
| 7621 | const struct nl80211_vendor_cmd_info *info, |
| 7622 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7623 | { |
| 7624 | struct sk_buff *skb; |
| 7625 | void *hdr; |
| 7626 | struct nlattr *data; |
| 7627 | |
| 7628 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7629 | if (!skb) |
| 7630 | return NULL; |
| 7631 | |
| 7632 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7633 | if (!hdr) { |
| 7634 | kfree_skb(skb); |
| 7635 | return NULL; |
| 7636 | } |
| 7637 | |
| 7638 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7639 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7640 | |
| 7641 | if (info) { |
| 7642 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7643 | info->vendor_id)) |
| 7644 | goto nla_put_failure; |
| 7645 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7646 | info->subcmd)) |
| 7647 | goto nla_put_failure; |
| 7648 | } |
| 7649 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7650 | if (wdev) { |
| 7651 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 7652 | wdev_id(wdev))) |
| 7653 | goto nla_put_failure; |
| 7654 | if (wdev->netdev && |
| 7655 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7656 | wdev->netdev->ifindex)) |
| 7657 | goto nla_put_failure; |
| 7658 | } |
| 7659 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7660 | data = nla_nest_start(skb, attr); |
| 7661 | |
| 7662 | ((void **)skb->cb)[0] = rdev; |
| 7663 | ((void **)skb->cb)[1] = hdr; |
| 7664 | ((void **)skb->cb)[2] = data; |
| 7665 | |
| 7666 | return skb; |
| 7667 | |
| 7668 | nla_put_failure: |
| 7669 | kfree_skb(skb); |
| 7670 | return NULL; |
| 7671 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7672 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7673 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7674 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7675 | enum nl80211_commands cmd, |
| 7676 | enum nl80211_attrs attr, |
| 7677 | int vendor_event_idx, |
| 7678 | int approxlen, gfp_t gfp) |
| 7679 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7680 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7681 | const struct nl80211_vendor_cmd_info *info; |
| 7682 | |
| 7683 | switch (cmd) { |
| 7684 | case NL80211_CMD_TESTMODE: |
| 7685 | if (WARN_ON(vendor_event_idx != -1)) |
| 7686 | return NULL; |
| 7687 | info = NULL; |
| 7688 | break; |
| 7689 | case NL80211_CMD_VENDOR: |
| 7690 | if (WARN_ON(vendor_event_idx < 0 || |
| 7691 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7692 | return NULL; |
| 7693 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7694 | break; |
| 7695 | default: |
| 7696 | WARN_ON(1); |
| 7697 | return NULL; |
| 7698 | } |
| 7699 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7700 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7701 | cmd, attr, info, gfp); |
| 7702 | } |
| 7703 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7704 | |
| 7705 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7706 | { |
| 7707 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7708 | void *hdr = ((void **)skb->cb)[1]; |
| 7709 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7710 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7711 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7712 | /* clear CB data for netlink core to own from now on */ |
| 7713 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7714 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7715 | nla_nest_end(skb, data); |
| 7716 | genlmsg_end(skb, hdr); |
| 7717 | |
| 7718 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7719 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7720 | |
| 7721 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7722 | mcgrp, gfp); |
| 7723 | } |
| 7724 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7725 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7726 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7727 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7728 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7730 | struct wireless_dev *wdev = |
| 7731 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7732 | int err; |
| 7733 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7734 | if (!rdev->ops->testmode_cmd) |
| 7735 | return -EOPNOTSUPP; |
| 7736 | |
| 7737 | if (IS_ERR(wdev)) { |
| 7738 | err = PTR_ERR(wdev); |
| 7739 | if (err != -EINVAL) |
| 7740 | return err; |
| 7741 | wdev = NULL; |
| 7742 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7743 | return -EINVAL; |
| 7744 | } |
| 7745 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7746 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7747 | return -EINVAL; |
| 7748 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7749 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7750 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7751 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7752 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7753 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7754 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7755 | return err; |
| 7756 | } |
| 7757 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7758 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7759 | struct netlink_callback *cb) |
| 7760 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7761 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7762 | int err; |
| 7763 | long phy_idx; |
| 7764 | void *data = NULL; |
| 7765 | int data_len = 0; |
| 7766 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7767 | rtnl_lock(); |
| 7768 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7769 | if (cb->args[0]) { |
| 7770 | /* |
| 7771 | * 0 is a valid index, but not valid for args[0], |
| 7772 | * so we need to offset by 1. |
| 7773 | */ |
| 7774 | phy_idx = cb->args[0] - 1; |
| 7775 | } else { |
| 7776 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7777 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7778 | nl80211_policy); |
| 7779 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7780 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7781 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7782 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7783 | nl80211_fam.attrbuf); |
| 7784 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7785 | err = PTR_ERR(rdev); |
| 7786 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7787 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7788 | phy_idx = rdev->wiphy_idx; |
| 7789 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7790 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7791 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7792 | cb->args[1] = |
| 7793 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7794 | } |
| 7795 | |
| 7796 | if (cb->args[1]) { |
| 7797 | data = nla_data((void *)cb->args[1]); |
| 7798 | data_len = nla_len((void *)cb->args[1]); |
| 7799 | } |
| 7800 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7801 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7802 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7803 | err = -ENOENT; |
| 7804 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7805 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7806 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7807 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7808 | err = -EOPNOTSUPP; |
| 7809 | goto out_err; |
| 7810 | } |
| 7811 | |
| 7812 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7813 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7814 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7815 | NL80211_CMD_TESTMODE); |
| 7816 | struct nlattr *tmdata; |
| 7817 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7818 | if (!hdr) |
| 7819 | break; |
| 7820 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7821 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7822 | genlmsg_cancel(skb, hdr); |
| 7823 | break; |
| 7824 | } |
| 7825 | |
| 7826 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7827 | if (!tmdata) { |
| 7828 | genlmsg_cancel(skb, hdr); |
| 7829 | break; |
| 7830 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7831 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7832 | nla_nest_end(skb, tmdata); |
| 7833 | |
| 7834 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7835 | genlmsg_cancel(skb, hdr); |
| 7836 | break; |
| 7837 | } else if (err) { |
| 7838 | genlmsg_cancel(skb, hdr); |
| 7839 | goto out_err; |
| 7840 | } |
| 7841 | |
| 7842 | genlmsg_end(skb, hdr); |
| 7843 | } |
| 7844 | |
| 7845 | err = skb->len; |
| 7846 | /* see above */ |
| 7847 | cb->args[0] = phy_idx + 1; |
| 7848 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7849 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7850 | return err; |
| 7851 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7852 | #endif |
| 7853 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7854 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7855 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7857 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7858 | struct cfg80211_connect_params connect; |
| 7859 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7860 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7861 | int err; |
| 7862 | |
| 7863 | memset(&connect, 0, sizeof(connect)); |
| 7864 | |
| 7865 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7866 | return -EINVAL; |
| 7867 | |
| 7868 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7869 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7870 | return -EINVAL; |
| 7871 | |
| 7872 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7873 | connect.auth_type = |
| 7874 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7875 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7876 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7877 | return -EINVAL; |
| 7878 | } else |
| 7879 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7880 | |
| 7881 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7882 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7883 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7884 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7885 | if (err) |
| 7886 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7887 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7888 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7890 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7891 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7892 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7893 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7894 | connect.bg_scan_period = -1; |
| 7895 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7896 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7897 | connect.bg_scan_period = |
| 7898 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7899 | } |
| 7900 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7901 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7902 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7903 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7904 | connect.bssid_hint = |
| 7905 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7906 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7907 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7908 | |
| 7909 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7910 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7911 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7912 | } |
| 7913 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7914 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7915 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7916 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7917 | connect.mfp != NL80211_MFP_NO) |
| 7918 | return -EINVAL; |
| 7919 | } else { |
| 7920 | connect.mfp = NL80211_MFP_NO; |
| 7921 | } |
| 7922 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7923 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7924 | connect.channel = nl80211_get_valid_chan( |
| 7925 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7926 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7927 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7928 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7929 | connect.channel_hint = nl80211_get_valid_chan( |
| 7930 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7931 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7932 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7933 | } |
| 7934 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7935 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7936 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7937 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7938 | if (IS_ERR(connkeys)) |
| 7939 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7940 | } |
| 7941 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7942 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7943 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7944 | |
| 7945 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7946 | memcpy(&connect.ht_capa_mask, |
| 7947 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7948 | sizeof(connect.ht_capa_mask)); |
| 7949 | |
| 7950 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7951 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7952 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7953 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7954 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7955 | memcpy(&connect.ht_capa, |
| 7956 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7957 | sizeof(connect.ht_capa)); |
| 7958 | } |
| 7959 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7960 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7961 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7962 | |
| 7963 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7964 | memcpy(&connect.vht_capa_mask, |
| 7965 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7966 | sizeof(connect.vht_capa_mask)); |
| 7967 | |
| 7968 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7969 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7970 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7971 | return -EINVAL; |
| 7972 | } |
| 7973 | memcpy(&connect.vht_capa, |
| 7974 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7975 | sizeof(connect.vht_capa)); |
| 7976 | } |
| 7977 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7978 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7979 | if (!(rdev->wiphy.features & |
| 7980 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 7981 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) { |
| 7982 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7983 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 7984 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7985 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7986 | } |
| 7987 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame^] | 7988 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 7989 | if (connect.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) { |
| 7990 | kzfree(connkeys); |
| 7991 | return -EOPNOTSUPP; |
| 7992 | } |
| 7993 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7994 | wdev_lock(dev->ieee80211_ptr); |
| 7995 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7996 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7997 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7998 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7999 | return err; |
| 8000 | } |
| 8001 | |
| 8002 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8005 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8006 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8007 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8008 | |
| 8009 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8010 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8011 | else |
| 8012 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8013 | |
| 8014 | if (reason == 0) |
| 8015 | return -EINVAL; |
| 8016 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8018 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8019 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8020 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8021 | wdev_lock(dev->ieee80211_ptr); |
| 8022 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8023 | wdev_unlock(dev->ieee80211_ptr); |
| 8024 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8025 | } |
| 8026 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8027 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8030 | struct net *net; |
| 8031 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8032 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8033 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8034 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8035 | |
| 8036 | net = get_net_ns_by_pid(pid); |
| 8037 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8038 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8039 | |
| 8040 | net = get_net_ns_by_fd(fd); |
| 8041 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8042 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8043 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8044 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8045 | if (IS_ERR(net)) |
| 8046 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8047 | |
| 8048 | err = 0; |
| 8049 | |
| 8050 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8051 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8052 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8053 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8054 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8055 | return err; |
| 8056 | } |
| 8057 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8058 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8059 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8060 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8061 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8062 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8063 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8064 | struct cfg80211_pmksa pmksa; |
| 8065 | |
| 8066 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8067 | |
| 8068 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8069 | return -EINVAL; |
| 8070 | |
| 8071 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8072 | return -EINVAL; |
| 8073 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8074 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8075 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8076 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8079 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8080 | |
| 8081 | switch (info->genlhdr->cmd) { |
| 8082 | case NL80211_CMD_SET_PMKSA: |
| 8083 | rdev_ops = rdev->ops->set_pmksa; |
| 8084 | break; |
| 8085 | case NL80211_CMD_DEL_PMKSA: |
| 8086 | rdev_ops = rdev->ops->del_pmksa; |
| 8087 | break; |
| 8088 | default: |
| 8089 | WARN_ON(1); |
| 8090 | break; |
| 8091 | } |
| 8092 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8093 | if (!rdev_ops) |
| 8094 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8095 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8096 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8097 | } |
| 8098 | |
| 8099 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8100 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8101 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8102 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8103 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8104 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8105 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8106 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8108 | if (!rdev->ops->flush_pmksa) |
| 8109 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8110 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8111 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8112 | } |
| 8113 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8114 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8115 | { |
| 8116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8117 | struct net_device *dev = info->user_ptr[1]; |
| 8118 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8119 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8120 | u16 status_code; |
| 8121 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8122 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8123 | |
| 8124 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8125 | !rdev->ops->tdls_mgmt) |
| 8126 | return -EOPNOTSUPP; |
| 8127 | |
| 8128 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8129 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8130 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8131 | !info->attrs[NL80211_ATTR_IE] || |
| 8132 | !info->attrs[NL80211_ATTR_MAC]) |
| 8133 | return -EINVAL; |
| 8134 | |
| 8135 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8136 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8137 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8138 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8139 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8140 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8141 | peer_capability = |
| 8142 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8143 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8144 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8145 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8146 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8147 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8148 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8149 | } |
| 8150 | |
| 8151 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8152 | { |
| 8153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8154 | struct net_device *dev = info->user_ptr[1]; |
| 8155 | enum nl80211_tdls_operation operation; |
| 8156 | u8 *peer; |
| 8157 | |
| 8158 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8159 | !rdev->ops->tdls_oper) |
| 8160 | return -EOPNOTSUPP; |
| 8161 | |
| 8162 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8163 | !info->attrs[NL80211_ATTR_MAC]) |
| 8164 | return -EINVAL; |
| 8165 | |
| 8166 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8167 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8168 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8169 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8170 | } |
| 8171 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8172 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8173 | struct genl_info *info) |
| 8174 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8175 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8176 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8177 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8178 | struct sk_buff *msg; |
| 8179 | void *hdr; |
| 8180 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8181 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8182 | int err; |
| 8183 | |
| 8184 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8185 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8186 | return -EINVAL; |
| 8187 | |
| 8188 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8189 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8190 | if (!rdev->ops->remain_on_channel || |
| 8191 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8192 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8193 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8194 | /* |
| 8195 | * We should be on that channel for at least a minimum amount of |
| 8196 | * time (10ms) but no longer than the driver supports. |
| 8197 | */ |
| 8198 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8199 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8200 | return -EINVAL; |
| 8201 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8202 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8203 | if (err) |
| 8204 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8205 | |
| 8206 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8207 | if (!msg) |
| 8208 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8210 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8211 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8212 | if (!hdr) { |
| 8213 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8214 | goto free_msg; |
| 8215 | } |
| 8216 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8217 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8218 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8219 | |
| 8220 | if (err) |
| 8221 | goto free_msg; |
| 8222 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8223 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8224 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8225 | |
| 8226 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8227 | |
| 8228 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8229 | |
| 8230 | nla_put_failure: |
| 8231 | err = -ENOBUFS; |
| 8232 | free_msg: |
| 8233 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8234 | return err; |
| 8235 | } |
| 8236 | |
| 8237 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8238 | struct genl_info *info) |
| 8239 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8241 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8242 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8243 | |
| 8244 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8245 | return -EINVAL; |
| 8246 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8247 | if (!rdev->ops->cancel_remain_on_channel) |
| 8248 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8249 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8250 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8251 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8252 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8253 | } |
| 8254 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8255 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8256 | u8 *rates, u8 rates_len) |
| 8257 | { |
| 8258 | u8 i; |
| 8259 | u32 mask = 0; |
| 8260 | |
| 8261 | for (i = 0; i < rates_len; i++) { |
| 8262 | int rate = (rates[i] & 0x7f) * 5; |
| 8263 | int ridx; |
| 8264 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8265 | struct ieee80211_rate *srate = |
| 8266 | &sband->bitrates[ridx]; |
| 8267 | if (rate == srate->bitrate) { |
| 8268 | mask |= 1 << ridx; |
| 8269 | break; |
| 8270 | } |
| 8271 | } |
| 8272 | if (ridx == sband->n_bitrates) |
| 8273 | return 0; /* rate not found */ |
| 8274 | } |
| 8275 | |
| 8276 | return mask; |
| 8277 | } |
| 8278 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8279 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8280 | u8 *rates, u8 rates_len, |
| 8281 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8282 | { |
| 8283 | u8 i; |
| 8284 | |
| 8285 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8286 | |
| 8287 | for (i = 0; i < rates_len; i++) { |
| 8288 | int ridx, rbit; |
| 8289 | |
| 8290 | ridx = rates[i] / 8; |
| 8291 | rbit = BIT(rates[i] % 8); |
| 8292 | |
| 8293 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8294 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8295 | return false; |
| 8296 | |
| 8297 | /* check availability */ |
| 8298 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8299 | mcs[ridx] |= rbit; |
| 8300 | else |
| 8301 | return false; |
| 8302 | } |
| 8303 | |
| 8304 | return true; |
| 8305 | } |
| 8306 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8307 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8308 | { |
| 8309 | u16 mcs_mask = 0; |
| 8310 | |
| 8311 | switch (vht_mcs_map) { |
| 8312 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8313 | break; |
| 8314 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8315 | mcs_mask = 0x00FF; |
| 8316 | break; |
| 8317 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8318 | mcs_mask = 0x01FF; |
| 8319 | break; |
| 8320 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8321 | mcs_mask = 0x03FF; |
| 8322 | break; |
| 8323 | default: |
| 8324 | break; |
| 8325 | } |
| 8326 | |
| 8327 | return mcs_mask; |
| 8328 | } |
| 8329 | |
| 8330 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8331 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8332 | { |
| 8333 | u8 nss; |
| 8334 | |
| 8335 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8336 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8337 | vht_mcs_map >>= 2; |
| 8338 | } |
| 8339 | } |
| 8340 | |
| 8341 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8342 | struct nl80211_txrate_vht *txrate, |
| 8343 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8344 | { |
| 8345 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8346 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8347 | u8 i; |
| 8348 | |
| 8349 | if (!sband->vht_cap.vht_supported) |
| 8350 | return false; |
| 8351 | |
| 8352 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8353 | |
| 8354 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8355 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8356 | |
| 8357 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8358 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8359 | mcs[i] = txrate->mcs[i]; |
| 8360 | else |
| 8361 | return false; |
| 8362 | } |
| 8363 | |
| 8364 | return true; |
| 8365 | } |
| 8366 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8367 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8368 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8369 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8370 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8371 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8372 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8373 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8374 | }; |
| 8375 | |
| 8376 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8377 | struct genl_info *info) |
| 8378 | { |
| 8379 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8381 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8382 | int rem, i; |
| 8383 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8384 | struct nlattr *tx_rates; |
| 8385 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8386 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8388 | if (!rdev->ops->set_bitrate_mask) |
| 8389 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8390 | |
| 8391 | memset(&mask, 0, sizeof(mask)); |
| 8392 | /* Default to all rates enabled */ |
| 8393 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8394 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8395 | |
| 8396 | if (!sband) |
| 8397 | continue; |
| 8398 | |
| 8399 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8400 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8401 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8402 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8403 | |
| 8404 | if (!sband->vht_cap.vht_supported) |
| 8405 | continue; |
| 8406 | |
| 8407 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8408 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8409 | } |
| 8410 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8411 | /* if no rates are given set it back to the defaults */ |
| 8412 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8413 | goto out; |
| 8414 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8415 | /* |
| 8416 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8417 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8418 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8419 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8420 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8421 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8422 | int err; |
| 8423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8424 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8425 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8426 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8427 | if (sband == NULL) |
| 8428 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8429 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8430 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8431 | if (err) |
| 8432 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8433 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8434 | mask.control[band].legacy = rateset_to_mask( |
| 8435 | sband, |
| 8436 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8437 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8438 | if ((mask.control[band].legacy == 0) && |
| 8439 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8440 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8441 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8442 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8443 | if (!ht_rateset_to_mask( |
| 8444 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8445 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8446 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8447 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8448 | return -EINVAL; |
| 8449 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8450 | if (tb[NL80211_TXRATE_VHT]) { |
| 8451 | if (!vht_set_mcs_mask( |
| 8452 | sband, |
| 8453 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8454 | mask.control[band].vht_mcs)) |
| 8455 | return -EINVAL; |
| 8456 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8457 | if (tb[NL80211_TXRATE_GI]) { |
| 8458 | mask.control[band].gi = |
| 8459 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8460 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8461 | return -EINVAL; |
| 8462 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8463 | |
| 8464 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8465 | /* don't allow empty legacy rates if HT or VHT |
| 8466 | * are not even supported. |
| 8467 | */ |
| 8468 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8469 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8470 | return -EINVAL; |
| 8471 | |
| 8472 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8473 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8474 | goto out; |
| 8475 | |
| 8476 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8477 | if (mask.control[band].vht_mcs[i]) |
| 8478 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8479 | |
| 8480 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8481 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8482 | } |
| 8483 | } |
| 8484 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8485 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8486 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8487 | } |
| 8488 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8489 | 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] | 8490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8492 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8493 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8494 | |
| 8495 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8496 | return -EINVAL; |
| 8497 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8498 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8499 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8500 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8501 | switch (wdev->iftype) { |
| 8502 | case NL80211_IFTYPE_STATION: |
| 8503 | case NL80211_IFTYPE_ADHOC: |
| 8504 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8505 | case NL80211_IFTYPE_AP: |
| 8506 | case NL80211_IFTYPE_AP_VLAN: |
| 8507 | case NL80211_IFTYPE_MESH_POINT: |
| 8508 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8509 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8510 | break; |
| 8511 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8512 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8513 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8514 | |
| 8515 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8516 | if (!rdev->ops->mgmt_tx) |
| 8517 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8518 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8519 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8520 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8521 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8522 | } |
| 8523 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8524 | 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] | 8525 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8527 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8528 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8529 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8530 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8531 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8532 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8533 | struct cfg80211_mgmt_tx_params params = { |
| 8534 | .dont_wait_for_ack = |
| 8535 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8536 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8537 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8538 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8539 | return -EINVAL; |
| 8540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8541 | if (!rdev->ops->mgmt_tx) |
| 8542 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8543 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8544 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8545 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8546 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8547 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8548 | case NL80211_IFTYPE_STATION: |
| 8549 | case NL80211_IFTYPE_ADHOC: |
| 8550 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8551 | case NL80211_IFTYPE_AP: |
| 8552 | case NL80211_IFTYPE_AP_VLAN: |
| 8553 | case NL80211_IFTYPE_MESH_POINT: |
| 8554 | case NL80211_IFTYPE_P2P_GO: |
| 8555 | break; |
| 8556 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8557 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8558 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8559 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8560 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8561 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8562 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8563 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8564 | |
| 8565 | /* |
| 8566 | * We should wait on the channel for at least a minimum amount |
| 8567 | * of time (10ms) but no longer than the driver supports. |
| 8568 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8569 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8570 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8571 | return -EINVAL; |
| 8572 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8573 | } |
| 8574 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8575 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8576 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8577 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8578 | return -EINVAL; |
| 8579 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8580 | 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] | 8581 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8582 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8583 | * the driver. The latter will use the current one |
| 8584 | */ |
| 8585 | chandef.chan = NULL; |
| 8586 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8587 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8588 | if (err) |
| 8589 | return err; |
| 8590 | } |
| 8591 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8592 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8593 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8594 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8595 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8596 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8597 | |
| 8598 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8599 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8600 | int i; |
| 8601 | |
| 8602 | if (len % sizeof(u16)) |
| 8603 | return -EINVAL; |
| 8604 | |
| 8605 | params.n_csa_offsets = len / sizeof(u16); |
| 8606 | params.csa_offsets = |
| 8607 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8608 | |
| 8609 | /* check that all the offsets fit the frame */ |
| 8610 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8611 | if (params.csa_offsets[i] >= params.len) |
| 8612 | return -EINVAL; |
| 8613 | } |
| 8614 | } |
| 8615 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8616 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8618 | if (!msg) |
| 8619 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8620 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8621 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8622 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8623 | if (!hdr) { |
| 8624 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8625 | goto free_msg; |
| 8626 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8627 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8628 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8629 | params.chan = chandef.chan; |
| 8630 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8631 | if (err) |
| 8632 | goto free_msg; |
| 8633 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8634 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8635 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8636 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8637 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8638 | genlmsg_end(msg, hdr); |
| 8639 | return genlmsg_reply(msg, info); |
| 8640 | } |
| 8641 | |
| 8642 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8643 | |
| 8644 | nla_put_failure: |
| 8645 | err = -ENOBUFS; |
| 8646 | free_msg: |
| 8647 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8648 | return err; |
| 8649 | } |
| 8650 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8651 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8652 | { |
| 8653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8654 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8655 | u64 cookie; |
| 8656 | |
| 8657 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8658 | return -EINVAL; |
| 8659 | |
| 8660 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8661 | return -EOPNOTSUPP; |
| 8662 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8663 | switch (wdev->iftype) { |
| 8664 | case NL80211_IFTYPE_STATION: |
| 8665 | case NL80211_IFTYPE_ADHOC: |
| 8666 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8667 | case NL80211_IFTYPE_AP: |
| 8668 | case NL80211_IFTYPE_AP_VLAN: |
| 8669 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8670 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8671 | break; |
| 8672 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8673 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8674 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8675 | |
| 8676 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8677 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8678 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8679 | } |
| 8680 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8681 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8684 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8685 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8686 | u8 ps_state; |
| 8687 | bool state; |
| 8688 | int err; |
| 8689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8690 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8691 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8692 | |
| 8693 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8694 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8695 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8696 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8697 | |
| 8698 | wdev = dev->ieee80211_ptr; |
| 8699 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8700 | if (!rdev->ops->set_power_mgmt) |
| 8701 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8702 | |
| 8703 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8704 | |
| 8705 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8706 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8707 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8708 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8709 | if (!err) |
| 8710 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8711 | return err; |
| 8712 | } |
| 8713 | |
| 8714 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8715 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8717 | enum nl80211_ps_state ps_state; |
| 8718 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8719 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8720 | struct sk_buff *msg; |
| 8721 | void *hdr; |
| 8722 | int err; |
| 8723 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8724 | wdev = dev->ieee80211_ptr; |
| 8725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8726 | if (!rdev->ops->set_power_mgmt) |
| 8727 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8728 | |
| 8729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8730 | if (!msg) |
| 8731 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8732 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8733 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8734 | NL80211_CMD_GET_POWER_SAVE); |
| 8735 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8736 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8737 | goto free_msg; |
| 8738 | } |
| 8739 | |
| 8740 | if (wdev->ps) |
| 8741 | ps_state = NL80211_PS_ENABLED; |
| 8742 | else |
| 8743 | ps_state = NL80211_PS_DISABLED; |
| 8744 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8745 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8746 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8747 | |
| 8748 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8749 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8750 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8751 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8752 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8753 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8754 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8755 | return err; |
| 8756 | } |
| 8757 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8758 | static const struct nla_policy |
| 8759 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8760 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8761 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8762 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8763 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8764 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8765 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8766 | }; |
| 8767 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8768 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8769 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8770 | { |
| 8771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8772 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8773 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8774 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8775 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8776 | return -EINVAL; |
| 8777 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8778 | if (!rdev->ops->set_cqm_txe_config) |
| 8779 | return -EOPNOTSUPP; |
| 8780 | |
| 8781 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8782 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8783 | return -EOPNOTSUPP; |
| 8784 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8785 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8786 | } |
| 8787 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8788 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8789 | s32 threshold, u32 hysteresis) |
| 8790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8792 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8793 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8794 | |
| 8795 | if (threshold > 0) |
| 8796 | return -EINVAL; |
| 8797 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8798 | /* disabling - hysteresis should also be zero then */ |
| 8799 | if (threshold == 0) |
| 8800 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8801 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8802 | if (!rdev->ops->set_cqm_rssi_config) |
| 8803 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8804 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8805 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8806 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8807 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8808 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8809 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8810 | } |
| 8811 | |
| 8812 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8813 | { |
| 8814 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8815 | struct nlattr *cqm; |
| 8816 | int err; |
| 8817 | |
| 8818 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8819 | if (!cqm) |
| 8820 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8821 | |
| 8822 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8823 | nl80211_attr_cqm_policy); |
| 8824 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8825 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8826 | |
| 8827 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8828 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8829 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8830 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8831 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8832 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8833 | } |
| 8834 | |
| 8835 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8836 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8837 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8838 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8839 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8840 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8841 | |
| 8842 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8843 | } |
| 8844 | |
| 8845 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8846 | } |
| 8847 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8848 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8849 | { |
| 8850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8851 | struct net_device *dev = info->user_ptr[1]; |
| 8852 | struct ocb_setup setup = {}; |
| 8853 | int err; |
| 8854 | |
| 8855 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8856 | if (err) |
| 8857 | return err; |
| 8858 | |
| 8859 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8860 | } |
| 8861 | |
| 8862 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8863 | { |
| 8864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8865 | struct net_device *dev = info->user_ptr[1]; |
| 8866 | |
| 8867 | return cfg80211_leave_ocb(rdev, dev); |
| 8868 | } |
| 8869 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8870 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8871 | { |
| 8872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8873 | struct net_device *dev = info->user_ptr[1]; |
| 8874 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8875 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8876 | int err; |
| 8877 | |
| 8878 | /* start with default */ |
| 8879 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8880 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8881 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8882 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8883 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8884 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8885 | if (err) |
| 8886 | return err; |
| 8887 | } |
| 8888 | |
| 8889 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8890 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8891 | return -EINVAL; |
| 8892 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8893 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8894 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8895 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8896 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8897 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8898 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8899 | return -EINVAL; |
| 8900 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8901 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8902 | setup.beacon_interval = |
| 8903 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8904 | if (setup.beacon_interval < 10 || |
| 8905 | setup.beacon_interval > 10000) |
| 8906 | return -EINVAL; |
| 8907 | } |
| 8908 | |
| 8909 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8910 | setup.dtim_period = |
| 8911 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8912 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8913 | return -EINVAL; |
| 8914 | } |
| 8915 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8916 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8917 | /* parse additional setup parameters if given */ |
| 8918 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8919 | if (err) |
| 8920 | return err; |
| 8921 | } |
| 8922 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8923 | if (setup.user_mpm) |
| 8924 | cfg.auto_open_plinks = false; |
| 8925 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8926 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8927 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8928 | if (err) |
| 8929 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8930 | } else { |
| 8931 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8932 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8933 | } |
| 8934 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8935 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8936 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8937 | int n_rates = |
| 8938 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8939 | struct ieee80211_supported_band *sband; |
| 8940 | |
| 8941 | if (!setup.chandef.chan) |
| 8942 | return -EINVAL; |
| 8943 | |
| 8944 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8945 | |
| 8946 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8947 | &setup.basic_rates); |
| 8948 | if (err) |
| 8949 | return err; |
| 8950 | } |
| 8951 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8952 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8953 | } |
| 8954 | |
| 8955 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8956 | { |
| 8957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8958 | struct net_device *dev = info->user_ptr[1]; |
| 8959 | |
| 8960 | return cfg80211_leave_mesh(rdev, dev); |
| 8961 | } |
| 8962 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8963 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8964 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8965 | struct cfg80211_registered_device *rdev) |
| 8966 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8967 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8968 | struct nlattr *nl_pats, *nl_pat; |
| 8969 | int i, pat_len; |
| 8970 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8971 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8972 | return 0; |
| 8973 | |
| 8974 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8975 | if (!nl_pats) |
| 8976 | return -ENOBUFS; |
| 8977 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8978 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8979 | nl_pat = nla_nest_start(msg, i + 1); |
| 8980 | if (!nl_pat) |
| 8981 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8982 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8983 | 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] | 8984 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8985 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8986 | wowlan->patterns[i].pattern) || |
| 8987 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8988 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8989 | return -ENOBUFS; |
| 8990 | nla_nest_end(msg, nl_pat); |
| 8991 | } |
| 8992 | nla_nest_end(msg, nl_pats); |
| 8993 | |
| 8994 | return 0; |
| 8995 | } |
| 8996 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8997 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8998 | struct cfg80211_wowlan_tcp *tcp) |
| 8999 | { |
| 9000 | struct nlattr *nl_tcp; |
| 9001 | |
| 9002 | if (!tcp) |
| 9003 | return 0; |
| 9004 | |
| 9005 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9006 | if (!nl_tcp) |
| 9007 | return -ENOBUFS; |
| 9008 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9009 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9010 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9011 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9012 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9013 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9014 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9015 | tcp->payload_len, tcp->payload) || |
| 9016 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9017 | tcp->data_interval) || |
| 9018 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9019 | tcp->wake_len, tcp->wake_data) || |
| 9020 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9021 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9022 | return -ENOBUFS; |
| 9023 | |
| 9024 | if (tcp->payload_seq.len && |
| 9025 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9026 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9027 | return -ENOBUFS; |
| 9028 | |
| 9029 | if (tcp->payload_tok.len && |
| 9030 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9031 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9032 | &tcp->payload_tok)) |
| 9033 | return -ENOBUFS; |
| 9034 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9035 | nla_nest_end(msg, nl_tcp); |
| 9036 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9037 | return 0; |
| 9038 | } |
| 9039 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9040 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9041 | struct cfg80211_sched_scan_request *req) |
| 9042 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9043 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9044 | int i; |
| 9045 | |
| 9046 | if (!req) |
| 9047 | return 0; |
| 9048 | |
| 9049 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9050 | if (!nd) |
| 9051 | return -ENOBUFS; |
| 9052 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9053 | if (req->n_scan_plans == 1 && |
| 9054 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9055 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9056 | return -ENOBUFS; |
| 9057 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9058 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9059 | return -ENOBUFS; |
| 9060 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9061 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9062 | if (!freqs) |
| 9063 | return -ENOBUFS; |
| 9064 | |
| 9065 | for (i = 0; i < req->n_channels; i++) |
| 9066 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 9067 | |
| 9068 | nla_nest_end(msg, freqs); |
| 9069 | |
| 9070 | if (req->n_match_sets) { |
| 9071 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 9072 | for (i = 0; i < req->n_match_sets; i++) { |
| 9073 | match = nla_nest_start(msg, i); |
| 9074 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9075 | req->match_sets[i].ssid.ssid_len, |
| 9076 | req->match_sets[i].ssid.ssid); |
| 9077 | nla_nest_end(msg, match); |
| 9078 | } |
| 9079 | nla_nest_end(msg, matches); |
| 9080 | } |
| 9081 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9082 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9083 | if (!scan_plans) |
| 9084 | return -ENOBUFS; |
| 9085 | |
| 9086 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9087 | scan_plan = nla_nest_start(msg, i + 1); |
| 9088 | if (!scan_plan || |
| 9089 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9090 | req->scan_plans[i].interval) || |
| 9091 | (req->scan_plans[i].iterations && |
| 9092 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9093 | req->scan_plans[i].iterations))) |
| 9094 | return -ENOBUFS; |
| 9095 | nla_nest_end(msg, scan_plan); |
| 9096 | } |
| 9097 | nla_nest_end(msg, scan_plans); |
| 9098 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9099 | nla_nest_end(msg, nd); |
| 9100 | |
| 9101 | return 0; |
| 9102 | } |
| 9103 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9104 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9105 | { |
| 9106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9107 | struct sk_buff *msg; |
| 9108 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9109 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9110 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9111 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9112 | return -EOPNOTSUPP; |
| 9113 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9114 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9115 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9116 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9117 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9118 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9119 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9120 | } |
| 9121 | |
| 9122 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9123 | if (!msg) |
| 9124 | return -ENOMEM; |
| 9125 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9126 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9127 | NL80211_CMD_GET_WOWLAN); |
| 9128 | if (!hdr) |
| 9129 | goto nla_put_failure; |
| 9130 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9131 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9132 | struct nlattr *nl_wowlan; |
| 9133 | |
| 9134 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9135 | if (!nl_wowlan) |
| 9136 | goto nla_put_failure; |
| 9137 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9138 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9139 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9140 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9141 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9142 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9143 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9144 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9145 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9146 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9147 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9148 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9149 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9150 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9151 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9152 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9153 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9154 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9155 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9156 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9157 | if (nl80211_send_wowlan_tcp(msg, |
| 9158 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9159 | goto nla_put_failure; |
| 9160 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9161 | if (nl80211_send_wowlan_nd( |
| 9162 | msg, |
| 9163 | rdev->wiphy.wowlan_config->nd_config)) |
| 9164 | goto nla_put_failure; |
| 9165 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9166 | nla_nest_end(msg, nl_wowlan); |
| 9167 | } |
| 9168 | |
| 9169 | genlmsg_end(msg, hdr); |
| 9170 | return genlmsg_reply(msg, info); |
| 9171 | |
| 9172 | nla_put_failure: |
| 9173 | nlmsg_free(msg); |
| 9174 | return -ENOBUFS; |
| 9175 | } |
| 9176 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9177 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9178 | struct nlattr *attr, |
| 9179 | struct cfg80211_wowlan *trig) |
| 9180 | { |
| 9181 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9182 | struct cfg80211_wowlan_tcp *cfg; |
| 9183 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9184 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9185 | u32 size; |
| 9186 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9187 | int err, port; |
| 9188 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9189 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9190 | return -EINVAL; |
| 9191 | |
| 9192 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9193 | nla_data(attr), nla_len(attr), |
| 9194 | nl80211_wowlan_tcp_policy); |
| 9195 | if (err) |
| 9196 | return err; |
| 9197 | |
| 9198 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9199 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9200 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9201 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9202 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9203 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9204 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9205 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9206 | return -EINVAL; |
| 9207 | |
| 9208 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9209 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9210 | return -EINVAL; |
| 9211 | |
| 9212 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9213 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9214 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9215 | return -EINVAL; |
| 9216 | |
| 9217 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9218 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9219 | return -EINVAL; |
| 9220 | |
| 9221 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9222 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9223 | return -EINVAL; |
| 9224 | |
| 9225 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9226 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9227 | |
| 9228 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9229 | tokens_size = tokln - sizeof(*tok); |
| 9230 | |
| 9231 | if (!tok->len || tokens_size % tok->len) |
| 9232 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9233 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9234 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9235 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9236 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9237 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9238 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9239 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9240 | return -EINVAL; |
| 9241 | if (tok->offset + tok->len > data_size) |
| 9242 | return -EINVAL; |
| 9243 | } |
| 9244 | |
| 9245 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9246 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9247 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9248 | return -EINVAL; |
| 9249 | if (seq->len == 0 || seq->len > 4) |
| 9250 | return -EINVAL; |
| 9251 | if (seq->len + seq->offset > data_size) |
| 9252 | return -EINVAL; |
| 9253 | } |
| 9254 | |
| 9255 | size = sizeof(*cfg); |
| 9256 | size += data_size; |
| 9257 | size += wake_size + wake_mask_size; |
| 9258 | size += tokens_size; |
| 9259 | |
| 9260 | cfg = kzalloc(size, GFP_KERNEL); |
| 9261 | if (!cfg) |
| 9262 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9263 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9264 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9265 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9266 | ETH_ALEN); |
| 9267 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9268 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9269 | else |
| 9270 | port = 0; |
| 9271 | #ifdef CONFIG_INET |
| 9272 | /* allocate a socket and port for it and use it */ |
| 9273 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9274 | IPPROTO_TCP, &cfg->sock, 1); |
| 9275 | if (err) { |
| 9276 | kfree(cfg); |
| 9277 | return err; |
| 9278 | } |
| 9279 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9280 | sock_release(cfg->sock); |
| 9281 | kfree(cfg); |
| 9282 | return -EADDRINUSE; |
| 9283 | } |
| 9284 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9285 | #else |
| 9286 | if (!port) { |
| 9287 | kfree(cfg); |
| 9288 | return -EINVAL; |
| 9289 | } |
| 9290 | cfg->src_port = port; |
| 9291 | #endif |
| 9292 | |
| 9293 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9294 | cfg->payload_len = data_size; |
| 9295 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9296 | memcpy((void *)cfg->payload, |
| 9297 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9298 | data_size); |
| 9299 | if (seq) |
| 9300 | cfg->payload_seq = *seq; |
| 9301 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9302 | cfg->wake_len = wake_size; |
| 9303 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9304 | memcpy((void *)cfg->wake_data, |
| 9305 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9306 | wake_size); |
| 9307 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9308 | data_size + wake_size; |
| 9309 | memcpy((void *)cfg->wake_mask, |
| 9310 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9311 | wake_mask_size); |
| 9312 | if (tok) { |
| 9313 | cfg->tokens_size = tokens_size; |
| 9314 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9315 | } |
| 9316 | |
| 9317 | trig->tcp = cfg; |
| 9318 | |
| 9319 | return 0; |
| 9320 | } |
| 9321 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9322 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9323 | const struct wiphy_wowlan_support *wowlan, |
| 9324 | struct nlattr *attr, |
| 9325 | struct cfg80211_wowlan *trig) |
| 9326 | { |
| 9327 | struct nlattr **tb; |
| 9328 | int err; |
| 9329 | |
| 9330 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9331 | if (!tb) |
| 9332 | return -ENOMEM; |
| 9333 | |
| 9334 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9335 | err = -EOPNOTSUPP; |
| 9336 | goto out; |
| 9337 | } |
| 9338 | |
| 9339 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9340 | nla_data(attr), nla_len(attr), |
| 9341 | nl80211_policy); |
| 9342 | if (err) |
| 9343 | goto out; |
| 9344 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9345 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9346 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9347 | if (err) |
| 9348 | trig->nd_config = NULL; |
| 9349 | |
| 9350 | out: |
| 9351 | kfree(tb); |
| 9352 | return err; |
| 9353 | } |
| 9354 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9355 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9356 | { |
| 9357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9358 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9359 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9360 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9361 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9362 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9363 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9364 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9365 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9366 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9367 | return -EOPNOTSUPP; |
| 9368 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9369 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9370 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9371 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9372 | goto set_wakeup; |
| 9373 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9374 | |
| 9375 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9376 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9377 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9378 | nl80211_wowlan_policy); |
| 9379 | if (err) |
| 9380 | return err; |
| 9381 | |
| 9382 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9383 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9384 | return -EINVAL; |
| 9385 | new_triggers.any = true; |
| 9386 | } |
| 9387 | |
| 9388 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9389 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9390 | return -EINVAL; |
| 9391 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9392 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9393 | } |
| 9394 | |
| 9395 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9396 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9397 | return -EINVAL; |
| 9398 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9399 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9400 | } |
| 9401 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9402 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9403 | return -EINVAL; |
| 9404 | |
| 9405 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9406 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9407 | return -EINVAL; |
| 9408 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9409 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9410 | } |
| 9411 | |
| 9412 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9413 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9414 | return -EINVAL; |
| 9415 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9416 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9417 | } |
| 9418 | |
| 9419 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9420 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9421 | return -EINVAL; |
| 9422 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9423 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9424 | } |
| 9425 | |
| 9426 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9427 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9428 | return -EINVAL; |
| 9429 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9430 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9431 | } |
| 9432 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9433 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9434 | struct nlattr *pat; |
| 9435 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9436 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9437 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9438 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9439 | regular = true; |
| 9440 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9441 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9442 | rem) |
| 9443 | n_patterns++; |
| 9444 | if (n_patterns > wowlan->n_patterns) |
| 9445 | return -EINVAL; |
| 9446 | |
| 9447 | new_triggers.patterns = kcalloc(n_patterns, |
| 9448 | sizeof(new_triggers.patterns[0]), |
| 9449 | GFP_KERNEL); |
| 9450 | if (!new_triggers.patterns) |
| 9451 | return -ENOMEM; |
| 9452 | |
| 9453 | new_triggers.n_patterns = n_patterns; |
| 9454 | i = 0; |
| 9455 | |
| 9456 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9457 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9458 | u8 *mask_pat; |
| 9459 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9460 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9461 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9462 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9463 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9464 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9465 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9466 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9467 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9468 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9469 | goto error; |
| 9470 | if (pat_len > wowlan->pattern_max_len || |
| 9471 | pat_len < wowlan->pattern_min_len) |
| 9472 | goto error; |
| 9473 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9474 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9475 | pkt_offset = 0; |
| 9476 | else |
| 9477 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9478 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9479 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9480 | goto error; |
| 9481 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9482 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9483 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9484 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9485 | err = -ENOMEM; |
| 9486 | goto error; |
| 9487 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9488 | new_triggers.patterns[i].mask = mask_pat; |
| 9489 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9490 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9491 | mask_pat += mask_len; |
| 9492 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9493 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9494 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9495 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9496 | pat_len); |
| 9497 | i++; |
| 9498 | } |
| 9499 | } |
| 9500 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9501 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9502 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9503 | err = nl80211_parse_wowlan_tcp( |
| 9504 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9505 | &new_triggers); |
| 9506 | if (err) |
| 9507 | goto error; |
| 9508 | } |
| 9509 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9510 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9511 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9512 | err = nl80211_parse_wowlan_nd( |
| 9513 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9514 | &new_triggers); |
| 9515 | if (err) |
| 9516 | goto error; |
| 9517 | } |
| 9518 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9519 | /* The 'any' trigger means the device continues operating more or less |
| 9520 | * as in its normal operation mode and wakes up the host on most of the |
| 9521 | * normal interrupts (like packet RX, ...) |
| 9522 | * It therefore makes little sense to combine with the more constrained |
| 9523 | * wakeup trigger modes. |
| 9524 | */ |
| 9525 | if (new_triggers.any && regular) { |
| 9526 | err = -EINVAL; |
| 9527 | goto error; |
| 9528 | } |
| 9529 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9530 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9531 | if (!ntrig) { |
| 9532 | err = -ENOMEM; |
| 9533 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9534 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9535 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9536 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9537 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9538 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9539 | if (rdev->ops->set_wakeup && |
| 9540 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9541 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9542 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9543 | return 0; |
| 9544 | error: |
| 9545 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9546 | kfree(new_triggers.patterns[i].mask); |
| 9547 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9548 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9549 | sock_release(new_triggers.tcp->sock); |
| 9550 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 9551 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9552 | return err; |
| 9553 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9554 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9555 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9556 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9557 | struct cfg80211_registered_device *rdev) |
| 9558 | { |
| 9559 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9560 | int i, j, pat_len; |
| 9561 | struct cfg80211_coalesce_rules *rule; |
| 9562 | |
| 9563 | if (!rdev->coalesce->n_rules) |
| 9564 | return 0; |
| 9565 | |
| 9566 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9567 | if (!nl_rules) |
| 9568 | return -ENOBUFS; |
| 9569 | |
| 9570 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9571 | nl_rule = nla_nest_start(msg, i + 1); |
| 9572 | if (!nl_rule) |
| 9573 | return -ENOBUFS; |
| 9574 | |
| 9575 | rule = &rdev->coalesce->rules[i]; |
| 9576 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9577 | rule->delay)) |
| 9578 | return -ENOBUFS; |
| 9579 | |
| 9580 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9581 | rule->condition)) |
| 9582 | return -ENOBUFS; |
| 9583 | |
| 9584 | nl_pats = nla_nest_start(msg, |
| 9585 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9586 | if (!nl_pats) |
| 9587 | return -ENOBUFS; |
| 9588 | |
| 9589 | for (j = 0; j < rule->n_patterns; j++) { |
| 9590 | nl_pat = nla_nest_start(msg, j + 1); |
| 9591 | if (!nl_pat) |
| 9592 | return -ENOBUFS; |
| 9593 | pat_len = rule->patterns[j].pattern_len; |
| 9594 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9595 | DIV_ROUND_UP(pat_len, 8), |
| 9596 | rule->patterns[j].mask) || |
| 9597 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9598 | rule->patterns[j].pattern) || |
| 9599 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9600 | rule->patterns[j].pkt_offset)) |
| 9601 | return -ENOBUFS; |
| 9602 | nla_nest_end(msg, nl_pat); |
| 9603 | } |
| 9604 | nla_nest_end(msg, nl_pats); |
| 9605 | nla_nest_end(msg, nl_rule); |
| 9606 | } |
| 9607 | nla_nest_end(msg, nl_rules); |
| 9608 | |
| 9609 | return 0; |
| 9610 | } |
| 9611 | |
| 9612 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9613 | { |
| 9614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9615 | struct sk_buff *msg; |
| 9616 | void *hdr; |
| 9617 | |
| 9618 | if (!rdev->wiphy.coalesce) |
| 9619 | return -EOPNOTSUPP; |
| 9620 | |
| 9621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9622 | if (!msg) |
| 9623 | return -ENOMEM; |
| 9624 | |
| 9625 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9626 | NL80211_CMD_GET_COALESCE); |
| 9627 | if (!hdr) |
| 9628 | goto nla_put_failure; |
| 9629 | |
| 9630 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9631 | goto nla_put_failure; |
| 9632 | |
| 9633 | genlmsg_end(msg, hdr); |
| 9634 | return genlmsg_reply(msg, info); |
| 9635 | |
| 9636 | nla_put_failure: |
| 9637 | nlmsg_free(msg); |
| 9638 | return -ENOBUFS; |
| 9639 | } |
| 9640 | |
| 9641 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9642 | { |
| 9643 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9644 | int i, j; |
| 9645 | struct cfg80211_coalesce_rules *rule; |
| 9646 | |
| 9647 | if (!coalesce) |
| 9648 | return; |
| 9649 | |
| 9650 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9651 | rule = &coalesce->rules[i]; |
| 9652 | for (j = 0; j < rule->n_patterns; j++) |
| 9653 | kfree(rule->patterns[j].mask); |
| 9654 | kfree(rule->patterns); |
| 9655 | } |
| 9656 | kfree(coalesce->rules); |
| 9657 | kfree(coalesce); |
| 9658 | rdev->coalesce = NULL; |
| 9659 | } |
| 9660 | |
| 9661 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9662 | struct nlattr *rule, |
| 9663 | struct cfg80211_coalesce_rules *new_rule) |
| 9664 | { |
| 9665 | int err, i; |
| 9666 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9667 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9668 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9669 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9670 | |
| 9671 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9672 | nla_len(rule), nl80211_coalesce_policy); |
| 9673 | if (err) |
| 9674 | return err; |
| 9675 | |
| 9676 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9677 | new_rule->delay = |
| 9678 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9679 | if (new_rule->delay > coalesce->max_delay) |
| 9680 | return -EINVAL; |
| 9681 | |
| 9682 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9683 | new_rule->condition = |
| 9684 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9685 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9686 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9687 | return -EINVAL; |
| 9688 | |
| 9689 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9690 | return -EINVAL; |
| 9691 | |
| 9692 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9693 | rem) |
| 9694 | n_patterns++; |
| 9695 | if (n_patterns > coalesce->n_patterns) |
| 9696 | return -EINVAL; |
| 9697 | |
| 9698 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9699 | GFP_KERNEL); |
| 9700 | if (!new_rule->patterns) |
| 9701 | return -ENOMEM; |
| 9702 | |
| 9703 | new_rule->n_patterns = n_patterns; |
| 9704 | i = 0; |
| 9705 | |
| 9706 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9707 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9708 | u8 *mask_pat; |
| 9709 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9710 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9711 | nla_len(pat), NULL); |
| 9712 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9713 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9714 | return -EINVAL; |
| 9715 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9716 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9717 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9718 | return -EINVAL; |
| 9719 | if (pat_len > coalesce->pattern_max_len || |
| 9720 | pat_len < coalesce->pattern_min_len) |
| 9721 | return -EINVAL; |
| 9722 | |
| 9723 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9724 | pkt_offset = 0; |
| 9725 | else |
| 9726 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9727 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9728 | return -EINVAL; |
| 9729 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9730 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9731 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9732 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9733 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9734 | |
| 9735 | new_rule->patterns[i].mask = mask_pat; |
| 9736 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9737 | mask_len); |
| 9738 | |
| 9739 | mask_pat += mask_len; |
| 9740 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9741 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9742 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9743 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9744 | i++; |
| 9745 | } |
| 9746 | |
| 9747 | return 0; |
| 9748 | } |
| 9749 | |
| 9750 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9751 | { |
| 9752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9753 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9754 | struct cfg80211_coalesce new_coalesce = {}; |
| 9755 | struct cfg80211_coalesce *n_coalesce; |
| 9756 | int err, rem_rule, n_rules = 0, i, j; |
| 9757 | struct nlattr *rule; |
| 9758 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9759 | |
| 9760 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9761 | return -EOPNOTSUPP; |
| 9762 | |
| 9763 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9764 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9765 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9766 | return 0; |
| 9767 | } |
| 9768 | |
| 9769 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9770 | rem_rule) |
| 9771 | n_rules++; |
| 9772 | if (n_rules > coalesce->n_rules) |
| 9773 | return -EINVAL; |
| 9774 | |
| 9775 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9776 | GFP_KERNEL); |
| 9777 | if (!new_coalesce.rules) |
| 9778 | return -ENOMEM; |
| 9779 | |
| 9780 | new_coalesce.n_rules = n_rules; |
| 9781 | i = 0; |
| 9782 | |
| 9783 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9784 | rem_rule) { |
| 9785 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9786 | &new_coalesce.rules[i]); |
| 9787 | if (err) |
| 9788 | goto error; |
| 9789 | |
| 9790 | i++; |
| 9791 | } |
| 9792 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9793 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9794 | if (err) |
| 9795 | goto error; |
| 9796 | |
| 9797 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9798 | if (!n_coalesce) { |
| 9799 | err = -ENOMEM; |
| 9800 | goto error; |
| 9801 | } |
| 9802 | cfg80211_rdev_free_coalesce(rdev); |
| 9803 | rdev->coalesce = n_coalesce; |
| 9804 | |
| 9805 | return 0; |
| 9806 | error: |
| 9807 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9808 | tmp_rule = &new_coalesce.rules[i]; |
| 9809 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9810 | kfree(tmp_rule->patterns[j].mask); |
| 9811 | kfree(tmp_rule->patterns); |
| 9812 | } |
| 9813 | kfree(new_coalesce.rules); |
| 9814 | |
| 9815 | return err; |
| 9816 | } |
| 9817 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9818 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9819 | { |
| 9820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9821 | struct net_device *dev = info->user_ptr[1]; |
| 9822 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9823 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9824 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9825 | int err; |
| 9826 | |
| 9827 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9828 | return -EINVAL; |
| 9829 | |
| 9830 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9831 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9832 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9833 | nl80211_rekey_policy); |
| 9834 | if (err) |
| 9835 | return err; |
| 9836 | |
| 9837 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9838 | return -ERANGE; |
| 9839 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9840 | return -ERANGE; |
| 9841 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9842 | return -ERANGE; |
| 9843 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9844 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9845 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9846 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9847 | |
| 9848 | wdev_lock(wdev); |
| 9849 | if (!wdev->current_bss) { |
| 9850 | err = -ENOTCONN; |
| 9851 | goto out; |
| 9852 | } |
| 9853 | |
| 9854 | if (!rdev->ops->set_rekey_data) { |
| 9855 | err = -EOPNOTSUPP; |
| 9856 | goto out; |
| 9857 | } |
| 9858 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9859 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9860 | out: |
| 9861 | wdev_unlock(wdev); |
| 9862 | return err; |
| 9863 | } |
| 9864 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9865 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9866 | struct genl_info *info) |
| 9867 | { |
| 9868 | struct net_device *dev = info->user_ptr[1]; |
| 9869 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9870 | |
| 9871 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9872 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9873 | return -EINVAL; |
| 9874 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9875 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9876 | return -EBUSY; |
| 9877 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9878 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9879 | return 0; |
| 9880 | } |
| 9881 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9882 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9883 | struct genl_info *info) |
| 9884 | { |
| 9885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9886 | struct net_device *dev = info->user_ptr[1]; |
| 9887 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9888 | struct sk_buff *msg; |
| 9889 | void *hdr; |
| 9890 | const u8 *addr; |
| 9891 | u64 cookie; |
| 9892 | int err; |
| 9893 | |
| 9894 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9895 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9896 | return -EOPNOTSUPP; |
| 9897 | |
| 9898 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9899 | return -EINVAL; |
| 9900 | |
| 9901 | if (!rdev->ops->probe_client) |
| 9902 | return -EOPNOTSUPP; |
| 9903 | |
| 9904 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9905 | if (!msg) |
| 9906 | return -ENOMEM; |
| 9907 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9908 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9909 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9910 | if (!hdr) { |
| 9911 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9912 | goto free_msg; |
| 9913 | } |
| 9914 | |
| 9915 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9916 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9917 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9918 | if (err) |
| 9919 | goto free_msg; |
| 9920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9921 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9922 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9923 | |
| 9924 | genlmsg_end(msg, hdr); |
| 9925 | |
| 9926 | return genlmsg_reply(msg, info); |
| 9927 | |
| 9928 | nla_put_failure: |
| 9929 | err = -ENOBUFS; |
| 9930 | free_msg: |
| 9931 | nlmsg_free(msg); |
| 9932 | return err; |
| 9933 | } |
| 9934 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9935 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9936 | { |
| 9937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9938 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9939 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9940 | |
| 9941 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9942 | return -EOPNOTSUPP; |
| 9943 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9944 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9945 | if (!nreg) |
| 9946 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9947 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9948 | /* First, check if already registered. */ |
| 9949 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9950 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9951 | if (reg->nlportid == info->snd_portid) { |
| 9952 | rv = -EALREADY; |
| 9953 | goto out_err; |
| 9954 | } |
| 9955 | } |
| 9956 | /* Add it to the list */ |
| 9957 | nreg->nlportid = info->snd_portid; |
| 9958 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9959 | |
| 9960 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9961 | |
| 9962 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9963 | out_err: |
| 9964 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9965 | kfree(nreg); |
| 9966 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9967 | } |
| 9968 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9969 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9970 | { |
| 9971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9972 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9973 | int err; |
| 9974 | |
| 9975 | if (!rdev->ops->start_p2p_device) |
| 9976 | return -EOPNOTSUPP; |
| 9977 | |
| 9978 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9979 | return -EOPNOTSUPP; |
| 9980 | |
| 9981 | if (wdev->p2p_started) |
| 9982 | return 0; |
| 9983 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9984 | if (rfkill_blocked(rdev->rfkill)) |
| 9985 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9986 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9987 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9988 | if (err) |
| 9989 | return err; |
| 9990 | |
| 9991 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9992 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9993 | |
| 9994 | return 0; |
| 9995 | } |
| 9996 | |
| 9997 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9998 | { |
| 9999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10000 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10001 | |
| 10002 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10003 | return -EOPNOTSUPP; |
| 10004 | |
| 10005 | if (!rdev->ops->stop_p2p_device) |
| 10006 | return -EOPNOTSUPP; |
| 10007 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10008 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10009 | |
| 10010 | return 0; |
| 10011 | } |
| 10012 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10013 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 10014 | struct genl_info *info) |
| 10015 | { |
| 10016 | void *hdr; |
| 10017 | struct sk_buff *msg; |
| 10018 | |
| 10019 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10020 | if (!msg) |
| 10021 | return -ENOMEM; |
| 10022 | |
| 10023 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10024 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 10025 | if (!hdr) |
| 10026 | goto nla_put_failure; |
| 10027 | |
| 10028 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 10029 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 10030 | goto nla_put_failure; |
| 10031 | |
| 10032 | genlmsg_end(msg, hdr); |
| 10033 | return genlmsg_reply(msg, info); |
| 10034 | |
| 10035 | nla_put_failure: |
| 10036 | kfree_skb(msg); |
| 10037 | return -ENOBUFS; |
| 10038 | } |
| 10039 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10040 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 10041 | { |
| 10042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10043 | struct cfg80211_update_ft_ies_params ft_params; |
| 10044 | struct net_device *dev = info->user_ptr[1]; |
| 10045 | |
| 10046 | if (!rdev->ops->update_ft_ies) |
| 10047 | return -EOPNOTSUPP; |
| 10048 | |
| 10049 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 10050 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 10051 | return -EINVAL; |
| 10052 | |
| 10053 | memset(&ft_params, 0, sizeof(ft_params)); |
| 10054 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 10055 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10056 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10057 | |
| 10058 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 10059 | } |
| 10060 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10061 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 10062 | struct genl_info *info) |
| 10063 | { |
| 10064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10065 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10066 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 10067 | u16 duration; |
| 10068 | int ret; |
| 10069 | |
| 10070 | if (!rdev->ops->crit_proto_start) |
| 10071 | return -EOPNOTSUPP; |
| 10072 | |
| 10073 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 10074 | return -EINVAL; |
| 10075 | |
| 10076 | if (rdev->crit_proto_nlportid) |
| 10077 | return -EBUSY; |
| 10078 | |
| 10079 | /* determine protocol if provided */ |
| 10080 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 10081 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 10082 | |
| 10083 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 10084 | return -EINVAL; |
| 10085 | |
| 10086 | /* timeout must be provided */ |
| 10087 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 10088 | return -EINVAL; |
| 10089 | |
| 10090 | duration = |
| 10091 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 10092 | |
| 10093 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 10094 | return -ERANGE; |
| 10095 | |
| 10096 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 10097 | if (!ret) |
| 10098 | rdev->crit_proto_nlportid = info->snd_portid; |
| 10099 | |
| 10100 | return ret; |
| 10101 | } |
| 10102 | |
| 10103 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 10104 | struct genl_info *info) |
| 10105 | { |
| 10106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10107 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10108 | |
| 10109 | if (!rdev->ops->crit_proto_stop) |
| 10110 | return -EOPNOTSUPP; |
| 10111 | |
| 10112 | if (rdev->crit_proto_nlportid) { |
| 10113 | rdev->crit_proto_nlportid = 0; |
| 10114 | rdev_crit_proto_stop(rdev, wdev); |
| 10115 | } |
| 10116 | return 0; |
| 10117 | } |
| 10118 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10119 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 10120 | { |
| 10121 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10122 | struct wireless_dev *wdev = |
| 10123 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10124 | int i, err; |
| 10125 | u32 vid, subcmd; |
| 10126 | |
| 10127 | if (!rdev->wiphy.vendor_commands) |
| 10128 | return -EOPNOTSUPP; |
| 10129 | |
| 10130 | if (IS_ERR(wdev)) { |
| 10131 | err = PTR_ERR(wdev); |
| 10132 | if (err != -EINVAL) |
| 10133 | return err; |
| 10134 | wdev = NULL; |
| 10135 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10136 | return -EINVAL; |
| 10137 | } |
| 10138 | |
| 10139 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 10140 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 10141 | return -EINVAL; |
| 10142 | |
| 10143 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 10144 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10145 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 10146 | const struct wiphy_vendor_command *vcmd; |
| 10147 | void *data = NULL; |
| 10148 | int len = 0; |
| 10149 | |
| 10150 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 10151 | |
| 10152 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10153 | continue; |
| 10154 | |
| 10155 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10156 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10157 | if (!wdev) |
| 10158 | return -EINVAL; |
| 10159 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10160 | !wdev->netdev) |
| 10161 | return -EINVAL; |
| 10162 | |
| 10163 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10164 | if (wdev->netdev && |
| 10165 | !netif_running(wdev->netdev)) |
| 10166 | return -ENETDOWN; |
| 10167 | if (!wdev->netdev && !wdev->p2p_started) |
| 10168 | return -ENETDOWN; |
| 10169 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10170 | |
| 10171 | if (!vcmd->doit) |
| 10172 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10173 | } else { |
| 10174 | wdev = NULL; |
| 10175 | } |
| 10176 | |
| 10177 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 10178 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10179 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10180 | } |
| 10181 | |
| 10182 | rdev->cur_cmd_info = info; |
| 10183 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 10184 | data, len); |
| 10185 | rdev->cur_cmd_info = NULL; |
| 10186 | return err; |
| 10187 | } |
| 10188 | |
| 10189 | return -EOPNOTSUPP; |
| 10190 | } |
| 10191 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10192 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 10193 | struct netlink_callback *cb, |
| 10194 | struct cfg80211_registered_device **rdev, |
| 10195 | struct wireless_dev **wdev) |
| 10196 | { |
| 10197 | u32 vid, subcmd; |
| 10198 | unsigned int i; |
| 10199 | int vcmd_idx = -1; |
| 10200 | int err; |
| 10201 | void *data = NULL; |
| 10202 | unsigned int data_len = 0; |
| 10203 | |
| 10204 | rtnl_lock(); |
| 10205 | |
| 10206 | if (cb->args[0]) { |
| 10207 | /* subtract the 1 again here */ |
| 10208 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 10209 | struct wireless_dev *tmp; |
| 10210 | |
| 10211 | if (!wiphy) { |
| 10212 | err = -ENODEV; |
| 10213 | goto out_unlock; |
| 10214 | } |
| 10215 | *rdev = wiphy_to_rdev(wiphy); |
| 10216 | *wdev = NULL; |
| 10217 | |
| 10218 | if (cb->args[1]) { |
| 10219 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 10220 | if (tmp->identifier == cb->args[1] - 1) { |
| 10221 | *wdev = tmp; |
| 10222 | break; |
| 10223 | } |
| 10224 | } |
| 10225 | } |
| 10226 | |
| 10227 | /* keep rtnl locked in successful case */ |
| 10228 | return 0; |
| 10229 | } |
| 10230 | |
| 10231 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10232 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 10233 | nl80211_policy); |
| 10234 | if (err) |
| 10235 | goto out_unlock; |
| 10236 | |
| 10237 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 10238 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 10239 | err = -EINVAL; |
| 10240 | goto out_unlock; |
| 10241 | } |
| 10242 | |
| 10243 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 10244 | nl80211_fam.attrbuf); |
| 10245 | if (IS_ERR(*wdev)) |
| 10246 | *wdev = NULL; |
| 10247 | |
| 10248 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 10249 | nl80211_fam.attrbuf); |
| 10250 | if (IS_ERR(*rdev)) { |
| 10251 | err = PTR_ERR(*rdev); |
| 10252 | goto out_unlock; |
| 10253 | } |
| 10254 | |
| 10255 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 10256 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10257 | |
| 10258 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 10259 | const struct wiphy_vendor_command *vcmd; |
| 10260 | |
| 10261 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 10262 | |
| 10263 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10264 | continue; |
| 10265 | |
| 10266 | if (!vcmd->dumpit) { |
| 10267 | err = -EOPNOTSUPP; |
| 10268 | goto out_unlock; |
| 10269 | } |
| 10270 | |
| 10271 | vcmd_idx = i; |
| 10272 | break; |
| 10273 | } |
| 10274 | |
| 10275 | if (vcmd_idx < 0) { |
| 10276 | err = -EOPNOTSUPP; |
| 10277 | goto out_unlock; |
| 10278 | } |
| 10279 | |
| 10280 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 10281 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10282 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10283 | } |
| 10284 | |
| 10285 | /* 0 is the first index - add 1 to parse only once */ |
| 10286 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 10287 | /* add 1 to know if it was NULL */ |
| 10288 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 10289 | cb->args[2] = vcmd_idx; |
| 10290 | cb->args[3] = (unsigned long)data; |
| 10291 | cb->args[4] = data_len; |
| 10292 | |
| 10293 | /* keep rtnl locked in successful case */ |
| 10294 | return 0; |
| 10295 | out_unlock: |
| 10296 | rtnl_unlock(); |
| 10297 | return err; |
| 10298 | } |
| 10299 | |
| 10300 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 10301 | struct netlink_callback *cb) |
| 10302 | { |
| 10303 | struct cfg80211_registered_device *rdev; |
| 10304 | struct wireless_dev *wdev; |
| 10305 | unsigned int vcmd_idx; |
| 10306 | const struct wiphy_vendor_command *vcmd; |
| 10307 | void *data; |
| 10308 | int data_len; |
| 10309 | int err; |
| 10310 | struct nlattr *vendor_data; |
| 10311 | |
| 10312 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 10313 | if (err) |
| 10314 | return err; |
| 10315 | |
| 10316 | vcmd_idx = cb->args[2]; |
| 10317 | data = (void *)cb->args[3]; |
| 10318 | data_len = cb->args[4]; |
| 10319 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 10320 | |
| 10321 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10322 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10323 | if (!wdev) |
| 10324 | return -EINVAL; |
| 10325 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10326 | !wdev->netdev) |
| 10327 | return -EINVAL; |
| 10328 | |
| 10329 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10330 | if (wdev->netdev && |
| 10331 | !netif_running(wdev->netdev)) |
| 10332 | return -ENETDOWN; |
| 10333 | if (!wdev->netdev && !wdev->p2p_started) |
| 10334 | return -ENETDOWN; |
| 10335 | } |
| 10336 | } |
| 10337 | |
| 10338 | while (1) { |
| 10339 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10340 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10341 | NL80211_CMD_VENDOR); |
| 10342 | if (!hdr) |
| 10343 | break; |
| 10344 | |
| 10345 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10346 | (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 10347 | wdev_id(wdev)))) { |
| 10348 | genlmsg_cancel(skb, hdr); |
| 10349 | break; |
| 10350 | } |
| 10351 | |
| 10352 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 10353 | if (!vendor_data) { |
| 10354 | genlmsg_cancel(skb, hdr); |
| 10355 | break; |
| 10356 | } |
| 10357 | |
| 10358 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 10359 | (unsigned long *)&cb->args[5]); |
| 10360 | nla_nest_end(skb, vendor_data); |
| 10361 | |
| 10362 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10363 | genlmsg_cancel(skb, hdr); |
| 10364 | break; |
| 10365 | } else if (err) { |
| 10366 | genlmsg_cancel(skb, hdr); |
| 10367 | goto out; |
| 10368 | } |
| 10369 | |
| 10370 | genlmsg_end(skb, hdr); |
| 10371 | } |
| 10372 | |
| 10373 | err = skb->len; |
| 10374 | out: |
| 10375 | rtnl_unlock(); |
| 10376 | return err; |
| 10377 | } |
| 10378 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10379 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 10380 | enum nl80211_commands cmd, |
| 10381 | enum nl80211_attrs attr, |
| 10382 | int approxlen) |
| 10383 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10384 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10385 | |
| 10386 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 10387 | return NULL; |
| 10388 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10389 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10390 | rdev->cur_cmd_info->snd_portid, |
| 10391 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10392 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10393 | } |
| 10394 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 10395 | |
| 10396 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 10397 | { |
| 10398 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10399 | void *hdr = ((void **)skb->cb)[1]; |
| 10400 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10401 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10402 | /* clear CB data for netlink core to own from now on */ |
| 10403 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10404 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10405 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 10406 | kfree_skb(skb); |
| 10407 | return -EINVAL; |
| 10408 | } |
| 10409 | |
| 10410 | nla_nest_end(skb, data); |
| 10411 | genlmsg_end(skb, hdr); |
| 10412 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 10413 | } |
| 10414 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 10415 | |
| 10416 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10417 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 10418 | struct genl_info *info) |
| 10419 | { |
| 10420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10421 | struct cfg80211_qos_map *qos_map = NULL; |
| 10422 | struct net_device *dev = info->user_ptr[1]; |
| 10423 | u8 *pos, len, num_des, des_len, des; |
| 10424 | int ret; |
| 10425 | |
| 10426 | if (!rdev->ops->set_qos_map) |
| 10427 | return -EOPNOTSUPP; |
| 10428 | |
| 10429 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10430 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10431 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10432 | |
| 10433 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10434 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10435 | return -EINVAL; |
| 10436 | |
| 10437 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10438 | if (!qos_map) |
| 10439 | return -ENOMEM; |
| 10440 | |
| 10441 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10442 | if (num_des) { |
| 10443 | des_len = num_des * |
| 10444 | sizeof(struct cfg80211_dscp_exception); |
| 10445 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10446 | qos_map->num_des = num_des; |
| 10447 | for (des = 0; des < num_des; des++) { |
| 10448 | if (qos_map->dscp_exception[des].up > 7) { |
| 10449 | kfree(qos_map); |
| 10450 | return -EINVAL; |
| 10451 | } |
| 10452 | } |
| 10453 | pos += des_len; |
| 10454 | } |
| 10455 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10456 | } |
| 10457 | |
| 10458 | wdev_lock(dev->ieee80211_ptr); |
| 10459 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10460 | if (!ret) |
| 10461 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10462 | wdev_unlock(dev->ieee80211_ptr); |
| 10463 | |
| 10464 | kfree(qos_map); |
| 10465 | return ret; |
| 10466 | } |
| 10467 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10468 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10469 | { |
| 10470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10471 | struct net_device *dev = info->user_ptr[1]; |
| 10472 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10473 | const u8 *peer; |
| 10474 | u8 tsid, up; |
| 10475 | u16 admitted_time = 0; |
| 10476 | int err; |
| 10477 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10478 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10479 | return -EOPNOTSUPP; |
| 10480 | |
| 10481 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10482 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10483 | return -EINVAL; |
| 10484 | |
| 10485 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10486 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10487 | return -EINVAL; |
| 10488 | |
| 10489 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10490 | if (up >= IEEE80211_NUM_UPS) |
| 10491 | return -EINVAL; |
| 10492 | |
| 10493 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10494 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10495 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10496 | * need more attributes for that (e.g. BA session requirement); |
| 10497 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10498 | */ |
| 10499 | return -EINVAL; |
| 10500 | } |
| 10501 | |
| 10502 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10503 | |
| 10504 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10505 | admitted_time = |
| 10506 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10507 | if (!admitted_time) |
| 10508 | return -EINVAL; |
| 10509 | } |
| 10510 | |
| 10511 | wdev_lock(wdev); |
| 10512 | switch (wdev->iftype) { |
| 10513 | case NL80211_IFTYPE_STATION: |
| 10514 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10515 | if (wdev->current_bss) |
| 10516 | break; |
| 10517 | err = -ENOTCONN; |
| 10518 | goto out; |
| 10519 | default: |
| 10520 | err = -EOPNOTSUPP; |
| 10521 | goto out; |
| 10522 | } |
| 10523 | |
| 10524 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10525 | |
| 10526 | out: |
| 10527 | wdev_unlock(wdev); |
| 10528 | return err; |
| 10529 | } |
| 10530 | |
| 10531 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10532 | { |
| 10533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10534 | struct net_device *dev = info->user_ptr[1]; |
| 10535 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10536 | const u8 *peer; |
| 10537 | u8 tsid; |
| 10538 | int err; |
| 10539 | |
| 10540 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10541 | return -EINVAL; |
| 10542 | |
| 10543 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10544 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10545 | |
| 10546 | wdev_lock(wdev); |
| 10547 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10548 | wdev_unlock(wdev); |
| 10549 | |
| 10550 | return err; |
| 10551 | } |
| 10552 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10553 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10554 | struct genl_info *info) |
| 10555 | { |
| 10556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10557 | struct net_device *dev = info->user_ptr[1]; |
| 10558 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10559 | struct cfg80211_chan_def chandef = {}; |
| 10560 | const u8 *addr; |
| 10561 | u8 oper_class; |
| 10562 | int err; |
| 10563 | |
| 10564 | if (!rdev->ops->tdls_channel_switch || |
| 10565 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10566 | return -EOPNOTSUPP; |
| 10567 | |
| 10568 | switch (dev->ieee80211_ptr->iftype) { |
| 10569 | case NL80211_IFTYPE_STATION: |
| 10570 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10571 | break; |
| 10572 | default: |
| 10573 | return -EOPNOTSUPP; |
| 10574 | } |
| 10575 | |
| 10576 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10577 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10578 | return -EINVAL; |
| 10579 | |
| 10580 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10581 | if (err) |
| 10582 | return err; |
| 10583 | |
| 10584 | /* |
| 10585 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10586 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10587 | * specification is not defined for them. |
| 10588 | */ |
| 10589 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 10590 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10591 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10592 | return -EINVAL; |
| 10593 | |
| 10594 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10595 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10596 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10597 | return -EINVAL; |
| 10598 | |
| 10599 | /* don't allow switching to DFS channels */ |
| 10600 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10601 | return -EINVAL; |
| 10602 | |
| 10603 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10604 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10605 | |
| 10606 | wdev_lock(wdev); |
| 10607 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10608 | wdev_unlock(wdev); |
| 10609 | |
| 10610 | return err; |
| 10611 | } |
| 10612 | |
| 10613 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10614 | struct genl_info *info) |
| 10615 | { |
| 10616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10617 | struct net_device *dev = info->user_ptr[1]; |
| 10618 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10619 | const u8 *addr; |
| 10620 | |
| 10621 | if (!rdev->ops->tdls_channel_switch || |
| 10622 | !rdev->ops->tdls_cancel_channel_switch || |
| 10623 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10624 | return -EOPNOTSUPP; |
| 10625 | |
| 10626 | switch (dev->ieee80211_ptr->iftype) { |
| 10627 | case NL80211_IFTYPE_STATION: |
| 10628 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10629 | break; |
| 10630 | default: |
| 10631 | return -EOPNOTSUPP; |
| 10632 | } |
| 10633 | |
| 10634 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10635 | return -EINVAL; |
| 10636 | |
| 10637 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10638 | |
| 10639 | wdev_lock(wdev); |
| 10640 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10641 | wdev_unlock(wdev); |
| 10642 | |
| 10643 | return 0; |
| 10644 | } |
| 10645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10646 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10647 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10648 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10649 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10650 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10651 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10652 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10653 | /* 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] | 10654 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10655 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10656 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10657 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10658 | 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] | 10659 | struct genl_info *info) |
| 10660 | { |
| 10661 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10662 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10663 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10664 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10665 | |
| 10666 | if (rtnl) |
| 10667 | rtnl_lock(); |
| 10668 | |
| 10669 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10670 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10671 | if (IS_ERR(rdev)) { |
| 10672 | if (rtnl) |
| 10673 | rtnl_unlock(); |
| 10674 | return PTR_ERR(rdev); |
| 10675 | } |
| 10676 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10677 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10678 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10679 | ASSERT_RTNL(); |
| 10680 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10681 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10682 | info->attrs); |
| 10683 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10684 | if (rtnl) |
| 10685 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10686 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10687 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10688 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10689 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10690 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10691 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10692 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10693 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10694 | if (rtnl) |
| 10695 | rtnl_unlock(); |
| 10696 | return -EINVAL; |
| 10697 | } |
| 10698 | |
| 10699 | info->user_ptr[1] = dev; |
| 10700 | } else { |
| 10701 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10702 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10703 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10704 | if (dev) { |
| 10705 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10706 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10707 | if (rtnl) |
| 10708 | rtnl_unlock(); |
| 10709 | return -ENETDOWN; |
| 10710 | } |
| 10711 | |
| 10712 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10713 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10714 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10715 | if (rtnl) |
| 10716 | rtnl_unlock(); |
| 10717 | return -ENETDOWN; |
| 10718 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10719 | } |
| 10720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10721 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10722 | } |
| 10723 | |
| 10724 | return 0; |
| 10725 | } |
| 10726 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10727 | 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] | 10728 | struct genl_info *info) |
| 10729 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10730 | if (info->user_ptr[1]) { |
| 10731 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10732 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10733 | |
| 10734 | if (wdev->netdev) |
| 10735 | dev_put(wdev->netdev); |
| 10736 | } else { |
| 10737 | dev_put(info->user_ptr[1]); |
| 10738 | } |
| 10739 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10740 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10741 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10742 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10743 | |
| 10744 | /* If needed, clear the netlink message payload from the SKB |
| 10745 | * as it might contain key data that shouldn't stick around on |
| 10746 | * the heap after the SKB is freed. The netlink message header |
| 10747 | * is still needed for further processing, so leave it intact. |
| 10748 | */ |
| 10749 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10750 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10751 | |
| 10752 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10753 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10754 | } |
| 10755 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10756 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10757 | { |
| 10758 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10759 | .doit = nl80211_get_wiphy, |
| 10760 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10761 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10762 | .policy = nl80211_policy, |
| 10763 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10764 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10765 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10766 | }, |
| 10767 | { |
| 10768 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10769 | .doit = nl80211_set_wiphy, |
| 10770 | .policy = nl80211_policy, |
| 10771 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10772 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10773 | }, |
| 10774 | { |
| 10775 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10776 | .doit = nl80211_get_interface, |
| 10777 | .dumpit = nl80211_dump_interface, |
| 10778 | .policy = nl80211_policy, |
| 10779 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10780 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10781 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10782 | }, |
| 10783 | { |
| 10784 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10785 | .doit = nl80211_set_interface, |
| 10786 | .policy = nl80211_policy, |
| 10787 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10788 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10789 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10790 | }, |
| 10791 | { |
| 10792 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10793 | .doit = nl80211_new_interface, |
| 10794 | .policy = nl80211_policy, |
| 10795 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10796 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10797 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10798 | }, |
| 10799 | { |
| 10800 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10801 | .doit = nl80211_del_interface, |
| 10802 | .policy = nl80211_policy, |
| 10803 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10804 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10805 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10806 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10807 | { |
| 10808 | .cmd = NL80211_CMD_GET_KEY, |
| 10809 | .doit = nl80211_get_key, |
| 10810 | .policy = nl80211_policy, |
| 10811 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10813 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10814 | }, |
| 10815 | { |
| 10816 | .cmd = NL80211_CMD_SET_KEY, |
| 10817 | .doit = nl80211_set_key, |
| 10818 | .policy = nl80211_policy, |
| 10819 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10821 | NL80211_FLAG_NEED_RTNL | |
| 10822 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10823 | }, |
| 10824 | { |
| 10825 | .cmd = NL80211_CMD_NEW_KEY, |
| 10826 | .doit = nl80211_new_key, |
| 10827 | .policy = nl80211_policy, |
| 10828 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10829 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10830 | NL80211_FLAG_NEED_RTNL | |
| 10831 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10832 | }, |
| 10833 | { |
| 10834 | .cmd = NL80211_CMD_DEL_KEY, |
| 10835 | .doit = nl80211_del_key, |
| 10836 | .policy = nl80211_policy, |
| 10837 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10838 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10839 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10840 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10841 | { |
| 10842 | .cmd = NL80211_CMD_SET_BEACON, |
| 10843 | .policy = nl80211_policy, |
| 10844 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10845 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10847 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10848 | }, |
| 10849 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10850 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10851 | .policy = nl80211_policy, |
| 10852 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10853 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10855 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10856 | }, |
| 10857 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10858 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10859 | .policy = nl80211_policy, |
| 10860 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10861 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10863 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10864 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10865 | { |
| 10866 | .cmd = NL80211_CMD_GET_STATION, |
| 10867 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10868 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10869 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10870 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10871 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10872 | }, |
| 10873 | { |
| 10874 | .cmd = NL80211_CMD_SET_STATION, |
| 10875 | .doit = nl80211_set_station, |
| 10876 | .policy = nl80211_policy, |
| 10877 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10879 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10880 | }, |
| 10881 | { |
| 10882 | .cmd = NL80211_CMD_NEW_STATION, |
| 10883 | .doit = nl80211_new_station, |
| 10884 | .policy = nl80211_policy, |
| 10885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10887 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10888 | }, |
| 10889 | { |
| 10890 | .cmd = NL80211_CMD_DEL_STATION, |
| 10891 | .doit = nl80211_del_station, |
| 10892 | .policy = nl80211_policy, |
| 10893 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10894 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10895 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10896 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10897 | { |
| 10898 | .cmd = NL80211_CMD_GET_MPATH, |
| 10899 | .doit = nl80211_get_mpath, |
| 10900 | .dumpit = nl80211_dump_mpath, |
| 10901 | .policy = nl80211_policy, |
| 10902 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10903 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10904 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10905 | }, |
| 10906 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10907 | .cmd = NL80211_CMD_GET_MPP, |
| 10908 | .doit = nl80211_get_mpp, |
| 10909 | .dumpit = nl80211_dump_mpp, |
| 10910 | .policy = nl80211_policy, |
| 10911 | .flags = GENL_ADMIN_PERM, |
| 10912 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10913 | NL80211_FLAG_NEED_RTNL, |
| 10914 | }, |
| 10915 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10916 | .cmd = NL80211_CMD_SET_MPATH, |
| 10917 | .doit = nl80211_set_mpath, |
| 10918 | .policy = nl80211_policy, |
| 10919 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10920 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10921 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10922 | }, |
| 10923 | { |
| 10924 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10925 | .doit = nl80211_new_mpath, |
| 10926 | .policy = nl80211_policy, |
| 10927 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10928 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10929 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10930 | }, |
| 10931 | { |
| 10932 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10933 | .doit = nl80211_del_mpath, |
| 10934 | .policy = nl80211_policy, |
| 10935 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10936 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10937 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10938 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10939 | { |
| 10940 | .cmd = NL80211_CMD_SET_BSS, |
| 10941 | .doit = nl80211_set_bss, |
| 10942 | .policy = nl80211_policy, |
| 10943 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10944 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10945 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10946 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10947 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10948 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10949 | .doit = nl80211_get_reg_do, |
| 10950 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10951 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10952 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10953 | /* can be retrieved by unprivileged users */ |
| 10954 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 10955 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10956 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10957 | .cmd = NL80211_CMD_SET_REG, |
| 10958 | .doit = nl80211_set_reg, |
| 10959 | .policy = nl80211_policy, |
| 10960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10961 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10962 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 10963 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10964 | { |
| 10965 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10966 | .doit = nl80211_req_set_reg, |
| 10967 | .policy = nl80211_policy, |
| 10968 | .flags = GENL_ADMIN_PERM, |
| 10969 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10970 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10971 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10972 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10973 | .policy = nl80211_policy, |
| 10974 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10976 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10977 | }, |
| 10978 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10979 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10980 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10981 | .policy = nl80211_policy, |
| 10982 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10984 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10985 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10986 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10987 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10988 | .doit = nl80211_trigger_scan, |
| 10989 | .policy = nl80211_policy, |
| 10990 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10991 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10992 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10993 | }, |
| 10994 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 10995 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 10996 | .doit = nl80211_abort_scan, |
| 10997 | .policy = nl80211_policy, |
| 10998 | .flags = GENL_ADMIN_PERM, |
| 10999 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11000 | NL80211_FLAG_NEED_RTNL, |
| 11001 | }, |
| 11002 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11003 | .cmd = NL80211_CMD_GET_SCAN, |
| 11004 | .policy = nl80211_policy, |
| 11005 | .dumpit = nl80211_dump_scan, |
| 11006 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11007 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11008 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 11009 | .doit = nl80211_start_sched_scan, |
| 11010 | .policy = nl80211_policy, |
| 11011 | .flags = GENL_ADMIN_PERM, |
| 11012 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11013 | NL80211_FLAG_NEED_RTNL, |
| 11014 | }, |
| 11015 | { |
| 11016 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 11017 | .doit = nl80211_stop_sched_scan, |
| 11018 | .policy = nl80211_policy, |
| 11019 | .flags = GENL_ADMIN_PERM, |
| 11020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11021 | NL80211_FLAG_NEED_RTNL, |
| 11022 | }, |
| 11023 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11024 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 11025 | .doit = nl80211_authenticate, |
| 11026 | .policy = nl80211_policy, |
| 11027 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11028 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11029 | NL80211_FLAG_NEED_RTNL | |
| 11030 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11031 | }, |
| 11032 | { |
| 11033 | .cmd = NL80211_CMD_ASSOCIATE, |
| 11034 | .doit = nl80211_associate, |
| 11035 | .policy = nl80211_policy, |
| 11036 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11037 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11038 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11039 | }, |
| 11040 | { |
| 11041 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 11042 | .doit = nl80211_deauthenticate, |
| 11043 | .policy = nl80211_policy, |
| 11044 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11045 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11046 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11047 | }, |
| 11048 | { |
| 11049 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 11050 | .doit = nl80211_disassociate, |
| 11051 | .policy = nl80211_policy, |
| 11052 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11053 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11054 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11055 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11056 | { |
| 11057 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 11058 | .doit = nl80211_join_ibss, |
| 11059 | .policy = nl80211_policy, |
| 11060 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11061 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11062 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11063 | }, |
| 11064 | { |
| 11065 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 11066 | .doit = nl80211_leave_ibss, |
| 11067 | .policy = nl80211_policy, |
| 11068 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11069 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11070 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11071 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11072 | #ifdef CONFIG_NL80211_TESTMODE |
| 11073 | { |
| 11074 | .cmd = NL80211_CMD_TESTMODE, |
| 11075 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 11076 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11077 | .policy = nl80211_policy, |
| 11078 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11079 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11080 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11081 | }, |
| 11082 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11083 | { |
| 11084 | .cmd = NL80211_CMD_CONNECT, |
| 11085 | .doit = nl80211_connect, |
| 11086 | .policy = nl80211_policy, |
| 11087 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11088 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11089 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11090 | }, |
| 11091 | { |
| 11092 | .cmd = NL80211_CMD_DISCONNECT, |
| 11093 | .doit = nl80211_disconnect, |
| 11094 | .policy = nl80211_policy, |
| 11095 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11096 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11097 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11098 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11099 | { |
| 11100 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 11101 | .doit = nl80211_wiphy_netns, |
| 11102 | .policy = nl80211_policy, |
| 11103 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11104 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11105 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11106 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 11107 | { |
| 11108 | .cmd = NL80211_CMD_GET_SURVEY, |
| 11109 | .policy = nl80211_policy, |
| 11110 | .dumpit = nl80211_dump_survey, |
| 11111 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11112 | { |
| 11113 | .cmd = NL80211_CMD_SET_PMKSA, |
| 11114 | .doit = nl80211_setdel_pmksa, |
| 11115 | .policy = nl80211_policy, |
| 11116 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11118 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11119 | }, |
| 11120 | { |
| 11121 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 11122 | .doit = nl80211_setdel_pmksa, |
| 11123 | .policy = nl80211_policy, |
| 11124 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11125 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11126 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11127 | }, |
| 11128 | { |
| 11129 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 11130 | .doit = nl80211_flush_pmksa, |
| 11131 | .policy = nl80211_policy, |
| 11132 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11133 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11134 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11135 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11136 | { |
| 11137 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 11138 | .doit = nl80211_remain_on_channel, |
| 11139 | .policy = nl80211_policy, |
| 11140 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11141 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11142 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11143 | }, |
| 11144 | { |
| 11145 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 11146 | .doit = nl80211_cancel_remain_on_channel, |
| 11147 | .policy = nl80211_policy, |
| 11148 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11149 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11150 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11151 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11152 | { |
| 11153 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 11154 | .doit = nl80211_set_tx_bitrate_mask, |
| 11155 | .policy = nl80211_policy, |
| 11156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11157 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11158 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11159 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11160 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11161 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 11162 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11163 | .policy = nl80211_policy, |
| 11164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11165 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11166 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11167 | }, |
| 11168 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11169 | .cmd = NL80211_CMD_FRAME, |
| 11170 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11171 | .policy = nl80211_policy, |
| 11172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11173 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11174 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11175 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11176 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11177 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 11178 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 11179 | .policy = nl80211_policy, |
| 11180 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11181 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11182 | NL80211_FLAG_NEED_RTNL, |
| 11183 | }, |
| 11184 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11185 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 11186 | .doit = nl80211_set_power_save, |
| 11187 | .policy = nl80211_policy, |
| 11188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11189 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11190 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11191 | }, |
| 11192 | { |
| 11193 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 11194 | .doit = nl80211_get_power_save, |
| 11195 | .policy = nl80211_policy, |
| 11196 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11197 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11198 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11199 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11200 | { |
| 11201 | .cmd = NL80211_CMD_SET_CQM, |
| 11202 | .doit = nl80211_set_cqm, |
| 11203 | .policy = nl80211_policy, |
| 11204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11205 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11206 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11207 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11208 | { |
| 11209 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 11210 | .doit = nl80211_set_channel, |
| 11211 | .policy = nl80211_policy, |
| 11212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11213 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11214 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11215 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11216 | { |
| 11217 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 11218 | .doit = nl80211_set_wds_peer, |
| 11219 | .policy = nl80211_policy, |
| 11220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 11221 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11222 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11223 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11224 | { |
| 11225 | .cmd = NL80211_CMD_JOIN_MESH, |
| 11226 | .doit = nl80211_join_mesh, |
| 11227 | .policy = nl80211_policy, |
| 11228 | .flags = GENL_ADMIN_PERM, |
| 11229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11230 | NL80211_FLAG_NEED_RTNL, |
| 11231 | }, |
| 11232 | { |
| 11233 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 11234 | .doit = nl80211_leave_mesh, |
| 11235 | .policy = nl80211_policy, |
| 11236 | .flags = GENL_ADMIN_PERM, |
| 11237 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11238 | NL80211_FLAG_NEED_RTNL, |
| 11239 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11240 | { |
| 11241 | .cmd = NL80211_CMD_JOIN_OCB, |
| 11242 | .doit = nl80211_join_ocb, |
| 11243 | .policy = nl80211_policy, |
| 11244 | .flags = GENL_ADMIN_PERM, |
| 11245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11246 | NL80211_FLAG_NEED_RTNL, |
| 11247 | }, |
| 11248 | { |
| 11249 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 11250 | .doit = nl80211_leave_ocb, |
| 11251 | .policy = nl80211_policy, |
| 11252 | .flags = GENL_ADMIN_PERM, |
| 11253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11254 | NL80211_FLAG_NEED_RTNL, |
| 11255 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11256 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11257 | { |
| 11258 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 11259 | .doit = nl80211_get_wowlan, |
| 11260 | .policy = nl80211_policy, |
| 11261 | /* can be retrieved by unprivileged users */ |
| 11262 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11263 | NL80211_FLAG_NEED_RTNL, |
| 11264 | }, |
| 11265 | { |
| 11266 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 11267 | .doit = nl80211_set_wowlan, |
| 11268 | .policy = nl80211_policy, |
| 11269 | .flags = GENL_ADMIN_PERM, |
| 11270 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11271 | NL80211_FLAG_NEED_RTNL, |
| 11272 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11273 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11274 | { |
| 11275 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 11276 | .doit = nl80211_set_rekey_data, |
| 11277 | .policy = nl80211_policy, |
| 11278 | .flags = GENL_ADMIN_PERM, |
| 11279 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11280 | NL80211_FLAG_NEED_RTNL | |
| 11281 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11282 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11283 | { |
| 11284 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 11285 | .doit = nl80211_tdls_mgmt, |
| 11286 | .policy = nl80211_policy, |
| 11287 | .flags = GENL_ADMIN_PERM, |
| 11288 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11289 | NL80211_FLAG_NEED_RTNL, |
| 11290 | }, |
| 11291 | { |
| 11292 | .cmd = NL80211_CMD_TDLS_OPER, |
| 11293 | .doit = nl80211_tdls_oper, |
| 11294 | .policy = nl80211_policy, |
| 11295 | .flags = GENL_ADMIN_PERM, |
| 11296 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11297 | NL80211_FLAG_NEED_RTNL, |
| 11298 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11299 | { |
| 11300 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 11301 | .doit = nl80211_register_unexpected_frame, |
| 11302 | .policy = nl80211_policy, |
| 11303 | .flags = GENL_ADMIN_PERM, |
| 11304 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11305 | NL80211_FLAG_NEED_RTNL, |
| 11306 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11307 | { |
| 11308 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 11309 | .doit = nl80211_probe_client, |
| 11310 | .policy = nl80211_policy, |
| 11311 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11313 | NL80211_FLAG_NEED_RTNL, |
| 11314 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11315 | { |
| 11316 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 11317 | .doit = nl80211_register_beacons, |
| 11318 | .policy = nl80211_policy, |
| 11319 | .flags = GENL_ADMIN_PERM, |
| 11320 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11321 | NL80211_FLAG_NEED_RTNL, |
| 11322 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11323 | { |
| 11324 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 11325 | .doit = nl80211_set_noack_map, |
| 11326 | .policy = nl80211_policy, |
| 11327 | .flags = GENL_ADMIN_PERM, |
| 11328 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11329 | NL80211_FLAG_NEED_RTNL, |
| 11330 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11331 | { |
| 11332 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 11333 | .doit = nl80211_start_p2p_device, |
| 11334 | .policy = nl80211_policy, |
| 11335 | .flags = GENL_ADMIN_PERM, |
| 11336 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11337 | NL80211_FLAG_NEED_RTNL, |
| 11338 | }, |
| 11339 | { |
| 11340 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 11341 | .doit = nl80211_stop_p2p_device, |
| 11342 | .policy = nl80211_policy, |
| 11343 | .flags = GENL_ADMIN_PERM, |
| 11344 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11345 | NL80211_FLAG_NEED_RTNL, |
| 11346 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11347 | { |
| 11348 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 11349 | .doit = nl80211_set_mcast_rate, |
| 11350 | .policy = nl80211_policy, |
| 11351 | .flags = GENL_ADMIN_PERM, |
| 11352 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11353 | NL80211_FLAG_NEED_RTNL, |
| 11354 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11355 | { |
| 11356 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 11357 | .doit = nl80211_set_mac_acl, |
| 11358 | .policy = nl80211_policy, |
| 11359 | .flags = GENL_ADMIN_PERM, |
| 11360 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11361 | NL80211_FLAG_NEED_RTNL, |
| 11362 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11363 | { |
| 11364 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 11365 | .doit = nl80211_start_radar_detection, |
| 11366 | .policy = nl80211_policy, |
| 11367 | .flags = GENL_ADMIN_PERM, |
| 11368 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11369 | NL80211_FLAG_NEED_RTNL, |
| 11370 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11371 | { |
| 11372 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 11373 | .doit = nl80211_get_protocol_features, |
| 11374 | .policy = nl80211_policy, |
| 11375 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11376 | { |
| 11377 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 11378 | .doit = nl80211_update_ft_ies, |
| 11379 | .policy = nl80211_policy, |
| 11380 | .flags = GENL_ADMIN_PERM, |
| 11381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11382 | NL80211_FLAG_NEED_RTNL, |
| 11383 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11384 | { |
| 11385 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 11386 | .doit = nl80211_crit_protocol_start, |
| 11387 | .policy = nl80211_policy, |
| 11388 | .flags = GENL_ADMIN_PERM, |
| 11389 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11390 | NL80211_FLAG_NEED_RTNL, |
| 11391 | }, |
| 11392 | { |
| 11393 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 11394 | .doit = nl80211_crit_protocol_stop, |
| 11395 | .policy = nl80211_policy, |
| 11396 | .flags = GENL_ADMIN_PERM, |
| 11397 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11398 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11399 | }, |
| 11400 | { |
| 11401 | .cmd = NL80211_CMD_GET_COALESCE, |
| 11402 | .doit = nl80211_get_coalesce, |
| 11403 | .policy = nl80211_policy, |
| 11404 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11405 | NL80211_FLAG_NEED_RTNL, |
| 11406 | }, |
| 11407 | { |
| 11408 | .cmd = NL80211_CMD_SET_COALESCE, |
| 11409 | .doit = nl80211_set_coalesce, |
| 11410 | .policy = nl80211_policy, |
| 11411 | .flags = GENL_ADMIN_PERM, |
| 11412 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11413 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11414 | }, |
| 11415 | { |
| 11416 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 11417 | .doit = nl80211_channel_switch, |
| 11418 | .policy = nl80211_policy, |
| 11419 | .flags = GENL_ADMIN_PERM, |
| 11420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11421 | NL80211_FLAG_NEED_RTNL, |
| 11422 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11423 | { |
| 11424 | .cmd = NL80211_CMD_VENDOR, |
| 11425 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11426 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11427 | .policy = nl80211_policy, |
| 11428 | .flags = GENL_ADMIN_PERM, |
| 11429 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11430 | NL80211_FLAG_NEED_RTNL, |
| 11431 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11432 | { |
| 11433 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11434 | .doit = nl80211_set_qos_map, |
| 11435 | .policy = nl80211_policy, |
| 11436 | .flags = GENL_ADMIN_PERM, |
| 11437 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11438 | NL80211_FLAG_NEED_RTNL, |
| 11439 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11440 | { |
| 11441 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11442 | .doit = nl80211_add_tx_ts, |
| 11443 | .policy = nl80211_policy, |
| 11444 | .flags = GENL_ADMIN_PERM, |
| 11445 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11446 | NL80211_FLAG_NEED_RTNL, |
| 11447 | }, |
| 11448 | { |
| 11449 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11450 | .doit = nl80211_del_tx_ts, |
| 11451 | .policy = nl80211_policy, |
| 11452 | .flags = GENL_ADMIN_PERM, |
| 11453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11454 | NL80211_FLAG_NEED_RTNL, |
| 11455 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11456 | { |
| 11457 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11458 | .doit = nl80211_tdls_channel_switch, |
| 11459 | .policy = nl80211_policy, |
| 11460 | .flags = GENL_ADMIN_PERM, |
| 11461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11462 | NL80211_FLAG_NEED_RTNL, |
| 11463 | }, |
| 11464 | { |
| 11465 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11466 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11467 | .policy = nl80211_policy, |
| 11468 | .flags = GENL_ADMIN_PERM, |
| 11469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11470 | NL80211_FLAG_NEED_RTNL, |
| 11471 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11472 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11473 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11474 | /* notification functions */ |
| 11475 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11476 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11477 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11478 | { |
| 11479 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11480 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11481 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11482 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11483 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11484 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11485 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11486 | if (!msg) |
| 11487 | return; |
| 11488 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11489 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11490 | nlmsg_free(msg); |
| 11491 | return; |
| 11492 | } |
| 11493 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11494 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11495 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11496 | } |
| 11497 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11498 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11499 | struct cfg80211_registered_device *rdev) |
| 11500 | { |
| 11501 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11502 | struct nlattr *nest; |
| 11503 | int i; |
| 11504 | |
| 11505 | if (WARN_ON(!req)) |
| 11506 | return 0; |
| 11507 | |
| 11508 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11509 | if (!nest) |
| 11510 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11511 | for (i = 0; i < req->n_ssids; i++) { |
| 11512 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11513 | goto nla_put_failure; |
| 11514 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11515 | nla_nest_end(msg, nest); |
| 11516 | |
| 11517 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11518 | if (!nest) |
| 11519 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11520 | for (i = 0; i < req->n_channels; i++) { |
| 11521 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11522 | goto nla_put_failure; |
| 11523 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11524 | nla_nest_end(msg, nest); |
| 11525 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11526 | if (req->ie && |
| 11527 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11528 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11529 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11530 | if (req->flags && |
| 11531 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11532 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11533 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11534 | return 0; |
| 11535 | nla_put_failure: |
| 11536 | return -ENOBUFS; |
| 11537 | } |
| 11538 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11539 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11540 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11541 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11542 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11543 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11544 | { |
| 11545 | void *hdr; |
| 11546 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11547 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11548 | if (!hdr) |
| 11549 | return -1; |
| 11550 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11551 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11552 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11553 | wdev->netdev->ifindex)) || |
| 11554 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11555 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11556 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11557 | /* ignore errors and send incomplete event anyway */ |
| 11558 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11559 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11560 | genlmsg_end(msg, hdr); |
| 11561 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11562 | |
| 11563 | nla_put_failure: |
| 11564 | genlmsg_cancel(msg, hdr); |
| 11565 | return -EMSGSIZE; |
| 11566 | } |
| 11567 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11568 | static int |
| 11569 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11570 | struct cfg80211_registered_device *rdev, |
| 11571 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11572 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11573 | { |
| 11574 | void *hdr; |
| 11575 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11576 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11577 | if (!hdr) |
| 11578 | return -1; |
| 11579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11580 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11581 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11582 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11583 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11584 | genlmsg_end(msg, hdr); |
| 11585 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11586 | |
| 11587 | nla_put_failure: |
| 11588 | genlmsg_cancel(msg, hdr); |
| 11589 | return -EMSGSIZE; |
| 11590 | } |
| 11591 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11592 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11593 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11594 | { |
| 11595 | struct sk_buff *msg; |
| 11596 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11597 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11598 | if (!msg) |
| 11599 | return; |
| 11600 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11601 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11602 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11603 | nlmsg_free(msg); |
| 11604 | return; |
| 11605 | } |
| 11606 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11607 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11608 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11609 | } |
| 11610 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11611 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11612 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11613 | { |
| 11614 | struct sk_buff *msg; |
| 11615 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11617 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11618 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11619 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11620 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11621 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11622 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11623 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11624 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11625 | } |
| 11626 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11627 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11628 | } |
| 11629 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11630 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11631 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11632 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11633 | if (!msg) |
| 11634 | return; |
| 11635 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11636 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11637 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11638 | } |
| 11639 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11640 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11641 | struct net_device *netdev) |
| 11642 | { |
| 11643 | struct sk_buff *msg; |
| 11644 | |
| 11645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11646 | if (!msg) |
| 11647 | return; |
| 11648 | |
| 11649 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11650 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11651 | nlmsg_free(msg); |
| 11652 | return; |
| 11653 | } |
| 11654 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11655 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11656 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11657 | } |
| 11658 | |
| 11659 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11660 | struct net_device *netdev, u32 cmd) |
| 11661 | { |
| 11662 | struct sk_buff *msg; |
| 11663 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11665 | if (!msg) |
| 11666 | return; |
| 11667 | |
| 11668 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11669 | nlmsg_free(msg); |
| 11670 | return; |
| 11671 | } |
| 11672 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11673 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11674 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11675 | } |
| 11676 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11677 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11678 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11679 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11680 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11681 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11682 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11684 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11685 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11686 | NL80211_REGDOM_TYPE_WORLD)) |
| 11687 | goto nla_put_failure; |
| 11688 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11689 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11690 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11691 | goto nla_put_failure; |
| 11692 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11693 | request->intersect) { |
| 11694 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11695 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11696 | goto nla_put_failure; |
| 11697 | } else { |
| 11698 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11699 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11700 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11701 | request->alpha2)) |
| 11702 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11703 | } |
| 11704 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11705 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11706 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11707 | |
| 11708 | if (wiphy && |
| 11709 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11710 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 11711 | |
| 11712 | if (wiphy && |
| 11713 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 11714 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 11715 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11716 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11717 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11718 | return true; |
| 11719 | |
| 11720 | nla_put_failure: |
| 11721 | return false; |
| 11722 | } |
| 11723 | |
| 11724 | /* |
| 11725 | * This can happen on global regulatory changes or device specific settings |
| 11726 | * based on custom regulatory domains. |
| 11727 | */ |
| 11728 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11729 | struct regulatory_request *request) |
| 11730 | { |
| 11731 | struct sk_buff *msg; |
| 11732 | void *hdr; |
| 11733 | |
| 11734 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11735 | if (!msg) |
| 11736 | return; |
| 11737 | |
| 11738 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11739 | if (!hdr) { |
| 11740 | nlmsg_free(msg); |
| 11741 | return; |
| 11742 | } |
| 11743 | |
| 11744 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11745 | goto nla_put_failure; |
| 11746 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11747 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11748 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11749 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11750 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11751 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11752 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11753 | |
| 11754 | return; |
| 11755 | |
| 11756 | nla_put_failure: |
| 11757 | genlmsg_cancel(msg, hdr); |
| 11758 | nlmsg_free(msg); |
| 11759 | } |
| 11760 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11761 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11762 | struct net_device *netdev, |
| 11763 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11764 | enum nl80211_commands cmd, gfp_t gfp, |
| 11765 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11766 | { |
| 11767 | struct sk_buff *msg; |
| 11768 | void *hdr; |
| 11769 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11771 | if (!msg) |
| 11772 | return; |
| 11773 | |
| 11774 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11775 | if (!hdr) { |
| 11776 | nlmsg_free(msg); |
| 11777 | return; |
| 11778 | } |
| 11779 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11780 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11781 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11782 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11783 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11784 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11785 | if (uapsd_queues >= 0) { |
| 11786 | struct nlattr *nla_wmm = |
| 11787 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11788 | if (!nla_wmm) |
| 11789 | goto nla_put_failure; |
| 11790 | |
| 11791 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11792 | uapsd_queues)) |
| 11793 | goto nla_put_failure; |
| 11794 | |
| 11795 | nla_nest_end(msg, nla_wmm); |
| 11796 | } |
| 11797 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11798 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11799 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11801 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11802 | return; |
| 11803 | |
| 11804 | nla_put_failure: |
| 11805 | genlmsg_cancel(msg, hdr); |
| 11806 | nlmsg_free(msg); |
| 11807 | } |
| 11808 | |
| 11809 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11810 | struct net_device *netdev, const u8 *buf, |
| 11811 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11812 | { |
| 11813 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11814 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11815 | } |
| 11816 | |
| 11817 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11818 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11819 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11820 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11821 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11822 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11823 | } |
| 11824 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11825 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11826 | struct net_device *netdev, const u8 *buf, |
| 11827 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11828 | { |
| 11829 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11830 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11831 | } |
| 11832 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11833 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11834 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11835 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11836 | { |
| 11837 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11838 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11839 | } |
| 11840 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11841 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11842 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11843 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11844 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11845 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11846 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11847 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11848 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11849 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11850 | if (WARN_ON(len < 2)) |
| 11851 | return; |
| 11852 | |
| 11853 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11854 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11855 | else |
| 11856 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11857 | |
| 11858 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11859 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11860 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11861 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11862 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11863 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11864 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11865 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11866 | { |
| 11867 | struct sk_buff *msg; |
| 11868 | void *hdr; |
| 11869 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11870 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11871 | if (!msg) |
| 11872 | return; |
| 11873 | |
| 11874 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11875 | if (!hdr) { |
| 11876 | nlmsg_free(msg); |
| 11877 | return; |
| 11878 | } |
| 11879 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11880 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11881 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11882 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11884 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11885 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11886 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11887 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11889 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11890 | return; |
| 11891 | |
| 11892 | nla_put_failure: |
| 11893 | genlmsg_cancel(msg, hdr); |
| 11894 | nlmsg_free(msg); |
| 11895 | } |
| 11896 | |
| 11897 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11898 | struct net_device *netdev, const u8 *addr, |
| 11899 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11900 | { |
| 11901 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11902 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11903 | } |
| 11904 | |
| 11905 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11906 | struct net_device *netdev, const u8 *addr, |
| 11907 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11908 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11909 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11910 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11911 | } |
| 11912 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11913 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11914 | struct net_device *netdev, const u8 *bssid, |
| 11915 | const u8 *req_ie, size_t req_ie_len, |
| 11916 | const u8 *resp_ie, size_t resp_ie_len, |
| 11917 | u16 status, gfp_t gfp) |
| 11918 | { |
| 11919 | struct sk_buff *msg; |
| 11920 | void *hdr; |
| 11921 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11923 | if (!msg) |
| 11924 | return; |
| 11925 | |
| 11926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11927 | if (!hdr) { |
| 11928 | nlmsg_free(msg); |
| 11929 | return; |
| 11930 | } |
| 11931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11933 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11934 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11935 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11936 | (req_ie && |
| 11937 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11938 | (resp_ie && |
| 11939 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11940 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11941 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11942 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11943 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11944 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11945 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11946 | return; |
| 11947 | |
| 11948 | nla_put_failure: |
| 11949 | genlmsg_cancel(msg, hdr); |
| 11950 | nlmsg_free(msg); |
| 11951 | |
| 11952 | } |
| 11953 | |
| 11954 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11955 | struct net_device *netdev, const u8 *bssid, |
| 11956 | const u8 *req_ie, size_t req_ie_len, |
| 11957 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11958 | { |
| 11959 | struct sk_buff *msg; |
| 11960 | void *hdr; |
| 11961 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11962 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11963 | if (!msg) |
| 11964 | return; |
| 11965 | |
| 11966 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11967 | if (!hdr) { |
| 11968 | nlmsg_free(msg); |
| 11969 | return; |
| 11970 | } |
| 11971 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11972 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11973 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11974 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11975 | (req_ie && |
| 11976 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11977 | (resp_ie && |
| 11978 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11979 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11980 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11981 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11982 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11983 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11984 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11985 | return; |
| 11986 | |
| 11987 | nla_put_failure: |
| 11988 | genlmsg_cancel(msg, hdr); |
| 11989 | nlmsg_free(msg); |
| 11990 | |
| 11991 | } |
| 11992 | |
| 11993 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11994 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11995 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11996 | { |
| 11997 | struct sk_buff *msg; |
| 11998 | void *hdr; |
| 11999 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12000 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12001 | if (!msg) |
| 12002 | return; |
| 12003 | |
| 12004 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 12005 | if (!hdr) { |
| 12006 | nlmsg_free(msg); |
| 12007 | return; |
| 12008 | } |
| 12009 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12010 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12011 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12012 | (from_ap && reason && |
| 12013 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 12014 | (from_ap && |
| 12015 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 12016 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 12017 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12018 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12019 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12020 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12021 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12022 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12023 | return; |
| 12024 | |
| 12025 | nla_put_failure: |
| 12026 | genlmsg_cancel(msg, hdr); |
| 12027 | nlmsg_free(msg); |
| 12028 | |
| 12029 | } |
| 12030 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12031 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 12032 | struct net_device *netdev, const u8 *bssid, |
| 12033 | gfp_t gfp) |
| 12034 | { |
| 12035 | struct sk_buff *msg; |
| 12036 | void *hdr; |
| 12037 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12039 | if (!msg) |
| 12040 | return; |
| 12041 | |
| 12042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 12043 | if (!hdr) { |
| 12044 | nlmsg_free(msg); |
| 12045 | return; |
| 12046 | } |
| 12047 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12049 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12050 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12051 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12052 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12053 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12054 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12055 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12056 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12057 | return; |
| 12058 | |
| 12059 | nla_put_failure: |
| 12060 | genlmsg_cancel(msg, hdr); |
| 12061 | nlmsg_free(msg); |
| 12062 | } |
| 12063 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12064 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 12065 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12066 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12067 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12068 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12069 | struct sk_buff *msg; |
| 12070 | void *hdr; |
| 12071 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12072 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 12073 | return; |
| 12074 | |
| 12075 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 12076 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12078 | if (!msg) |
| 12079 | return; |
| 12080 | |
| 12081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 12082 | if (!hdr) { |
| 12083 | nlmsg_free(msg); |
| 12084 | return; |
| 12085 | } |
| 12086 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12087 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12088 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12089 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12090 | (ie_len && ie && |
| 12091 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 12092 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12093 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12094 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12095 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12096 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12097 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12098 | return; |
| 12099 | |
| 12100 | nla_put_failure: |
| 12101 | genlmsg_cancel(msg, hdr); |
| 12102 | nlmsg_free(msg); |
| 12103 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12104 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12105 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12106 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 12107 | struct net_device *netdev, const u8 *addr, |
| 12108 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12109 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12110 | { |
| 12111 | struct sk_buff *msg; |
| 12112 | void *hdr; |
| 12113 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12115 | if (!msg) |
| 12116 | return; |
| 12117 | |
| 12118 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 12119 | if (!hdr) { |
| 12120 | nlmsg_free(msg); |
| 12121 | return; |
| 12122 | } |
| 12123 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12124 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12125 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12126 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 12127 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 12128 | (key_id != -1 && |
| 12129 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 12130 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 12131 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12132 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12133 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12134 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12135 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12136 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12137 | return; |
| 12138 | |
| 12139 | nla_put_failure: |
| 12140 | genlmsg_cancel(msg, hdr); |
| 12141 | nlmsg_free(msg); |
| 12142 | } |
| 12143 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12144 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 12145 | struct ieee80211_channel *channel_before, |
| 12146 | struct ieee80211_channel *channel_after) |
| 12147 | { |
| 12148 | struct sk_buff *msg; |
| 12149 | void *hdr; |
| 12150 | struct nlattr *nl_freq; |
| 12151 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12153 | if (!msg) |
| 12154 | return; |
| 12155 | |
| 12156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 12157 | if (!hdr) { |
| 12158 | nlmsg_free(msg); |
| 12159 | return; |
| 12160 | } |
| 12161 | |
| 12162 | /* |
| 12163 | * Since we are applying the beacon hint to a wiphy we know its |
| 12164 | * wiphy_idx is valid |
| 12165 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12166 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 12167 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12168 | |
| 12169 | /* Before */ |
| 12170 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 12171 | if (!nl_freq) |
| 12172 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12173 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12174 | goto nla_put_failure; |
| 12175 | nla_nest_end(msg, nl_freq); |
| 12176 | |
| 12177 | /* After */ |
| 12178 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 12179 | if (!nl_freq) |
| 12180 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12181 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12182 | goto nla_put_failure; |
| 12183 | nla_nest_end(msg, nl_freq); |
| 12184 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12185 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12186 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12187 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12188 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12189 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12190 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12191 | |
| 12192 | return; |
| 12193 | |
| 12194 | nla_put_failure: |
| 12195 | genlmsg_cancel(msg, hdr); |
| 12196 | nlmsg_free(msg); |
| 12197 | } |
| 12198 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12199 | static void nl80211_send_remain_on_chan_event( |
| 12200 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12201 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12202 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12203 | unsigned int duration, gfp_t gfp) |
| 12204 | { |
| 12205 | struct sk_buff *msg; |
| 12206 | void *hdr; |
| 12207 | |
| 12208 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12209 | if (!msg) |
| 12210 | return; |
| 12211 | |
| 12212 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12213 | if (!hdr) { |
| 12214 | nlmsg_free(msg); |
| 12215 | return; |
| 12216 | } |
| 12217 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12218 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12219 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12220 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 12221 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12222 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12223 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 12224 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12225 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 12226 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12227 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12228 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 12229 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 12230 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12231 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12232 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12233 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12235 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12236 | return; |
| 12237 | |
| 12238 | nla_put_failure: |
| 12239 | genlmsg_cancel(msg, hdr); |
| 12240 | nlmsg_free(msg); |
| 12241 | } |
| 12242 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12243 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 12244 | struct ieee80211_channel *chan, |
| 12245 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12246 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12247 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12248 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12249 | |
| 12250 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12251 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12252 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12253 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12254 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12255 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12256 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12257 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 12258 | struct ieee80211_channel *chan, |
| 12259 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12260 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12261 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12262 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12263 | |
| 12264 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12265 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12266 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12267 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12268 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12269 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12270 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 12271 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12272 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12273 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12274 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12275 | struct sk_buff *msg; |
| 12276 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12277 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 12278 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12279 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12280 | if (!msg) |
| 12281 | return; |
| 12282 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12283 | 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] | 12284 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12285 | nlmsg_free(msg); |
| 12286 | return; |
| 12287 | } |
| 12288 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12289 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12290 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12291 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12292 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12293 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12294 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 12295 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12296 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12297 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12298 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12299 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12300 | struct station_info empty_sinfo = {}; |
| 12301 | |
| 12302 | if (!sinfo) |
| 12303 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12304 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12305 | trace_cfg80211_del_sta(dev, mac_addr); |
| 12306 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12307 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12308 | if (!msg) |
| 12309 | return; |
| 12310 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12311 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 12312 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12313 | nlmsg_free(msg); |
| 12314 | return; |
| 12315 | } |
| 12316 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12317 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12318 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12319 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12320 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12321 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12322 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 12323 | enum nl80211_connect_failed_reason reason, |
| 12324 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12325 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12326 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12327 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12328 | struct sk_buff *msg; |
| 12329 | void *hdr; |
| 12330 | |
| 12331 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 12332 | if (!msg) |
| 12333 | return; |
| 12334 | |
| 12335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 12336 | if (!hdr) { |
| 12337 | nlmsg_free(msg); |
| 12338 | return; |
| 12339 | } |
| 12340 | |
| 12341 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12342 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 12343 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 12344 | goto nla_put_failure; |
| 12345 | |
| 12346 | genlmsg_end(msg, hdr); |
| 12347 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12348 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12349 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12350 | return; |
| 12351 | |
| 12352 | nla_put_failure: |
| 12353 | genlmsg_cancel(msg, hdr); |
| 12354 | nlmsg_free(msg); |
| 12355 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12356 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12357 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12358 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 12359 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12360 | { |
| 12361 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12362 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12363 | struct sk_buff *msg; |
| 12364 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12365 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12366 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12367 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12368 | return false; |
| 12369 | |
| 12370 | msg = nlmsg_new(100, gfp); |
| 12371 | if (!msg) |
| 12372 | return true; |
| 12373 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12374 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12375 | if (!hdr) { |
| 12376 | nlmsg_free(msg); |
| 12377 | return true; |
| 12378 | } |
| 12379 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12380 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12381 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12382 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12383 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12384 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12385 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12386 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12387 | return true; |
| 12388 | |
| 12389 | nla_put_failure: |
| 12390 | genlmsg_cancel(msg, hdr); |
| 12391 | nlmsg_free(msg); |
| 12392 | return true; |
| 12393 | } |
| 12394 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12395 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 12396 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12397 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12398 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12399 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12400 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12401 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 12402 | |
| 12403 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12404 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 12405 | trace_cfg80211_return_bool(false); |
| 12406 | return false; |
| 12407 | } |
| 12408 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 12409 | addr, gfp); |
| 12410 | trace_cfg80211_return_bool(ret); |
| 12411 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12412 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12413 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 12414 | |
| 12415 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 12416 | const u8 *addr, gfp_t gfp) |
| 12417 | { |
| 12418 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12419 | bool ret; |
| 12420 | |
| 12421 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 12422 | |
| 12423 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12424 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 12425 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 12426 | trace_cfg80211_return_bool(false); |
| 12427 | return false; |
| 12428 | } |
| 12429 | ret = __nl80211_unexpected_frame(dev, |
| 12430 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12431 | addr, gfp); |
| 12432 | trace_cfg80211_return_bool(ret); |
| 12433 | return ret; |
| 12434 | } |
| 12435 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12436 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12437 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12438 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12439 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12440 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12441 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12442 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12443 | struct sk_buff *msg; |
| 12444 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12445 | |
| 12446 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12447 | if (!msg) |
| 12448 | return -ENOMEM; |
| 12449 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12450 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12451 | if (!hdr) { |
| 12452 | nlmsg_free(msg); |
| 12453 | return -ENOMEM; |
| 12454 | } |
| 12455 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12456 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12457 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12458 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12459 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12460 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12461 | (sig_dbm && |
| 12462 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12463 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12464 | (flags && |
| 12465 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12466 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12467 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12468 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12469 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12470 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12471 | |
| 12472 | nla_put_failure: |
| 12473 | genlmsg_cancel(msg, hdr); |
| 12474 | nlmsg_free(msg); |
| 12475 | return -ENOBUFS; |
| 12476 | } |
| 12477 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12478 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12479 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12480 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12481 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12482 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12483 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12484 | struct sk_buff *msg; |
| 12485 | void *hdr; |
| 12486 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12487 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12488 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12489 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12490 | if (!msg) |
| 12491 | return; |
| 12492 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12493 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12494 | if (!hdr) { |
| 12495 | nlmsg_free(msg); |
| 12496 | return; |
| 12497 | } |
| 12498 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12499 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12500 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12501 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12502 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12503 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12504 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12505 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12506 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12507 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12508 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12509 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12510 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12511 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12512 | return; |
| 12513 | |
| 12514 | nla_put_failure: |
| 12515 | genlmsg_cancel(msg, hdr); |
| 12516 | nlmsg_free(msg); |
| 12517 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12518 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12519 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12520 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12521 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12522 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12524 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12525 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12526 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12527 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12528 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12529 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12530 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12531 | cb = (void **)msg->cb; |
| 12532 | |
| 12533 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12534 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12535 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12536 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12537 | } |
| 12538 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12539 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12540 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12541 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12542 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12543 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12544 | goto nla_put_failure; |
| 12545 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12546 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12547 | if (!cb[1]) |
| 12548 | goto nla_put_failure; |
| 12549 | |
| 12550 | cb[2] = rdev; |
| 12551 | |
| 12552 | return msg; |
| 12553 | nla_put_failure: |
| 12554 | nlmsg_free(msg); |
| 12555 | return NULL; |
| 12556 | } |
| 12557 | |
| 12558 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12559 | { |
| 12560 | void **cb = (void **)msg->cb; |
| 12561 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12562 | |
| 12563 | nla_nest_end(msg, cb[1]); |
| 12564 | genlmsg_end(msg, cb[0]); |
| 12565 | |
| 12566 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12567 | |
| 12568 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12569 | NL80211_MCGRP_MLME, gfp); |
| 12570 | } |
| 12571 | |
| 12572 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12573 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12574 | gfp_t gfp) |
| 12575 | { |
| 12576 | struct sk_buff *msg; |
| 12577 | |
| 12578 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12579 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12580 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12581 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12582 | return; |
| 12583 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12584 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12585 | if (!msg) |
| 12586 | return; |
| 12587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12588 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12589 | rssi_event)) |
| 12590 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12591 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12592 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12593 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12594 | return; |
| 12595 | |
| 12596 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12597 | nlmsg_free(msg); |
| 12598 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12599 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12600 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12601 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12602 | const u8 *peer, u32 num_packets, |
| 12603 | u32 rate, u32 intvl, gfp_t gfp) |
| 12604 | { |
| 12605 | struct sk_buff *msg; |
| 12606 | |
| 12607 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12608 | if (!msg) |
| 12609 | return; |
| 12610 | |
| 12611 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12612 | goto nla_put_failure; |
| 12613 | |
| 12614 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12615 | goto nla_put_failure; |
| 12616 | |
| 12617 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12618 | goto nla_put_failure; |
| 12619 | |
| 12620 | cfg80211_send_cqm(msg, gfp); |
| 12621 | return; |
| 12622 | |
| 12623 | nla_put_failure: |
| 12624 | nlmsg_free(msg); |
| 12625 | } |
| 12626 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12627 | |
| 12628 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12629 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12630 | { |
| 12631 | struct sk_buff *msg; |
| 12632 | |
| 12633 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12634 | |
| 12635 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12636 | if (!msg) |
| 12637 | return; |
| 12638 | |
| 12639 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12640 | goto nla_put_failure; |
| 12641 | |
| 12642 | cfg80211_send_cqm(msg, gfp); |
| 12643 | return; |
| 12644 | |
| 12645 | nla_put_failure: |
| 12646 | nlmsg_free(msg); |
| 12647 | } |
| 12648 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12649 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12650 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12651 | { |
| 12652 | struct sk_buff *msg; |
| 12653 | |
| 12654 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12655 | if (!msg) |
| 12656 | return; |
| 12657 | |
| 12658 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12659 | goto nla_put_failure; |
| 12660 | |
| 12661 | cfg80211_send_cqm(msg, gfp); |
| 12662 | return; |
| 12663 | |
| 12664 | nla_put_failure: |
| 12665 | nlmsg_free(msg); |
| 12666 | } |
| 12667 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12668 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12669 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12670 | struct net_device *netdev, const u8 *bssid, |
| 12671 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12672 | { |
| 12673 | struct sk_buff *msg; |
| 12674 | struct nlattr *rekey_attr; |
| 12675 | void *hdr; |
| 12676 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12677 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12678 | if (!msg) |
| 12679 | return; |
| 12680 | |
| 12681 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12682 | if (!hdr) { |
| 12683 | nlmsg_free(msg); |
| 12684 | return; |
| 12685 | } |
| 12686 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12687 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12688 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12689 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12690 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12691 | |
| 12692 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12693 | if (!rekey_attr) |
| 12694 | goto nla_put_failure; |
| 12695 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12696 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12697 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12698 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12699 | |
| 12700 | nla_nest_end(msg, rekey_attr); |
| 12701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12702 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12703 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12704 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12705 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12706 | return; |
| 12707 | |
| 12708 | nla_put_failure: |
| 12709 | genlmsg_cancel(msg, hdr); |
| 12710 | nlmsg_free(msg); |
| 12711 | } |
| 12712 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12713 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12714 | const u8 *replay_ctr, gfp_t gfp) |
| 12715 | { |
| 12716 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12717 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12718 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12719 | |
| 12720 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12721 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12722 | } |
| 12723 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12724 | |
| 12725 | static void |
| 12726 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12727 | struct net_device *netdev, int index, |
| 12728 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12729 | { |
| 12730 | struct sk_buff *msg; |
| 12731 | struct nlattr *attr; |
| 12732 | void *hdr; |
| 12733 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12734 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12735 | if (!msg) |
| 12736 | return; |
| 12737 | |
| 12738 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12739 | if (!hdr) { |
| 12740 | nlmsg_free(msg); |
| 12741 | return; |
| 12742 | } |
| 12743 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12744 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12745 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12746 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12747 | |
| 12748 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12749 | if (!attr) |
| 12750 | goto nla_put_failure; |
| 12751 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12752 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12753 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12754 | (preauth && |
| 12755 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12756 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12757 | |
| 12758 | nla_nest_end(msg, attr); |
| 12759 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12760 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12761 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12763 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12764 | return; |
| 12765 | |
| 12766 | nla_put_failure: |
| 12767 | genlmsg_cancel(msg, hdr); |
| 12768 | nlmsg_free(msg); |
| 12769 | } |
| 12770 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12771 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12772 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12773 | { |
| 12774 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12775 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12776 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12777 | |
| 12778 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12779 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12780 | } |
| 12781 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12782 | |
| 12783 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12784 | struct net_device *netdev, |
| 12785 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12786 | gfp_t gfp, |
| 12787 | enum nl80211_commands notif, |
| 12788 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12789 | { |
| 12790 | struct sk_buff *msg; |
| 12791 | void *hdr; |
| 12792 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12793 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12794 | if (!msg) |
| 12795 | return; |
| 12796 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12797 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12798 | if (!hdr) { |
| 12799 | nlmsg_free(msg); |
| 12800 | return; |
| 12801 | } |
| 12802 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12803 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12804 | goto nla_put_failure; |
| 12805 | |
| 12806 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12807 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12808 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12809 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12810 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12811 | goto nla_put_failure; |
| 12812 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12813 | genlmsg_end(msg, hdr); |
| 12814 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12815 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12816 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12817 | return; |
| 12818 | |
| 12819 | nla_put_failure: |
| 12820 | genlmsg_cancel(msg, hdr); |
| 12821 | nlmsg_free(msg); |
| 12822 | } |
| 12823 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12824 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12825 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12826 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12827 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12828 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12829 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12830 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12831 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12832 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12833 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12834 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12835 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12836 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12837 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12838 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12839 | } |
| 12840 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12841 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12842 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12843 | struct cfg80211_chan_def *chandef, |
| 12844 | u8 count) |
| 12845 | { |
| 12846 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12847 | struct wiphy *wiphy = wdev->wiphy; |
| 12848 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12849 | |
| 12850 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12851 | |
| 12852 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12853 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12854 | } |
| 12855 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12856 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12857 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12858 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12859 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12860 | enum nl80211_radar_event event, |
| 12861 | struct net_device *netdev, gfp_t gfp) |
| 12862 | { |
| 12863 | struct sk_buff *msg; |
| 12864 | void *hdr; |
| 12865 | |
| 12866 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12867 | if (!msg) |
| 12868 | return; |
| 12869 | |
| 12870 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12871 | if (!hdr) { |
| 12872 | nlmsg_free(msg); |
| 12873 | return; |
| 12874 | } |
| 12875 | |
| 12876 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12877 | goto nla_put_failure; |
| 12878 | |
| 12879 | /* NOP and radar events don't need a netdev parameter */ |
| 12880 | if (netdev) { |
| 12881 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12882 | |
| 12883 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12884 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12885 | goto nla_put_failure; |
| 12886 | } |
| 12887 | |
| 12888 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12889 | goto nla_put_failure; |
| 12890 | |
| 12891 | if (nl80211_send_chandef(msg, chandef)) |
| 12892 | goto nla_put_failure; |
| 12893 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12894 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12895 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12896 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12897 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12898 | return; |
| 12899 | |
| 12900 | nla_put_failure: |
| 12901 | genlmsg_cancel(msg, hdr); |
| 12902 | nlmsg_free(msg); |
| 12903 | } |
| 12904 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12905 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12906 | u64 cookie, bool acked, gfp_t gfp) |
| 12907 | { |
| 12908 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12909 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12910 | struct sk_buff *msg; |
| 12911 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12912 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12913 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12914 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12915 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12916 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12917 | if (!msg) |
| 12918 | return; |
| 12919 | |
| 12920 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12921 | if (!hdr) { |
| 12922 | nlmsg_free(msg); |
| 12923 | return; |
| 12924 | } |
| 12925 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12927 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12928 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12929 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12930 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12931 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12932 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12933 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12934 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12935 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12936 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12937 | return; |
| 12938 | |
| 12939 | nla_put_failure: |
| 12940 | genlmsg_cancel(msg, hdr); |
| 12941 | nlmsg_free(msg); |
| 12942 | } |
| 12943 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12944 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12945 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12946 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12947 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12948 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12949 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12950 | struct sk_buff *msg; |
| 12951 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12952 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12953 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12954 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12955 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12956 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12957 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12958 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12959 | if (!msg) { |
| 12960 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12961 | return; |
| 12962 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12963 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12965 | if (!hdr) |
| 12966 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12967 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12969 | (freq && |
| 12970 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12971 | (sig_dbm && |
| 12972 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12973 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12974 | goto nla_put_failure; |
| 12975 | |
| 12976 | genlmsg_end(msg, hdr); |
| 12977 | |
| 12978 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12979 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12980 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12981 | return; |
| 12982 | |
| 12983 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12984 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12985 | if (hdr) |
| 12986 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12987 | nlmsg_free(msg); |
| 12988 | } |
| 12989 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12990 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12991 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12992 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12993 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12994 | { |
| 12995 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12996 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12997 | int i, j; |
| 12998 | |
| 12999 | nl_results = nla_nest_start( |
| 13000 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 13001 | if (!nl_results) |
| 13002 | return -EMSGSIZE; |
| 13003 | |
| 13004 | for (i = 0; i < nd->n_matches; i++) { |
| 13005 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 13006 | |
| 13007 | nl_match = nla_nest_start(msg, i); |
| 13008 | if (!nl_match) |
| 13009 | break; |
| 13010 | |
| 13011 | /* The SSID attribute is optional in nl80211, but for |
| 13012 | * simplicity reasons it's always present in the |
| 13013 | * cfg80211 structure. If a driver can't pass the |
| 13014 | * SSID, that needs to be changed. A zero length SSID |
| 13015 | * is still a valid SSID (wildcard), so it cannot be |
| 13016 | * used for this purpose. |
| 13017 | */ |
| 13018 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 13019 | match->ssid.ssid)) { |
| 13020 | nla_nest_cancel(msg, nl_match); |
| 13021 | goto out; |
| 13022 | } |
| 13023 | |
| 13024 | if (match->n_channels) { |
| 13025 | nl_freqs = nla_nest_start( |
| 13026 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13027 | if (!nl_freqs) { |
| 13028 | nla_nest_cancel(msg, nl_match); |
| 13029 | goto out; |
| 13030 | } |
| 13031 | |
| 13032 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 13033 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13034 | nla_nest_cancel(msg, nl_freqs); |
| 13035 | nla_nest_cancel(msg, nl_match); |
| 13036 | goto out; |
| 13037 | } |
| 13038 | } |
| 13039 | |
| 13040 | nla_nest_end(msg, nl_freqs); |
| 13041 | } |
| 13042 | |
| 13043 | nla_nest_end(msg, nl_match); |
| 13044 | } |
| 13045 | |
| 13046 | out: |
| 13047 | nla_nest_end(msg, nl_results); |
| 13048 | return 0; |
| 13049 | } |
| 13050 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13051 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 13052 | struct cfg80211_wowlan_wakeup *wakeup, |
| 13053 | gfp_t gfp) |
| 13054 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13055 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13056 | struct sk_buff *msg; |
| 13057 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13058 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13059 | |
| 13060 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 13061 | |
| 13062 | if (wakeup) |
| 13063 | size += wakeup->packet_present_len; |
| 13064 | |
| 13065 | msg = nlmsg_new(size, gfp); |
| 13066 | if (!msg) |
| 13067 | return; |
| 13068 | |
| 13069 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 13070 | if (!hdr) |
| 13071 | goto free_msg; |
| 13072 | |
| 13073 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13074 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13075 | goto free_msg; |
| 13076 | |
| 13077 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13078 | wdev->netdev->ifindex)) |
| 13079 | goto free_msg; |
| 13080 | |
| 13081 | if (wakeup) { |
| 13082 | struct nlattr *reasons; |
| 13083 | |
| 13084 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 13085 | if (!reasons) |
| 13086 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13087 | |
| 13088 | if (wakeup->disconnect && |
| 13089 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 13090 | goto free_msg; |
| 13091 | if (wakeup->magic_pkt && |
| 13092 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 13093 | goto free_msg; |
| 13094 | if (wakeup->gtk_rekey_failure && |
| 13095 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 13096 | goto free_msg; |
| 13097 | if (wakeup->eap_identity_req && |
| 13098 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 13099 | goto free_msg; |
| 13100 | if (wakeup->four_way_handshake && |
| 13101 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 13102 | goto free_msg; |
| 13103 | if (wakeup->rfkill_release && |
| 13104 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 13105 | goto free_msg; |
| 13106 | |
| 13107 | if (wakeup->pattern_idx >= 0 && |
| 13108 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 13109 | wakeup->pattern_idx)) |
| 13110 | goto free_msg; |
| 13111 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13112 | if (wakeup->tcp_match && |
| 13113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 13114 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13115 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13116 | if (wakeup->tcp_connlost && |
| 13117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 13118 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13119 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13120 | if (wakeup->tcp_nomoretokens && |
| 13121 | nla_put_flag(msg, |
| 13122 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 13123 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13124 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13125 | if (wakeup->packet) { |
| 13126 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 13127 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 13128 | |
| 13129 | if (!wakeup->packet_80211) { |
| 13130 | pkt_attr = |
| 13131 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 13132 | len_attr = |
| 13133 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 13134 | } |
| 13135 | |
| 13136 | if (wakeup->packet_len && |
| 13137 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 13138 | goto free_msg; |
| 13139 | |
| 13140 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 13141 | wakeup->packet)) |
| 13142 | goto free_msg; |
| 13143 | } |
| 13144 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13145 | if (wakeup->net_detect && |
| 13146 | cfg80211_net_detect_results(msg, wakeup)) |
| 13147 | goto free_msg; |
| 13148 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13149 | nla_nest_end(msg, reasons); |
| 13150 | } |
| 13151 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13152 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13153 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13154 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13155 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13156 | return; |
| 13157 | |
| 13158 | free_msg: |
| 13159 | nlmsg_free(msg); |
| 13160 | } |
| 13161 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 13162 | #endif |
| 13163 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13164 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 13165 | enum nl80211_tdls_operation oper, |
| 13166 | u16 reason_code, gfp_t gfp) |
| 13167 | { |
| 13168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13169 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13170 | struct sk_buff *msg; |
| 13171 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13172 | |
| 13173 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 13174 | reason_code); |
| 13175 | |
| 13176 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13177 | if (!msg) |
| 13178 | return; |
| 13179 | |
| 13180 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 13181 | if (!hdr) { |
| 13182 | nlmsg_free(msg); |
| 13183 | return; |
| 13184 | } |
| 13185 | |
| 13186 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13187 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13188 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 13189 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 13190 | (reason_code > 0 && |
| 13191 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 13192 | goto nla_put_failure; |
| 13193 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13194 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +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); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13198 | return; |
| 13199 | |
| 13200 | nla_put_failure: |
| 13201 | genlmsg_cancel(msg, hdr); |
| 13202 | nlmsg_free(msg); |
| 13203 | } |
| 13204 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 13205 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13206 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 13207 | unsigned long state, |
| 13208 | void *_notify) |
| 13209 | { |
| 13210 | struct netlink_notify *notify = _notify; |
| 13211 | struct cfg80211_registered_device *rdev; |
| 13212 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13213 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13214 | |
| 13215 | if (state != NETLINK_URELEASE) |
| 13216 | return NOTIFY_DONE; |
| 13217 | |
| 13218 | rcu_read_lock(); |
| 13219 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13220 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13221 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13222 | bool schedule_scan_stop = false; |
| 13223 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 13224 | rcu_dereference(rdev->sched_scan_req); |
| 13225 | |
| 13226 | if (sched_scan_req && notify->portid && |
| 13227 | sched_scan_req->owner_nlportid == notify->portid) |
| 13228 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13229 | |
| 13230 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13231 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13232 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13233 | if (wdev->owner_nlportid == notify->portid) |
| 13234 | schedule_destroy_work = true; |
| 13235 | } |
| 13236 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13237 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13238 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 13239 | list) { |
| 13240 | if (reg->nlportid == notify->portid) { |
| 13241 | list_del(®->list); |
| 13242 | kfree(reg); |
| 13243 | break; |
| 13244 | } |
| 13245 | } |
| 13246 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13247 | |
| 13248 | if (schedule_destroy_work) { |
| 13249 | struct cfg80211_iface_destroy *destroy; |
| 13250 | |
| 13251 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 13252 | if (destroy) { |
| 13253 | destroy->nlportid = notify->portid; |
| 13254 | spin_lock(&rdev->destroy_list_lock); |
| 13255 | list_add(&destroy->list, &rdev->destroy_list); |
| 13256 | spin_unlock(&rdev->destroy_list_lock); |
| 13257 | schedule_work(&rdev->destroy_work); |
| 13258 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13259 | } else if (schedule_scan_stop) { |
| 13260 | sched_scan_req->owner_nlportid = 0; |
| 13261 | |
| 13262 | if (rdev->ops->sched_scan_stop && |
| 13263 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 13264 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13265 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13266 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13267 | |
| 13268 | rcu_read_unlock(); |
| 13269 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 13270 | /* |
| 13271 | * It is possible that the user space process that is controlling the |
| 13272 | * indoor setting disappeared, so notify the regulatory core. |
| 13273 | */ |
| 13274 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 13275 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13276 | } |
| 13277 | |
| 13278 | static struct notifier_block nl80211_netlink_notifier = { |
| 13279 | .notifier_call = nl80211_netlink_notify, |
| 13280 | }; |
| 13281 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13282 | void cfg80211_ft_event(struct net_device *netdev, |
| 13283 | struct cfg80211_ft_event_params *ft_event) |
| 13284 | { |
| 13285 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13286 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13287 | struct sk_buff *msg; |
| 13288 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13289 | |
| 13290 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 13291 | |
| 13292 | if (!ft_event->target_ap) |
| 13293 | return; |
| 13294 | |
| 13295 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13296 | if (!msg) |
| 13297 | return; |
| 13298 | |
| 13299 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13300 | if (!hdr) |
| 13301 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13302 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13303 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13304 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13305 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 13306 | goto out; |
| 13307 | |
| 13308 | if (ft_event->ies && |
| 13309 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 13310 | goto out; |
| 13311 | if (ft_event->ric_ies && |
| 13312 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 13313 | ft_event->ric_ies)) |
| 13314 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13315 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13316 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13317 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13318 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13319 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13320 | return; |
| 13321 | out: |
| 13322 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13323 | } |
| 13324 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 13325 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13326 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 13327 | { |
| 13328 | struct cfg80211_registered_device *rdev; |
| 13329 | struct sk_buff *msg; |
| 13330 | void *hdr; |
| 13331 | u32 nlportid; |
| 13332 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13333 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13334 | if (!rdev->crit_proto_nlportid) |
| 13335 | return; |
| 13336 | |
| 13337 | nlportid = rdev->crit_proto_nlportid; |
| 13338 | rdev->crit_proto_nlportid = 0; |
| 13339 | |
| 13340 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13341 | if (!msg) |
| 13342 | return; |
| 13343 | |
| 13344 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 13345 | if (!hdr) |
| 13346 | goto nla_put_failure; |
| 13347 | |
| 13348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13349 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13350 | goto nla_put_failure; |
| 13351 | |
| 13352 | genlmsg_end(msg, hdr); |
| 13353 | |
| 13354 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 13355 | return; |
| 13356 | |
| 13357 | nla_put_failure: |
| 13358 | if (hdr) |
| 13359 | genlmsg_cancel(msg, hdr); |
| 13360 | nlmsg_free(msg); |
| 13361 | |
| 13362 | } |
| 13363 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 13364 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13365 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 13366 | { |
| 13367 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13368 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13369 | struct sk_buff *msg; |
| 13370 | void *hdr; |
| 13371 | |
| 13372 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13373 | if (!msg) |
| 13374 | return; |
| 13375 | |
| 13376 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 13377 | if (!hdr) |
| 13378 | goto out; |
| 13379 | |
| 13380 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13381 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 13382 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13383 | goto out; |
| 13384 | |
| 13385 | genlmsg_end(msg, hdr); |
| 13386 | |
| 13387 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 13388 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13389 | return; |
| 13390 | out: |
| 13391 | nlmsg_free(msg); |
| 13392 | } |
| 13393 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13394 | /* initialisation/exit functions */ |
| 13395 | |
| 13396 | int nl80211_init(void) |
| 13397 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 13398 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13399 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13400 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 13401 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13402 | if (err) |
| 13403 | return err; |
| 13404 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13405 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 13406 | if (err) |
| 13407 | goto err_out; |
| 13408 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13409 | return 0; |
| 13410 | err_out: |
| 13411 | genl_unregister_family(&nl80211_fam); |
| 13412 | return err; |
| 13413 | } |
| 13414 | |
| 13415 | void nl80211_exit(void) |
| 13416 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13417 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13418 | genl_unregister_family(&nl80211_fam); |
| 13419 | } |