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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 404 | }; |
| 405 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 406 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 407 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 408 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 409 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 410 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 411 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 412 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 413 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 415 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 416 | }; |
| 417 | |
| 418 | /* policy for the key default flags */ |
| 419 | static const struct nla_policy |
| 420 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 421 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 422 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 423 | }; |
| 424 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 425 | /* policy for WoWLAN attributes */ |
| 426 | static const struct nla_policy |
| 427 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 428 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 430 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 431 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 432 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 433 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 434 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 435 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 436 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 437 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 438 | }; |
| 439 | |
| 440 | static const struct nla_policy |
| 441 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 442 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 443 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 444 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 445 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 446 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 448 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 449 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 450 | }, |
| 451 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 452 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 453 | }, |
| 454 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 455 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 456 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 457 | }; |
| 458 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 459 | /* policy for coalesce rule attributes */ |
| 460 | static const struct nla_policy |
| 461 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 462 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 463 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 464 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 465 | }; |
| 466 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 467 | /* policy for GTK rekey offload attributes */ |
| 468 | static const struct nla_policy |
| 469 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 470 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 471 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 472 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 473 | }; |
| 474 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 475 | static const struct nla_policy |
| 476 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 477 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 478 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 479 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 480 | }; |
| 481 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 482 | static const struct nla_policy |
| 483 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 484 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 485 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 486 | }; |
| 487 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 488 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 489 | struct netlink_callback *cb, |
| 490 | struct cfg80211_registered_device **rdev, |
| 491 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 492 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 493 | int err; |
| 494 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 495 | rtnl_lock(); |
| 496 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 497 | if (!cb->args[0]) { |
| 498 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 499 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 500 | nl80211_policy); |
| 501 | if (err) |
| 502 | goto out_unlock; |
| 503 | |
| 504 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 505 | nl80211_fam.attrbuf); |
| 506 | if (IS_ERR(*wdev)) { |
| 507 | err = PTR_ERR(*wdev); |
| 508 | goto out_unlock; |
| 509 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 510 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 511 | /* 0 is the first index - add 1 to parse only once */ |
| 512 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 513 | cb->args[1] = (*wdev)->identifier; |
| 514 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 515 | /* subtract the 1 again here */ |
| 516 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 517 | struct wireless_dev *tmp; |
| 518 | |
| 519 | if (!wiphy) { |
| 520 | err = -ENODEV; |
| 521 | goto out_unlock; |
| 522 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 523 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 524 | *wdev = NULL; |
| 525 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 526 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 527 | if (tmp->identifier == cb->args[1]) { |
| 528 | *wdev = tmp; |
| 529 | break; |
| 530 | } |
| 531 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 532 | |
| 533 | if (!*wdev) { |
| 534 | err = -ENODEV; |
| 535 | goto out_unlock; |
| 536 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 537 | } |
| 538 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 539 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 540 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 541 | rtnl_unlock(); |
| 542 | return err; |
| 543 | } |
| 544 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 545 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 546 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 547 | rtnl_unlock(); |
| 548 | } |
| 549 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 550 | /* IE validation */ |
| 551 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 552 | { |
| 553 | const u8 *pos; |
| 554 | int len; |
| 555 | |
| 556 | if (!attr) |
| 557 | return true; |
| 558 | |
| 559 | pos = nla_data(attr); |
| 560 | len = nla_len(attr); |
| 561 | |
| 562 | while (len) { |
| 563 | u8 elemlen; |
| 564 | |
| 565 | if (len < 2) |
| 566 | return false; |
| 567 | len -= 2; |
| 568 | |
| 569 | elemlen = pos[1]; |
| 570 | if (elemlen > len) |
| 571 | return false; |
| 572 | |
| 573 | len -= elemlen; |
| 574 | pos += 2 + elemlen; |
| 575 | } |
| 576 | |
| 577 | return true; |
| 578 | } |
| 579 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 580 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 581 | 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] | 582 | int flags, u8 cmd) |
| 583 | { |
| 584 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 585 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 588 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 589 | struct ieee80211_channel *chan, |
| 590 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 591 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 592 | /* Some channels must be completely excluded from the |
| 593 | * list to protect old user-space tools from breaking |
| 594 | */ |
| 595 | if (!large && chan->flags & |
| 596 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 597 | return 0; |
| 598 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 599 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 600 | chan->center_freq)) |
| 601 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 602 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 603 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 604 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 605 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 606 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 607 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 608 | goto nla_put_failure; |
| 609 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 610 | goto nla_put_failure; |
| 611 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 612 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 613 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 614 | goto nla_put_failure; |
| 615 | if (large) { |
| 616 | u32 time; |
| 617 | |
| 618 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 619 | |
| 620 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 621 | chan->dfs_state)) |
| 622 | goto nla_put_failure; |
| 623 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 624 | time)) |
| 625 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 626 | if (nla_put_u32(msg, |
| 627 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 628 | chan->dfs_cac_ms)) |
| 629 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 630 | } |
| 631 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 632 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 633 | if (large) { |
| 634 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 635 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 636 | goto nla_put_failure; |
| 637 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 638 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 639 | goto nla_put_failure; |
| 640 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 641 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 642 | goto nla_put_failure; |
| 643 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 644 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 645 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 646 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 647 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 648 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 649 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 650 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 651 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 652 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 653 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 654 | goto nla_put_failure; |
| 655 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 656 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 657 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 658 | } |
| 659 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 660 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 661 | DBM_TO_MBM(chan->max_power))) |
| 662 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | |
| 666 | nla_put_failure: |
| 667 | return -ENOBUFS; |
| 668 | } |
| 669 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 670 | /* netlink command implementations */ |
| 671 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 672 | struct key_parse { |
| 673 | struct key_params p; |
| 674 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 675 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 676 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 681 | { |
| 682 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 683 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 684 | nl80211_key_policy); |
| 685 | if (err) |
| 686 | return err; |
| 687 | |
| 688 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 689 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 690 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 691 | if (k->def) { |
| 692 | k->def_uni = true; |
| 693 | k->def_multi = true; |
| 694 | } |
| 695 | if (k->defmgmt) |
| 696 | k->def_multi = true; |
| 697 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 698 | if (tb[NL80211_KEY_IDX]) |
| 699 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 700 | |
| 701 | if (tb[NL80211_KEY_DATA]) { |
| 702 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 703 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 704 | } |
| 705 | |
| 706 | if (tb[NL80211_KEY_SEQ]) { |
| 707 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 708 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 709 | } |
| 710 | |
| 711 | if (tb[NL80211_KEY_CIPHER]) |
| 712 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 713 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 714 | if (tb[NL80211_KEY_TYPE]) { |
| 715 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 716 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 717 | return -EINVAL; |
| 718 | } |
| 719 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 720 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 721 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 722 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 723 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 724 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 725 | if (err) |
| 726 | return err; |
| 727 | |
| 728 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 729 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 730 | } |
| 731 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 736 | { |
| 737 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 738 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 739 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 740 | } |
| 741 | |
| 742 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 743 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 744 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 745 | } |
| 746 | |
| 747 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 748 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 749 | |
| 750 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 751 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 752 | |
| 753 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 754 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 755 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 756 | if (k->def) { |
| 757 | k->def_uni = true; |
| 758 | k->def_multi = true; |
| 759 | } |
| 760 | if (k->defmgmt) |
| 761 | k->def_multi = true; |
| 762 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 763 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 764 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 765 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 769 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 770 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 771 | int err = nla_parse_nested( |
| 772 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 773 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 774 | nl80211_key_default_policy); |
| 775 | if (err) |
| 776 | return err; |
| 777 | |
| 778 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 779 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 780 | } |
| 781 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 786 | { |
| 787 | int err; |
| 788 | |
| 789 | memset(k, 0, sizeof(*k)); |
| 790 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 791 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 792 | |
| 793 | if (info->attrs[NL80211_ATTR_KEY]) |
| 794 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 795 | else |
| 796 | err = nl80211_parse_key_old(info, k); |
| 797 | |
| 798 | if (err) |
| 799 | return err; |
| 800 | |
| 801 | if (k->def && k->defmgmt) |
| 802 | return -EINVAL; |
| 803 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 804 | if (k->defmgmt) { |
| 805 | if (k->def_uni || !k->def_multi) |
| 806 | return -EINVAL; |
| 807 | } |
| 808 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 809 | if (k->idx != -1) { |
| 810 | if (k->defmgmt) { |
| 811 | if (k->idx < 4 || k->idx > 5) |
| 812 | return -EINVAL; |
| 813 | } else if (k->def) { |
| 814 | if (k->idx < 0 || k->idx > 3) |
| 815 | return -EINVAL; |
| 816 | } else { |
| 817 | if (k->idx < 0 || k->idx > 5) |
| 818 | return -EINVAL; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 825 | static struct cfg80211_cached_keys * |
| 826 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 827 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 828 | { |
| 829 | struct key_parse parse; |
| 830 | struct nlattr *key; |
| 831 | struct cfg80211_cached_keys *result; |
| 832 | int rem, err, def = 0; |
| 833 | |
| 834 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 835 | if (!result) |
| 836 | return ERR_PTR(-ENOMEM); |
| 837 | |
| 838 | result->def = -1; |
| 839 | result->defmgmt = -1; |
| 840 | |
| 841 | nla_for_each_nested(key, keys, rem) { |
| 842 | memset(&parse, 0, sizeof(parse)); |
| 843 | parse.idx = -1; |
| 844 | |
| 845 | err = nl80211_parse_key_new(key, &parse); |
| 846 | if (err) |
| 847 | goto error; |
| 848 | err = -EINVAL; |
| 849 | if (!parse.p.key) |
| 850 | goto error; |
| 851 | if (parse.idx < 0 || parse.idx > 4) |
| 852 | goto error; |
| 853 | if (parse.def) { |
| 854 | if (def) |
| 855 | goto error; |
| 856 | def = 1; |
| 857 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 858 | if (!parse.def_uni || !parse.def_multi) |
| 859 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 860 | } else if (parse.defmgmt) |
| 861 | goto error; |
| 862 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 863 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 864 | if (err) |
| 865 | goto error; |
| 866 | result->params[parse.idx].cipher = parse.p.cipher; |
| 867 | result->params[parse.idx].key_len = parse.p.key_len; |
| 868 | result->params[parse.idx].key = result->data[parse.idx]; |
| 869 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 870 | |
| 871 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 872 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 873 | if (no_ht) |
| 874 | *no_ht = true; |
| 875 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | return result; |
| 879 | error: |
| 880 | kfree(result); |
| 881 | return ERR_PTR(err); |
| 882 | } |
| 883 | |
| 884 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 885 | { |
| 886 | ASSERT_WDEV_LOCK(wdev); |
| 887 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 888 | switch (wdev->iftype) { |
| 889 | case NL80211_IFTYPE_AP: |
| 890 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 891 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 892 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 893 | break; |
| 894 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 895 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 896 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 897 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 898 | return -ENOLINK; |
| 899 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 900 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 901 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 902 | case NL80211_IFTYPE_MONITOR: |
| 903 | case NL80211_IFTYPE_P2P_DEVICE: |
| 904 | case NL80211_IFTYPE_WDS: |
| 905 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 906 | return -EINVAL; |
| 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 912 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 913 | struct nlattr *tb) |
| 914 | { |
| 915 | struct ieee80211_channel *chan; |
| 916 | |
| 917 | if (tb == NULL) |
| 918 | return NULL; |
| 919 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 920 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 921 | return NULL; |
| 922 | return chan; |
| 923 | } |
| 924 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 925 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 926 | { |
| 927 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 928 | int i; |
| 929 | |
| 930 | if (!nl_modes) |
| 931 | goto nla_put_failure; |
| 932 | |
| 933 | i = 0; |
| 934 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 935 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 936 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 937 | ifmodes >>= 1; |
| 938 | i++; |
| 939 | } |
| 940 | |
| 941 | nla_nest_end(msg, nl_modes); |
| 942 | return 0; |
| 943 | |
| 944 | nla_put_failure: |
| 945 | return -ENOBUFS; |
| 946 | } |
| 947 | |
| 948 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 949 | struct sk_buff *msg, |
| 950 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 951 | { |
| 952 | struct nlattr *nl_combis; |
| 953 | int i, j; |
| 954 | |
| 955 | nl_combis = nla_nest_start(msg, |
| 956 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 957 | if (!nl_combis) |
| 958 | goto nla_put_failure; |
| 959 | |
| 960 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 961 | const struct ieee80211_iface_combination *c; |
| 962 | struct nlattr *nl_combi, *nl_limits; |
| 963 | |
| 964 | c = &wiphy->iface_combinations[i]; |
| 965 | |
| 966 | nl_combi = nla_nest_start(msg, i + 1); |
| 967 | if (!nl_combi) |
| 968 | goto nla_put_failure; |
| 969 | |
| 970 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 971 | if (!nl_limits) |
| 972 | goto nla_put_failure; |
| 973 | |
| 974 | for (j = 0; j < c->n_limits; j++) { |
| 975 | struct nlattr *nl_limit; |
| 976 | |
| 977 | nl_limit = nla_nest_start(msg, j + 1); |
| 978 | if (!nl_limit) |
| 979 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 980 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 981 | c->limits[j].max)) |
| 982 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 983 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 984 | c->limits[j].types)) |
| 985 | goto nla_put_failure; |
| 986 | nla_nest_end(msg, nl_limit); |
| 987 | } |
| 988 | |
| 989 | nla_nest_end(msg, nl_limits); |
| 990 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 991 | if (c->beacon_int_infra_match && |
| 992 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 993 | goto nla_put_failure; |
| 994 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 995 | c->num_different_channels) || |
| 996 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 997 | c->max_interfaces)) |
| 998 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 999 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1000 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1001 | c->radar_detect_widths) || |
| 1002 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1003 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1004 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1005 | |
| 1006 | nla_nest_end(msg, nl_combi); |
| 1007 | } |
| 1008 | |
| 1009 | nla_nest_end(msg, nl_combis); |
| 1010 | |
| 1011 | return 0; |
| 1012 | nla_put_failure: |
| 1013 | return -ENOBUFS; |
| 1014 | } |
| 1015 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1016 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1017 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1018 | struct sk_buff *msg) |
| 1019 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1020 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1021 | struct nlattr *nl_tcp; |
| 1022 | |
| 1023 | if (!tcp) |
| 1024 | return 0; |
| 1025 | |
| 1026 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1027 | if (!nl_tcp) |
| 1028 | return -ENOBUFS; |
| 1029 | |
| 1030 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1031 | tcp->data_payload_max)) |
| 1032 | return -ENOBUFS; |
| 1033 | |
| 1034 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1035 | tcp->data_payload_max)) |
| 1036 | return -ENOBUFS; |
| 1037 | |
| 1038 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1039 | return -ENOBUFS; |
| 1040 | |
| 1041 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1042 | sizeof(*tcp->tok), tcp->tok)) |
| 1043 | return -ENOBUFS; |
| 1044 | |
| 1045 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1046 | tcp->data_interval_max)) |
| 1047 | return -ENOBUFS; |
| 1048 | |
| 1049 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1050 | tcp->wake_payload_max)) |
| 1051 | return -ENOBUFS; |
| 1052 | |
| 1053 | nla_nest_end(msg, nl_tcp); |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1057 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1058 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1059 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | { |
| 1061 | struct nlattr *nl_wowlan; |
| 1062 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | return 0; |
| 1065 | |
| 1066 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1067 | if (!nl_wowlan) |
| 1068 | return -ENOBUFS; |
| 1069 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1070 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1076 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1078 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1079 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1080 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1081 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1082 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1083 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1084 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1085 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1086 | return -ENOBUFS; |
| 1087 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1088 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1089 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1090 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1091 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1092 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1093 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1094 | }; |
| 1095 | |
| 1096 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1097 | sizeof(pat), &pat)) |
| 1098 | return -ENOBUFS; |
| 1099 | } |
| 1100 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1101 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1102 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1103 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1104 | return -ENOBUFS; |
| 1105 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1106 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1107 | return -ENOBUFS; |
| 1108 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1109 | nla_nest_end(msg, nl_wowlan); |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | #endif |
| 1114 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1115 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1116 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1117 | { |
| 1118 | struct nl80211_coalesce_rule_support rule; |
| 1119 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1120 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1121 | return 0; |
| 1122 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1123 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1124 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1125 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1126 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1127 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1128 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1129 | |
| 1130 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1131 | return -ENOBUFS; |
| 1132 | |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1136 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1137 | struct ieee80211_supported_band *sband) |
| 1138 | { |
| 1139 | struct nlattr *nl_rates, *nl_rate; |
| 1140 | struct ieee80211_rate *rate; |
| 1141 | int i; |
| 1142 | |
| 1143 | /* add HT info */ |
| 1144 | if (sband->ht_cap.ht_supported && |
| 1145 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1146 | sizeof(sband->ht_cap.mcs), |
| 1147 | &sband->ht_cap.mcs) || |
| 1148 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1149 | sband->ht_cap.cap) || |
| 1150 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1151 | sband->ht_cap.ampdu_factor) || |
| 1152 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1153 | sband->ht_cap.ampdu_density))) |
| 1154 | return -ENOBUFS; |
| 1155 | |
| 1156 | /* add VHT info */ |
| 1157 | if (sband->vht_cap.vht_supported && |
| 1158 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1159 | sizeof(sband->vht_cap.vht_mcs), |
| 1160 | &sband->vht_cap.vht_mcs) || |
| 1161 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1162 | sband->vht_cap.cap))) |
| 1163 | return -ENOBUFS; |
| 1164 | |
| 1165 | /* add bitrates */ |
| 1166 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1167 | if (!nl_rates) |
| 1168 | return -ENOBUFS; |
| 1169 | |
| 1170 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1171 | nl_rate = nla_nest_start(msg, i); |
| 1172 | if (!nl_rate) |
| 1173 | return -ENOBUFS; |
| 1174 | |
| 1175 | rate = &sband->bitrates[i]; |
| 1176 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1177 | rate->bitrate)) |
| 1178 | return -ENOBUFS; |
| 1179 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1180 | nla_put_flag(msg, |
| 1181 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1182 | return -ENOBUFS; |
| 1183 | |
| 1184 | nla_nest_end(msg, nl_rate); |
| 1185 | } |
| 1186 | |
| 1187 | nla_nest_end(msg, nl_rates); |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | static int |
| 1193 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1194 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1195 | { |
| 1196 | u16 stypes; |
| 1197 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1198 | enum nl80211_iftype ift; |
| 1199 | int i; |
| 1200 | |
| 1201 | if (!mgmt_stypes) |
| 1202 | return 0; |
| 1203 | |
| 1204 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1205 | if (!nl_ifs) |
| 1206 | return -ENOBUFS; |
| 1207 | |
| 1208 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1209 | nl_ftypes = nla_nest_start(msg, ift); |
| 1210 | if (!nl_ftypes) |
| 1211 | return -ENOBUFS; |
| 1212 | i = 0; |
| 1213 | stypes = mgmt_stypes[ift].tx; |
| 1214 | while (stypes) { |
| 1215 | if ((stypes & 1) && |
| 1216 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1217 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1218 | return -ENOBUFS; |
| 1219 | stypes >>= 1; |
| 1220 | i++; |
| 1221 | } |
| 1222 | nla_nest_end(msg, nl_ftypes); |
| 1223 | } |
| 1224 | |
| 1225 | nla_nest_end(msg, nl_ifs); |
| 1226 | |
| 1227 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1228 | if (!nl_ifs) |
| 1229 | return -ENOBUFS; |
| 1230 | |
| 1231 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1232 | nl_ftypes = nla_nest_start(msg, ift); |
| 1233 | if (!nl_ftypes) |
| 1234 | return -ENOBUFS; |
| 1235 | i = 0; |
| 1236 | stypes = mgmt_stypes[ift].rx; |
| 1237 | while (stypes) { |
| 1238 | if ((stypes & 1) && |
| 1239 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1240 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1241 | return -ENOBUFS; |
| 1242 | stypes >>= 1; |
| 1243 | i++; |
| 1244 | } |
| 1245 | nla_nest_end(msg, nl_ftypes); |
| 1246 | } |
| 1247 | nla_nest_end(msg, nl_ifs); |
| 1248 | |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1252 | struct nl80211_dump_wiphy_state { |
| 1253 | s64 filter_wiphy; |
| 1254 | long start; |
| 1255 | long split_start, band_start, chan_start; |
| 1256 | bool split; |
| 1257 | }; |
| 1258 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1259 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1260 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1261 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1262 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1263 | { |
| 1264 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1265 | struct nlattr *nl_bands, *nl_band; |
| 1266 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1267 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1268 | enum ieee80211_band band; |
| 1269 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1270 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1271 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1272 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1273 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1274 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1275 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1276 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | return -ENOBUFS; |
| 1278 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1279 | if (WARN_ON(!state)) |
| 1280 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1281 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1285 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1287 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1288 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1289 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1290 | goto finish; |
| 1291 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1292 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | case 0: |
| 1294 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1295 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1297 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1298 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1299 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1300 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1303 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1305 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1307 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1311 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1312 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1313 | rdev->wiphy.max_match_sets) || |
| 1314 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1315 | rdev->wiphy.max_sched_scan_plans) || |
| 1316 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1317 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1318 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1319 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1320 | goto nla_put_failure; |
| 1321 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1322 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1324 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1325 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1326 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1327 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1328 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1330 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1332 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1333 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1336 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1337 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1339 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1340 | state->split_start++; |
| 1341 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | break; |
| 1343 | case 1: |
| 1344 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1345 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1346 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1347 | goto nla_put_failure; |
| 1348 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1349 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1350 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1351 | goto nla_put_failure; |
| 1352 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1353 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1354 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1355 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1356 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1358 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1360 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1362 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1363 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1365 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1367 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | if ((rdev->wiphy.available_antennas_tx || |
| 1369 | rdev->wiphy.available_antennas_rx) && |
| 1370 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | u32 tx_ant = 0, rx_ant = 0; |
| 1372 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1373 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | if (!res) { |
| 1375 | if (nla_put_u32(msg, |
| 1376 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1377 | tx_ant) || |
| 1378 | nla_put_u32(msg, |
| 1379 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1380 | rx_ant)) |
| 1381 | goto nla_put_failure; |
| 1382 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1385 | state->split_start++; |
| 1386 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1387 | break; |
| 1388 | case 2: |
| 1389 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1390 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1392 | state->split_start++; |
| 1393 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1394 | break; |
| 1395 | case 3: |
| 1396 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1397 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1398 | goto nla_put_failure; |
| 1399 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1400 | for (band = state->band_start; |
| 1401 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1402 | struct ieee80211_supported_band *sband; |
| 1403 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1404 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1405 | |
| 1406 | if (!sband) |
| 1407 | continue; |
| 1408 | |
| 1409 | nl_band = nla_nest_start(msg, band); |
| 1410 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1411 | goto nla_put_failure; |
| 1412 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1413 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1414 | case 0: |
| 1415 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1416 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | state->chan_start++; |
| 1418 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | break; |
| 1420 | default: |
| 1421 | /* add frequencies */ |
| 1422 | nl_freqs = nla_nest_start( |
| 1423 | msg, NL80211_BAND_ATTR_FREQS); |
| 1424 | if (!nl_freqs) |
| 1425 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1426 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | i < sband->n_channels; |
| 1429 | i++) { |
| 1430 | nl_freq = nla_nest_start(msg, i); |
| 1431 | if (!nl_freq) |
| 1432 | goto nla_put_failure; |
| 1433 | |
| 1434 | chan = &sband->channels[i]; |
| 1435 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | if (nl80211_msg_put_channel( |
| 1437 | msg, chan, |
| 1438 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1439 | goto nla_put_failure; |
| 1440 | |
| 1441 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1442 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1443 | break; |
| 1444 | } |
| 1445 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1446 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1448 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1449 | nla_nest_end(msg, nl_freqs); |
| 1450 | } |
| 1451 | |
| 1452 | nla_nest_end(msg, nl_band); |
| 1453 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1454 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1455 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1456 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | band--; |
| 1458 | break; |
| 1459 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1460 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1461 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1462 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1464 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1465 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1466 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1467 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1469 | if (state->band_start == 0 && state->chan_start == 0) |
| 1470 | state->split_start++; |
| 1471 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1472 | break; |
| 1473 | case 4: |
| 1474 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1475 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1476 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | |
| 1478 | i = 0; |
| 1479 | #define CMD(op, n) \ |
| 1480 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1481 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | i++; \ |
| 1483 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1484 | goto nla_put_failure; \ |
| 1485 | } \ |
| 1486 | } while (0) |
| 1487 | |
| 1488 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1489 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1490 | CMD(add_key, NEW_KEY); |
| 1491 | CMD(start_ap, START_AP); |
| 1492 | CMD(add_station, NEW_STATION); |
| 1493 | CMD(add_mpath, NEW_MPATH); |
| 1494 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1495 | CMD(change_bss, SET_BSS); |
| 1496 | CMD(auth, AUTHENTICATE); |
| 1497 | CMD(assoc, ASSOCIATE); |
| 1498 | CMD(deauth, DEAUTHENTICATE); |
| 1499 | CMD(disassoc, DISASSOCIATE); |
| 1500 | CMD(join_ibss, JOIN_IBSS); |
| 1501 | CMD(join_mesh, JOIN_MESH); |
| 1502 | CMD(set_pmksa, SET_PMKSA); |
| 1503 | CMD(del_pmksa, DEL_PMKSA); |
| 1504 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1505 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1507 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1508 | CMD(mgmt_tx, FRAME); |
| 1509 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1510 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | i++; |
| 1512 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1513 | goto nla_put_failure; |
| 1514 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1515 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1516 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1517 | i++; |
| 1518 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1519 | goto nla_put_failure; |
| 1520 | } |
| 1521 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1522 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1523 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1524 | CMD(tdls_oper, TDLS_OPER); |
| 1525 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1526 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1527 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1528 | CMD(probe_client, PROBE_CLIENT); |
| 1529 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1530 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | i++; |
| 1532 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1533 | goto nla_put_failure; |
| 1534 | } |
| 1535 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1536 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1537 | #ifdef CONFIG_NL80211_TESTMODE |
| 1538 | CMD(testmode_cmd, TESTMODE); |
| 1539 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1540 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1541 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1542 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1543 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1544 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1545 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1546 | if (rdev->wiphy.features & |
| 1547 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1548 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1549 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1550 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1551 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1552 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1553 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | i++; |
| 1555 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1556 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1559 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | i++; |
| 1561 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1562 | goto nla_put_failure; |
| 1563 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1564 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1566 | state->split_start++; |
| 1567 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1570 | if (rdev->ops->remain_on_channel && |
| 1571 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | nla_put_u32(msg, |
| 1573 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1574 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1575 | goto nla_put_failure; |
| 1576 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1577 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1578 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1579 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1580 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1582 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1583 | state->split_start++; |
| 1584 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1585 | break; |
| 1586 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1587 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1590 | state->split_start++; |
| 1591 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1592 | break; |
| 1593 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1594 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1595 | #endif |
| 1596 | case 7: |
| 1597 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1598 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1599 | goto nla_put_failure; |
| 1600 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1601 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1602 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1604 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1605 | state->split_start++; |
| 1606 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1607 | break; |
| 1608 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1609 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1610 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1611 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1612 | goto nla_put_failure; |
| 1613 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1614 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1615 | /* |
| 1616 | * We can only add the per-channel limit information if the |
| 1617 | * dump is split, otherwise it makes it too big. Therefore |
| 1618 | * only advertise it in that case. |
| 1619 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1620 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1621 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1622 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | goto nla_put_failure; |
| 1624 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1625 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1626 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1627 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1628 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | goto nla_put_failure; |
| 1630 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1632 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1633 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1634 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1635 | goto nla_put_failure; |
| 1636 | |
| 1637 | /* |
| 1638 | * Any information below this point is only available to |
| 1639 | * applications that can deal with it being split. This |
| 1640 | * helps ensure that newly added capabilities don't break |
| 1641 | * older tools by overrunning their buffers. |
| 1642 | * |
| 1643 | * We still increment split_start so that in the split |
| 1644 | * case we'll continue with more data in the next round, |
| 1645 | * but break unconditionally so unsplit data stops here. |
| 1646 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1647 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | break; |
| 1649 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1650 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1651 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1652 | rdev->wiphy.extended_capabilities_len, |
| 1653 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1654 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1655 | rdev->wiphy.extended_capabilities_len, |
| 1656 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1657 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1659 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1660 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1661 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1662 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1663 | goto nla_put_failure; |
| 1664 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1665 | state->split_start++; |
| 1666 | break; |
| 1667 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1668 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1669 | goto nla_put_failure; |
| 1670 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1672 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1673 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1674 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1675 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1676 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1677 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1678 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1679 | goto nla_put_failure; |
| 1680 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1681 | state->split_start++; |
| 1682 | break; |
| 1683 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1684 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1685 | const struct nl80211_vendor_cmd_info *info; |
| 1686 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1687 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1688 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1689 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1690 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1691 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1692 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1693 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1694 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1695 | goto nla_put_failure; |
| 1696 | } |
| 1697 | nla_nest_end(msg, nested); |
| 1698 | } |
| 1699 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1700 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1701 | const struct nl80211_vendor_cmd_info *info; |
| 1702 | struct nlattr *nested; |
| 1703 | |
| 1704 | nested = nla_nest_start(msg, |
| 1705 | NL80211_ATTR_VENDOR_EVENTS); |
| 1706 | if (!nested) |
| 1707 | goto nla_put_failure; |
| 1708 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1709 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1710 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1711 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1712 | goto nla_put_failure; |
| 1713 | } |
| 1714 | nla_nest_end(msg, nested); |
| 1715 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1716 | state->split_start++; |
| 1717 | break; |
| 1718 | case 12: |
| 1719 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1720 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1721 | rdev->wiphy.max_num_csa_counters)) |
| 1722 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1723 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1724 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1725 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1726 | goto nla_put_failure; |
| 1727 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1728 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1729 | sizeof(rdev->wiphy.ext_features), |
| 1730 | rdev->wiphy.ext_features)) |
| 1731 | goto nla_put_failure; |
| 1732 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1733 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1734 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1735 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1736 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1737 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1738 | genlmsg_end(msg, hdr); |
| 1739 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1740 | |
| 1741 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1742 | genlmsg_cancel(msg, hdr); |
| 1743 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1744 | } |
| 1745 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1746 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1747 | struct netlink_callback *cb, |
| 1748 | struct nl80211_dump_wiphy_state *state) |
| 1749 | { |
| 1750 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1751 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1752 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1753 | /* ignore parse errors for backward compatibility */ |
| 1754 | if (ret) |
| 1755 | return 0; |
| 1756 | |
| 1757 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1758 | if (tb[NL80211_ATTR_WIPHY]) |
| 1759 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1760 | if (tb[NL80211_ATTR_WDEV]) |
| 1761 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1762 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1763 | struct net_device *netdev; |
| 1764 | struct cfg80211_registered_device *rdev; |
| 1765 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1766 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1767 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1768 | if (!netdev) |
| 1769 | return -ENODEV; |
| 1770 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1771 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1772 | netdev->ieee80211_ptr->wiphy); |
| 1773 | state->filter_wiphy = rdev->wiphy_idx; |
| 1774 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1780 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1781 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1782 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1783 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1784 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1785 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1786 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1787 | if (!state) { |
| 1788 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1789 | if (!state) { |
| 1790 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1791 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1792 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1793 | state->filter_wiphy = -1; |
| 1794 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1795 | if (ret) { |
| 1796 | kfree(state); |
| 1797 | rtnl_unlock(); |
| 1798 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1799 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1800 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1801 | } |
| 1802 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1803 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1804 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1805 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1806 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1807 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1808 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1809 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1810 | continue; |
| 1811 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1812 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1813 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1814 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1815 | NETLINK_CB(cb->skb).portid, |
| 1816 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1817 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1818 | if (ret < 0) { |
| 1819 | /* |
| 1820 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1821 | * or EMSGSIZE returned), this SKB is still |
| 1822 | * empty (so it's not too big because another |
| 1823 | * wiphy dataset is already in the skb) and |
| 1824 | * we've not tried to adjust the dump allocation |
| 1825 | * yet ... then adjust the alloc size to be |
| 1826 | * bigger, and return 1 but with the empty skb. |
| 1827 | * This results in an empty message being RX'ed |
| 1828 | * in userspace, but that is ignored. |
| 1829 | * |
| 1830 | * We can then retry with the larger buffer. |
| 1831 | */ |
| 1832 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1833 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1834 | cb->min_dump_alloc < 4096) { |
| 1835 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1836 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1837 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1838 | return 1; |
| 1839 | } |
| 1840 | idx--; |
| 1841 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1842 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1843 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1844 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1845 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1846 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1847 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1848 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1849 | |
| 1850 | return skb->len; |
| 1851 | } |
| 1852 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1853 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1854 | { |
| 1855 | kfree((void *)cb->args[0]); |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1859 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1860 | { |
| 1861 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1863 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1864 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1865 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1866 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1867 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1868 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1869 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1870 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1871 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1872 | nlmsg_free(msg); |
| 1873 | return -ENOBUFS; |
| 1874 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1875 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1876 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1877 | } |
| 1878 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1879 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1880 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1881 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1882 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1883 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1884 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1885 | }; |
| 1886 | |
| 1887 | static int parse_txq_params(struct nlattr *tb[], |
| 1888 | struct ieee80211_txq_params *txq_params) |
| 1889 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1890 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1891 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1892 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1893 | return -EINVAL; |
| 1894 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1895 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1896 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1897 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1898 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1899 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1900 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1901 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1902 | return -EINVAL; |
| 1903 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1904 | return 0; |
| 1905 | } |
| 1906 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1907 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1908 | { |
| 1909 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1910 | * You can only set the channel explicitly for WDS interfaces, |
| 1911 | * all others have their channel managed via their respective |
| 1912 | * "establish a connection" command (connect, join, ...) |
| 1913 | * |
| 1914 | * For AP/GO and mesh mode, the channel can be set with the |
| 1915 | * channel userspace API, but is only stored and passed to the |
| 1916 | * low-level driver when the AP starts or the mesh is joined. |
| 1917 | * This is for backward compatibility, userspace can also give |
| 1918 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1919 | * |
| 1920 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1921 | * whatever else is going on, so they have their own special |
| 1922 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1923 | */ |
| 1924 | return !wdev || |
| 1925 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1926 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1927 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1928 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1929 | } |
| 1930 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1931 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1932 | struct genl_info *info, |
| 1933 | struct cfg80211_chan_def *chandef) |
| 1934 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1935 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1936 | |
| 1937 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1938 | return -EINVAL; |
| 1939 | |
| 1940 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1941 | |
| 1942 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1943 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1944 | chandef->center_freq1 = control_freq; |
| 1945 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1946 | |
| 1947 | /* Primary channel not allowed */ |
| 1948 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1949 | return -EINVAL; |
| 1950 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1951 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1952 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1953 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1954 | chantype = nla_get_u32( |
| 1955 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1956 | |
| 1957 | switch (chantype) { |
| 1958 | case NL80211_CHAN_NO_HT: |
| 1959 | case NL80211_CHAN_HT20: |
| 1960 | case NL80211_CHAN_HT40PLUS: |
| 1961 | case NL80211_CHAN_HT40MINUS: |
| 1962 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1963 | chantype); |
| 1964 | break; |
| 1965 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1966 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1967 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1968 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1969 | chandef->width = |
| 1970 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1971 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1972 | chandef->center_freq1 = |
| 1973 | nla_get_u32( |
| 1974 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1975 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1976 | chandef->center_freq2 = |
| 1977 | nla_get_u32( |
| 1978 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1979 | } |
| 1980 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1981 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1982 | return -EINVAL; |
| 1983 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1984 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1985 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1986 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1987 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1988 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1989 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1990 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1991 | return -EINVAL; |
| 1992 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1993 | return 0; |
| 1994 | } |
| 1995 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1996 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1997 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1998 | struct genl_info *info) |
| 1999 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2000 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2001 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2002 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2003 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2004 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2005 | if (dev) |
| 2006 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2007 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2008 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2009 | if (wdev) |
| 2010 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2011 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2012 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2013 | if (result) |
| 2014 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2015 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2016 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2017 | case NL80211_IFTYPE_AP: |
| 2018 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2019 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2020 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2021 | result = -EINVAL; |
| 2022 | break; |
| 2023 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2024 | if (wdev->beacon_interval) { |
| 2025 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2026 | !(rdev->wiphy.features & |
| 2027 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2028 | result = -EBUSY; |
| 2029 | break; |
| 2030 | } |
| 2031 | |
| 2032 | /* Only allow dynamic channel width changes */ |
| 2033 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2034 | result = -EBUSY; |
| 2035 | break; |
| 2036 | } |
| 2037 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2038 | if (result) |
| 2039 | break; |
| 2040 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2041 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2042 | result = 0; |
| 2043 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2044 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2045 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2046 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2047 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2048 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2049 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2050 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2051 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2052 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2053 | |
| 2054 | return result; |
| 2055 | } |
| 2056 | |
| 2057 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2058 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2060 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2061 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2062 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2063 | } |
| 2064 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2065 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2066 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2068 | struct net_device *dev = info->user_ptr[1]; |
| 2069 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2070 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2071 | |
| 2072 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2073 | return -EINVAL; |
| 2074 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2075 | if (netif_running(dev)) |
| 2076 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2077 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2078 | if (!rdev->ops->set_wds_peer) |
| 2079 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2080 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2081 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2082 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2083 | |
| 2084 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2085 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2089 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2090 | { |
| 2091 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | struct net_device *netdev = NULL; |
| 2093 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2094 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2095 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2096 | u32 changed; |
| 2097 | u8 retry_short = 0, retry_long = 0; |
| 2098 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2099 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2100 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2101 | ASSERT_RTNL(); |
| 2102 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2103 | /* |
| 2104 | * Try to find the wiphy and netdev. Normally this |
| 2105 | * function shouldn't need the netdev, but this is |
| 2106 | * done for backward compatibility -- previously |
| 2107 | * setting the channel was done per wiphy, but now |
| 2108 | * it is per netdev. Previous userland like hostapd |
| 2109 | * also passed a netdev to set_wiphy, so that it is |
| 2110 | * possible to let that go to the right netdev! |
| 2111 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2112 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2113 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2114 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2115 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2116 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2117 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2118 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2119 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2120 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2123 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2124 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2125 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2126 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2127 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2128 | wdev = NULL; |
| 2129 | netdev = NULL; |
| 2130 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2131 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2132 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2133 | |
| 2134 | /* |
| 2135 | * end workaround code, by now the rdev is available |
| 2136 | * and locked, and wdev may or may not be NULL. |
| 2137 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2138 | |
| 2139 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2140 | result = cfg80211_dev_rename( |
| 2141 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2142 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2143 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2144 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2145 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2146 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2147 | struct ieee80211_txq_params txq_params; |
| 2148 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2149 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2150 | if (!rdev->ops->set_txq_params) |
| 2151 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2152 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2153 | if (!netdev) |
| 2154 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2155 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2156 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2157 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2158 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2159 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2160 | if (!netif_running(netdev)) |
| 2161 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2162 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2163 | nla_for_each_nested(nl_txq_params, |
| 2164 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2165 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2166 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2167 | nla_data(nl_txq_params), |
| 2168 | nla_len(nl_txq_params), |
| 2169 | txq_params_policy); |
| 2170 | if (result) |
| 2171 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2172 | result = parse_txq_params(tb, &txq_params); |
| 2173 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2174 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2175 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2176 | result = rdev_set_txq_params(rdev, netdev, |
| 2177 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2178 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2179 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2183 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2184 | result = __nl80211_set_channel( |
| 2185 | rdev, |
| 2186 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2187 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2188 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2189 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2190 | } |
| 2191 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2192 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2193 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2194 | enum nl80211_tx_power_setting type; |
| 2195 | int idx, mbm = 0; |
| 2196 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2197 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2198 | txp_wdev = NULL; |
| 2199 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2200 | if (!rdev->ops->set_tx_power) |
| 2201 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2202 | |
| 2203 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2204 | type = nla_get_u32(info->attrs[idx]); |
| 2205 | |
| 2206 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2207 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2208 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2209 | |
| 2210 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2211 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2212 | mbm = nla_get_u32(info->attrs[idx]); |
| 2213 | } |
| 2214 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2215 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2216 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2217 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2218 | } |
| 2219 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2220 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2221 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2222 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2223 | if ((!rdev->wiphy.available_antennas_tx && |
| 2224 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2225 | !rdev->ops->set_antenna) |
| 2226 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2227 | |
| 2228 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2229 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2230 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2231 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2232 | * available antenna masks, except for the "all" mask */ |
| 2233 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2234 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2235 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2236 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2237 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2238 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2240 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2241 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2242 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2243 | } |
| 2244 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2245 | changed = 0; |
| 2246 | |
| 2247 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2248 | retry_short = nla_get_u8( |
| 2249 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2250 | if (retry_short == 0) |
| 2251 | return -EINVAL; |
| 2252 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2253 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2254 | } |
| 2255 | |
| 2256 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2257 | retry_long = nla_get_u8( |
| 2258 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2259 | if (retry_long == 0) |
| 2260 | return -EINVAL; |
| 2261 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2262 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2263 | } |
| 2264 | |
| 2265 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2266 | frag_threshold = nla_get_u32( |
| 2267 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2268 | if (frag_threshold < 256) |
| 2269 | return -EINVAL; |
| 2270 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2271 | if (frag_threshold != (u32) -1) { |
| 2272 | /* |
| 2273 | * Fragments (apart from the last one) are required to |
| 2274 | * have even length. Make the fragmentation code |
| 2275 | * simpler by stripping LSB should someone try to use |
| 2276 | * odd threshold value. |
| 2277 | */ |
| 2278 | frag_threshold &= ~0x1; |
| 2279 | } |
| 2280 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2281 | } |
| 2282 | |
| 2283 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2284 | rts_threshold = nla_get_u32( |
| 2285 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2286 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2287 | } |
| 2288 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2289 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2290 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2291 | return -EINVAL; |
| 2292 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2293 | coverage_class = nla_get_u8( |
| 2294 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2295 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2296 | } |
| 2297 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2298 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2299 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2300 | return -EOPNOTSUPP; |
| 2301 | |
| 2302 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2303 | } |
| 2304 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2305 | if (changed) { |
| 2306 | u8 old_retry_short, old_retry_long; |
| 2307 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2308 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2309 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2310 | if (!rdev->ops->set_wiphy_params) |
| 2311 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2312 | |
| 2313 | old_retry_short = rdev->wiphy.retry_short; |
| 2314 | old_retry_long = rdev->wiphy.retry_long; |
| 2315 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2316 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2317 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2318 | |
| 2319 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2320 | rdev->wiphy.retry_short = retry_short; |
| 2321 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2322 | rdev->wiphy.retry_long = retry_long; |
| 2323 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2324 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2325 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2326 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2327 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2328 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2329 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2330 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2331 | if (result) { |
| 2332 | rdev->wiphy.retry_short = old_retry_short; |
| 2333 | rdev->wiphy.retry_long = old_retry_long; |
| 2334 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2335 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2336 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2337 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2338 | } |
| 2339 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2340 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2341 | } |
| 2342 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2343 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2344 | { |
| 2345 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2346 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2347 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2348 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2349 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2350 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2351 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2352 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2353 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2354 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2356 | chandef->chan->center_freq)) |
| 2357 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2358 | switch (chandef->width) { |
| 2359 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2360 | case NL80211_CHAN_WIDTH_20: |
| 2361 | case NL80211_CHAN_WIDTH_40: |
| 2362 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2363 | cfg80211_get_chandef_type(chandef))) |
| 2364 | return -ENOBUFS; |
| 2365 | break; |
| 2366 | default: |
| 2367 | break; |
| 2368 | } |
| 2369 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2370 | return -ENOBUFS; |
| 2371 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2372 | return -ENOBUFS; |
| 2373 | if (chandef->center_freq2 && |
| 2374 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2375 | return -ENOBUFS; |
| 2376 | return 0; |
| 2377 | } |
| 2378 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2379 | 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] | 2380 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2381 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2382 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2383 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2384 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2385 | void *hdr; |
| 2386 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2387 | if (removal) |
| 2388 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2389 | |
| 2390 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2391 | if (!hdr) |
| 2392 | return -1; |
| 2393 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2394 | if (dev && |
| 2395 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2396 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2397 | goto nla_put_failure; |
| 2398 | |
| 2399 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2400 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2401 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2402 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2403 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2404 | rdev->devlist_generation ^ |
| 2405 | (cfg80211_rdev_list_generation << 2))) |
| 2406 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2407 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2408 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2409 | int ret; |
| 2410 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2411 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2412 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2413 | if (ret == 0) { |
| 2414 | if (nl80211_send_chandef(msg, &chandef)) |
| 2415 | goto nla_put_failure; |
| 2416 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2417 | } |
| 2418 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2419 | if (rdev->ops->get_tx_power) { |
| 2420 | int dbm, ret; |
| 2421 | |
| 2422 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2423 | if (ret == 0 && |
| 2424 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2425 | DBM_TO_MBM(dbm))) |
| 2426 | goto nla_put_failure; |
| 2427 | } |
| 2428 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2429 | if (wdev->ssid_len) { |
| 2430 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2431 | goto nla_put_failure; |
| 2432 | } |
| 2433 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2434 | genlmsg_end(msg, hdr); |
| 2435 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2436 | |
| 2437 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2438 | genlmsg_cancel(msg, hdr); |
| 2439 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2443 | { |
| 2444 | int wp_idx = 0; |
| 2445 | int if_idx = 0; |
| 2446 | int wp_start = cb->args[0]; |
| 2447 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2448 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2449 | struct wireless_dev *wdev; |
| 2450 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2451 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2452 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2453 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2454 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2455 | if (wp_idx < wp_start) { |
| 2456 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2457 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2458 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2459 | if_idx = 0; |
| 2460 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2461 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2462 | if (if_idx < if_start) { |
| 2463 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2464 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2465 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2466 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2468 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2469 | goto out; |
| 2470 | } |
| 2471 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2472 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2473 | |
| 2474 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2475 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2476 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2477 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2478 | |
| 2479 | cb->args[0] = wp_idx; |
| 2480 | cb->args[1] = if_idx; |
| 2481 | |
| 2482 | return skb->len; |
| 2483 | } |
| 2484 | |
| 2485 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2486 | { |
| 2487 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2489 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2490 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2492 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2493 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2494 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2495 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2496 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2497 | nlmsg_free(msg); |
| 2498 | return -ENOBUFS; |
| 2499 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2500 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2501 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2502 | } |
| 2503 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2504 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2505 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2506 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2507 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2508 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2509 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2510 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2511 | }; |
| 2512 | |
| 2513 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2514 | { |
| 2515 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2516 | int flag; |
| 2517 | |
| 2518 | *mntrflags = 0; |
| 2519 | |
| 2520 | if (!nla) |
| 2521 | return -EINVAL; |
| 2522 | |
| 2523 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2524 | nla, mntr_flags_policy)) |
| 2525 | return -EINVAL; |
| 2526 | |
| 2527 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2528 | if (flags[flag]) |
| 2529 | *mntrflags |= (1<<flag); |
| 2530 | |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2534 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2535 | struct net_device *netdev, u8 use_4addr, |
| 2536 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2537 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2538 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2539 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2540 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2541 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2542 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2543 | |
| 2544 | switch (iftype) { |
| 2545 | case NL80211_IFTYPE_AP_VLAN: |
| 2546 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2547 | return 0; |
| 2548 | break; |
| 2549 | case NL80211_IFTYPE_STATION: |
| 2550 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2551 | return 0; |
| 2552 | break; |
| 2553 | default: |
| 2554 | break; |
| 2555 | } |
| 2556 | |
| 2557 | return -EOPNOTSUPP; |
| 2558 | } |
| 2559 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2560 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2563 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2564 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2565 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2567 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2568 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2569 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2570 | memset(¶ms, 0, sizeof(params)); |
| 2571 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2572 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2573 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2574 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2575 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2576 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2577 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | if (ntype > NL80211_IFTYPE_MAX) |
| 2579 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2580 | } |
| 2581 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2582 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2583 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2584 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2585 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2586 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2587 | if (netif_running(dev)) |
| 2588 | return -EBUSY; |
| 2589 | |
| 2590 | wdev_lock(wdev); |
| 2591 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2592 | IEEE80211_MAX_MESH_ID_LEN); |
| 2593 | wdev->mesh_id_up_len = |
| 2594 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2595 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2596 | wdev->mesh_id_up_len); |
| 2597 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2598 | } |
| 2599 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2600 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2601 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2602 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2603 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2604 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2605 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2606 | } else { |
| 2607 | params.use_4addr = -1; |
| 2608 | } |
| 2609 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2610 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2611 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2612 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2613 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2614 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2615 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2616 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2617 | |
| 2618 | flags = &_flags; |
| 2619 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2620 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2621 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2622 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2623 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2624 | return -EOPNOTSUPP; |
| 2625 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2626 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2627 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2628 | else |
| 2629 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2630 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2631 | if (!err && params.use_4addr != -1) |
| 2632 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2633 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2634 | return err; |
| 2635 | } |
| 2636 | |
| 2637 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2638 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2640 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2641 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2642 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2643 | int err; |
| 2644 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2645 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2646 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2647 | /* to avoid failing a new interface creation due to pending removal */ |
| 2648 | cfg80211_destroy_ifaces(rdev); |
| 2649 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2650 | memset(¶ms, 0, sizeof(params)); |
| 2651 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2652 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2653 | return -EINVAL; |
| 2654 | |
| 2655 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2656 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2657 | if (type > NL80211_IFTYPE_MAX) |
| 2658 | return -EINVAL; |
| 2659 | } |
| 2660 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2661 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2662 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2663 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2664 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2665 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2666 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2667 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2668 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2669 | ETH_ALEN); |
| 2670 | if (!is_valid_ether_addr(params.macaddr)) |
| 2671 | return -EADDRNOTAVAIL; |
| 2672 | } |
| 2673 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2674 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2675 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2676 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2677 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2678 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2679 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2680 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2681 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2682 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2683 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2684 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2685 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2686 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2687 | return -EOPNOTSUPP; |
| 2688 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2690 | if (!msg) |
| 2691 | return -ENOMEM; |
| 2692 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2693 | wdev = rdev_add_virtual_intf(rdev, |
| 2694 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2695 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2696 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2697 | if (WARN_ON(!wdev)) { |
| 2698 | nlmsg_free(msg); |
| 2699 | return -EPROTO; |
| 2700 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2701 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2702 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2703 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2704 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2705 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2706 | wdev->owner_nlportid = info->snd_portid; |
| 2707 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2708 | switch (type) { |
| 2709 | case NL80211_IFTYPE_MESH_POINT: |
| 2710 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2711 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2712 | wdev_lock(wdev); |
| 2713 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2714 | IEEE80211_MAX_MESH_ID_LEN); |
| 2715 | wdev->mesh_id_up_len = |
| 2716 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2717 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2718 | wdev->mesh_id_up_len); |
| 2719 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2720 | break; |
| 2721 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2722 | /* |
| 2723 | * P2P Device doesn't have a netdev, so doesn't go |
| 2724 | * through the netdev notifier and must be added here |
| 2725 | */ |
| 2726 | mutex_init(&wdev->mtx); |
| 2727 | INIT_LIST_HEAD(&wdev->event_list); |
| 2728 | spin_lock_init(&wdev->event_lock); |
| 2729 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2730 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2731 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2732 | wdev->identifier = ++rdev->wdev_id; |
| 2733 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2734 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2735 | break; |
| 2736 | default: |
| 2737 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2740 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2741 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2742 | nlmsg_free(msg); |
| 2743 | return -ENOBUFS; |
| 2744 | } |
| 2745 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2746 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2747 | if (event) { |
| 2748 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2749 | rdev, wdev, false) < 0) { |
| 2750 | nlmsg_free(event); |
| 2751 | goto out; |
| 2752 | } |
| 2753 | |
| 2754 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2755 | event, 0, NL80211_MCGRP_CONFIG, |
| 2756 | GFP_KERNEL); |
| 2757 | } |
| 2758 | |
| 2759 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2760 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2766 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2767 | struct sk_buff *msg; |
| 2768 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2769 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2770 | if (!rdev->ops->del_virtual_intf) |
| 2771 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2772 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2774 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2775 | nlmsg_free(msg); |
| 2776 | msg = NULL; |
| 2777 | } |
| 2778 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2779 | /* |
| 2780 | * If we remove a wireless device without a netdev then clear |
| 2781 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2782 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2783 | * since the wdev has been freed, unlike with a netdev where |
| 2784 | * we need the dev_put() for the netdev to really be freed. |
| 2785 | */ |
| 2786 | if (!wdev->netdev) |
| 2787 | info->user_ptr[1] = NULL; |
| 2788 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2789 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2790 | if (status >= 0 && msg) |
| 2791 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2792 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2793 | GFP_KERNEL); |
| 2794 | else |
| 2795 | nlmsg_free(msg); |
| 2796 | |
| 2797 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2798 | } |
| 2799 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2800 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2801 | { |
| 2802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2803 | struct net_device *dev = info->user_ptr[1]; |
| 2804 | u16 noack_map; |
| 2805 | |
| 2806 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2807 | return -EINVAL; |
| 2808 | |
| 2809 | if (!rdev->ops->set_noack_map) |
| 2810 | return -EOPNOTSUPP; |
| 2811 | |
| 2812 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2813 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2814 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2815 | } |
| 2816 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2817 | struct get_key_cookie { |
| 2818 | struct sk_buff *msg; |
| 2819 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2820 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2821 | }; |
| 2822 | |
| 2823 | static void get_key_callback(void *c, struct key_params *params) |
| 2824 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | struct get_key_cookie *cookie = c; |
| 2827 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2828 | if ((params->key && |
| 2829 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2830 | params->key_len, params->key)) || |
| 2831 | (params->seq && |
| 2832 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2833 | params->seq_len, params->seq)) || |
| 2834 | (params->cipher && |
| 2835 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2836 | params->cipher))) |
| 2837 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2838 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2839 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2840 | if (!key) |
| 2841 | goto nla_put_failure; |
| 2842 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2843 | if ((params->key && |
| 2844 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2845 | params->key_len, params->key)) || |
| 2846 | (params->seq && |
| 2847 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2848 | params->seq_len, params->seq)) || |
| 2849 | (params->cipher && |
| 2850 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2851 | params->cipher))) |
| 2852 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2853 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2854 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2855 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2856 | |
| 2857 | nla_nest_end(cookie->msg, key); |
| 2858 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2859 | return; |
| 2860 | nla_put_failure: |
| 2861 | cookie->error = 1; |
| 2862 | } |
| 2863 | |
| 2864 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2865 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2867 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2868 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2869 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2870 | const u8 *mac_addr = NULL; |
| 2871 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | struct get_key_cookie cookie = { |
| 2873 | .error = 0, |
| 2874 | }; |
| 2875 | void *hdr; |
| 2876 | struct sk_buff *msg; |
| 2877 | |
| 2878 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2879 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2880 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2881 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2882 | return -EINVAL; |
| 2883 | |
| 2884 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2885 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2886 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2887 | pairwise = !!mac_addr; |
| 2888 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2889 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2890 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2891 | return -EINVAL; |
| 2892 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2893 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2894 | return -EINVAL; |
| 2895 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2896 | } |
| 2897 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2898 | if (!rdev->ops->get_key) |
| 2899 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2900 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 2901 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2902 | return -ENOENT; |
| 2903 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2904 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2905 | if (!msg) |
| 2906 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2907 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2908 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2909 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2910 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2911 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | |
| 2913 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2914 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2916 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2917 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2918 | goto nla_put_failure; |
| 2919 | if (mac_addr && |
| 2920 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2921 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2922 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2923 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2924 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2925 | |
| 2926 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2927 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2928 | |
| 2929 | if (cookie.error) |
| 2930 | goto nla_put_failure; |
| 2931 | |
| 2932 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2933 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2934 | |
| 2935 | nla_put_failure: |
| 2936 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2937 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2938 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2939 | return err; |
| 2940 | } |
| 2941 | |
| 2942 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2943 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2945 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2946 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2947 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2948 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2949 | err = nl80211_parse_key(info, &key); |
| 2950 | if (err) |
| 2951 | return err; |
| 2952 | |
| 2953 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2954 | return -EINVAL; |
| 2955 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2956 | /* only support setting default key */ |
| 2957 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2958 | return -EINVAL; |
| 2959 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2960 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2961 | |
| 2962 | if (key.def) { |
| 2963 | if (!rdev->ops->set_default_key) { |
| 2964 | err = -EOPNOTSUPP; |
| 2965 | goto out; |
| 2966 | } |
| 2967 | |
| 2968 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2969 | if (err) |
| 2970 | goto out; |
| 2971 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2972 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2973 | key.def_uni, key.def_multi); |
| 2974 | |
| 2975 | if (err) |
| 2976 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2977 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2978 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2979 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2980 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2981 | } else { |
| 2982 | if (key.def_uni || !key.def_multi) { |
| 2983 | err = -EINVAL; |
| 2984 | goto out; |
| 2985 | } |
| 2986 | |
| 2987 | if (!rdev->ops->set_default_mgmt_key) { |
| 2988 | err = -EOPNOTSUPP; |
| 2989 | goto out; |
| 2990 | } |
| 2991 | |
| 2992 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2993 | if (err) |
| 2994 | goto out; |
| 2995 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2996 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2997 | if (err) |
| 2998 | goto out; |
| 2999 | |
| 3000 | #ifdef CONFIG_CFG80211_WEXT |
| 3001 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3002 | #endif |
| 3003 | } |
| 3004 | |
| 3005 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3006 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3007 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3008 | return err; |
| 3009 | } |
| 3010 | |
| 3011 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3012 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3014 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3015 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3016 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3017 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3018 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3019 | err = nl80211_parse_key(info, &key); |
| 3020 | if (err) |
| 3021 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3022 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3023 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3024 | return -EINVAL; |
| 3025 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3026 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3027 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3028 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3029 | if (key.type == -1) { |
| 3030 | if (mac_addr) |
| 3031 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3032 | else |
| 3033 | key.type = NL80211_KEYTYPE_GROUP; |
| 3034 | } |
| 3035 | |
| 3036 | /* for now */ |
| 3037 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3038 | key.type != NL80211_KEYTYPE_GROUP) |
| 3039 | return -EINVAL; |
| 3040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3041 | if (!rdev->ops->add_key) |
| 3042 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3043 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3044 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3045 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3046 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3047 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3048 | |
| 3049 | wdev_lock(dev->ieee80211_ptr); |
| 3050 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3051 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3052 | err = rdev_add_key(rdev, dev, key.idx, |
| 3053 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3054 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3055 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3056 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3057 | return err; |
| 3058 | } |
| 3059 | |
| 3060 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3061 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3063 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3064 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3065 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3066 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3067 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3068 | err = nl80211_parse_key(info, &key); |
| 3069 | if (err) |
| 3070 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3071 | |
| 3072 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3073 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3074 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3075 | if (key.type == -1) { |
| 3076 | if (mac_addr) |
| 3077 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3078 | else |
| 3079 | key.type = NL80211_KEYTYPE_GROUP; |
| 3080 | } |
| 3081 | |
| 3082 | /* for now */ |
| 3083 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3084 | key.type != NL80211_KEYTYPE_GROUP) |
| 3085 | return -EINVAL; |
| 3086 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3087 | if (!rdev->ops->del_key) |
| 3088 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3089 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3090 | wdev_lock(dev->ieee80211_ptr); |
| 3091 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3092 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3093 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3094 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3095 | err = -ENOENT; |
| 3096 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3097 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3098 | err = rdev_del_key(rdev, dev, key.idx, |
| 3099 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3100 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3101 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3102 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3103 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3104 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3105 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3106 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3107 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3108 | } |
| 3109 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3110 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3111 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3112 | return err; |
| 3113 | } |
| 3114 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3115 | /* This function returns an error or the number of nested attributes */ |
| 3116 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3117 | { |
| 3118 | struct nlattr *attr; |
| 3119 | int n_entries = 0, tmp; |
| 3120 | |
| 3121 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3122 | if (nla_len(attr) != ETH_ALEN) |
| 3123 | return -EINVAL; |
| 3124 | |
| 3125 | n_entries++; |
| 3126 | } |
| 3127 | |
| 3128 | return n_entries; |
| 3129 | } |
| 3130 | |
| 3131 | /* |
| 3132 | * This function parses ACL information and allocates memory for ACL data. |
| 3133 | * On successful return, the calling function is responsible to free the |
| 3134 | * ACL buffer returned by this function. |
| 3135 | */ |
| 3136 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3137 | struct genl_info *info) |
| 3138 | { |
| 3139 | enum nl80211_acl_policy acl_policy; |
| 3140 | struct nlattr *attr; |
| 3141 | struct cfg80211_acl_data *acl; |
| 3142 | int i = 0, n_entries, tmp; |
| 3143 | |
| 3144 | if (!wiphy->max_acl_mac_addrs) |
| 3145 | return ERR_PTR(-EOPNOTSUPP); |
| 3146 | |
| 3147 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3148 | return ERR_PTR(-EINVAL); |
| 3149 | |
| 3150 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3151 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3152 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3153 | return ERR_PTR(-EINVAL); |
| 3154 | |
| 3155 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3156 | return ERR_PTR(-EINVAL); |
| 3157 | |
| 3158 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3159 | if (n_entries < 0) |
| 3160 | return ERR_PTR(n_entries); |
| 3161 | |
| 3162 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3163 | return ERR_PTR(-ENOTSUPP); |
| 3164 | |
| 3165 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3166 | GFP_KERNEL); |
| 3167 | if (!acl) |
| 3168 | return ERR_PTR(-ENOMEM); |
| 3169 | |
| 3170 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3171 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3172 | i++; |
| 3173 | } |
| 3174 | |
| 3175 | acl->n_acl_entries = n_entries; |
| 3176 | acl->acl_policy = acl_policy; |
| 3177 | |
| 3178 | return acl; |
| 3179 | } |
| 3180 | |
| 3181 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3182 | { |
| 3183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3184 | struct net_device *dev = info->user_ptr[1]; |
| 3185 | struct cfg80211_acl_data *acl; |
| 3186 | int err; |
| 3187 | |
| 3188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3190 | return -EOPNOTSUPP; |
| 3191 | |
| 3192 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3193 | return -EINVAL; |
| 3194 | |
| 3195 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3196 | if (IS_ERR(acl)) |
| 3197 | return PTR_ERR(acl); |
| 3198 | |
| 3199 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3200 | |
| 3201 | kfree(acl); |
| 3202 | |
| 3203 | return err; |
| 3204 | } |
| 3205 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3206 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3207 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3208 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3209 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3210 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3211 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3212 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3213 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3214 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3215 | return -EINVAL; |
| 3216 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3217 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3218 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3219 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3220 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3221 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3222 | if (!bcn->head_len) |
| 3223 | return -EINVAL; |
| 3224 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3225 | } |
| 3226 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3227 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3228 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3229 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3230 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3233 | if (!haveinfo) |
| 3234 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3235 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3236 | if (attrs[NL80211_ATTR_IE]) { |
| 3237 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3238 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3239 | } |
| 3240 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3241 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3242 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3243 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3244 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3245 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3246 | } |
| 3247 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3248 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3249 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3250 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3251 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3252 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3253 | } |
| 3254 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3255 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3256 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3257 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3258 | } |
| 3259 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3260 | return 0; |
| 3261 | } |
| 3262 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3263 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3264 | struct cfg80211_ap_settings *params) |
| 3265 | { |
| 3266 | struct wireless_dev *wdev; |
| 3267 | bool ret = false; |
| 3268 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3269 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3270 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3271 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3272 | continue; |
| 3273 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3274 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3275 | continue; |
| 3276 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3277 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3278 | ret = true; |
| 3279 | break; |
| 3280 | } |
| 3281 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3282 | return ret; |
| 3283 | } |
| 3284 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3285 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3286 | enum nl80211_auth_type auth_type, |
| 3287 | enum nl80211_commands cmd) |
| 3288 | { |
| 3289 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3290 | return false; |
| 3291 | |
| 3292 | switch (cmd) { |
| 3293 | case NL80211_CMD_AUTHENTICATE: |
| 3294 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3295 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3296 | return false; |
| 3297 | return true; |
| 3298 | case NL80211_CMD_CONNECT: |
| 3299 | case NL80211_CMD_START_AP: |
| 3300 | /* SAE not supported yet */ |
| 3301 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3302 | return false; |
| 3303 | return true; |
| 3304 | default: |
| 3305 | return false; |
| 3306 | } |
| 3307 | } |
| 3308 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3309 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3310 | { |
| 3311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3312 | struct net_device *dev = info->user_ptr[1]; |
| 3313 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3314 | struct cfg80211_ap_settings params; |
| 3315 | int err; |
| 3316 | |
| 3317 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3318 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3319 | return -EOPNOTSUPP; |
| 3320 | |
| 3321 | if (!rdev->ops->start_ap) |
| 3322 | return -EOPNOTSUPP; |
| 3323 | |
| 3324 | if (wdev->beacon_interval) |
| 3325 | return -EALREADY; |
| 3326 | |
| 3327 | memset(¶ms, 0, sizeof(params)); |
| 3328 | |
| 3329 | /* these are required for START_AP */ |
| 3330 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3331 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3332 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3333 | return -EINVAL; |
| 3334 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3335 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3336 | if (err) |
| 3337 | return err; |
| 3338 | |
| 3339 | params.beacon_interval = |
| 3340 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3341 | params.dtim_period = |
| 3342 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3343 | |
| 3344 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3345 | if (err) |
| 3346 | return err; |
| 3347 | |
| 3348 | /* |
| 3349 | * In theory, some of these attributes should be required here |
| 3350 | * but since they were not used when the command was originally |
| 3351 | * added, keep them optional for old user space programs to let |
| 3352 | * them continue to work with drivers that do not need the |
| 3353 | * additional information -- drivers must check! |
| 3354 | */ |
| 3355 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3356 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3357 | params.ssid_len = |
| 3358 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3359 | if (params.ssid_len == 0 || |
| 3360 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3361 | return -EINVAL; |
| 3362 | } |
| 3363 | |
| 3364 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3365 | params.hidden_ssid = nla_get_u32( |
| 3366 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3367 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3368 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3369 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3370 | return -EINVAL; |
| 3371 | } |
| 3372 | |
| 3373 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3374 | |
| 3375 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3376 | params.auth_type = nla_get_u32( |
| 3377 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3378 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3379 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3380 | return -EINVAL; |
| 3381 | } else |
| 3382 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3383 | |
| 3384 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3385 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3386 | if (err) |
| 3387 | return err; |
| 3388 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3389 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3390 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3391 | return -EOPNOTSUPP; |
| 3392 | params.inactivity_timeout = nla_get_u16( |
| 3393 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3394 | } |
| 3395 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3396 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3397 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3398 | return -EINVAL; |
| 3399 | params.p2p_ctwindow = |
| 3400 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3401 | if (params.p2p_ctwindow > 127) |
| 3402 | return -EINVAL; |
| 3403 | if (params.p2p_ctwindow != 0 && |
| 3404 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3405 | return -EINVAL; |
| 3406 | } |
| 3407 | |
| 3408 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3409 | u8 tmp; |
| 3410 | |
| 3411 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3412 | return -EINVAL; |
| 3413 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3414 | if (tmp > 1) |
| 3415 | return -EINVAL; |
| 3416 | params.p2p_opp_ps = tmp; |
| 3417 | if (params.p2p_opp_ps != 0 && |
| 3418 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3419 | return -EINVAL; |
| 3420 | } |
| 3421 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3422 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3423 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3424 | if (err) |
| 3425 | return err; |
| 3426 | } else if (wdev->preset_chandef.chan) { |
| 3427 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3428 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3429 | return -EINVAL; |
| 3430 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3431 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3432 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3433 | return -EINVAL; |
| 3434 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3435 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3436 | params.smps_mode = |
| 3437 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3438 | switch (params.smps_mode) { |
| 3439 | case NL80211_SMPS_OFF: |
| 3440 | break; |
| 3441 | case NL80211_SMPS_STATIC: |
| 3442 | if (!(rdev->wiphy.features & |
| 3443 | NL80211_FEATURE_STATIC_SMPS)) |
| 3444 | return -EINVAL; |
| 3445 | break; |
| 3446 | case NL80211_SMPS_DYNAMIC: |
| 3447 | if (!(rdev->wiphy.features & |
| 3448 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3449 | return -EINVAL; |
| 3450 | break; |
| 3451 | default: |
| 3452 | return -EINVAL; |
| 3453 | } |
| 3454 | } else { |
| 3455 | params.smps_mode = NL80211_SMPS_OFF; |
| 3456 | } |
| 3457 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3458 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3459 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3460 | if (IS_ERR(params.acl)) |
| 3461 | return PTR_ERR(params.acl); |
| 3462 | } |
| 3463 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3464 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3465 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3466 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3467 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3468 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3469 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3470 | wdev->ssid_len = params.ssid_len; |
| 3471 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3472 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3473 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3474 | |
| 3475 | kfree(params.acl); |
| 3476 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3477 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3478 | } |
| 3479 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3480 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3481 | { |
| 3482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3483 | struct net_device *dev = info->user_ptr[1]; |
| 3484 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3485 | struct cfg80211_beacon_data params; |
| 3486 | int err; |
| 3487 | |
| 3488 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3489 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3490 | return -EOPNOTSUPP; |
| 3491 | |
| 3492 | if (!rdev->ops->change_beacon) |
| 3493 | return -EOPNOTSUPP; |
| 3494 | |
| 3495 | if (!wdev->beacon_interval) |
| 3496 | return -EINVAL; |
| 3497 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3498 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3499 | if (err) |
| 3500 | return err; |
| 3501 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3502 | wdev_lock(wdev); |
| 3503 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3504 | wdev_unlock(wdev); |
| 3505 | |
| 3506 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | 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] | 3510 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3512 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3513 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3514 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3517 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3518 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3519 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3520 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3521 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3522 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3523 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3524 | }; |
| 3525 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3526 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3527 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3528 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3529 | { |
| 3530 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3531 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3532 | int flag; |
| 3533 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3534 | /* |
| 3535 | * Try parsing the new attribute first so userspace |
| 3536 | * can specify both for older kernels. |
| 3537 | */ |
| 3538 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3539 | if (nla) { |
| 3540 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3541 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3542 | sta_flags = nla_data(nla); |
| 3543 | params->sta_flags_mask = sta_flags->mask; |
| 3544 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3545 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3546 | if ((params->sta_flags_mask | |
| 3547 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3548 | return -EINVAL; |
| 3549 | return 0; |
| 3550 | } |
| 3551 | |
| 3552 | /* if present, parse the old attribute */ |
| 3553 | |
| 3554 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3555 | if (!nla) |
| 3556 | return 0; |
| 3557 | |
| 3558 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3559 | nla, sta_flags_policy)) |
| 3560 | return -EINVAL; |
| 3561 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3562 | /* |
| 3563 | * Only allow certain flags for interface types so that |
| 3564 | * other attributes are silently ignored. Remember that |
| 3565 | * this is backward compatibility code with old userspace |
| 3566 | * and shouldn't be hit in other cases anyway. |
| 3567 | */ |
| 3568 | switch (iftype) { |
| 3569 | case NL80211_IFTYPE_AP: |
| 3570 | case NL80211_IFTYPE_AP_VLAN: |
| 3571 | case NL80211_IFTYPE_P2P_GO: |
| 3572 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3573 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3574 | BIT(NL80211_STA_FLAG_WME) | |
| 3575 | BIT(NL80211_STA_FLAG_MFP); |
| 3576 | break; |
| 3577 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3578 | case NL80211_IFTYPE_STATION: |
| 3579 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3580 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3581 | break; |
| 3582 | case NL80211_IFTYPE_MESH_POINT: |
| 3583 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3584 | BIT(NL80211_STA_FLAG_MFP) | |
| 3585 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3586 | default: |
| 3587 | return -EINVAL; |
| 3588 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3589 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3590 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3591 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3592 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3593 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3594 | /* no longer support new API additions in old API */ |
| 3595 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3596 | return -EINVAL; |
| 3597 | } |
| 3598 | } |
| 3599 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3600 | return 0; |
| 3601 | } |
| 3602 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3603 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3604 | int attr) |
| 3605 | { |
| 3606 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3607 | u32 bitrate; |
| 3608 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3609 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3610 | |
| 3611 | rate = nla_nest_start(msg, attr); |
| 3612 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3613 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3614 | |
| 3615 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3616 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3617 | /* report 16-bit bitrate only if we can */ |
| 3618 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3619 | if (bitrate > 0 && |
| 3620 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3621 | return false; |
| 3622 | if (bitrate_compat > 0 && |
| 3623 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3624 | return false; |
| 3625 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3626 | switch (info->bw) { |
| 3627 | case RATE_INFO_BW_5: |
| 3628 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3629 | break; |
| 3630 | case RATE_INFO_BW_10: |
| 3631 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3632 | break; |
| 3633 | default: |
| 3634 | WARN_ON(1); |
| 3635 | /* fall through */ |
| 3636 | case RATE_INFO_BW_20: |
| 3637 | rate_flg = 0; |
| 3638 | break; |
| 3639 | case RATE_INFO_BW_40: |
| 3640 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3641 | break; |
| 3642 | case RATE_INFO_BW_80: |
| 3643 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3644 | break; |
| 3645 | case RATE_INFO_BW_160: |
| 3646 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3651 | return false; |
| 3652 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3653 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3654 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3655 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3656 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3657 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3658 | return false; |
| 3659 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3660 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3661 | return false; |
| 3662 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3663 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3664 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3665 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3666 | return false; |
| 3667 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3668 | |
| 3669 | nla_nest_end(msg, rate); |
| 3670 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3673 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3674 | int id) |
| 3675 | { |
| 3676 | void *attr; |
| 3677 | int i = 0; |
| 3678 | |
| 3679 | if (!mask) |
| 3680 | return true; |
| 3681 | |
| 3682 | attr = nla_nest_start(msg, id); |
| 3683 | if (!attr) |
| 3684 | return false; |
| 3685 | |
| 3686 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3687 | if (!(mask & BIT(i))) |
| 3688 | continue; |
| 3689 | |
| 3690 | if (nla_put_u8(msg, i, signal[i])) |
| 3691 | return false; |
| 3692 | } |
| 3693 | |
| 3694 | nla_nest_end(msg, attr); |
| 3695 | |
| 3696 | return true; |
| 3697 | } |
| 3698 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3699 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3700 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3701 | struct cfg80211_registered_device *rdev, |
| 3702 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3703 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3704 | { |
| 3705 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3706 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3707 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3708 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3709 | if (!hdr) |
| 3710 | return -1; |
| 3711 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3712 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3713 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3714 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3715 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3716 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3717 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3718 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3719 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3720 | |
| 3721 | #define PUT_SINFO(attr, memb, type) do { \ |
| 3722 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ |
| 3723 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3724 | sinfo->memb)) \ |
| 3725 | goto nla_put_failure; \ |
| 3726 | } while (0) |
| 3727 | |
| 3728 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3729 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3730 | |
| 3731 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3732 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3733 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3734 | (u32)sinfo->rx_bytes)) |
| 3735 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3736 | |
| 3737 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3738 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3739 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3740 | (u32)sinfo->tx_bytes)) |
| 3741 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3742 | |
| 3743 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); |
| 3744 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); |
| 3745 | PUT_SINFO(LLID, llid, u16); |
| 3746 | PUT_SINFO(PLID, plid, u16); |
| 3747 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
| 3748 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3749 | switch (rdev->wiphy.signal_type) { |
| 3750 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3751 | PUT_SINFO(SIGNAL, signal, u8); |
| 3752 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3753 | break; |
| 3754 | default: |
| 3755 | break; |
| 3756 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3757 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3758 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3759 | sinfo->chain_signal, |
| 3760 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3761 | goto nla_put_failure; |
| 3762 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3763 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3764 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3765 | sinfo->chain_signal_avg, |
| 3766 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3767 | goto nla_put_failure; |
| 3768 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3769 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3770 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3771 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3772 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3773 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3774 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3775 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3776 | NL80211_STA_INFO_RX_BITRATE)) |
| 3777 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3778 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3779 | |
| 3780 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3781 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3782 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3783 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3784 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3785 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3786 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3787 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3788 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3789 | |
| 3790 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3791 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3792 | if (!bss_param) |
| 3793 | goto nla_put_failure; |
| 3794 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3795 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3796 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3797 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3798 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3799 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3800 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3801 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3802 | sinfo->bss_param.dtim_period) || |
| 3803 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3804 | sinfo->bss_param.beacon_interval)) |
| 3805 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3806 | |
| 3807 | nla_nest_end(msg, bss_param); |
| 3808 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3809 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3810 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3811 | sizeof(struct nl80211_sta_flag_update), |
| 3812 | &sinfo->sta_flags)) |
| 3813 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3814 | |
| 3815 | PUT_SINFO(T_OFFSET, t_offset, u64); |
| 3816 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3817 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
| 3818 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3819 | |
| 3820 | #undef PUT_SINFO |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3821 | |
| 3822 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3823 | struct nlattr *tidsattr; |
| 3824 | int tid; |
| 3825 | |
| 3826 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3827 | if (!tidsattr) |
| 3828 | goto nla_put_failure; |
| 3829 | |
| 3830 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3831 | struct cfg80211_tid_stats *tidstats; |
| 3832 | struct nlattr *tidattr; |
| 3833 | |
| 3834 | tidstats = &sinfo->pertid[tid]; |
| 3835 | |
| 3836 | if (!tidstats->filled) |
| 3837 | continue; |
| 3838 | |
| 3839 | tidattr = nla_nest_start(msg, tid + 1); |
| 3840 | if (!tidattr) |
| 3841 | goto nla_put_failure; |
| 3842 | |
| 3843 | #define PUT_TIDVAL(attr, memb, type) do { \ |
| 3844 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
| 3845 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ |
| 3846 | tidstats->memb)) \ |
| 3847 | goto nla_put_failure; \ |
| 3848 | } while (0) |
| 3849 | |
| 3850 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); |
| 3851 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); |
| 3852 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); |
| 3853 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); |
| 3854 | |
| 3855 | #undef PUT_TIDVAL |
| 3856 | nla_nest_end(msg, tidattr); |
| 3857 | } |
| 3858 | |
| 3859 | nla_nest_end(msg, tidsattr); |
| 3860 | } |
| 3861 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3862 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3863 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3864 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3865 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3866 | sinfo->assoc_req_ies)) |
| 3867 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3868 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3869 | genlmsg_end(msg, hdr); |
| 3870 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3871 | |
| 3872 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3873 | genlmsg_cancel(msg, hdr); |
| 3874 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3877 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3878 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3879 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3880 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3881 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3882 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3883 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3884 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3885 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3886 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3887 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3888 | if (err) |
| 3889 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3890 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3891 | if (!wdev->netdev) { |
| 3892 | err = -EINVAL; |
| 3893 | goto out_err; |
| 3894 | } |
| 3895 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3896 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3897 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3898 | goto out_err; |
| 3899 | } |
| 3900 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3901 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3902 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3903 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3904 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3905 | if (err == -ENOENT) |
| 3906 | break; |
| 3907 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3908 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3909 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3910 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3911 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3912 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3913 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3914 | &sinfo) < 0) |
| 3915 | goto out; |
| 3916 | |
| 3917 | sta_idx++; |
| 3918 | } |
| 3919 | |
| 3920 | |
| 3921 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3922 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3923 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3924 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3925 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3926 | |
| 3927 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3928 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3929 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3930 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3931 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3933 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3934 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3935 | struct sk_buff *msg; |
| 3936 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3937 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3938 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3939 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3940 | |
| 3941 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3942 | return -EINVAL; |
| 3943 | |
| 3944 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3945 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3946 | if (!rdev->ops->get_station) |
| 3947 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3948 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3949 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3950 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3951 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3952 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3954 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3955 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3956 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3957 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 3958 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3959 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3960 | nlmsg_free(msg); |
| 3961 | return -ENOBUFS; |
| 3962 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3963 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3964 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3967 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3968 | struct station_parameters *params, |
| 3969 | enum cfg80211_station_type statype) |
| 3970 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3971 | if (params->listen_interval != -1 && |
| 3972 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3973 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3974 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3975 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 3976 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 3977 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3978 | return -EINVAL; |
| 3979 | |
| 3980 | /* When you run into this, adjust the code below for the new flag */ |
| 3981 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3982 | |
| 3983 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3984 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3985 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3986 | /* |
| 3987 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3988 | * code doesn't have the bug of including TDLS in the |
| 3989 | * mask everywhere. |
| 3990 | */ |
| 3991 | if (params->sta_flags_mask & |
| 3992 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3993 | BIT(NL80211_STA_FLAG_MFP) | |
| 3994 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3995 | return -EINVAL; |
| 3996 | break; |
| 3997 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3998 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3999 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4000 | return -EINVAL; |
| 4001 | /* ignore since it can't change */ |
| 4002 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4003 | break; |
| 4004 | default: |
| 4005 | /* disallow mesh-specific things */ |
| 4006 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4007 | return -EINVAL; |
| 4008 | if (params->local_pm) |
| 4009 | return -EINVAL; |
| 4010 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4011 | return -EINVAL; |
| 4012 | } |
| 4013 | |
| 4014 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4015 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4016 | /* TDLS can't be set, ... */ |
| 4017 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4018 | return -EINVAL; |
| 4019 | /* |
| 4020 | * ... but don't bother the driver with it. This works around |
| 4021 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4022 | * TLDS_PEER flag in the mask even for AP mode. |
| 4023 | */ |
| 4024 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4025 | } |
| 4026 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4027 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4028 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4029 | /* reject other things that can't change */ |
| 4030 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4031 | return -EINVAL; |
| 4032 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4033 | return -EINVAL; |
| 4034 | if (params->supported_rates) |
| 4035 | return -EINVAL; |
| 4036 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4037 | return -EINVAL; |
| 4038 | } |
| 4039 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4040 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4041 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4042 | if (params->vlan) |
| 4043 | return -EINVAL; |
| 4044 | } |
| 4045 | |
| 4046 | switch (statype) { |
| 4047 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4048 | /* Use this only for authorizing/unauthorizing a station */ |
| 4049 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4050 | return -EOPNOTSUPP; |
| 4051 | break; |
| 4052 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4053 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4054 | /* accept only the listed bits */ |
| 4055 | if (params->sta_flags_mask & |
| 4056 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4057 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4058 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4059 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4060 | BIT(NL80211_STA_FLAG_WME) | |
| 4061 | BIT(NL80211_STA_FLAG_MFP))) |
| 4062 | return -EINVAL; |
| 4063 | |
| 4064 | /* but authenticated/associated only if driver handles it */ |
| 4065 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4066 | params->sta_flags_mask & |
| 4067 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4068 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4069 | return -EINVAL; |
| 4070 | break; |
| 4071 | case CFG80211_STA_IBSS: |
| 4072 | case CFG80211_STA_AP_STA: |
| 4073 | /* reject any changes other than AUTHORIZED */ |
| 4074 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4075 | return -EINVAL; |
| 4076 | break; |
| 4077 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4078 | /* reject any changes other than AUTHORIZED or WME */ |
| 4079 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4080 | BIT(NL80211_STA_FLAG_WME))) |
| 4081 | return -EINVAL; |
| 4082 | /* force (at least) rates when authorizing */ |
| 4083 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4084 | !params->supported_rates) |
| 4085 | return -EINVAL; |
| 4086 | break; |
| 4087 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4088 | /* reject any changes */ |
| 4089 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4090 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4091 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4092 | return -EINVAL; |
| 4093 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4094 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4095 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4096 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4097 | return -EINVAL; |
| 4098 | break; |
| 4099 | } |
| 4100 | |
| 4101 | return 0; |
| 4102 | } |
| 4103 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4104 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4105 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4106 | * 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] | 4107 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4108 | static struct net_device *get_vlan(struct genl_info *info, |
| 4109 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4110 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4111 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4112 | struct net_device *v; |
| 4113 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4115 | if (!vlanattr) |
| 4116 | return NULL; |
| 4117 | |
| 4118 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4119 | if (!v) |
| 4120 | return ERR_PTR(-ENODEV); |
| 4121 | |
| 4122 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4123 | ret = -EINVAL; |
| 4124 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4126 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4127 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4128 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4129 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4130 | ret = -EINVAL; |
| 4131 | goto error; |
| 4132 | } |
| 4133 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4134 | if (!netif_running(v)) { |
| 4135 | ret = -ENETDOWN; |
| 4136 | goto error; |
| 4137 | } |
| 4138 | |
| 4139 | return v; |
| 4140 | error: |
| 4141 | dev_put(v); |
| 4142 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4143 | } |
| 4144 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4145 | static const struct nla_policy |
| 4146 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4147 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4148 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4149 | }; |
| 4150 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4151 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4152 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4153 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4154 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4155 | struct nlattr *nla; |
| 4156 | int err; |
| 4157 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4158 | /* parse WME attributes if present */ |
| 4159 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4160 | return 0; |
| 4161 | |
| 4162 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4163 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4164 | nl80211_sta_wme_policy); |
| 4165 | if (err) |
| 4166 | return err; |
| 4167 | |
| 4168 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4169 | params->uapsd_queues = nla_get_u8( |
| 4170 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4171 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4172 | return -EINVAL; |
| 4173 | |
| 4174 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4175 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4176 | |
| 4177 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4178 | return -EINVAL; |
| 4179 | |
| 4180 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4181 | |
| 4182 | return 0; |
| 4183 | } |
| 4184 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4185 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4186 | struct station_parameters *params) |
| 4187 | { |
| 4188 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4189 | params->supported_channels = |
| 4190 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4191 | params->supported_channels_len = |
| 4192 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4193 | /* |
| 4194 | * Need to include at least one (first channel, number of |
| 4195 | * channels) tuple for each subband, and must have proper |
| 4196 | * tuples for the rest of the data as well. |
| 4197 | */ |
| 4198 | if (params->supported_channels_len < 2) |
| 4199 | return -EINVAL; |
| 4200 | if (params->supported_channels_len % 2) |
| 4201 | return -EINVAL; |
| 4202 | } |
| 4203 | |
| 4204 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4205 | params->supported_oper_classes = |
| 4206 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4207 | params->supported_oper_classes_len = |
| 4208 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4209 | /* |
| 4210 | * The value of the Length field of the Supported Operating |
| 4211 | * Classes element is between 2 and 253. |
| 4212 | */ |
| 4213 | if (params->supported_oper_classes_len < 2 || |
| 4214 | params->supported_oper_classes_len > 253) |
| 4215 | return -EINVAL; |
| 4216 | } |
| 4217 | return 0; |
| 4218 | } |
| 4219 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4220 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4221 | struct station_parameters *params) |
| 4222 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4223 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4224 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4225 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4226 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4227 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4228 | params->ht_capa = |
| 4229 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4230 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4231 | params->vht_capa = |
| 4232 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4233 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4234 | err = nl80211_parse_sta_channel_info(info, params); |
| 4235 | if (err) |
| 4236 | return err; |
| 4237 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4238 | return nl80211_parse_sta_wme(info, params); |
| 4239 | } |
| 4240 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4241 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4242 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4245 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4246 | u8 *mac_addr; |
| 4247 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4248 | |
| 4249 | memset(¶ms, 0, sizeof(params)); |
| 4250 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4251 | if (!rdev->ops->change_station) |
| 4252 | return -EOPNOTSUPP; |
| 4253 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4254 | /* |
| 4255 | * AID and listen_interval properties can be set only for unassociated |
| 4256 | * station. Include these parameters here and will check them in |
| 4257 | * cfg80211_check_station_change(). |
| 4258 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame^] | 4259 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4260 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4261 | |
| 4262 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4263 | params.listen_interval = |
| 4264 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4265 | else |
| 4266 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4267 | |
| 4268 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4269 | return -EINVAL; |
| 4270 | |
| 4271 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4272 | |
| 4273 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4274 | params.supported_rates = |
| 4275 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4276 | params.supported_rates_len = |
| 4277 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4278 | } |
| 4279 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4280 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4281 | params.capability = |
| 4282 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4283 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4284 | } |
| 4285 | |
| 4286 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4287 | params.ext_capab = |
| 4288 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4289 | params.ext_capab_len = |
| 4290 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4291 | } |
| 4292 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4293 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4294 | return -EINVAL; |
| 4295 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4296 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4297 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4298 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4299 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4300 | return -EINVAL; |
| 4301 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4302 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4303 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4304 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4305 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4306 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4307 | return -EINVAL; |
| 4308 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4309 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4310 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4311 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4312 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4313 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4314 | |
| 4315 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4316 | pm > NL80211_MESH_POWER_MAX) |
| 4317 | return -EINVAL; |
| 4318 | |
| 4319 | params.local_pm = pm; |
| 4320 | } |
| 4321 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4322 | /* Include parameters for TDLS peer (will check later) */ |
| 4323 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4324 | if (err) |
| 4325 | return err; |
| 4326 | |
| 4327 | params.vlan = get_vlan(info, rdev); |
| 4328 | if (IS_ERR(params.vlan)) |
| 4329 | return PTR_ERR(params.vlan); |
| 4330 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4331 | switch (dev->ieee80211_ptr->iftype) { |
| 4332 | case NL80211_IFTYPE_AP: |
| 4333 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4334 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4335 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4336 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4337 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4338 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4339 | break; |
| 4340 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4341 | err = -EOPNOTSUPP; |
| 4342 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4343 | } |
| 4344 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4345 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4346 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4347 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4348 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4349 | if (params.vlan) |
| 4350 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4351 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4352 | return err; |
| 4353 | } |
| 4354 | |
| 4355 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4358 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4359 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4360 | struct station_parameters params; |
| 4361 | u8 *mac_addr = NULL; |
| 4362 | |
| 4363 | memset(¶ms, 0, sizeof(params)); |
| 4364 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4365 | if (!rdev->ops->add_station) |
| 4366 | return -EOPNOTSUPP; |
| 4367 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4368 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4369 | return -EINVAL; |
| 4370 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4371 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4372 | return -EINVAL; |
| 4373 | |
| 4374 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4375 | return -EINVAL; |
| 4376 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4377 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4378 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4379 | return -EINVAL; |
| 4380 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4381 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4382 | params.supported_rates = |
| 4383 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4384 | params.supported_rates_len = |
| 4385 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4386 | params.listen_interval = |
| 4387 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4388 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4389 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4390 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4391 | else |
| 4392 | 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] | 4393 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4394 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4395 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4396 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4397 | params.capability = |
| 4398 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4399 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4400 | } |
| 4401 | |
| 4402 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4403 | params.ext_capab = |
| 4404 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4405 | params.ext_capab_len = |
| 4406 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4407 | } |
| 4408 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4409 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4410 | params.ht_capa = |
| 4411 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4412 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4413 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4414 | params.vht_capa = |
| 4415 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4416 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4417 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4418 | params.opmode_notif_used = true; |
| 4419 | params.opmode_notif = |
| 4420 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4421 | } |
| 4422 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4423 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4424 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4425 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4426 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4427 | return -EINVAL; |
| 4428 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4429 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4430 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4431 | if (err) |
| 4432 | return err; |
| 4433 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4434 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4435 | if (err) |
| 4436 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4437 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4438 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4439 | return -EINVAL; |
| 4440 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4441 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4442 | * as userspace might just pass through the capabilities from the IEs |
| 4443 | * directly, rather than enforcing this restriction and returning an |
| 4444 | * error in this case. |
| 4445 | */ |
| 4446 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4447 | params.ht_capa = NULL; |
| 4448 | params.vht_capa = NULL; |
| 4449 | } |
| 4450 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4451 | /* When you run into this, adjust the code below for the new flag */ |
| 4452 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4453 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4454 | switch (dev->ieee80211_ptr->iftype) { |
| 4455 | case NL80211_IFTYPE_AP: |
| 4456 | case NL80211_IFTYPE_AP_VLAN: |
| 4457 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4458 | /* ignore WME attributes if iface/sta is not capable */ |
| 4459 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4460 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4461 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4462 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4463 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4464 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4465 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4466 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4467 | /* but don't bother the driver with it */ |
| 4468 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4469 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4470 | /* allow authenticated/associated only if driver handles it */ |
| 4471 | if (!(rdev->wiphy.features & |
| 4472 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4473 | params.sta_flags_mask & |
| 4474 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4475 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4476 | return -EINVAL; |
| 4477 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4478 | /* must be last in here for error handling */ |
| 4479 | params.vlan = get_vlan(info, rdev); |
| 4480 | if (IS_ERR(params.vlan)) |
| 4481 | return PTR_ERR(params.vlan); |
| 4482 | break; |
| 4483 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4484 | /* ignore uAPSD data */ |
| 4485 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4486 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4487 | /* associated is disallowed */ |
| 4488 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4489 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4490 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4491 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4492 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4493 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4494 | break; |
| 4495 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4496 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4497 | /* ignore uAPSD data */ |
| 4498 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4499 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4500 | /* these are disallowed */ |
| 4501 | if (params.sta_flags_mask & |
| 4502 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4503 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4504 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4505 | /* Only TDLS peers can be added */ |
| 4506 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4507 | return -EINVAL; |
| 4508 | /* Can only add if TDLS ... */ |
| 4509 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4510 | return -EOPNOTSUPP; |
| 4511 | /* ... with external setup is supported */ |
| 4512 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4513 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4514 | /* |
| 4515 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4516 | * as authorized, but it shouldn't yet be. |
| 4517 | */ |
| 4518 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4519 | break; |
| 4520 | default: |
| 4521 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4522 | } |
| 4523 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4524 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4525 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4526 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4527 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4528 | if (params.vlan) |
| 4529 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4530 | return err; |
| 4531 | } |
| 4532 | |
| 4533 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4534 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4535 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4536 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4537 | struct station_del_parameters params; |
| 4538 | |
| 4539 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4540 | |
| 4541 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4542 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4543 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4544 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4545 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4546 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4547 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4548 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4550 | if (!rdev->ops->del_station) |
| 4551 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4552 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4553 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4554 | params.subtype = |
| 4555 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4556 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4557 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4558 | return -EINVAL; |
| 4559 | } else { |
| 4560 | /* Default to Deauthentication frame */ |
| 4561 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4562 | } |
| 4563 | |
| 4564 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4565 | params.reason_code = |
| 4566 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4567 | if (params.reason_code == 0) |
| 4568 | return -EINVAL; /* 0 is reserved */ |
| 4569 | } else { |
| 4570 | /* Default to reason code 2 */ |
| 4571 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4572 | } |
| 4573 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4574 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4575 | } |
| 4576 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4577 | 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] | 4578 | int flags, struct net_device *dev, |
| 4579 | u8 *dst, u8 *next_hop, |
| 4580 | struct mpath_info *pinfo) |
| 4581 | { |
| 4582 | void *hdr; |
| 4583 | struct nlattr *pinfoattr; |
| 4584 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4585 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4586 | if (!hdr) |
| 4587 | return -1; |
| 4588 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4589 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4590 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4591 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4592 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4593 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4594 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4595 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4596 | if (!pinfoattr) |
| 4597 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4598 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4599 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4600 | pinfo->frame_qlen)) |
| 4601 | goto nla_put_failure; |
| 4602 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4603 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4604 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4605 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4606 | pinfo->metric)) || |
| 4607 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4608 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4609 | pinfo->exptime)) || |
| 4610 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4611 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4612 | pinfo->flags)) || |
| 4613 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4614 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4615 | pinfo->discovery_timeout)) || |
| 4616 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4617 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4618 | pinfo->discovery_retries))) |
| 4619 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4620 | |
| 4621 | nla_nest_end(msg, pinfoattr); |
| 4622 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4623 | genlmsg_end(msg, hdr); |
| 4624 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4625 | |
| 4626 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4627 | genlmsg_cancel(msg, hdr); |
| 4628 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4632 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4633 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4634 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4635 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4636 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4637 | u8 dst[ETH_ALEN]; |
| 4638 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4639 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4640 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4641 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4642 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4643 | if (err) |
| 4644 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4645 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4646 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4647 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4648 | goto out_err; |
| 4649 | } |
| 4650 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4651 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4652 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4653 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4654 | } |
| 4655 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4656 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4657 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4658 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4659 | if (err == -ENOENT) |
| 4660 | break; |
| 4661 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4662 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4663 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4664 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4665 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4666 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4667 | &pinfo) < 0) |
| 4668 | goto out; |
| 4669 | |
| 4670 | path_idx++; |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4675 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4676 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4677 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4678 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4679 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4683 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4685 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4686 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4687 | struct mpath_info pinfo; |
| 4688 | struct sk_buff *msg; |
| 4689 | u8 *dst = NULL; |
| 4690 | u8 next_hop[ETH_ALEN]; |
| 4691 | |
| 4692 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4693 | |
| 4694 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4695 | return -EINVAL; |
| 4696 | |
| 4697 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4698 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4699 | if (!rdev->ops->get_mpath) |
| 4700 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4701 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4702 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4703 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4704 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4705 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4706 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4707 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4708 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4709 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4710 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4711 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4712 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4713 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | dev, dst, next_hop, &pinfo) < 0) { |
| 4715 | nlmsg_free(msg); |
| 4716 | return -ENOBUFS; |
| 4717 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4723 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4725 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4726 | u8 *dst = NULL; |
| 4727 | u8 *next_hop = NULL; |
| 4728 | |
| 4729 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4730 | return -EINVAL; |
| 4731 | |
| 4732 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4733 | return -EINVAL; |
| 4734 | |
| 4735 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4736 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4738 | if (!rdev->ops->change_mpath) |
| 4739 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4740 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4742 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4743 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4744 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4745 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4746 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4747 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4748 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4750 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4751 | u8 *dst = NULL; |
| 4752 | u8 *next_hop = NULL; |
| 4753 | |
| 4754 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4755 | return -EINVAL; |
| 4756 | |
| 4757 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4758 | return -EINVAL; |
| 4759 | |
| 4760 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4761 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4763 | if (!rdev->ops->add_mpath) |
| 4764 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4765 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4767 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4768 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4769 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4773 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4775 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4776 | u8 *dst = NULL; |
| 4777 | |
| 4778 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4779 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4780 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4781 | if (!rdev->ops->del_mpath) |
| 4782 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4783 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4784 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4785 | } |
| 4786 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4787 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4788 | { |
| 4789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4790 | int err; |
| 4791 | struct net_device *dev = info->user_ptr[1]; |
| 4792 | struct mpath_info pinfo; |
| 4793 | struct sk_buff *msg; |
| 4794 | u8 *dst = NULL; |
| 4795 | u8 mpp[ETH_ALEN]; |
| 4796 | |
| 4797 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4798 | |
| 4799 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4800 | return -EINVAL; |
| 4801 | |
| 4802 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4803 | |
| 4804 | if (!rdev->ops->get_mpp) |
| 4805 | return -EOPNOTSUPP; |
| 4806 | |
| 4807 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4808 | return -EOPNOTSUPP; |
| 4809 | |
| 4810 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4811 | if (err) |
| 4812 | return err; |
| 4813 | |
| 4814 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4815 | if (!msg) |
| 4816 | return -ENOMEM; |
| 4817 | |
| 4818 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4819 | dev, dst, mpp, &pinfo) < 0) { |
| 4820 | nlmsg_free(msg); |
| 4821 | return -ENOBUFS; |
| 4822 | } |
| 4823 | |
| 4824 | return genlmsg_reply(msg, info); |
| 4825 | } |
| 4826 | |
| 4827 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4828 | struct netlink_callback *cb) |
| 4829 | { |
| 4830 | struct mpath_info pinfo; |
| 4831 | struct cfg80211_registered_device *rdev; |
| 4832 | struct wireless_dev *wdev; |
| 4833 | u8 dst[ETH_ALEN]; |
| 4834 | u8 mpp[ETH_ALEN]; |
| 4835 | int path_idx = cb->args[2]; |
| 4836 | int err; |
| 4837 | |
| 4838 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4839 | if (err) |
| 4840 | return err; |
| 4841 | |
| 4842 | if (!rdev->ops->dump_mpp) { |
| 4843 | err = -EOPNOTSUPP; |
| 4844 | goto out_err; |
| 4845 | } |
| 4846 | |
| 4847 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4848 | err = -EOPNOTSUPP; |
| 4849 | goto out_err; |
| 4850 | } |
| 4851 | |
| 4852 | while (1) { |
| 4853 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4854 | mpp, &pinfo); |
| 4855 | if (err == -ENOENT) |
| 4856 | break; |
| 4857 | if (err) |
| 4858 | goto out_err; |
| 4859 | |
| 4860 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4861 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4862 | wdev->netdev, dst, mpp, |
| 4863 | &pinfo) < 0) |
| 4864 | goto out; |
| 4865 | |
| 4866 | path_idx++; |
| 4867 | } |
| 4868 | |
| 4869 | out: |
| 4870 | cb->args[2] = path_idx; |
| 4871 | err = skb->len; |
| 4872 | out_err: |
| 4873 | nl80211_finish_wdev_dump(rdev); |
| 4874 | return err; |
| 4875 | } |
| 4876 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4877 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4878 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4880 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4882 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4883 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4884 | |
| 4885 | memset(¶ms, 0, sizeof(params)); |
| 4886 | /* default to not changing parameters */ |
| 4887 | params.use_cts_prot = -1; |
| 4888 | params.use_short_preamble = -1; |
| 4889 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4890 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4891 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4892 | params.p2p_ctwindow = -1; |
| 4893 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4894 | |
| 4895 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4896 | params.use_cts_prot = |
| 4897 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4898 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4899 | params.use_short_preamble = |
| 4900 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4901 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4902 | params.use_short_slot_time = |
| 4903 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4904 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4905 | params.basic_rates = |
| 4906 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4907 | params.basic_rates_len = |
| 4908 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4909 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4910 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4911 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4912 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4913 | params.ht_opmode = |
| 4914 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4915 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4916 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4918 | return -EINVAL; |
| 4919 | params.p2p_ctwindow = |
| 4920 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4921 | if (params.p2p_ctwindow < 0) |
| 4922 | return -EINVAL; |
| 4923 | if (params.p2p_ctwindow != 0 && |
| 4924 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4925 | return -EINVAL; |
| 4926 | } |
| 4927 | |
| 4928 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4929 | u8 tmp; |
| 4930 | |
| 4931 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4932 | return -EINVAL; |
| 4933 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4934 | if (tmp > 1) |
| 4935 | return -EINVAL; |
| 4936 | params.p2p_opp_ps = tmp; |
| 4937 | if (params.p2p_opp_ps && |
| 4938 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4939 | return -EINVAL; |
| 4940 | } |
| 4941 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4942 | if (!rdev->ops->change_bss) |
| 4943 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4944 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4945 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4946 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4947 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4948 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4949 | wdev_lock(wdev); |
| 4950 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4951 | wdev_unlock(wdev); |
| 4952 | |
| 4953 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4954 | } |
| 4955 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4956 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4957 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4958 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4959 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4960 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4961 | u32 owner_nlportid; |
| 4962 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4963 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4964 | /* |
| 4965 | * You should only get this when cfg80211 hasn't yet initialized |
| 4966 | * completely when built-in to the kernel right between the time |
| 4967 | * window between nl80211_init() and regulatory_init(), if that is |
| 4968 | * even possible. |
| 4969 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4970 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4971 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4972 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4973 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4974 | user_reg_hint_type = |
| 4975 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4976 | else |
| 4977 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4978 | |
| 4979 | switch (user_reg_hint_type) { |
| 4980 | case NL80211_USER_REG_HINT_USER: |
| 4981 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4982 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4983 | return -EINVAL; |
| 4984 | |
| 4985 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4986 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4987 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4988 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 4989 | owner_nlportid = info->snd_portid; |
| 4990 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 4991 | } else { |
| 4992 | owner_nlportid = 0; |
| 4993 | is_indoor = true; |
| 4994 | } |
| 4995 | |
| 4996 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4997 | default: |
| 4998 | return -EINVAL; |
| 4999 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5002 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5003 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5004 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5006 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5007 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5008 | struct mesh_config cur_params; |
| 5009 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5010 | void *hdr; |
| 5011 | struct nlattr *pinfoattr; |
| 5012 | struct sk_buff *msg; |
| 5013 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5014 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5015 | return -EOPNOTSUPP; |
| 5016 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5017 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5018 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5019 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5020 | wdev_lock(wdev); |
| 5021 | /* If not connected, get default parameters */ |
| 5022 | if (!wdev->mesh_id_len) |
| 5023 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5024 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5025 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5026 | wdev_unlock(wdev); |
| 5027 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5028 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5029 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5030 | |
| 5031 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5033 | if (!msg) |
| 5034 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5035 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5036 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5037 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5038 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5039 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5040 | if (!pinfoattr) |
| 5041 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5042 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5043 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5044 | cur_params.dot11MeshRetryTimeout) || |
| 5045 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5046 | cur_params.dot11MeshConfirmTimeout) || |
| 5047 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5048 | cur_params.dot11MeshHoldingTimeout) || |
| 5049 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5050 | cur_params.dot11MeshMaxPeerLinks) || |
| 5051 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5052 | cur_params.dot11MeshMaxRetries) || |
| 5053 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5054 | cur_params.dot11MeshTTL) || |
| 5055 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5056 | cur_params.element_ttl) || |
| 5057 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5058 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5059 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5060 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5061 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5062 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5063 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5064 | cur_params.path_refresh_time) || |
| 5065 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5066 | cur_params.min_discovery_timeout) || |
| 5067 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5068 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5069 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5070 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5071 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5072 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5073 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5074 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5075 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5076 | cur_params.dot11MeshHWMPRootMode) || |
| 5077 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5078 | cur_params.dot11MeshHWMPRannInterval) || |
| 5079 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5080 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5081 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5082 | cur_params.dot11MeshForwarding) || |
| 5083 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5084 | cur_params.rssi_threshold) || |
| 5085 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5086 | cur_params.ht_opmode) || |
| 5087 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5088 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5089 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5090 | cur_params.dot11MeshHWMProotInterval) || |
| 5091 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5092 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5093 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5094 | cur_params.power_mode) || |
| 5095 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5096 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5097 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5098 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5099 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5100 | nla_nest_end(msg, pinfoattr); |
| 5101 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5102 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5103 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5104 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5105 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5106 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5107 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5108 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5109 | } |
| 5110 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5111 | 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] | 5112 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5113 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5114 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5115 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5116 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5117 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5118 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5119 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5120 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5121 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5122 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5123 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5124 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5125 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5126 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5127 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5128 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5129 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5130 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5131 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5132 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5133 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5134 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5135 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5136 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5137 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5138 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5139 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5140 | }; |
| 5141 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5142 | static const struct nla_policy |
| 5143 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5144 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5145 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5146 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5147 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5148 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5149 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5150 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5151 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5152 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5153 | }; |
| 5154 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5155 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5156 | struct mesh_config *cfg, |
| 5157 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5158 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5159 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5160 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5161 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5162 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5163 | do { \ |
| 5164 | if (tb[attr]) { \ |
| 5165 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5166 | return -EINVAL; \ |
| 5167 | cfg->param = fn(tb[attr]); \ |
| 5168 | mask |= (1 << (attr - 1)); \ |
| 5169 | } \ |
| 5170 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5171 | |
| 5172 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5173 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5174 | return -EINVAL; |
| 5175 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5176 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5177 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5178 | return -EINVAL; |
| 5179 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5180 | /* This makes sure that there aren't more than 32 mesh config |
| 5181 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5182 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5183 | |
| 5184 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5186 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5187 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5189 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5190 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5191 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5192 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5193 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5195 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5196 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5197 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5198 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5199 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5200 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5201 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5202 | 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] | 5203 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5204 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5205 | 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] | 5206 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5207 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5209 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5210 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5211 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5213 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5214 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5215 | 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] | 5216 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5217 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5218 | 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] | 5219 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5220 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5222 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5223 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5224 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5226 | 1, 65535, mask, |
| 5227 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5228 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5230 | 1, 65535, mask, |
| 5231 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5232 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5233 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5234 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5235 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5236 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5237 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5239 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5240 | nla_get_u8); |
| 5241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5242 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5243 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5245 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5246 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5247 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5249 | mask, NL80211_MESHCONF_FORWARDING, |
| 5250 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5251 | 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] | 5252 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5253 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5254 | 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] | 5255 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5256 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5257 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5258 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5259 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5260 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5262 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5263 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5265 | dot11MeshHWMPconfirmationInterval, |
| 5266 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5267 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5268 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5269 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5270 | NL80211_MESH_POWER_ACTIVE, |
| 5271 | NL80211_MESH_POWER_MAX, |
| 5272 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5273 | nla_get_u32); |
| 5274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5275 | 0, 65535, mask, |
| 5276 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5278 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5279 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5280 | if (mask_out) |
| 5281 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5282 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5283 | return 0; |
| 5284 | |
| 5285 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5286 | } |
| 5287 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5288 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5289 | struct mesh_setup *setup) |
| 5290 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5292 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5293 | |
| 5294 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5295 | return -EINVAL; |
| 5296 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5297 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5298 | nl80211_mesh_setup_params_policy)) |
| 5299 | return -EINVAL; |
| 5300 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5301 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5302 | setup->sync_method = |
| 5303 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5304 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5305 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5306 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5307 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5308 | setup->path_sel_proto = |
| 5309 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5310 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5311 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5312 | |
| 5313 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5314 | setup->path_metric = |
| 5315 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5316 | IEEE80211_PATH_METRIC_VENDOR : |
| 5317 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5318 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5319 | |
| 5320 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5321 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5322 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5323 | if (!is_valid_ie_attr(ieattr)) |
| 5324 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5325 | setup->ie = nla_data(ieattr); |
| 5326 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5327 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5328 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5329 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5330 | return -EINVAL; |
| 5331 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5332 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5333 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5334 | if (setup->is_secure) |
| 5335 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5336 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5337 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5338 | if (!setup->user_mpm) |
| 5339 | return -EINVAL; |
| 5340 | setup->auth_id = |
| 5341 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5342 | } |
| 5343 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5344 | return 0; |
| 5345 | } |
| 5346 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5347 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5348 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5349 | { |
| 5350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5351 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5352 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5353 | struct mesh_config cfg; |
| 5354 | u32 mask; |
| 5355 | int err; |
| 5356 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5357 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5358 | return -EOPNOTSUPP; |
| 5359 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5360 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5361 | return -EOPNOTSUPP; |
| 5362 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5363 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5364 | if (err) |
| 5365 | return err; |
| 5366 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5367 | wdev_lock(wdev); |
| 5368 | if (!wdev->mesh_id_len) |
| 5369 | err = -ENOLINK; |
| 5370 | |
| 5371 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5372 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5373 | |
| 5374 | wdev_unlock(wdev); |
| 5375 | |
| 5376 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5379 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5380 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5381 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5382 | struct nlattr *nl_reg_rules; |
| 5383 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5384 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5385 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5386 | (regdom->dfs_region && |
| 5387 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5388 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5389 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5390 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5391 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5392 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5393 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5394 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5395 | struct nlattr *nl_reg_rule; |
| 5396 | const struct ieee80211_reg_rule *reg_rule; |
| 5397 | const struct ieee80211_freq_range *freq_range; |
| 5398 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5399 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5400 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5401 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5402 | freq_range = ®_rule->freq_range; |
| 5403 | power_rule = ®_rule->power_rule; |
| 5404 | |
| 5405 | nl_reg_rule = nla_nest_start(msg, i); |
| 5406 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5407 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5408 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5409 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5410 | if (!max_bandwidth_khz) |
| 5411 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5412 | reg_rule); |
| 5413 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5414 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5415 | reg_rule->flags) || |
| 5416 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5417 | freq_range->start_freq_khz) || |
| 5418 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5419 | freq_range->end_freq_khz) || |
| 5420 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5421 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5422 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5423 | power_rule->max_antenna_gain) || |
| 5424 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5425 | power_rule->max_eirp) || |
| 5426 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5427 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5428 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5429 | |
| 5430 | nla_nest_end(msg, nl_reg_rule); |
| 5431 | } |
| 5432 | |
| 5433 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5434 | return 0; |
| 5435 | |
| 5436 | nla_put_failure: |
| 5437 | return -EMSGSIZE; |
| 5438 | } |
| 5439 | |
| 5440 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5441 | { |
| 5442 | const struct ieee80211_regdomain *regdom = NULL; |
| 5443 | struct cfg80211_registered_device *rdev; |
| 5444 | struct wiphy *wiphy = NULL; |
| 5445 | struct sk_buff *msg; |
| 5446 | void *hdr; |
| 5447 | |
| 5448 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5449 | if (!msg) |
| 5450 | return -ENOBUFS; |
| 5451 | |
| 5452 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5453 | NL80211_CMD_GET_REG); |
| 5454 | if (!hdr) |
| 5455 | goto put_failure; |
| 5456 | |
| 5457 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5458 | bool self_managed; |
| 5459 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5460 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5461 | if (IS_ERR(rdev)) { |
| 5462 | nlmsg_free(msg); |
| 5463 | return PTR_ERR(rdev); |
| 5464 | } |
| 5465 | |
| 5466 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5467 | self_managed = wiphy->regulatory_flags & |
| 5468 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5469 | regdom = get_wiphy_regdom(wiphy); |
| 5470 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5471 | /* a self-managed-reg device must have a private regdom */ |
| 5472 | if (WARN_ON(!regdom && self_managed)) { |
| 5473 | nlmsg_free(msg); |
| 5474 | return -EINVAL; |
| 5475 | } |
| 5476 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5477 | if (regdom && |
| 5478 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5479 | goto nla_put_failure; |
| 5480 | } |
| 5481 | |
| 5482 | if (!wiphy && reg_last_request_cell_base() && |
| 5483 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5484 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5485 | goto nla_put_failure; |
| 5486 | |
| 5487 | rcu_read_lock(); |
| 5488 | |
| 5489 | if (!regdom) |
| 5490 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5491 | |
| 5492 | if (nl80211_put_regdom(regdom, msg)) |
| 5493 | goto nla_put_failure_rcu; |
| 5494 | |
| 5495 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5496 | |
| 5497 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5498 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5499 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5500 | nla_put_failure_rcu: |
| 5501 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5502 | nla_put_failure: |
| 5503 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5504 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5505 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5506 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5509 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5510 | u32 seq, int flags, struct wiphy *wiphy, |
| 5511 | const struct ieee80211_regdomain *regdom) |
| 5512 | { |
| 5513 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5514 | NL80211_CMD_GET_REG); |
| 5515 | |
| 5516 | if (!hdr) |
| 5517 | return -1; |
| 5518 | |
| 5519 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5520 | |
| 5521 | if (nl80211_put_regdom(regdom, msg)) |
| 5522 | goto nla_put_failure; |
| 5523 | |
| 5524 | if (!wiphy && reg_last_request_cell_base() && |
| 5525 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5526 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5527 | goto nla_put_failure; |
| 5528 | |
| 5529 | if (wiphy && |
| 5530 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5531 | goto nla_put_failure; |
| 5532 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5533 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5534 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5535 | goto nla_put_failure; |
| 5536 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5537 | genlmsg_end(msg, hdr); |
| 5538 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5539 | |
| 5540 | nla_put_failure: |
| 5541 | genlmsg_cancel(msg, hdr); |
| 5542 | return -EMSGSIZE; |
| 5543 | } |
| 5544 | |
| 5545 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5546 | struct netlink_callback *cb) |
| 5547 | { |
| 5548 | const struct ieee80211_regdomain *regdom = NULL; |
| 5549 | struct cfg80211_registered_device *rdev; |
| 5550 | int err, reg_idx, start = cb->args[2]; |
| 5551 | |
| 5552 | rtnl_lock(); |
| 5553 | |
| 5554 | if (cfg80211_regdomain && start == 0) { |
| 5555 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5556 | NLM_F_MULTI, NULL, |
| 5557 | rtnl_dereference(cfg80211_regdomain)); |
| 5558 | if (err < 0) |
| 5559 | goto out_err; |
| 5560 | } |
| 5561 | |
| 5562 | /* the global regdom is idx 0 */ |
| 5563 | reg_idx = 1; |
| 5564 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5565 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5566 | if (!regdom) |
| 5567 | continue; |
| 5568 | |
| 5569 | if (++reg_idx <= start) |
| 5570 | continue; |
| 5571 | |
| 5572 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5573 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5574 | if (err < 0) { |
| 5575 | reg_idx--; |
| 5576 | break; |
| 5577 | } |
| 5578 | } |
| 5579 | |
| 5580 | cb->args[2] = reg_idx; |
| 5581 | err = skb->len; |
| 5582 | out_err: |
| 5583 | rtnl_unlock(); |
| 5584 | return err; |
| 5585 | } |
| 5586 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5587 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 5588 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 5589 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5590 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5591 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5592 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5593 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5594 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5595 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 5596 | }; |
| 5597 | |
| 5598 | static int parse_reg_rule(struct nlattr *tb[], |
| 5599 | struct ieee80211_reg_rule *reg_rule) |
| 5600 | { |
| 5601 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 5602 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 5603 | |
| 5604 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 5605 | return -EINVAL; |
| 5606 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 5607 | return -EINVAL; |
| 5608 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 5609 | return -EINVAL; |
| 5610 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 5611 | return -EINVAL; |
| 5612 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 5613 | return -EINVAL; |
| 5614 | |
| 5615 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 5616 | |
| 5617 | freq_range->start_freq_khz = |
| 5618 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 5619 | freq_range->end_freq_khz = |
| 5620 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 5621 | freq_range->max_bandwidth_khz = |
| 5622 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 5623 | |
| 5624 | power_rule->max_eirp = |
| 5625 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 5626 | |
| 5627 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 5628 | power_rule->max_antenna_gain = |
| 5629 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 5630 | |
| 5631 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 5632 | reg_rule->dfs_cac_ms = |
| 5633 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 5634 | |
| 5635 | return 0; |
| 5636 | } |
| 5637 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5638 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5639 | { |
| 5640 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5641 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5642 | char *alpha2; |
| 5643 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5644 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5645 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5646 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5647 | |
| 5648 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5649 | return -EINVAL; |
| 5650 | |
| 5651 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5652 | return -EINVAL; |
| 5653 | |
| 5654 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5655 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5656 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5657 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5658 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5659 | 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] | 5660 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5661 | num_rules++; |
| 5662 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5663 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5664 | } |
| 5665 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5666 | if (!reg_is_valid_request(alpha2)) |
| 5667 | return -EINVAL; |
| 5668 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5669 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5670 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5671 | |
| 5672 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5673 | if (!rd) |
| 5674 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5675 | |
| 5676 | rd->n_reg_rules = num_rules; |
| 5677 | rd->alpha2[0] = alpha2[0]; |
| 5678 | rd->alpha2[1] = alpha2[1]; |
| 5679 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5680 | /* |
| 5681 | * Disable DFS master mode if the DFS region was |
| 5682 | * not supported or known on this kernel. |
| 5683 | */ |
| 5684 | if (reg_supported_dfs_region(dfs_region)) |
| 5685 | rd->dfs_region = dfs_region; |
| 5686 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5687 | 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] | 5688 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5689 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5690 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5691 | reg_rule_policy); |
| 5692 | if (r) |
| 5693 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5694 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5695 | if (r) |
| 5696 | goto bad_reg; |
| 5697 | |
| 5698 | rule_idx++; |
| 5699 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5700 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5701 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5702 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5703 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5704 | } |
| 5705 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 5706 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5707 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5708 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5709 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5710 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5711 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5712 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5713 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5714 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5715 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5716 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5717 | { |
| 5718 | struct nlattr *attr1, *attr2; |
| 5719 | int n_channels = 0, tmp1, tmp2; |
| 5720 | |
| 5721 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5722 | n_channels++; |
| 5723 | /* |
| 5724 | * Some hardware has a limited channel list for |
| 5725 | * scanning, and it is pretty much nonsensical |
| 5726 | * to scan for a channel twice, so disallow that |
| 5727 | * and don't require drivers to check that the |
| 5728 | * channel list they get isn't longer than what |
| 5729 | * they can scan, as long as they can scan all |
| 5730 | * the channels they registered at once. |
| 5731 | */ |
| 5732 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5733 | if (attr1 != attr2 && |
| 5734 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5735 | return 0; |
| 5736 | } |
| 5737 | |
| 5738 | return n_channels; |
| 5739 | } |
| 5740 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5741 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5742 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5743 | { |
| 5744 | int i; |
| 5745 | |
| 5746 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 5747 | eth_zero_addr(mac_addr); |
| 5748 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5749 | mac_addr[0] = 0x2; |
| 5750 | mac_addr_mask[0] = 0x3; |
| 5751 | |
| 5752 | return 0; |
| 5753 | } |
| 5754 | |
| 5755 | /* need both or none */ |
| 5756 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5757 | return -EINVAL; |
| 5758 | |
| 5759 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5760 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5761 | |
| 5762 | /* don't allow or configure an mcast address */ |
| 5763 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5764 | is_multicast_ether_addr(mac_addr)) |
| 5765 | return -EINVAL; |
| 5766 | |
| 5767 | /* |
| 5768 | * allow users to pass a MAC address that has bits set outside |
| 5769 | * of the mask, but don't bother drivers with having to deal |
| 5770 | * with such bits |
| 5771 | */ |
| 5772 | for (i = 0; i < ETH_ALEN; i++) |
| 5773 | mac_addr[i] &= mac_addr_mask[i]; |
| 5774 | |
| 5775 | return 0; |
| 5776 | } |
| 5777 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5778 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5779 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5781 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5782 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5783 | struct nlattr *attr; |
| 5784 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5785 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5786 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5787 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5788 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5789 | return -EINVAL; |
| 5790 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5791 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5793 | if (!rdev->ops->scan) |
| 5794 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5795 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5796 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5797 | err = -EBUSY; |
| 5798 | goto unlock; |
| 5799 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5800 | |
| 5801 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5802 | n_channels = validate_scan_freqs( |
| 5803 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5804 | if (!n_channels) { |
| 5805 | err = -EINVAL; |
| 5806 | goto unlock; |
| 5807 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5808 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5809 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5813 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5814 | n_ssids++; |
| 5815 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5816 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5817 | err = -EINVAL; |
| 5818 | goto unlock; |
| 5819 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5820 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5821 | if (info->attrs[NL80211_ATTR_IE]) |
| 5822 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5823 | else |
| 5824 | ie_len = 0; |
| 5825 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5826 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5827 | err = -EINVAL; |
| 5828 | goto unlock; |
| 5829 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5830 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5831 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5832 | + sizeof(*request->ssids) * n_ssids |
| 5833 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5834 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5835 | if (!request) { |
| 5836 | err = -ENOMEM; |
| 5837 | goto unlock; |
| 5838 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5839 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5840 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5841 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5842 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5843 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5844 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5845 | request->ie = (void *)(request->ssids + n_ssids); |
| 5846 | else |
| 5847 | request->ie = (void *)(request->channels + n_channels); |
| 5848 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5849 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5850 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5851 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5852 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5853 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5854 | struct ieee80211_channel *chan; |
| 5855 | |
| 5856 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5857 | |
| 5858 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5859 | err = -EINVAL; |
| 5860 | goto out_free; |
| 5861 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5862 | |
| 5863 | /* ignore disabled channels */ |
| 5864 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5865 | continue; |
| 5866 | |
| 5867 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5868 | i++; |
| 5869 | } |
| 5870 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5871 | enum ieee80211_band band; |
| 5872 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5873 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5874 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5875 | int j; |
| 5876 | if (!wiphy->bands[band]) |
| 5877 | continue; |
| 5878 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5879 | struct ieee80211_channel *chan; |
| 5880 | |
| 5881 | chan = &wiphy->bands[band]->channels[j]; |
| 5882 | |
| 5883 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5884 | continue; |
| 5885 | |
| 5886 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5887 | i++; |
| 5888 | } |
| 5889 | } |
| 5890 | } |
| 5891 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5892 | if (!i) { |
| 5893 | err = -EINVAL; |
| 5894 | goto out_free; |
| 5895 | } |
| 5896 | |
| 5897 | request->n_channels = i; |
| 5898 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5900 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5901 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5902 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5903 | err = -EINVAL; |
| 5904 | goto out_free; |
| 5905 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5906 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5907 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5908 | i++; |
| 5909 | } |
| 5910 | } |
| 5911 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5912 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5913 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5914 | memcpy((void *)request->ie, |
| 5915 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5916 | request->ie_len); |
| 5917 | } |
| 5918 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5919 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5920 | if (wiphy->bands[i]) |
| 5921 | request->rates[i] = |
| 5922 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5923 | |
| 5924 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5925 | nla_for_each_nested(attr, |
| 5926 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5927 | tmp) { |
| 5928 | enum ieee80211_band band = nla_type(attr); |
| 5929 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5930 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5931 | err = -EINVAL; |
| 5932 | goto out_free; |
| 5933 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5934 | |
| 5935 | if (!wiphy->bands[band]) |
| 5936 | continue; |
| 5937 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5938 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5939 | nla_data(attr), |
| 5940 | nla_len(attr), |
| 5941 | &request->rates[band]); |
| 5942 | if (err) |
| 5943 | goto out_free; |
| 5944 | } |
| 5945 | } |
| 5946 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5947 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5948 | request->flags = nla_get_u32( |
| 5949 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5950 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5951 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5952 | err = -EOPNOTSUPP; |
| 5953 | goto out_free; |
| 5954 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5955 | |
| 5956 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5957 | if (!(wiphy->features & |
| 5958 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5959 | err = -EOPNOTSUPP; |
| 5960 | goto out_free; |
| 5961 | } |
| 5962 | |
| 5963 | if (wdev->current_bss) { |
| 5964 | err = -EOPNOTSUPP; |
| 5965 | goto out_free; |
| 5966 | } |
| 5967 | |
| 5968 | err = nl80211_parse_random_mac(info->attrs, |
| 5969 | request->mac_addr, |
| 5970 | request->mac_addr_mask); |
| 5971 | if (err) |
| 5972 | goto out_free; |
| 5973 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5974 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5975 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5976 | request->no_cck = |
| 5977 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5978 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5979 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5980 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5981 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5982 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5983 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5984 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5985 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5986 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5987 | nl80211_send_scan_start(rdev, wdev); |
| 5988 | if (wdev->netdev) |
| 5989 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5990 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5991 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5992 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5993 | kfree(request); |
| 5994 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5995 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5996 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5997 | return err; |
| 5998 | } |
| 5999 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6000 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6001 | { |
| 6002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6003 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6004 | |
| 6005 | if (!rdev->ops->abort_scan) |
| 6006 | return -EOPNOTSUPP; |
| 6007 | |
| 6008 | if (rdev->scan_msg) |
| 6009 | return 0; |
| 6010 | |
| 6011 | if (!rdev->scan_req) |
| 6012 | return -ENOENT; |
| 6013 | |
| 6014 | rdev_abort_scan(rdev, wdev); |
| 6015 | return 0; |
| 6016 | } |
| 6017 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6018 | static int |
| 6019 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6020 | struct cfg80211_sched_scan_request *request, |
| 6021 | struct nlattr **attrs) |
| 6022 | { |
| 6023 | int tmp, err, i = 0; |
| 6024 | struct nlattr *attr; |
| 6025 | |
| 6026 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6027 | u32 interval; |
| 6028 | |
| 6029 | /* |
| 6030 | * If scan plans are not specified, |
| 6031 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6032 | * case one scan plan will be set with the specified scan |
| 6033 | * interval and infinite number of iterations. |
| 6034 | */ |
| 6035 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6036 | return -EINVAL; |
| 6037 | |
| 6038 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6039 | if (!interval) |
| 6040 | return -EINVAL; |
| 6041 | |
| 6042 | request->scan_plans[0].interval = |
| 6043 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6044 | if (!request->scan_plans[0].interval) |
| 6045 | return -EINVAL; |
| 6046 | |
| 6047 | if (request->scan_plans[0].interval > |
| 6048 | wiphy->max_sched_scan_plan_interval) |
| 6049 | request->scan_plans[0].interval = |
| 6050 | wiphy->max_sched_scan_plan_interval; |
| 6051 | |
| 6052 | return 0; |
| 6053 | } |
| 6054 | |
| 6055 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6056 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6057 | |
| 6058 | if (WARN_ON(i >= n_plans)) |
| 6059 | return -EINVAL; |
| 6060 | |
| 6061 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6062 | nla_data(attr), nla_len(attr), |
| 6063 | nl80211_plan_policy); |
| 6064 | if (err) |
| 6065 | return err; |
| 6066 | |
| 6067 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6068 | return -EINVAL; |
| 6069 | |
| 6070 | request->scan_plans[i].interval = |
| 6071 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6072 | if (!request->scan_plans[i].interval || |
| 6073 | request->scan_plans[i].interval > |
| 6074 | wiphy->max_sched_scan_plan_interval) |
| 6075 | return -EINVAL; |
| 6076 | |
| 6077 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6078 | request->scan_plans[i].iterations = |
| 6079 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6080 | if (!request->scan_plans[i].iterations || |
| 6081 | (request->scan_plans[i].iterations > |
| 6082 | wiphy->max_sched_scan_plan_iterations)) |
| 6083 | return -EINVAL; |
| 6084 | } else if (i < n_plans - 1) { |
| 6085 | /* |
| 6086 | * All scan plans but the last one must specify |
| 6087 | * a finite number of iterations |
| 6088 | */ |
| 6089 | return -EINVAL; |
| 6090 | } |
| 6091 | |
| 6092 | i++; |
| 6093 | } |
| 6094 | |
| 6095 | /* |
| 6096 | * The last scan plan must not specify the number of |
| 6097 | * iterations, it is supposed to run infinitely |
| 6098 | */ |
| 6099 | if (request->scan_plans[n_plans - 1].iterations) |
| 6100 | return -EINVAL; |
| 6101 | |
| 6102 | return 0; |
| 6103 | } |
| 6104 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6105 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6106 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6107 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6108 | { |
| 6109 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6110 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6111 | 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] | 6112 | enum ieee80211_band band; |
| 6113 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6114 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6115 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6116 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6117 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6118 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6119 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6120 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6121 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6122 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6123 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6124 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6125 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6126 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6127 | } |
| 6128 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6129 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6130 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6131 | tmp) |
| 6132 | n_ssids++; |
| 6133 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6134 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6135 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6136 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6137 | /* |
| 6138 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6139 | * the old implementation, matchsets containing only the RSSI attribute |
| 6140 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6141 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6142 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6143 | * older userspace that treated a matchset with only the RSSI as the |
| 6144 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6145 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6146 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6147 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6148 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6149 | tmp) { |
| 6150 | struct nlattr *rssi; |
| 6151 | |
| 6152 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6153 | nla_data(attr), nla_len(attr), |
| 6154 | nl80211_match_policy); |
| 6155 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6156 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6157 | /* add other standalone attributes here */ |
| 6158 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6159 | n_match_sets++; |
| 6160 | continue; |
| 6161 | } |
| 6162 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6163 | if (rssi) |
| 6164 | default_match_rssi = nla_get_s32(rssi); |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | /* However, if there's no other matchset, add the RSSI one */ |
| 6169 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6170 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6171 | |
| 6172 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6173 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6174 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6175 | if (attrs[NL80211_ATTR_IE]) |
| 6176 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6177 | else |
| 6178 | ie_len = 0; |
| 6179 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6180 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6181 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6182 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6183 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6184 | /* |
| 6185 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6186 | * each scan plan already specifies its own interval |
| 6187 | */ |
| 6188 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6189 | return ERR_PTR(-EINVAL); |
| 6190 | |
| 6191 | nla_for_each_nested(attr, |
| 6192 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6193 | n_plans++; |
| 6194 | } else { |
| 6195 | /* |
| 6196 | * The scan interval attribute is kept for backward |
| 6197 | * compatibility. If no scan plans are specified and sched scan |
| 6198 | * interval is specified, one scan plan will be set with this |
| 6199 | * scan interval and infinite number of iterations. |
| 6200 | */ |
| 6201 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6202 | return ERR_PTR(-EINVAL); |
| 6203 | |
| 6204 | n_plans = 1; |
| 6205 | } |
| 6206 | |
| 6207 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6208 | return ERR_PTR(-EINVAL); |
| 6209 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6210 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6211 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6212 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6213 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6214 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6215 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6216 | if (!request) |
| 6217 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6218 | |
| 6219 | if (n_ssids) |
| 6220 | request->ssids = (void *)&request->channels[n_channels]; |
| 6221 | request->n_ssids = n_ssids; |
| 6222 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6223 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6224 | request->ie = (void *)(request->ssids + n_ssids); |
| 6225 | else |
| 6226 | request->ie = (void *)(request->channels + n_channels); |
| 6227 | } |
| 6228 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6229 | if (n_match_sets) { |
| 6230 | if (request->ie) |
| 6231 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6232 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6233 | request->match_sets = |
| 6234 | (void *)(request->ssids + n_ssids); |
| 6235 | else |
| 6236 | request->match_sets = |
| 6237 | (void *)(request->channels + n_channels); |
| 6238 | } |
| 6239 | request->n_match_sets = n_match_sets; |
| 6240 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6241 | if (n_match_sets) |
| 6242 | request->scan_plans = (void *)(request->match_sets + |
| 6243 | n_match_sets); |
| 6244 | else if (request->ie) |
| 6245 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6246 | else if (n_ssids) |
| 6247 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6248 | else |
| 6249 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6250 | |
| 6251 | request->n_scan_plans = n_plans; |
| 6252 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6253 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6254 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6255 | /* user specified, bail out if channel not found */ |
| 6256 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6257 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6258 | tmp) { |
| 6259 | struct ieee80211_channel *chan; |
| 6260 | |
| 6261 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6262 | |
| 6263 | if (!chan) { |
| 6264 | err = -EINVAL; |
| 6265 | goto out_free; |
| 6266 | } |
| 6267 | |
| 6268 | /* ignore disabled channels */ |
| 6269 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6270 | continue; |
| 6271 | |
| 6272 | request->channels[i] = chan; |
| 6273 | i++; |
| 6274 | } |
| 6275 | } else { |
| 6276 | /* all channels */ |
| 6277 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6278 | int j; |
| 6279 | if (!wiphy->bands[band]) |
| 6280 | continue; |
| 6281 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6282 | struct ieee80211_channel *chan; |
| 6283 | |
| 6284 | chan = &wiphy->bands[band]->channels[j]; |
| 6285 | |
| 6286 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6287 | continue; |
| 6288 | |
| 6289 | request->channels[i] = chan; |
| 6290 | i++; |
| 6291 | } |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | if (!i) { |
| 6296 | err = -EINVAL; |
| 6297 | goto out_free; |
| 6298 | } |
| 6299 | |
| 6300 | request->n_channels = i; |
| 6301 | |
| 6302 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6303 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6304 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6305 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6306 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6307 | err = -EINVAL; |
| 6308 | goto out_free; |
| 6309 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6310 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6311 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6312 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6313 | i++; |
| 6314 | } |
| 6315 | } |
| 6316 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6317 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6318 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6319 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6320 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6321 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6322 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6323 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6324 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6325 | nla_data(attr), nla_len(attr), |
| 6326 | nl80211_match_policy); |
| 6327 | if (err) |
| 6328 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6329 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6330 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6331 | if (WARN_ON(i >= n_match_sets)) { |
| 6332 | /* this indicates a programming error, |
| 6333 | * the loop above should have verified |
| 6334 | * things properly |
| 6335 | */ |
| 6336 | err = -EINVAL; |
| 6337 | goto out_free; |
| 6338 | } |
| 6339 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6340 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6341 | err = -EINVAL; |
| 6342 | goto out_free; |
| 6343 | } |
| 6344 | memcpy(request->match_sets[i].ssid.ssid, |
| 6345 | nla_data(ssid), nla_len(ssid)); |
| 6346 | request->match_sets[i].ssid.ssid_len = |
| 6347 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6348 | /* special attribute - old implemenation w/a */ |
| 6349 | request->match_sets[i].rssi_thold = |
| 6350 | default_match_rssi; |
| 6351 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6352 | if (rssi) |
| 6353 | request->match_sets[i].rssi_thold = |
| 6354 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6355 | } |
| 6356 | i++; |
| 6357 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6358 | |
| 6359 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6360 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6361 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6362 | |
| 6363 | request->min_rssi_thold = INT_MAX; |
| 6364 | for (i = 0; i < n_match_sets; i++) |
| 6365 | request->min_rssi_thold = |
| 6366 | min(request->match_sets[i].rssi_thold, |
| 6367 | request->min_rssi_thold); |
| 6368 | } else { |
| 6369 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6370 | } |
| 6371 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6372 | if (ie_len) { |
| 6373 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6374 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6375 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6376 | request->ie_len); |
| 6377 | } |
| 6378 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6379 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6380 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6381 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6382 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6383 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6384 | err = -EOPNOTSUPP; |
| 6385 | goto out_free; |
| 6386 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6387 | |
| 6388 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6389 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6390 | |
| 6391 | if (!wdev) /* must be net-detect */ |
| 6392 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6393 | |
| 6394 | if (!(wiphy->features & flg)) { |
| 6395 | err = -EOPNOTSUPP; |
| 6396 | goto out_free; |
| 6397 | } |
| 6398 | |
| 6399 | if (wdev && wdev->current_bss) { |
| 6400 | err = -EOPNOTSUPP; |
| 6401 | goto out_free; |
| 6402 | } |
| 6403 | |
| 6404 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6405 | request->mac_addr_mask); |
| 6406 | if (err) |
| 6407 | goto out_free; |
| 6408 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6409 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6410 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6411 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6412 | request->delay = |
| 6413 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6414 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6415 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 6416 | if (err) |
| 6417 | goto out_free; |
| 6418 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6419 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6420 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6421 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6422 | |
| 6423 | out_free: |
| 6424 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6425 | return ERR_PTR(err); |
| 6426 | } |
| 6427 | |
| 6428 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6429 | struct genl_info *info) |
| 6430 | { |
| 6431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6432 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6433 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6434 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6435 | int err; |
| 6436 | |
| 6437 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6438 | !rdev->ops->sched_scan_start) |
| 6439 | return -EOPNOTSUPP; |
| 6440 | |
| 6441 | if (rdev->sched_scan_req) |
| 6442 | return -EINPROGRESS; |
| 6443 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6444 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6445 | info->attrs); |
| 6446 | |
| 6447 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6448 | if (err) |
| 6449 | goto out_err; |
| 6450 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6451 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6452 | if (err) |
| 6453 | goto out_free; |
| 6454 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6455 | sched_scan_req->dev = dev; |
| 6456 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6457 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6458 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6459 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6460 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6461 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6462 | |
| 6463 | nl80211_send_sched_scan(rdev, dev, |
| 6464 | NL80211_CMD_START_SCHED_SCAN); |
| 6465 | return 0; |
| 6466 | |
| 6467 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6468 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6469 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6470 | return err; |
| 6471 | } |
| 6472 | |
| 6473 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6474 | struct genl_info *info) |
| 6475 | { |
| 6476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6477 | |
| 6478 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6479 | !rdev->ops->sched_scan_stop) |
| 6480 | return -EOPNOTSUPP; |
| 6481 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6482 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6483 | } |
| 6484 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6485 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6486 | struct genl_info *info) |
| 6487 | { |
| 6488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6489 | struct net_device *dev = info->user_ptr[1]; |
| 6490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6491 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6492 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6493 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6494 | int err; |
| 6495 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6496 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6497 | if (dfs_region == NL80211_DFS_UNSET) |
| 6498 | return -EINVAL; |
| 6499 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6500 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6501 | if (err) |
| 6502 | return err; |
| 6503 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6504 | if (netif_carrier_ok(dev)) |
| 6505 | return -EBUSY; |
| 6506 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6507 | if (wdev->cac_started) |
| 6508 | return -EBUSY; |
| 6509 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6510 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6511 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6512 | if (err < 0) |
| 6513 | return err; |
| 6514 | |
| 6515 | if (err == 0) |
| 6516 | return -EINVAL; |
| 6517 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6518 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6519 | return -EINVAL; |
| 6520 | |
| 6521 | if (!rdev->ops->start_radar_detection) |
| 6522 | return -EOPNOTSUPP; |
| 6523 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6524 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6525 | if (WARN_ON(!cac_time_ms)) |
| 6526 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6527 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 6528 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6529 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6530 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6531 | wdev->cac_started = true; |
| 6532 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6533 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6534 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6535 | return err; |
| 6536 | } |
| 6537 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6538 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6539 | { |
| 6540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6541 | struct net_device *dev = info->user_ptr[1]; |
| 6542 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6543 | struct cfg80211_csa_settings params; |
| 6544 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6545 | * function is called under RTNL lock, so this should not be a problem. |
| 6546 | */ |
| 6547 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6548 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6549 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6550 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6551 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6552 | |
| 6553 | if (!rdev->ops->channel_switch || |
| 6554 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6555 | return -EOPNOTSUPP; |
| 6556 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6557 | switch (dev->ieee80211_ptr->iftype) { |
| 6558 | case NL80211_IFTYPE_AP: |
| 6559 | case NL80211_IFTYPE_P2P_GO: |
| 6560 | need_new_beacon = true; |
| 6561 | |
| 6562 | /* useless if AP is not running */ |
| 6563 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6564 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6565 | break; |
| 6566 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6567 | if (!wdev->ssid_len) |
| 6568 | return -ENOTCONN; |
| 6569 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6570 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6571 | if (!wdev->mesh_id_len) |
| 6572 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6573 | break; |
| 6574 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6575 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6576 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6577 | |
| 6578 | memset(¶ms, 0, sizeof(params)); |
| 6579 | |
| 6580 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6581 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6582 | return -EINVAL; |
| 6583 | |
| 6584 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6585 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6586 | return -EINVAL; |
| 6587 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6588 | /* Even though the attribute is u32, the specification says |
| 6589 | * u8, so let's make sure we don't overflow. |
| 6590 | */ |
| 6591 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6592 | if (cs_count > 255) |
| 6593 | return -EINVAL; |
| 6594 | |
| 6595 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6596 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6597 | if (!need_new_beacon) |
| 6598 | goto skip_beacons; |
| 6599 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6600 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6601 | if (err) |
| 6602 | return err; |
| 6603 | |
| 6604 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6605 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6606 | nl80211_policy); |
| 6607 | if (err) |
| 6608 | return err; |
| 6609 | |
| 6610 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6611 | if (err) |
| 6612 | return err; |
| 6613 | |
| 6614 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6615 | return -EINVAL; |
| 6616 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6617 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6618 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6619 | return -EINVAL; |
| 6620 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6621 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6622 | if (rdev->wiphy.max_num_csa_counters && |
| 6623 | (params.n_counter_offsets_beacon > |
| 6624 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6625 | return -EINVAL; |
| 6626 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6627 | params.counter_offsets_beacon = |
| 6628 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6629 | |
| 6630 | /* sanity checks - counters should fit and be the same */ |
| 6631 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6632 | u16 offset = params.counter_offsets_beacon[i]; |
| 6633 | |
| 6634 | if (offset >= params.beacon_csa.tail_len) |
| 6635 | return -EINVAL; |
| 6636 | |
| 6637 | if (params.beacon_csa.tail[offset] != params.count) |
| 6638 | return -EINVAL; |
| 6639 | } |
| 6640 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6641 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6642 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6643 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6644 | return -EINVAL; |
| 6645 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6646 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6647 | if (rdev->wiphy.max_num_csa_counters && |
| 6648 | (params.n_counter_offsets_beacon > |
| 6649 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6650 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6651 | |
| 6652 | params.counter_offsets_presp = |
| 6653 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6654 | |
| 6655 | /* sanity checks - counters should fit and be the same */ |
| 6656 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6657 | u16 offset = params.counter_offsets_presp[i]; |
| 6658 | |
| 6659 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6660 | return -EINVAL; |
| 6661 | |
| 6662 | if (params.beacon_csa.probe_resp[offset] != |
| 6663 | params.count) |
| 6664 | return -EINVAL; |
| 6665 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6666 | } |
| 6667 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6668 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6669 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6670 | if (err) |
| 6671 | return err; |
| 6672 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 6673 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 6674 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6675 | return -EINVAL; |
| 6676 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6677 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6678 | ¶ms.chandef, |
| 6679 | wdev->iftype); |
| 6680 | if (err < 0) |
| 6681 | return err; |
| 6682 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6683 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6684 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6685 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6686 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6687 | params.block_tx = true; |
| 6688 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6689 | wdev_lock(wdev); |
| 6690 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6691 | wdev_unlock(wdev); |
| 6692 | |
| 6693 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6694 | } |
| 6695 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6696 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6697 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6698 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6699 | struct wireless_dev *wdev, |
| 6700 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6701 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6702 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6703 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6704 | void *hdr; |
| 6705 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6706 | |
| 6707 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6708 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6709 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6710 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6711 | if (!hdr) |
| 6712 | return -1; |
| 6713 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6714 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6715 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6716 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6717 | goto nla_put_failure; |
| 6718 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6719 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6720 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6721 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6722 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6723 | |
| 6724 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6725 | if (!bss) |
| 6726 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6727 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6728 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6729 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6730 | |
| 6731 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6732 | /* indicate whether we have probe response data or not */ |
| 6733 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6734 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6735 | goto fail_unlock_rcu; |
| 6736 | |
| 6737 | /* this pointer prefers to be pointed to probe response data |
| 6738 | * but is always valid |
| 6739 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6740 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6741 | if (ies) { |
| 6742 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6743 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6744 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6745 | ies->len, ies->data)) |
| 6746 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6747 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6748 | |
| 6749 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6750 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6751 | if (ies && ies->from_beacon) { |
| 6752 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6753 | goto fail_unlock_rcu; |
| 6754 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6755 | ies->len, ies->data)) |
| 6756 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6757 | } |
| 6758 | rcu_read_unlock(); |
| 6759 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6760 | if (res->beacon_interval && |
| 6761 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6762 | goto nla_put_failure; |
| 6763 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6764 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6765 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6766 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6767 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6768 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6769 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 6770 | if (intbss->ts_boottime && |
| 6771 | nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 6772 | intbss->ts_boottime)) |
| 6773 | goto nla_put_failure; |
| 6774 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6775 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6776 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6777 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6778 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6779 | break; |
| 6780 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6781 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6782 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6783 | break; |
| 6784 | default: |
| 6785 | break; |
| 6786 | } |
| 6787 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6788 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6789 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6790 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6791 | if (intbss == wdev->current_bss && |
| 6792 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6793 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6794 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6795 | break; |
| 6796 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6797 | if (intbss == wdev->current_bss && |
| 6798 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6799 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6800 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6801 | break; |
| 6802 | default: |
| 6803 | break; |
| 6804 | } |
| 6805 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6806 | nla_nest_end(msg, bss); |
| 6807 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6808 | genlmsg_end(msg, hdr); |
| 6809 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6810 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6811 | fail_unlock_rcu: |
| 6812 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6813 | nla_put_failure: |
| 6814 | genlmsg_cancel(msg, hdr); |
| 6815 | return -EMSGSIZE; |
| 6816 | } |
| 6817 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6818 | 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] | 6819 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6820 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6821 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6822 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6823 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6824 | int err; |
| 6825 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6826 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6827 | if (err) |
| 6828 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6829 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6830 | wdev_lock(wdev); |
| 6831 | spin_lock_bh(&rdev->bss_lock); |
| 6832 | cfg80211_bss_expire(rdev); |
| 6833 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6834 | cb->seq = rdev->bss_generation; |
| 6835 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6836 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6837 | if (++idx <= start) |
| 6838 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6839 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6840 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6841 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6842 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6843 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6844 | } |
| 6845 | } |
| 6846 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6847 | spin_unlock_bh(&rdev->bss_lock); |
| 6848 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6849 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6850 | cb->args[2] = idx; |
| 6851 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6852 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6853 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6854 | } |
| 6855 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6856 | 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] | 6857 | int flags, struct net_device *dev, |
| 6858 | bool allow_radio_stats, |
| 6859 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6860 | { |
| 6861 | void *hdr; |
| 6862 | struct nlattr *infoattr; |
| 6863 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6864 | /* skip radio stats if userspace didn't request them */ |
| 6865 | if (!survey->channel && !allow_radio_stats) |
| 6866 | return 0; |
| 6867 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6868 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6869 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6870 | if (!hdr) |
| 6871 | return -ENOMEM; |
| 6872 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6873 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6874 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6875 | |
| 6876 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6877 | if (!infoattr) |
| 6878 | goto nla_put_failure; |
| 6879 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6880 | if (survey->channel && |
| 6881 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6882 | survey->channel->center_freq)) |
| 6883 | goto nla_put_failure; |
| 6884 | |
| 6885 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6886 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6887 | goto nla_put_failure; |
| 6888 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6889 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6890 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6891 | if ((survey->filled & SURVEY_INFO_TIME) && |
| 6892 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, |
| 6893 | survey->time)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6894 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6895 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
| 6896 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 6897 | survey->time_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6898 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6899 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
| 6900 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 6901 | survey->time_ext_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6902 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6903 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
| 6904 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 6905 | survey->time_rx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6906 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6907 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
| 6908 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 6909 | survey->time_tx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6910 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 6911 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
| 6912 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 6913 | survey->time_scan)) |
| 6914 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6915 | |
| 6916 | nla_nest_end(msg, infoattr); |
| 6917 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6918 | genlmsg_end(msg, hdr); |
| 6919 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6920 | |
| 6921 | nla_put_failure: |
| 6922 | genlmsg_cancel(msg, hdr); |
| 6923 | return -EMSGSIZE; |
| 6924 | } |
| 6925 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6926 | 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] | 6927 | { |
| 6928 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6929 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6930 | struct wireless_dev *wdev; |
| 6931 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6932 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6933 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6934 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6935 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6936 | if (res) |
| 6937 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6938 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6939 | /* prepare_wdev_dump parsed the attributes */ |
| 6940 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 6941 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6942 | if (!wdev->netdev) { |
| 6943 | res = -EINVAL; |
| 6944 | goto out_err; |
| 6945 | } |
| 6946 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6947 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6948 | res = -EOPNOTSUPP; |
| 6949 | goto out_err; |
| 6950 | } |
| 6951 | |
| 6952 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6953 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6954 | if (res == -ENOENT) |
| 6955 | break; |
| 6956 | if (res) |
| 6957 | goto out_err; |
| 6958 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6959 | /* don't send disabled channels, but do send non-channel data */ |
| 6960 | if (survey.channel && |
| 6961 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6962 | survey_idx++; |
| 6963 | continue; |
| 6964 | } |
| 6965 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6966 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6967 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6968 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6969 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6970 | goto out; |
| 6971 | survey_idx++; |
| 6972 | } |
| 6973 | |
| 6974 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6975 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6976 | res = skb->len; |
| 6977 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6978 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6979 | return res; |
| 6980 | } |
| 6981 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6982 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6983 | { |
| 6984 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6985 | NL80211_WPA_VERSION_2)); |
| 6986 | } |
| 6987 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6988 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6991 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6992 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6993 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6994 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6995 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6996 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6997 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6998 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6999 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7000 | return -EINVAL; |
| 7001 | |
| 7002 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7003 | return -EINVAL; |
| 7004 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7005 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7006 | return -EINVAL; |
| 7007 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7008 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7009 | return -EINVAL; |
| 7010 | |
| 7011 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7012 | return -EINVAL; |
| 7013 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7014 | err = nl80211_parse_key(info, &key); |
| 7015 | if (err) |
| 7016 | return err; |
| 7017 | |
| 7018 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7019 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7020 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7021 | if (!key.p.key || !key.p.key_len) |
| 7022 | return -EINVAL; |
| 7023 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7024 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7025 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7026 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7027 | return -EINVAL; |
| 7028 | if (key.idx > 4) |
| 7029 | return -EINVAL; |
| 7030 | } else { |
| 7031 | key.p.key_len = 0; |
| 7032 | key.p.key = NULL; |
| 7033 | } |
| 7034 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7035 | if (key.idx >= 0) { |
| 7036 | int i; |
| 7037 | bool ok = false; |
| 7038 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7039 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7040 | ok = true; |
| 7041 | break; |
| 7042 | } |
| 7043 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7044 | if (!ok) |
| 7045 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7046 | } |
| 7047 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7048 | if (!rdev->ops->auth) |
| 7049 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7050 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7051 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7052 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7053 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7054 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7055 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7056 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7057 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7058 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7059 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7060 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7061 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7062 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7063 | |
| 7064 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7065 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7066 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7067 | } |
| 7068 | |
| 7069 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7070 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7072 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7073 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7074 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7075 | return -EINVAL; |
| 7076 | |
| 7077 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7078 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7079 | return -EINVAL; |
| 7080 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7081 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7082 | /* need to include at least Auth Transaction and Status Code */ |
| 7083 | if (sae_data_len < 4) |
| 7084 | return -EINVAL; |
| 7085 | } |
| 7086 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7087 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7088 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7089 | /* |
| 7090 | * Since we no longer track auth state, ignore |
| 7091 | * requests to only change local state. |
| 7092 | */ |
| 7093 | if (local_state_change) |
| 7094 | return 0; |
| 7095 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7096 | wdev_lock(dev->ieee80211_ptr); |
| 7097 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7098 | ssid, ssid_len, ie, ie_len, |
| 7099 | key.p.key, key.p.key_len, key.idx, |
| 7100 | sae_data, sae_data_len); |
| 7101 | wdev_unlock(dev->ieee80211_ptr); |
| 7102 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7103 | } |
| 7104 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7105 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7106 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7107 | struct cfg80211_crypto_settings *settings, |
| 7108 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7109 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7110 | memset(settings, 0, sizeof(*settings)); |
| 7111 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7112 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7113 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7114 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7115 | u16 proto; |
| 7116 | proto = nla_get_u16( |
| 7117 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7118 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7119 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7120 | proto != ETH_P_PAE) |
| 7121 | return -EINVAL; |
| 7122 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7123 | settings->control_port_no_encrypt = true; |
| 7124 | } else |
| 7125 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7126 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7127 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7128 | void *data; |
| 7129 | int len, i; |
| 7130 | |
| 7131 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7132 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7133 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7134 | |
| 7135 | if (len % sizeof(u32)) |
| 7136 | return -EINVAL; |
| 7137 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7138 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7139 | return -EINVAL; |
| 7140 | |
| 7141 | memcpy(settings->ciphers_pairwise, data, len); |
| 7142 | |
| 7143 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7144 | if (!cfg80211_supported_cipher_suite( |
| 7145 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7146 | settings->ciphers_pairwise[i])) |
| 7147 | return -EINVAL; |
| 7148 | } |
| 7149 | |
| 7150 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7151 | settings->cipher_group = |
| 7152 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7153 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7154 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7155 | return -EINVAL; |
| 7156 | } |
| 7157 | |
| 7158 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7159 | settings->wpa_versions = |
| 7160 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7161 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7162 | return -EINVAL; |
| 7163 | } |
| 7164 | |
| 7165 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7166 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7167 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7168 | |
| 7169 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7170 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7171 | settings->n_akm_suites = len / sizeof(u32); |
| 7172 | |
| 7173 | if (len % sizeof(u32)) |
| 7174 | return -EINVAL; |
| 7175 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7176 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7177 | return -EINVAL; |
| 7178 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7179 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | return 0; |
| 7183 | } |
| 7184 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7185 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7186 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7188 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7189 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7190 | struct cfg80211_assoc_request req = {}; |
| 7191 | const u8 *bssid, *ssid; |
| 7192 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7193 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7194 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7195 | return -EINVAL; |
| 7196 | |
| 7197 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7198 | !info->attrs[NL80211_ATTR_SSID] || |
| 7199 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7200 | return -EINVAL; |
| 7201 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7202 | if (!rdev->ops->assoc) |
| 7203 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7204 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7205 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7206 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7207 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7208 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7209 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7210 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7211 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7212 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7213 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7214 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7215 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7216 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7217 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7218 | |
| 7219 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7220 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7221 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7222 | } |
| 7223 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7224 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7225 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7226 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7227 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7228 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7229 | else if (mfp != NL80211_MFP_NO) |
| 7230 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7231 | } |
| 7232 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7233 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7234 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7235 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7236 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7237 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7238 | |
| 7239 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7240 | memcpy(&req.ht_capa_mask, |
| 7241 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7242 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7243 | |
| 7244 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7245 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7246 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7247 | memcpy(&req.ht_capa, |
| 7248 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7249 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7250 | } |
| 7251 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7252 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7253 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7254 | |
| 7255 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7256 | memcpy(&req.vht_capa_mask, |
| 7257 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7258 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7259 | |
| 7260 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7261 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7262 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7263 | memcpy(&req.vht_capa, |
| 7264 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7265 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7266 | } |
| 7267 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7268 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7269 | if (!(rdev->wiphy.features & |
| 7270 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7271 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7272 | return -EINVAL; |
| 7273 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7274 | } |
| 7275 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7276 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7277 | if (!err) { |
| 7278 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7279 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7280 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7281 | wdev_unlock(dev->ieee80211_ptr); |
| 7282 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7283 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7284 | return err; |
| 7285 | } |
| 7286 | |
| 7287 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7290 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7291 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7292 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7293 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7294 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7295 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7296 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7297 | return -EINVAL; |
| 7298 | |
| 7299 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7300 | return -EINVAL; |
| 7301 | |
| 7302 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7303 | return -EINVAL; |
| 7304 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7305 | if (!rdev->ops->deauth) |
| 7306 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7307 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7308 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7310 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7311 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7312 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7313 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7314 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7315 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7316 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7317 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7318 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7319 | |
| 7320 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7321 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7322 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7323 | } |
| 7324 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7325 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7326 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7327 | wdev_lock(dev->ieee80211_ptr); |
| 7328 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7329 | local_state_change); |
| 7330 | wdev_unlock(dev->ieee80211_ptr); |
| 7331 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7335 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7337 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7338 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7339 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7340 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7341 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7342 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7343 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7344 | return -EINVAL; |
| 7345 | |
| 7346 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7347 | return -EINVAL; |
| 7348 | |
| 7349 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7350 | return -EINVAL; |
| 7351 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7352 | if (!rdev->ops->disassoc) |
| 7353 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7354 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7355 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7356 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7357 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7358 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7359 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7360 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7361 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7362 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7363 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7364 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7365 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7366 | |
| 7367 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7368 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7369 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7370 | } |
| 7371 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7372 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7373 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7374 | wdev_lock(dev->ieee80211_ptr); |
| 7375 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7376 | local_state_change); |
| 7377 | wdev_unlock(dev->ieee80211_ptr); |
| 7378 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7379 | } |
| 7380 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7381 | static bool |
| 7382 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7383 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7384 | int rateval) |
| 7385 | { |
| 7386 | struct wiphy *wiphy = &rdev->wiphy; |
| 7387 | bool found = false; |
| 7388 | int band, i; |
| 7389 | |
| 7390 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7391 | struct ieee80211_supported_band *sband; |
| 7392 | |
| 7393 | sband = wiphy->bands[band]; |
| 7394 | if (!sband) |
| 7395 | continue; |
| 7396 | |
| 7397 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7398 | if (sband->bitrates[i].bitrate == rateval) { |
| 7399 | mcast_rate[band] = i + 1; |
| 7400 | found = true; |
| 7401 | break; |
| 7402 | } |
| 7403 | } |
| 7404 | } |
| 7405 | |
| 7406 | return found; |
| 7407 | } |
| 7408 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7409 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7410 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7412 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7413 | struct cfg80211_ibss_params ibss; |
| 7414 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7415 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7416 | int err; |
| 7417 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7418 | memset(&ibss, 0, sizeof(ibss)); |
| 7419 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7420 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7421 | return -EINVAL; |
| 7422 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7423 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7424 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7425 | return -EINVAL; |
| 7426 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7427 | ibss.beacon_interval = 100; |
| 7428 | |
| 7429 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7430 | ibss.beacon_interval = |
| 7431 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7432 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7433 | return -EINVAL; |
| 7434 | } |
| 7435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7436 | if (!rdev->ops->join_ibss) |
| 7437 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7440 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7441 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7442 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7443 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7444 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7445 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7446 | |
| 7447 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7448 | return -EINVAL; |
| 7449 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7450 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7451 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7452 | |
| 7453 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7454 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7455 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7456 | } |
| 7457 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7458 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7459 | if (err) |
| 7460 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7461 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7462 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7463 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7464 | return -EINVAL; |
| 7465 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7466 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7467 | case NL80211_CHAN_WIDTH_5: |
| 7468 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7469 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7470 | break; |
| 7471 | case NL80211_CHAN_WIDTH_20: |
| 7472 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7473 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7474 | return -EINVAL; |
| 7475 | break; |
| 7476 | case NL80211_CHAN_WIDTH_80: |
| 7477 | case NL80211_CHAN_WIDTH_80P80: |
| 7478 | case NL80211_CHAN_WIDTH_160: |
| 7479 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7480 | return -EINVAL; |
| 7481 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7482 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7483 | return -EINVAL; |
| 7484 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7485 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7486 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7487 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7488 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7489 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7490 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7491 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7492 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7493 | u8 *rates = |
| 7494 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7495 | int n_rates = |
| 7496 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7497 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7498 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7499 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7500 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7501 | &ibss.basic_rates); |
| 7502 | if (err) |
| 7503 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7504 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7505 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7506 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7507 | memcpy(&ibss.ht_capa_mask, |
| 7508 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7509 | sizeof(ibss.ht_capa_mask)); |
| 7510 | |
| 7511 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7512 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7513 | return -EINVAL; |
| 7514 | memcpy(&ibss.ht_capa, |
| 7515 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7516 | sizeof(ibss.ht_capa)); |
| 7517 | } |
| 7518 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7519 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7520 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7521 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7522 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7524 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7525 | bool no_ht = false; |
| 7526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7527 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7528 | info->attrs[NL80211_ATTR_KEYS], |
| 7529 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | if (IS_ERR(connkeys)) |
| 7531 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7532 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7533 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7534 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7535 | kfree(connkeys); |
| 7536 | return -EINVAL; |
| 7537 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7538 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7539 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7540 | ibss.control_port = |
| 7541 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7542 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7543 | ibss.userspace_handles_dfs = |
| 7544 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7545 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7546 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7547 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7548 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7549 | return err; |
| 7550 | } |
| 7551 | |
| 7552 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7553 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7555 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7557 | if (!rdev->ops->leave_ibss) |
| 7558 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7560 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7561 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7562 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7563 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7564 | } |
| 7565 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7566 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7567 | { |
| 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7569 | struct net_device *dev = info->user_ptr[1]; |
| 7570 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7571 | u32 nla_rate; |
| 7572 | int err; |
| 7573 | |
| 7574 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7575 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7576 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7577 | return -EOPNOTSUPP; |
| 7578 | |
| 7579 | if (!rdev->ops->set_mcast_rate) |
| 7580 | return -EOPNOTSUPP; |
| 7581 | |
| 7582 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7583 | |
| 7584 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7585 | return -EINVAL; |
| 7586 | |
| 7587 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7588 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7589 | return -EINVAL; |
| 7590 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7591 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7592 | |
| 7593 | return err; |
| 7594 | } |
| 7595 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7596 | static struct sk_buff * |
| 7597 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7598 | struct wireless_dev *wdev, int approxlen, |
| 7599 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7600 | enum nl80211_attrs attr, |
| 7601 | const struct nl80211_vendor_cmd_info *info, |
| 7602 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7603 | { |
| 7604 | struct sk_buff *skb; |
| 7605 | void *hdr; |
| 7606 | struct nlattr *data; |
| 7607 | |
| 7608 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7609 | if (!skb) |
| 7610 | return NULL; |
| 7611 | |
| 7612 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7613 | if (!hdr) { |
| 7614 | kfree_skb(skb); |
| 7615 | return NULL; |
| 7616 | } |
| 7617 | |
| 7618 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7619 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7620 | |
| 7621 | if (info) { |
| 7622 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7623 | info->vendor_id)) |
| 7624 | goto nla_put_failure; |
| 7625 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7626 | info->subcmd)) |
| 7627 | goto nla_put_failure; |
| 7628 | } |
| 7629 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7630 | if (wdev) { |
| 7631 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 7632 | wdev_id(wdev))) |
| 7633 | goto nla_put_failure; |
| 7634 | if (wdev->netdev && |
| 7635 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7636 | wdev->netdev->ifindex)) |
| 7637 | goto nla_put_failure; |
| 7638 | } |
| 7639 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7640 | data = nla_nest_start(skb, attr); |
| 7641 | |
| 7642 | ((void **)skb->cb)[0] = rdev; |
| 7643 | ((void **)skb->cb)[1] = hdr; |
| 7644 | ((void **)skb->cb)[2] = data; |
| 7645 | |
| 7646 | return skb; |
| 7647 | |
| 7648 | nla_put_failure: |
| 7649 | kfree_skb(skb); |
| 7650 | return NULL; |
| 7651 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7652 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7653 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7654 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7655 | enum nl80211_commands cmd, |
| 7656 | enum nl80211_attrs attr, |
| 7657 | int vendor_event_idx, |
| 7658 | int approxlen, gfp_t gfp) |
| 7659 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7660 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7661 | const struct nl80211_vendor_cmd_info *info; |
| 7662 | |
| 7663 | switch (cmd) { |
| 7664 | case NL80211_CMD_TESTMODE: |
| 7665 | if (WARN_ON(vendor_event_idx != -1)) |
| 7666 | return NULL; |
| 7667 | info = NULL; |
| 7668 | break; |
| 7669 | case NL80211_CMD_VENDOR: |
| 7670 | if (WARN_ON(vendor_event_idx < 0 || |
| 7671 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7672 | return NULL; |
| 7673 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7674 | break; |
| 7675 | default: |
| 7676 | WARN_ON(1); |
| 7677 | return NULL; |
| 7678 | } |
| 7679 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7680 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7681 | cmd, attr, info, gfp); |
| 7682 | } |
| 7683 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7684 | |
| 7685 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7686 | { |
| 7687 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7688 | void *hdr = ((void **)skb->cb)[1]; |
| 7689 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7690 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7691 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7692 | /* clear CB data for netlink core to own from now on */ |
| 7693 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7694 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7695 | nla_nest_end(skb, data); |
| 7696 | genlmsg_end(skb, hdr); |
| 7697 | |
| 7698 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7699 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7700 | |
| 7701 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7702 | mcgrp, gfp); |
| 7703 | } |
| 7704 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7705 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7706 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7707 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7708 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7710 | struct wireless_dev *wdev = |
| 7711 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7712 | int err; |
| 7713 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7714 | if (!rdev->ops->testmode_cmd) |
| 7715 | return -EOPNOTSUPP; |
| 7716 | |
| 7717 | if (IS_ERR(wdev)) { |
| 7718 | err = PTR_ERR(wdev); |
| 7719 | if (err != -EINVAL) |
| 7720 | return err; |
| 7721 | wdev = NULL; |
| 7722 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7723 | return -EINVAL; |
| 7724 | } |
| 7725 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7726 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7727 | return -EINVAL; |
| 7728 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7729 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7730 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7731 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7732 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7733 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7734 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7735 | return err; |
| 7736 | } |
| 7737 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7738 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7739 | struct netlink_callback *cb) |
| 7740 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7741 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7742 | int err; |
| 7743 | long phy_idx; |
| 7744 | void *data = NULL; |
| 7745 | int data_len = 0; |
| 7746 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7747 | rtnl_lock(); |
| 7748 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7749 | if (cb->args[0]) { |
| 7750 | /* |
| 7751 | * 0 is a valid index, but not valid for args[0], |
| 7752 | * so we need to offset by 1. |
| 7753 | */ |
| 7754 | phy_idx = cb->args[0] - 1; |
| 7755 | } else { |
| 7756 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7757 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7758 | nl80211_policy); |
| 7759 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7760 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7761 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7762 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7763 | nl80211_fam.attrbuf); |
| 7764 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7765 | err = PTR_ERR(rdev); |
| 7766 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7767 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7768 | phy_idx = rdev->wiphy_idx; |
| 7769 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7770 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7771 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7772 | cb->args[1] = |
| 7773 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7774 | } |
| 7775 | |
| 7776 | if (cb->args[1]) { |
| 7777 | data = nla_data((void *)cb->args[1]); |
| 7778 | data_len = nla_len((void *)cb->args[1]); |
| 7779 | } |
| 7780 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7781 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7782 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7783 | err = -ENOENT; |
| 7784 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7785 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7786 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7787 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7788 | err = -EOPNOTSUPP; |
| 7789 | goto out_err; |
| 7790 | } |
| 7791 | |
| 7792 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7793 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7794 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7795 | NL80211_CMD_TESTMODE); |
| 7796 | struct nlattr *tmdata; |
| 7797 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7798 | if (!hdr) |
| 7799 | break; |
| 7800 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7801 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7802 | genlmsg_cancel(skb, hdr); |
| 7803 | break; |
| 7804 | } |
| 7805 | |
| 7806 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7807 | if (!tmdata) { |
| 7808 | genlmsg_cancel(skb, hdr); |
| 7809 | break; |
| 7810 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7811 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7812 | nla_nest_end(skb, tmdata); |
| 7813 | |
| 7814 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7815 | genlmsg_cancel(skb, hdr); |
| 7816 | break; |
| 7817 | } else if (err) { |
| 7818 | genlmsg_cancel(skb, hdr); |
| 7819 | goto out_err; |
| 7820 | } |
| 7821 | |
| 7822 | genlmsg_end(skb, hdr); |
| 7823 | } |
| 7824 | |
| 7825 | err = skb->len; |
| 7826 | /* see above */ |
| 7827 | cb->args[0] = phy_idx + 1; |
| 7828 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7829 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7830 | return err; |
| 7831 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7832 | #endif |
| 7833 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7834 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7835 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7837 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7838 | struct cfg80211_connect_params connect; |
| 7839 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7840 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7841 | int err; |
| 7842 | |
| 7843 | memset(&connect, 0, sizeof(connect)); |
| 7844 | |
| 7845 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7846 | return -EINVAL; |
| 7847 | |
| 7848 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7849 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7850 | return -EINVAL; |
| 7851 | |
| 7852 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7853 | connect.auth_type = |
| 7854 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7855 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7856 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7857 | return -EINVAL; |
| 7858 | } else |
| 7859 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7860 | |
| 7861 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7862 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7863 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7864 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7865 | if (err) |
| 7866 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7867 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7868 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7869 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7870 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7871 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7872 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7873 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7874 | connect.bg_scan_period = -1; |
| 7875 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7876 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7877 | connect.bg_scan_period = |
| 7878 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7879 | } |
| 7880 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7881 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7882 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7883 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7884 | connect.bssid_hint = |
| 7885 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7886 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7887 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7888 | |
| 7889 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7890 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7891 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7892 | } |
| 7893 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7894 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7895 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7896 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7897 | connect.mfp != NL80211_MFP_NO) |
| 7898 | return -EINVAL; |
| 7899 | } else { |
| 7900 | connect.mfp = NL80211_MFP_NO; |
| 7901 | } |
| 7902 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7903 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7904 | connect.channel = nl80211_get_valid_chan( |
| 7905 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7906 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7907 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7908 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7909 | connect.channel_hint = nl80211_get_valid_chan( |
| 7910 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7911 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7912 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7913 | } |
| 7914 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7915 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7916 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7917 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7918 | if (IS_ERR(connkeys)) |
| 7919 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7920 | } |
| 7921 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7922 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7923 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7924 | |
| 7925 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7926 | memcpy(&connect.ht_capa_mask, |
| 7927 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7928 | sizeof(connect.ht_capa_mask)); |
| 7929 | |
| 7930 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7931 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7932 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7933 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7934 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7935 | memcpy(&connect.ht_capa, |
| 7936 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7937 | sizeof(connect.ht_capa)); |
| 7938 | } |
| 7939 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7940 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7941 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7942 | |
| 7943 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7944 | memcpy(&connect.vht_capa_mask, |
| 7945 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7946 | sizeof(connect.vht_capa_mask)); |
| 7947 | |
| 7948 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7949 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7950 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7951 | return -EINVAL; |
| 7952 | } |
| 7953 | memcpy(&connect.vht_capa, |
| 7954 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7955 | sizeof(connect.vht_capa)); |
| 7956 | } |
| 7957 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7958 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7959 | if (!(rdev->wiphy.features & |
| 7960 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7961 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7962 | return -EINVAL; |
| 7963 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7964 | } |
| 7965 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7966 | wdev_lock(dev->ieee80211_ptr); |
| 7967 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7968 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7969 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7970 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7971 | return err; |
| 7972 | } |
| 7973 | |
| 7974 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7975 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7977 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7978 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7979 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7980 | |
| 7981 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7982 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7983 | else |
| 7984 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7985 | |
| 7986 | if (reason == 0) |
| 7987 | return -EINVAL; |
| 7988 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7989 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7990 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7991 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7992 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7993 | wdev_lock(dev->ieee80211_ptr); |
| 7994 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7995 | wdev_unlock(dev->ieee80211_ptr); |
| 7996 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7997 | } |
| 7998 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7999 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8000 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8002 | struct net *net; |
| 8003 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8004 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8005 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8006 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8007 | |
| 8008 | net = get_net_ns_by_pid(pid); |
| 8009 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8010 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8011 | |
| 8012 | net = get_net_ns_by_fd(fd); |
| 8013 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8014 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8015 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8016 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8017 | if (IS_ERR(net)) |
| 8018 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8019 | |
| 8020 | err = 0; |
| 8021 | |
| 8022 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8023 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8024 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8025 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8026 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8027 | return err; |
| 8028 | } |
| 8029 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8030 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8031 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8032 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8033 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8034 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8035 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8036 | struct cfg80211_pmksa pmksa; |
| 8037 | |
| 8038 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8039 | |
| 8040 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8041 | return -EINVAL; |
| 8042 | |
| 8043 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8044 | return -EINVAL; |
| 8045 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8046 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8047 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8048 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8049 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8050 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8051 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8052 | |
| 8053 | switch (info->genlhdr->cmd) { |
| 8054 | case NL80211_CMD_SET_PMKSA: |
| 8055 | rdev_ops = rdev->ops->set_pmksa; |
| 8056 | break; |
| 8057 | case NL80211_CMD_DEL_PMKSA: |
| 8058 | rdev_ops = rdev->ops->del_pmksa; |
| 8059 | break; |
| 8060 | default: |
| 8061 | WARN_ON(1); |
| 8062 | break; |
| 8063 | } |
| 8064 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8065 | if (!rdev_ops) |
| 8066 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8068 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8069 | } |
| 8070 | |
| 8071 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8072 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8074 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8075 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8076 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8077 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8078 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8079 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8080 | if (!rdev->ops->flush_pmksa) |
| 8081 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8082 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8083 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8084 | } |
| 8085 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8086 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8087 | { |
| 8088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8089 | struct net_device *dev = info->user_ptr[1]; |
| 8090 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8091 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8092 | u16 status_code; |
| 8093 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8094 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8095 | |
| 8096 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8097 | !rdev->ops->tdls_mgmt) |
| 8098 | return -EOPNOTSUPP; |
| 8099 | |
| 8100 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8101 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8102 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8103 | !info->attrs[NL80211_ATTR_IE] || |
| 8104 | !info->attrs[NL80211_ATTR_MAC]) |
| 8105 | return -EINVAL; |
| 8106 | |
| 8107 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8108 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8109 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8110 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8111 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8112 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8113 | peer_capability = |
| 8114 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8115 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8116 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8117 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8118 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8119 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8120 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8124 | { |
| 8125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8126 | struct net_device *dev = info->user_ptr[1]; |
| 8127 | enum nl80211_tdls_operation operation; |
| 8128 | u8 *peer; |
| 8129 | |
| 8130 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8131 | !rdev->ops->tdls_oper) |
| 8132 | return -EOPNOTSUPP; |
| 8133 | |
| 8134 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8135 | !info->attrs[NL80211_ATTR_MAC]) |
| 8136 | return -EINVAL; |
| 8137 | |
| 8138 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8139 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8140 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8141 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8142 | } |
| 8143 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8144 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8145 | struct genl_info *info) |
| 8146 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8148 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8149 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8150 | struct sk_buff *msg; |
| 8151 | void *hdr; |
| 8152 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8153 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8154 | int err; |
| 8155 | |
| 8156 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8157 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8158 | return -EINVAL; |
| 8159 | |
| 8160 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8161 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8162 | if (!rdev->ops->remain_on_channel || |
| 8163 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8164 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8165 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8166 | /* |
| 8167 | * We should be on that channel for at least a minimum amount of |
| 8168 | * time (10ms) but no longer than the driver supports. |
| 8169 | */ |
| 8170 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8171 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8172 | return -EINVAL; |
| 8173 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8174 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8175 | if (err) |
| 8176 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8177 | |
| 8178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8179 | if (!msg) |
| 8180 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8181 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8182 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8183 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8184 | if (!hdr) { |
| 8185 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8186 | goto free_msg; |
| 8187 | } |
| 8188 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8189 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8190 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8191 | |
| 8192 | if (err) |
| 8193 | goto free_msg; |
| 8194 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8195 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8196 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8197 | |
| 8198 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8199 | |
| 8200 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8201 | |
| 8202 | nla_put_failure: |
| 8203 | err = -ENOBUFS; |
| 8204 | free_msg: |
| 8205 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8206 | return err; |
| 8207 | } |
| 8208 | |
| 8209 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8210 | struct genl_info *info) |
| 8211 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8213 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8214 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8215 | |
| 8216 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8217 | return -EINVAL; |
| 8218 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8219 | if (!rdev->ops->cancel_remain_on_channel) |
| 8220 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8221 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8222 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8223 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8224 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8225 | } |
| 8226 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8227 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8228 | u8 *rates, u8 rates_len) |
| 8229 | { |
| 8230 | u8 i; |
| 8231 | u32 mask = 0; |
| 8232 | |
| 8233 | for (i = 0; i < rates_len; i++) { |
| 8234 | int rate = (rates[i] & 0x7f) * 5; |
| 8235 | int ridx; |
| 8236 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8237 | struct ieee80211_rate *srate = |
| 8238 | &sband->bitrates[ridx]; |
| 8239 | if (rate == srate->bitrate) { |
| 8240 | mask |= 1 << ridx; |
| 8241 | break; |
| 8242 | } |
| 8243 | } |
| 8244 | if (ridx == sband->n_bitrates) |
| 8245 | return 0; /* rate not found */ |
| 8246 | } |
| 8247 | |
| 8248 | return mask; |
| 8249 | } |
| 8250 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8251 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8252 | u8 *rates, u8 rates_len, |
| 8253 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8254 | { |
| 8255 | u8 i; |
| 8256 | |
| 8257 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8258 | |
| 8259 | for (i = 0; i < rates_len; i++) { |
| 8260 | int ridx, rbit; |
| 8261 | |
| 8262 | ridx = rates[i] / 8; |
| 8263 | rbit = BIT(rates[i] % 8); |
| 8264 | |
| 8265 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8266 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8267 | return false; |
| 8268 | |
| 8269 | /* check availability */ |
| 8270 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8271 | mcs[ridx] |= rbit; |
| 8272 | else |
| 8273 | return false; |
| 8274 | } |
| 8275 | |
| 8276 | return true; |
| 8277 | } |
| 8278 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8279 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8280 | { |
| 8281 | u16 mcs_mask = 0; |
| 8282 | |
| 8283 | switch (vht_mcs_map) { |
| 8284 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8285 | break; |
| 8286 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8287 | mcs_mask = 0x00FF; |
| 8288 | break; |
| 8289 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8290 | mcs_mask = 0x01FF; |
| 8291 | break; |
| 8292 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8293 | mcs_mask = 0x03FF; |
| 8294 | break; |
| 8295 | default: |
| 8296 | break; |
| 8297 | } |
| 8298 | |
| 8299 | return mcs_mask; |
| 8300 | } |
| 8301 | |
| 8302 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8303 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8304 | { |
| 8305 | u8 nss; |
| 8306 | |
| 8307 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8308 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8309 | vht_mcs_map >>= 2; |
| 8310 | } |
| 8311 | } |
| 8312 | |
| 8313 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8314 | struct nl80211_txrate_vht *txrate, |
| 8315 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8316 | { |
| 8317 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8318 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8319 | u8 i; |
| 8320 | |
| 8321 | if (!sband->vht_cap.vht_supported) |
| 8322 | return false; |
| 8323 | |
| 8324 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8325 | |
| 8326 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8327 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8328 | |
| 8329 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8330 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8331 | mcs[i] = txrate->mcs[i]; |
| 8332 | else |
| 8333 | return false; |
| 8334 | } |
| 8335 | |
| 8336 | return true; |
| 8337 | } |
| 8338 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8339 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8340 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8341 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8342 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8343 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8344 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8345 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8346 | }; |
| 8347 | |
| 8348 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8349 | struct genl_info *info) |
| 8350 | { |
| 8351 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8353 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8354 | int rem, i; |
| 8355 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8356 | struct nlattr *tx_rates; |
| 8357 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8358 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8360 | if (!rdev->ops->set_bitrate_mask) |
| 8361 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8362 | |
| 8363 | memset(&mask, 0, sizeof(mask)); |
| 8364 | /* Default to all rates enabled */ |
| 8365 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8366 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8367 | |
| 8368 | if (!sband) |
| 8369 | continue; |
| 8370 | |
| 8371 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8372 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8373 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8374 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8375 | |
| 8376 | if (!sband->vht_cap.vht_supported) |
| 8377 | continue; |
| 8378 | |
| 8379 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8380 | 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] | 8381 | } |
| 8382 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8383 | /* if no rates are given set it back to the defaults */ |
| 8384 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8385 | goto out; |
| 8386 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8387 | /* |
| 8388 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8389 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8390 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8391 | 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] | 8392 | 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] | 8393 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8394 | int err; |
| 8395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8396 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8397 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8398 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8399 | if (sband == NULL) |
| 8400 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8401 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8402 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8403 | if (err) |
| 8404 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8405 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8406 | mask.control[band].legacy = rateset_to_mask( |
| 8407 | sband, |
| 8408 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8409 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8410 | if ((mask.control[band].legacy == 0) && |
| 8411 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8412 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8413 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8414 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8415 | if (!ht_rateset_to_mask( |
| 8416 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8417 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8418 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8419 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8420 | return -EINVAL; |
| 8421 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8422 | if (tb[NL80211_TXRATE_VHT]) { |
| 8423 | if (!vht_set_mcs_mask( |
| 8424 | sband, |
| 8425 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8426 | mask.control[band].vht_mcs)) |
| 8427 | return -EINVAL; |
| 8428 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8429 | if (tb[NL80211_TXRATE_GI]) { |
| 8430 | mask.control[band].gi = |
| 8431 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8432 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8433 | return -EINVAL; |
| 8434 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8435 | |
| 8436 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8437 | /* don't allow empty legacy rates if HT or VHT |
| 8438 | * are not even supported. |
| 8439 | */ |
| 8440 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8441 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8442 | return -EINVAL; |
| 8443 | |
| 8444 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8445 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8446 | goto out; |
| 8447 | |
| 8448 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8449 | if (mask.control[band].vht_mcs[i]) |
| 8450 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8451 | |
| 8452 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8453 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8454 | } |
| 8455 | } |
| 8456 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8457 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8458 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8459 | } |
| 8460 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8461 | 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] | 8462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8464 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8465 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8466 | |
| 8467 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8468 | return -EINVAL; |
| 8469 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8470 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8471 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8472 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8473 | switch (wdev->iftype) { |
| 8474 | case NL80211_IFTYPE_STATION: |
| 8475 | case NL80211_IFTYPE_ADHOC: |
| 8476 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8477 | case NL80211_IFTYPE_AP: |
| 8478 | case NL80211_IFTYPE_AP_VLAN: |
| 8479 | case NL80211_IFTYPE_MESH_POINT: |
| 8480 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8481 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8482 | break; |
| 8483 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8484 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8485 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8486 | |
| 8487 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8488 | if (!rdev->ops->mgmt_tx) |
| 8489 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8490 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8491 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8492 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8493 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8494 | } |
| 8495 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8496 | 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] | 8497 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8499 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8500 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8501 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8502 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8503 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8504 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8505 | struct cfg80211_mgmt_tx_params params = { |
| 8506 | .dont_wait_for_ack = |
| 8507 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8508 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8509 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8510 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8511 | return -EINVAL; |
| 8512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8513 | if (!rdev->ops->mgmt_tx) |
| 8514 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8515 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8516 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8517 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8518 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8519 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8520 | case NL80211_IFTYPE_STATION: |
| 8521 | case NL80211_IFTYPE_ADHOC: |
| 8522 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8523 | case NL80211_IFTYPE_AP: |
| 8524 | case NL80211_IFTYPE_AP_VLAN: |
| 8525 | case NL80211_IFTYPE_MESH_POINT: |
| 8526 | case NL80211_IFTYPE_P2P_GO: |
| 8527 | break; |
| 8528 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8529 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8530 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8531 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8532 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8533 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8534 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8535 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8536 | |
| 8537 | /* |
| 8538 | * We should wait on the channel for at least a minimum amount |
| 8539 | * of time (10ms) but no longer than the driver supports. |
| 8540 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8541 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8542 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8543 | return -EINVAL; |
| 8544 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8545 | } |
| 8546 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8547 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8548 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8549 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8550 | return -EINVAL; |
| 8551 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8552 | 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] | 8553 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8554 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8555 | * the driver. The latter will use the current one |
| 8556 | */ |
| 8557 | chandef.chan = NULL; |
| 8558 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8559 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8560 | if (err) |
| 8561 | return err; |
| 8562 | } |
| 8563 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8564 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8565 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8566 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8567 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8568 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8569 | |
| 8570 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8571 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8572 | int i; |
| 8573 | |
| 8574 | if (len % sizeof(u16)) |
| 8575 | return -EINVAL; |
| 8576 | |
| 8577 | params.n_csa_offsets = len / sizeof(u16); |
| 8578 | params.csa_offsets = |
| 8579 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8580 | |
| 8581 | /* check that all the offsets fit the frame */ |
| 8582 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8583 | if (params.csa_offsets[i] >= params.len) |
| 8584 | return -EINVAL; |
| 8585 | } |
| 8586 | } |
| 8587 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8588 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8589 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8590 | if (!msg) |
| 8591 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8592 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8593 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8594 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8595 | if (!hdr) { |
| 8596 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8597 | goto free_msg; |
| 8598 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8599 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8600 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8601 | params.chan = chandef.chan; |
| 8602 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8603 | if (err) |
| 8604 | goto free_msg; |
| 8605 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8606 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8607 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8608 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8609 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8610 | genlmsg_end(msg, hdr); |
| 8611 | return genlmsg_reply(msg, info); |
| 8612 | } |
| 8613 | |
| 8614 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8615 | |
| 8616 | nla_put_failure: |
| 8617 | err = -ENOBUFS; |
| 8618 | free_msg: |
| 8619 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8620 | return err; |
| 8621 | } |
| 8622 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8623 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8624 | { |
| 8625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8626 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8627 | u64 cookie; |
| 8628 | |
| 8629 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8630 | return -EINVAL; |
| 8631 | |
| 8632 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8633 | return -EOPNOTSUPP; |
| 8634 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8635 | switch (wdev->iftype) { |
| 8636 | case NL80211_IFTYPE_STATION: |
| 8637 | case NL80211_IFTYPE_ADHOC: |
| 8638 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8639 | case NL80211_IFTYPE_AP: |
| 8640 | case NL80211_IFTYPE_AP_VLAN: |
| 8641 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8642 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8643 | break; |
| 8644 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8645 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8646 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8647 | |
| 8648 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8649 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8650 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8651 | } |
| 8652 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8653 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8656 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8657 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8658 | u8 ps_state; |
| 8659 | bool state; |
| 8660 | int err; |
| 8661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8662 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8663 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8664 | |
| 8665 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8667 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8668 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8669 | |
| 8670 | wdev = dev->ieee80211_ptr; |
| 8671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8672 | if (!rdev->ops->set_power_mgmt) |
| 8673 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8674 | |
| 8675 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8676 | |
| 8677 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8678 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8679 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8680 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8681 | if (!err) |
| 8682 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8683 | return err; |
| 8684 | } |
| 8685 | |
| 8686 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8687 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8689 | enum nl80211_ps_state ps_state; |
| 8690 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8691 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8692 | struct sk_buff *msg; |
| 8693 | void *hdr; |
| 8694 | int err; |
| 8695 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8696 | wdev = dev->ieee80211_ptr; |
| 8697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8698 | if (!rdev->ops->set_power_mgmt) |
| 8699 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8700 | |
| 8701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8702 | if (!msg) |
| 8703 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8704 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8705 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8706 | NL80211_CMD_GET_POWER_SAVE); |
| 8707 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8708 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8709 | goto free_msg; |
| 8710 | } |
| 8711 | |
| 8712 | if (wdev->ps) |
| 8713 | ps_state = NL80211_PS_ENABLED; |
| 8714 | else |
| 8715 | ps_state = NL80211_PS_DISABLED; |
| 8716 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8717 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8718 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8719 | |
| 8720 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8721 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8722 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8723 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8724 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8725 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8726 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8727 | return err; |
| 8728 | } |
| 8729 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8730 | static const struct nla_policy |
| 8731 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8732 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8733 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8734 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8735 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8736 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8737 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8738 | }; |
| 8739 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8740 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8741 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8742 | { |
| 8743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8744 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8745 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8746 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8747 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8748 | return -EINVAL; |
| 8749 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8750 | if (!rdev->ops->set_cqm_txe_config) |
| 8751 | return -EOPNOTSUPP; |
| 8752 | |
| 8753 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8754 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8755 | return -EOPNOTSUPP; |
| 8756 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8757 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8758 | } |
| 8759 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8760 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8761 | s32 threshold, u32 hysteresis) |
| 8762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8764 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8765 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8766 | |
| 8767 | if (threshold > 0) |
| 8768 | return -EINVAL; |
| 8769 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8770 | /* disabling - hysteresis should also be zero then */ |
| 8771 | if (threshold == 0) |
| 8772 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8774 | if (!rdev->ops->set_cqm_rssi_config) |
| 8775 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8776 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8777 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8778 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8779 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8780 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8781 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8785 | { |
| 8786 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8787 | struct nlattr *cqm; |
| 8788 | int err; |
| 8789 | |
| 8790 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8791 | if (!cqm) |
| 8792 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8793 | |
| 8794 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8795 | nl80211_attr_cqm_policy); |
| 8796 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8797 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8798 | |
| 8799 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8800 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8801 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8802 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8803 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8804 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8805 | } |
| 8806 | |
| 8807 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8808 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8809 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8810 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8811 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8812 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8813 | |
| 8814 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8815 | } |
| 8816 | |
| 8817 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8818 | } |
| 8819 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8820 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8821 | { |
| 8822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8823 | struct net_device *dev = info->user_ptr[1]; |
| 8824 | struct ocb_setup setup = {}; |
| 8825 | int err; |
| 8826 | |
| 8827 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8828 | if (err) |
| 8829 | return err; |
| 8830 | |
| 8831 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8832 | } |
| 8833 | |
| 8834 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8835 | { |
| 8836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8837 | struct net_device *dev = info->user_ptr[1]; |
| 8838 | |
| 8839 | return cfg80211_leave_ocb(rdev, dev); |
| 8840 | } |
| 8841 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8842 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8843 | { |
| 8844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8845 | struct net_device *dev = info->user_ptr[1]; |
| 8846 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8847 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8848 | int err; |
| 8849 | |
| 8850 | /* start with default */ |
| 8851 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8852 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8853 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8854 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8855 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8856 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8857 | if (err) |
| 8858 | return err; |
| 8859 | } |
| 8860 | |
| 8861 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8862 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8863 | return -EINVAL; |
| 8864 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8865 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8866 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8867 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8868 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8869 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8870 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8871 | return -EINVAL; |
| 8872 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8873 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8874 | setup.beacon_interval = |
| 8875 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8876 | if (setup.beacon_interval < 10 || |
| 8877 | setup.beacon_interval > 10000) |
| 8878 | return -EINVAL; |
| 8879 | } |
| 8880 | |
| 8881 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8882 | setup.dtim_period = |
| 8883 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8884 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8885 | return -EINVAL; |
| 8886 | } |
| 8887 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8888 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8889 | /* parse additional setup parameters if given */ |
| 8890 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8891 | if (err) |
| 8892 | return err; |
| 8893 | } |
| 8894 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8895 | if (setup.user_mpm) |
| 8896 | cfg.auto_open_plinks = false; |
| 8897 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8898 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8899 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8900 | if (err) |
| 8901 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8902 | } else { |
| 8903 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8904 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8905 | } |
| 8906 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8907 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8908 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8909 | int n_rates = |
| 8910 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8911 | struct ieee80211_supported_band *sband; |
| 8912 | |
| 8913 | if (!setup.chandef.chan) |
| 8914 | return -EINVAL; |
| 8915 | |
| 8916 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8917 | |
| 8918 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8919 | &setup.basic_rates); |
| 8920 | if (err) |
| 8921 | return err; |
| 8922 | } |
| 8923 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8924 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8925 | } |
| 8926 | |
| 8927 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8928 | { |
| 8929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8930 | struct net_device *dev = info->user_ptr[1]; |
| 8931 | |
| 8932 | return cfg80211_leave_mesh(rdev, dev); |
| 8933 | } |
| 8934 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8935 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8936 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8937 | struct cfg80211_registered_device *rdev) |
| 8938 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8939 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8940 | struct nlattr *nl_pats, *nl_pat; |
| 8941 | int i, pat_len; |
| 8942 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8943 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8944 | return 0; |
| 8945 | |
| 8946 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8947 | if (!nl_pats) |
| 8948 | return -ENOBUFS; |
| 8949 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8950 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8951 | nl_pat = nla_nest_start(msg, i + 1); |
| 8952 | if (!nl_pat) |
| 8953 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8954 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8955 | 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] | 8956 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8957 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8958 | wowlan->patterns[i].pattern) || |
| 8959 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8960 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8961 | return -ENOBUFS; |
| 8962 | nla_nest_end(msg, nl_pat); |
| 8963 | } |
| 8964 | nla_nest_end(msg, nl_pats); |
| 8965 | |
| 8966 | return 0; |
| 8967 | } |
| 8968 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8969 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8970 | struct cfg80211_wowlan_tcp *tcp) |
| 8971 | { |
| 8972 | struct nlattr *nl_tcp; |
| 8973 | |
| 8974 | if (!tcp) |
| 8975 | return 0; |
| 8976 | |
| 8977 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8978 | if (!nl_tcp) |
| 8979 | return -ENOBUFS; |
| 8980 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 8981 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8982 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8983 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8984 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8985 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8986 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8987 | tcp->payload_len, tcp->payload) || |
| 8988 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8989 | tcp->data_interval) || |
| 8990 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8991 | tcp->wake_len, tcp->wake_data) || |
| 8992 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8993 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8994 | return -ENOBUFS; |
| 8995 | |
| 8996 | if (tcp->payload_seq.len && |
| 8997 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8998 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8999 | return -ENOBUFS; |
| 9000 | |
| 9001 | if (tcp->payload_tok.len && |
| 9002 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9003 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9004 | &tcp->payload_tok)) |
| 9005 | return -ENOBUFS; |
| 9006 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9007 | nla_nest_end(msg, nl_tcp); |
| 9008 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9009 | return 0; |
| 9010 | } |
| 9011 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9012 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9013 | struct cfg80211_sched_scan_request *req) |
| 9014 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9015 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9016 | int i; |
| 9017 | |
| 9018 | if (!req) |
| 9019 | return 0; |
| 9020 | |
| 9021 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9022 | if (!nd) |
| 9023 | return -ENOBUFS; |
| 9024 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9025 | if (req->n_scan_plans == 1 && |
| 9026 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9027 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9028 | return -ENOBUFS; |
| 9029 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9030 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9031 | return -ENOBUFS; |
| 9032 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9033 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9034 | if (!freqs) |
| 9035 | return -ENOBUFS; |
| 9036 | |
| 9037 | for (i = 0; i < req->n_channels; i++) |
| 9038 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 9039 | |
| 9040 | nla_nest_end(msg, freqs); |
| 9041 | |
| 9042 | if (req->n_match_sets) { |
| 9043 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 9044 | for (i = 0; i < req->n_match_sets; i++) { |
| 9045 | match = nla_nest_start(msg, i); |
| 9046 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9047 | req->match_sets[i].ssid.ssid_len, |
| 9048 | req->match_sets[i].ssid.ssid); |
| 9049 | nla_nest_end(msg, match); |
| 9050 | } |
| 9051 | nla_nest_end(msg, matches); |
| 9052 | } |
| 9053 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9054 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9055 | if (!scan_plans) |
| 9056 | return -ENOBUFS; |
| 9057 | |
| 9058 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9059 | scan_plan = nla_nest_start(msg, i + 1); |
| 9060 | if (!scan_plan || |
| 9061 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9062 | req->scan_plans[i].interval) || |
| 9063 | (req->scan_plans[i].iterations && |
| 9064 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9065 | req->scan_plans[i].iterations))) |
| 9066 | return -ENOBUFS; |
| 9067 | nla_nest_end(msg, scan_plan); |
| 9068 | } |
| 9069 | nla_nest_end(msg, scan_plans); |
| 9070 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9071 | nla_nest_end(msg, nd); |
| 9072 | |
| 9073 | return 0; |
| 9074 | } |
| 9075 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9076 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9077 | { |
| 9078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9079 | struct sk_buff *msg; |
| 9080 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9081 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9082 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9083 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9084 | return -EOPNOTSUPP; |
| 9085 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9086 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9087 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9088 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9089 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9090 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9091 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9092 | } |
| 9093 | |
| 9094 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9095 | if (!msg) |
| 9096 | return -ENOMEM; |
| 9097 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9098 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9099 | NL80211_CMD_GET_WOWLAN); |
| 9100 | if (!hdr) |
| 9101 | goto nla_put_failure; |
| 9102 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9103 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9104 | struct nlattr *nl_wowlan; |
| 9105 | |
| 9106 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9107 | if (!nl_wowlan) |
| 9108 | goto nla_put_failure; |
| 9109 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9110 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9111 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9112 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9114 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9115 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9116 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9118 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9119 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9120 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9121 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9122 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9124 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9125 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9126 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9127 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9128 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9129 | if (nl80211_send_wowlan_tcp(msg, |
| 9130 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9131 | goto nla_put_failure; |
| 9132 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9133 | if (nl80211_send_wowlan_nd( |
| 9134 | msg, |
| 9135 | rdev->wiphy.wowlan_config->nd_config)) |
| 9136 | goto nla_put_failure; |
| 9137 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9138 | nla_nest_end(msg, nl_wowlan); |
| 9139 | } |
| 9140 | |
| 9141 | genlmsg_end(msg, hdr); |
| 9142 | return genlmsg_reply(msg, info); |
| 9143 | |
| 9144 | nla_put_failure: |
| 9145 | nlmsg_free(msg); |
| 9146 | return -ENOBUFS; |
| 9147 | } |
| 9148 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9149 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9150 | struct nlattr *attr, |
| 9151 | struct cfg80211_wowlan *trig) |
| 9152 | { |
| 9153 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9154 | struct cfg80211_wowlan_tcp *cfg; |
| 9155 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9156 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9157 | u32 size; |
| 9158 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9159 | int err, port; |
| 9160 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9161 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9162 | return -EINVAL; |
| 9163 | |
| 9164 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9165 | nla_data(attr), nla_len(attr), |
| 9166 | nl80211_wowlan_tcp_policy); |
| 9167 | if (err) |
| 9168 | return err; |
| 9169 | |
| 9170 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9171 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9172 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9173 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9174 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9175 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9176 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9177 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9178 | return -EINVAL; |
| 9179 | |
| 9180 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9181 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9182 | return -EINVAL; |
| 9183 | |
| 9184 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9185 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9186 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9187 | return -EINVAL; |
| 9188 | |
| 9189 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9190 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9191 | return -EINVAL; |
| 9192 | |
| 9193 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9194 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9195 | return -EINVAL; |
| 9196 | |
| 9197 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9198 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9199 | |
| 9200 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9201 | tokens_size = tokln - sizeof(*tok); |
| 9202 | |
| 9203 | if (!tok->len || tokens_size % tok->len) |
| 9204 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9205 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9206 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9207 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9208 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9209 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9210 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9211 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9212 | return -EINVAL; |
| 9213 | if (tok->offset + tok->len > data_size) |
| 9214 | return -EINVAL; |
| 9215 | } |
| 9216 | |
| 9217 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9218 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9219 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9220 | return -EINVAL; |
| 9221 | if (seq->len == 0 || seq->len > 4) |
| 9222 | return -EINVAL; |
| 9223 | if (seq->len + seq->offset > data_size) |
| 9224 | return -EINVAL; |
| 9225 | } |
| 9226 | |
| 9227 | size = sizeof(*cfg); |
| 9228 | size += data_size; |
| 9229 | size += wake_size + wake_mask_size; |
| 9230 | size += tokens_size; |
| 9231 | |
| 9232 | cfg = kzalloc(size, GFP_KERNEL); |
| 9233 | if (!cfg) |
| 9234 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9235 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9236 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9237 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9238 | ETH_ALEN); |
| 9239 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9240 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9241 | else |
| 9242 | port = 0; |
| 9243 | #ifdef CONFIG_INET |
| 9244 | /* allocate a socket and port for it and use it */ |
| 9245 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9246 | IPPROTO_TCP, &cfg->sock, 1); |
| 9247 | if (err) { |
| 9248 | kfree(cfg); |
| 9249 | return err; |
| 9250 | } |
| 9251 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9252 | sock_release(cfg->sock); |
| 9253 | kfree(cfg); |
| 9254 | return -EADDRINUSE; |
| 9255 | } |
| 9256 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9257 | #else |
| 9258 | if (!port) { |
| 9259 | kfree(cfg); |
| 9260 | return -EINVAL; |
| 9261 | } |
| 9262 | cfg->src_port = port; |
| 9263 | #endif |
| 9264 | |
| 9265 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9266 | cfg->payload_len = data_size; |
| 9267 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9268 | memcpy((void *)cfg->payload, |
| 9269 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9270 | data_size); |
| 9271 | if (seq) |
| 9272 | cfg->payload_seq = *seq; |
| 9273 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9274 | cfg->wake_len = wake_size; |
| 9275 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9276 | memcpy((void *)cfg->wake_data, |
| 9277 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9278 | wake_size); |
| 9279 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9280 | data_size + wake_size; |
| 9281 | memcpy((void *)cfg->wake_mask, |
| 9282 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9283 | wake_mask_size); |
| 9284 | if (tok) { |
| 9285 | cfg->tokens_size = tokens_size; |
| 9286 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9287 | } |
| 9288 | |
| 9289 | trig->tcp = cfg; |
| 9290 | |
| 9291 | return 0; |
| 9292 | } |
| 9293 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9294 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9295 | const struct wiphy_wowlan_support *wowlan, |
| 9296 | struct nlattr *attr, |
| 9297 | struct cfg80211_wowlan *trig) |
| 9298 | { |
| 9299 | struct nlattr **tb; |
| 9300 | int err; |
| 9301 | |
| 9302 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9303 | if (!tb) |
| 9304 | return -ENOMEM; |
| 9305 | |
| 9306 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9307 | err = -EOPNOTSUPP; |
| 9308 | goto out; |
| 9309 | } |
| 9310 | |
| 9311 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9312 | nla_data(attr), nla_len(attr), |
| 9313 | nl80211_policy); |
| 9314 | if (err) |
| 9315 | goto out; |
| 9316 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9317 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9318 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9319 | if (err) |
| 9320 | trig->nd_config = NULL; |
| 9321 | |
| 9322 | out: |
| 9323 | kfree(tb); |
| 9324 | return err; |
| 9325 | } |
| 9326 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9327 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9328 | { |
| 9329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9330 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9331 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9332 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9333 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9334 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9335 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9336 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9337 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9338 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9339 | return -EOPNOTSUPP; |
| 9340 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9341 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9342 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9343 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9344 | goto set_wakeup; |
| 9345 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9346 | |
| 9347 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9348 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9349 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9350 | nl80211_wowlan_policy); |
| 9351 | if (err) |
| 9352 | return err; |
| 9353 | |
| 9354 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9355 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9356 | return -EINVAL; |
| 9357 | new_triggers.any = true; |
| 9358 | } |
| 9359 | |
| 9360 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9361 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9362 | return -EINVAL; |
| 9363 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9364 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9365 | } |
| 9366 | |
| 9367 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9368 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9369 | return -EINVAL; |
| 9370 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9371 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9372 | } |
| 9373 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9374 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9375 | return -EINVAL; |
| 9376 | |
| 9377 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9378 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9379 | return -EINVAL; |
| 9380 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9381 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9382 | } |
| 9383 | |
| 9384 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9385 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9386 | return -EINVAL; |
| 9387 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9388 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9389 | } |
| 9390 | |
| 9391 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9392 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9393 | return -EINVAL; |
| 9394 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9395 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9396 | } |
| 9397 | |
| 9398 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9399 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9400 | return -EINVAL; |
| 9401 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9402 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9403 | } |
| 9404 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9405 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9406 | struct nlattr *pat; |
| 9407 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9408 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9409 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9410 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9411 | regular = true; |
| 9412 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9413 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9414 | rem) |
| 9415 | n_patterns++; |
| 9416 | if (n_patterns > wowlan->n_patterns) |
| 9417 | return -EINVAL; |
| 9418 | |
| 9419 | new_triggers.patterns = kcalloc(n_patterns, |
| 9420 | sizeof(new_triggers.patterns[0]), |
| 9421 | GFP_KERNEL); |
| 9422 | if (!new_triggers.patterns) |
| 9423 | return -ENOMEM; |
| 9424 | |
| 9425 | new_triggers.n_patterns = n_patterns; |
| 9426 | i = 0; |
| 9427 | |
| 9428 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9429 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9430 | u8 *mask_pat; |
| 9431 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9432 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9433 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9434 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9435 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9436 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9437 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9438 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9439 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9440 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9441 | goto error; |
| 9442 | if (pat_len > wowlan->pattern_max_len || |
| 9443 | pat_len < wowlan->pattern_min_len) |
| 9444 | goto error; |
| 9445 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9446 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9447 | pkt_offset = 0; |
| 9448 | else |
| 9449 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9450 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9451 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9452 | goto error; |
| 9453 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9454 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9455 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9456 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9457 | err = -ENOMEM; |
| 9458 | goto error; |
| 9459 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9460 | new_triggers.patterns[i].mask = mask_pat; |
| 9461 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9462 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9463 | mask_pat += mask_len; |
| 9464 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9465 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9466 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9467 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9468 | pat_len); |
| 9469 | i++; |
| 9470 | } |
| 9471 | } |
| 9472 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9473 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9474 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9475 | err = nl80211_parse_wowlan_tcp( |
| 9476 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9477 | &new_triggers); |
| 9478 | if (err) |
| 9479 | goto error; |
| 9480 | } |
| 9481 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9482 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9483 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9484 | err = nl80211_parse_wowlan_nd( |
| 9485 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9486 | &new_triggers); |
| 9487 | if (err) |
| 9488 | goto error; |
| 9489 | } |
| 9490 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9491 | /* The 'any' trigger means the device continues operating more or less |
| 9492 | * as in its normal operation mode and wakes up the host on most of the |
| 9493 | * normal interrupts (like packet RX, ...) |
| 9494 | * It therefore makes little sense to combine with the more constrained |
| 9495 | * wakeup trigger modes. |
| 9496 | */ |
| 9497 | if (new_triggers.any && regular) { |
| 9498 | err = -EINVAL; |
| 9499 | goto error; |
| 9500 | } |
| 9501 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9502 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9503 | if (!ntrig) { |
| 9504 | err = -ENOMEM; |
| 9505 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9506 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9507 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9508 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9509 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9510 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9511 | if (rdev->ops->set_wakeup && |
| 9512 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9513 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9514 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9515 | return 0; |
| 9516 | error: |
| 9517 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9518 | kfree(new_triggers.patterns[i].mask); |
| 9519 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9520 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9521 | sock_release(new_triggers.tcp->sock); |
| 9522 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9523 | return err; |
| 9524 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9525 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9526 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9527 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9528 | struct cfg80211_registered_device *rdev) |
| 9529 | { |
| 9530 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9531 | int i, j, pat_len; |
| 9532 | struct cfg80211_coalesce_rules *rule; |
| 9533 | |
| 9534 | if (!rdev->coalesce->n_rules) |
| 9535 | return 0; |
| 9536 | |
| 9537 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9538 | if (!nl_rules) |
| 9539 | return -ENOBUFS; |
| 9540 | |
| 9541 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9542 | nl_rule = nla_nest_start(msg, i + 1); |
| 9543 | if (!nl_rule) |
| 9544 | return -ENOBUFS; |
| 9545 | |
| 9546 | rule = &rdev->coalesce->rules[i]; |
| 9547 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9548 | rule->delay)) |
| 9549 | return -ENOBUFS; |
| 9550 | |
| 9551 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9552 | rule->condition)) |
| 9553 | return -ENOBUFS; |
| 9554 | |
| 9555 | nl_pats = nla_nest_start(msg, |
| 9556 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9557 | if (!nl_pats) |
| 9558 | return -ENOBUFS; |
| 9559 | |
| 9560 | for (j = 0; j < rule->n_patterns; j++) { |
| 9561 | nl_pat = nla_nest_start(msg, j + 1); |
| 9562 | if (!nl_pat) |
| 9563 | return -ENOBUFS; |
| 9564 | pat_len = rule->patterns[j].pattern_len; |
| 9565 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9566 | DIV_ROUND_UP(pat_len, 8), |
| 9567 | rule->patterns[j].mask) || |
| 9568 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9569 | rule->patterns[j].pattern) || |
| 9570 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9571 | rule->patterns[j].pkt_offset)) |
| 9572 | return -ENOBUFS; |
| 9573 | nla_nest_end(msg, nl_pat); |
| 9574 | } |
| 9575 | nla_nest_end(msg, nl_pats); |
| 9576 | nla_nest_end(msg, nl_rule); |
| 9577 | } |
| 9578 | nla_nest_end(msg, nl_rules); |
| 9579 | |
| 9580 | return 0; |
| 9581 | } |
| 9582 | |
| 9583 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9584 | { |
| 9585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9586 | struct sk_buff *msg; |
| 9587 | void *hdr; |
| 9588 | |
| 9589 | if (!rdev->wiphy.coalesce) |
| 9590 | return -EOPNOTSUPP; |
| 9591 | |
| 9592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9593 | if (!msg) |
| 9594 | return -ENOMEM; |
| 9595 | |
| 9596 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9597 | NL80211_CMD_GET_COALESCE); |
| 9598 | if (!hdr) |
| 9599 | goto nla_put_failure; |
| 9600 | |
| 9601 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9602 | goto nla_put_failure; |
| 9603 | |
| 9604 | genlmsg_end(msg, hdr); |
| 9605 | return genlmsg_reply(msg, info); |
| 9606 | |
| 9607 | nla_put_failure: |
| 9608 | nlmsg_free(msg); |
| 9609 | return -ENOBUFS; |
| 9610 | } |
| 9611 | |
| 9612 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9613 | { |
| 9614 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9615 | int i, j; |
| 9616 | struct cfg80211_coalesce_rules *rule; |
| 9617 | |
| 9618 | if (!coalesce) |
| 9619 | return; |
| 9620 | |
| 9621 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9622 | rule = &coalesce->rules[i]; |
| 9623 | for (j = 0; j < rule->n_patterns; j++) |
| 9624 | kfree(rule->patterns[j].mask); |
| 9625 | kfree(rule->patterns); |
| 9626 | } |
| 9627 | kfree(coalesce->rules); |
| 9628 | kfree(coalesce); |
| 9629 | rdev->coalesce = NULL; |
| 9630 | } |
| 9631 | |
| 9632 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9633 | struct nlattr *rule, |
| 9634 | struct cfg80211_coalesce_rules *new_rule) |
| 9635 | { |
| 9636 | int err, i; |
| 9637 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9638 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9639 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9640 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9641 | |
| 9642 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9643 | nla_len(rule), nl80211_coalesce_policy); |
| 9644 | if (err) |
| 9645 | return err; |
| 9646 | |
| 9647 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9648 | new_rule->delay = |
| 9649 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9650 | if (new_rule->delay > coalesce->max_delay) |
| 9651 | return -EINVAL; |
| 9652 | |
| 9653 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9654 | new_rule->condition = |
| 9655 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9656 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9657 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9658 | return -EINVAL; |
| 9659 | |
| 9660 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9661 | return -EINVAL; |
| 9662 | |
| 9663 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9664 | rem) |
| 9665 | n_patterns++; |
| 9666 | if (n_patterns > coalesce->n_patterns) |
| 9667 | return -EINVAL; |
| 9668 | |
| 9669 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9670 | GFP_KERNEL); |
| 9671 | if (!new_rule->patterns) |
| 9672 | return -ENOMEM; |
| 9673 | |
| 9674 | new_rule->n_patterns = n_patterns; |
| 9675 | i = 0; |
| 9676 | |
| 9677 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9678 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9679 | u8 *mask_pat; |
| 9680 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9681 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9682 | nla_len(pat), NULL); |
| 9683 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9684 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9685 | return -EINVAL; |
| 9686 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9687 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9688 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9689 | return -EINVAL; |
| 9690 | if (pat_len > coalesce->pattern_max_len || |
| 9691 | pat_len < coalesce->pattern_min_len) |
| 9692 | return -EINVAL; |
| 9693 | |
| 9694 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9695 | pkt_offset = 0; |
| 9696 | else |
| 9697 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9698 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9699 | return -EINVAL; |
| 9700 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9701 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9702 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9703 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9704 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9705 | |
| 9706 | new_rule->patterns[i].mask = mask_pat; |
| 9707 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9708 | mask_len); |
| 9709 | |
| 9710 | mask_pat += mask_len; |
| 9711 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9712 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9713 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9714 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9715 | i++; |
| 9716 | } |
| 9717 | |
| 9718 | return 0; |
| 9719 | } |
| 9720 | |
| 9721 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9722 | { |
| 9723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9724 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9725 | struct cfg80211_coalesce new_coalesce = {}; |
| 9726 | struct cfg80211_coalesce *n_coalesce; |
| 9727 | int err, rem_rule, n_rules = 0, i, j; |
| 9728 | struct nlattr *rule; |
| 9729 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9730 | |
| 9731 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9732 | return -EOPNOTSUPP; |
| 9733 | |
| 9734 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9735 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9736 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9737 | return 0; |
| 9738 | } |
| 9739 | |
| 9740 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9741 | rem_rule) |
| 9742 | n_rules++; |
| 9743 | if (n_rules > coalesce->n_rules) |
| 9744 | return -EINVAL; |
| 9745 | |
| 9746 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9747 | GFP_KERNEL); |
| 9748 | if (!new_coalesce.rules) |
| 9749 | return -ENOMEM; |
| 9750 | |
| 9751 | new_coalesce.n_rules = n_rules; |
| 9752 | i = 0; |
| 9753 | |
| 9754 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9755 | rem_rule) { |
| 9756 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9757 | &new_coalesce.rules[i]); |
| 9758 | if (err) |
| 9759 | goto error; |
| 9760 | |
| 9761 | i++; |
| 9762 | } |
| 9763 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9764 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9765 | if (err) |
| 9766 | goto error; |
| 9767 | |
| 9768 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9769 | if (!n_coalesce) { |
| 9770 | err = -ENOMEM; |
| 9771 | goto error; |
| 9772 | } |
| 9773 | cfg80211_rdev_free_coalesce(rdev); |
| 9774 | rdev->coalesce = n_coalesce; |
| 9775 | |
| 9776 | return 0; |
| 9777 | error: |
| 9778 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9779 | tmp_rule = &new_coalesce.rules[i]; |
| 9780 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9781 | kfree(tmp_rule->patterns[j].mask); |
| 9782 | kfree(tmp_rule->patterns); |
| 9783 | } |
| 9784 | kfree(new_coalesce.rules); |
| 9785 | |
| 9786 | return err; |
| 9787 | } |
| 9788 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9789 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9790 | { |
| 9791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9792 | struct net_device *dev = info->user_ptr[1]; |
| 9793 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9794 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9795 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9796 | int err; |
| 9797 | |
| 9798 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9799 | return -EINVAL; |
| 9800 | |
| 9801 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9802 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9803 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9804 | nl80211_rekey_policy); |
| 9805 | if (err) |
| 9806 | return err; |
| 9807 | |
| 9808 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9809 | return -ERANGE; |
| 9810 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9811 | return -ERANGE; |
| 9812 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9813 | return -ERANGE; |
| 9814 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9815 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9816 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9817 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9818 | |
| 9819 | wdev_lock(wdev); |
| 9820 | if (!wdev->current_bss) { |
| 9821 | err = -ENOTCONN; |
| 9822 | goto out; |
| 9823 | } |
| 9824 | |
| 9825 | if (!rdev->ops->set_rekey_data) { |
| 9826 | err = -EOPNOTSUPP; |
| 9827 | goto out; |
| 9828 | } |
| 9829 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9830 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9831 | out: |
| 9832 | wdev_unlock(wdev); |
| 9833 | return err; |
| 9834 | } |
| 9835 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9836 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9837 | struct genl_info *info) |
| 9838 | { |
| 9839 | struct net_device *dev = info->user_ptr[1]; |
| 9840 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9841 | |
| 9842 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9843 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9844 | return -EINVAL; |
| 9845 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9846 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9847 | return -EBUSY; |
| 9848 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9849 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9850 | return 0; |
| 9851 | } |
| 9852 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9853 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9854 | struct genl_info *info) |
| 9855 | { |
| 9856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9857 | struct net_device *dev = info->user_ptr[1]; |
| 9858 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9859 | struct sk_buff *msg; |
| 9860 | void *hdr; |
| 9861 | const u8 *addr; |
| 9862 | u64 cookie; |
| 9863 | int err; |
| 9864 | |
| 9865 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9866 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9867 | return -EOPNOTSUPP; |
| 9868 | |
| 9869 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9870 | return -EINVAL; |
| 9871 | |
| 9872 | if (!rdev->ops->probe_client) |
| 9873 | return -EOPNOTSUPP; |
| 9874 | |
| 9875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9876 | if (!msg) |
| 9877 | return -ENOMEM; |
| 9878 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9879 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9880 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9881 | if (!hdr) { |
| 9882 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9883 | goto free_msg; |
| 9884 | } |
| 9885 | |
| 9886 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9887 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9888 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9889 | if (err) |
| 9890 | goto free_msg; |
| 9891 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9892 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9893 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9894 | |
| 9895 | genlmsg_end(msg, hdr); |
| 9896 | |
| 9897 | return genlmsg_reply(msg, info); |
| 9898 | |
| 9899 | nla_put_failure: |
| 9900 | err = -ENOBUFS; |
| 9901 | free_msg: |
| 9902 | nlmsg_free(msg); |
| 9903 | return err; |
| 9904 | } |
| 9905 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9906 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9907 | { |
| 9908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9909 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9910 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9911 | |
| 9912 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9913 | return -EOPNOTSUPP; |
| 9914 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9915 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9916 | if (!nreg) |
| 9917 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9918 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9919 | /* First, check if already registered. */ |
| 9920 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9921 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9922 | if (reg->nlportid == info->snd_portid) { |
| 9923 | rv = -EALREADY; |
| 9924 | goto out_err; |
| 9925 | } |
| 9926 | } |
| 9927 | /* Add it to the list */ |
| 9928 | nreg->nlportid = info->snd_portid; |
| 9929 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9930 | |
| 9931 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9932 | |
| 9933 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9934 | out_err: |
| 9935 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9936 | kfree(nreg); |
| 9937 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9938 | } |
| 9939 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9940 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9941 | { |
| 9942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9943 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9944 | int err; |
| 9945 | |
| 9946 | if (!rdev->ops->start_p2p_device) |
| 9947 | return -EOPNOTSUPP; |
| 9948 | |
| 9949 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9950 | return -EOPNOTSUPP; |
| 9951 | |
| 9952 | if (wdev->p2p_started) |
| 9953 | return 0; |
| 9954 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9955 | if (rfkill_blocked(rdev->rfkill)) |
| 9956 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9957 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9958 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9959 | if (err) |
| 9960 | return err; |
| 9961 | |
| 9962 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9963 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9964 | |
| 9965 | return 0; |
| 9966 | } |
| 9967 | |
| 9968 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9969 | { |
| 9970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9971 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9972 | |
| 9973 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9974 | return -EOPNOTSUPP; |
| 9975 | |
| 9976 | if (!rdev->ops->stop_p2p_device) |
| 9977 | return -EOPNOTSUPP; |
| 9978 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9979 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9980 | |
| 9981 | return 0; |
| 9982 | } |
| 9983 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9984 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9985 | struct genl_info *info) |
| 9986 | { |
| 9987 | void *hdr; |
| 9988 | struct sk_buff *msg; |
| 9989 | |
| 9990 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9991 | if (!msg) |
| 9992 | return -ENOMEM; |
| 9993 | |
| 9994 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9995 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9996 | if (!hdr) |
| 9997 | goto nla_put_failure; |
| 9998 | |
| 9999 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 10000 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 10001 | goto nla_put_failure; |
| 10002 | |
| 10003 | genlmsg_end(msg, hdr); |
| 10004 | return genlmsg_reply(msg, info); |
| 10005 | |
| 10006 | nla_put_failure: |
| 10007 | kfree_skb(msg); |
| 10008 | return -ENOBUFS; |
| 10009 | } |
| 10010 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10011 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 10012 | { |
| 10013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10014 | struct cfg80211_update_ft_ies_params ft_params; |
| 10015 | struct net_device *dev = info->user_ptr[1]; |
| 10016 | |
| 10017 | if (!rdev->ops->update_ft_ies) |
| 10018 | return -EOPNOTSUPP; |
| 10019 | |
| 10020 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 10021 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 10022 | return -EINVAL; |
| 10023 | |
| 10024 | memset(&ft_params, 0, sizeof(ft_params)); |
| 10025 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 10026 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10027 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10028 | |
| 10029 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 10030 | } |
| 10031 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10032 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 10033 | struct genl_info *info) |
| 10034 | { |
| 10035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10036 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10037 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 10038 | u16 duration; |
| 10039 | int ret; |
| 10040 | |
| 10041 | if (!rdev->ops->crit_proto_start) |
| 10042 | return -EOPNOTSUPP; |
| 10043 | |
| 10044 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 10045 | return -EINVAL; |
| 10046 | |
| 10047 | if (rdev->crit_proto_nlportid) |
| 10048 | return -EBUSY; |
| 10049 | |
| 10050 | /* determine protocol if provided */ |
| 10051 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 10052 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 10053 | |
| 10054 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 10055 | return -EINVAL; |
| 10056 | |
| 10057 | /* timeout must be provided */ |
| 10058 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 10059 | return -EINVAL; |
| 10060 | |
| 10061 | duration = |
| 10062 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 10063 | |
| 10064 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 10065 | return -ERANGE; |
| 10066 | |
| 10067 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 10068 | if (!ret) |
| 10069 | rdev->crit_proto_nlportid = info->snd_portid; |
| 10070 | |
| 10071 | return ret; |
| 10072 | } |
| 10073 | |
| 10074 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 10075 | struct genl_info *info) |
| 10076 | { |
| 10077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10078 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10079 | |
| 10080 | if (!rdev->ops->crit_proto_stop) |
| 10081 | return -EOPNOTSUPP; |
| 10082 | |
| 10083 | if (rdev->crit_proto_nlportid) { |
| 10084 | rdev->crit_proto_nlportid = 0; |
| 10085 | rdev_crit_proto_stop(rdev, wdev); |
| 10086 | } |
| 10087 | return 0; |
| 10088 | } |
| 10089 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10090 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 10091 | { |
| 10092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10093 | struct wireless_dev *wdev = |
| 10094 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10095 | int i, err; |
| 10096 | u32 vid, subcmd; |
| 10097 | |
| 10098 | if (!rdev->wiphy.vendor_commands) |
| 10099 | return -EOPNOTSUPP; |
| 10100 | |
| 10101 | if (IS_ERR(wdev)) { |
| 10102 | err = PTR_ERR(wdev); |
| 10103 | if (err != -EINVAL) |
| 10104 | return err; |
| 10105 | wdev = NULL; |
| 10106 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10107 | return -EINVAL; |
| 10108 | } |
| 10109 | |
| 10110 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 10111 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 10112 | return -EINVAL; |
| 10113 | |
| 10114 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 10115 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10116 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 10117 | const struct wiphy_vendor_command *vcmd; |
| 10118 | void *data = NULL; |
| 10119 | int len = 0; |
| 10120 | |
| 10121 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 10122 | |
| 10123 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10124 | continue; |
| 10125 | |
| 10126 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10127 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10128 | if (!wdev) |
| 10129 | return -EINVAL; |
| 10130 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10131 | !wdev->netdev) |
| 10132 | return -EINVAL; |
| 10133 | |
| 10134 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10135 | if (wdev->netdev && |
| 10136 | !netif_running(wdev->netdev)) |
| 10137 | return -ENETDOWN; |
| 10138 | if (!wdev->netdev && !wdev->p2p_started) |
| 10139 | return -ENETDOWN; |
| 10140 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10141 | |
| 10142 | if (!vcmd->doit) |
| 10143 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10144 | } else { |
| 10145 | wdev = NULL; |
| 10146 | } |
| 10147 | |
| 10148 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 10149 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10150 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10151 | } |
| 10152 | |
| 10153 | rdev->cur_cmd_info = info; |
| 10154 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 10155 | data, len); |
| 10156 | rdev->cur_cmd_info = NULL; |
| 10157 | return err; |
| 10158 | } |
| 10159 | |
| 10160 | return -EOPNOTSUPP; |
| 10161 | } |
| 10162 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10163 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 10164 | struct netlink_callback *cb, |
| 10165 | struct cfg80211_registered_device **rdev, |
| 10166 | struct wireless_dev **wdev) |
| 10167 | { |
| 10168 | u32 vid, subcmd; |
| 10169 | unsigned int i; |
| 10170 | int vcmd_idx = -1; |
| 10171 | int err; |
| 10172 | void *data = NULL; |
| 10173 | unsigned int data_len = 0; |
| 10174 | |
| 10175 | rtnl_lock(); |
| 10176 | |
| 10177 | if (cb->args[0]) { |
| 10178 | /* subtract the 1 again here */ |
| 10179 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 10180 | struct wireless_dev *tmp; |
| 10181 | |
| 10182 | if (!wiphy) { |
| 10183 | err = -ENODEV; |
| 10184 | goto out_unlock; |
| 10185 | } |
| 10186 | *rdev = wiphy_to_rdev(wiphy); |
| 10187 | *wdev = NULL; |
| 10188 | |
| 10189 | if (cb->args[1]) { |
| 10190 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 10191 | if (tmp->identifier == cb->args[1] - 1) { |
| 10192 | *wdev = tmp; |
| 10193 | break; |
| 10194 | } |
| 10195 | } |
| 10196 | } |
| 10197 | |
| 10198 | /* keep rtnl locked in successful case */ |
| 10199 | return 0; |
| 10200 | } |
| 10201 | |
| 10202 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10203 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 10204 | nl80211_policy); |
| 10205 | if (err) |
| 10206 | goto out_unlock; |
| 10207 | |
| 10208 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 10209 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 10210 | err = -EINVAL; |
| 10211 | goto out_unlock; |
| 10212 | } |
| 10213 | |
| 10214 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 10215 | nl80211_fam.attrbuf); |
| 10216 | if (IS_ERR(*wdev)) |
| 10217 | *wdev = NULL; |
| 10218 | |
| 10219 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 10220 | nl80211_fam.attrbuf); |
| 10221 | if (IS_ERR(*rdev)) { |
| 10222 | err = PTR_ERR(*rdev); |
| 10223 | goto out_unlock; |
| 10224 | } |
| 10225 | |
| 10226 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 10227 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10228 | |
| 10229 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 10230 | const struct wiphy_vendor_command *vcmd; |
| 10231 | |
| 10232 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 10233 | |
| 10234 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10235 | continue; |
| 10236 | |
| 10237 | if (!vcmd->dumpit) { |
| 10238 | err = -EOPNOTSUPP; |
| 10239 | goto out_unlock; |
| 10240 | } |
| 10241 | |
| 10242 | vcmd_idx = i; |
| 10243 | break; |
| 10244 | } |
| 10245 | |
| 10246 | if (vcmd_idx < 0) { |
| 10247 | err = -EOPNOTSUPP; |
| 10248 | goto out_unlock; |
| 10249 | } |
| 10250 | |
| 10251 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 10252 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10253 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10254 | } |
| 10255 | |
| 10256 | /* 0 is the first index - add 1 to parse only once */ |
| 10257 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 10258 | /* add 1 to know if it was NULL */ |
| 10259 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 10260 | cb->args[2] = vcmd_idx; |
| 10261 | cb->args[3] = (unsigned long)data; |
| 10262 | cb->args[4] = data_len; |
| 10263 | |
| 10264 | /* keep rtnl locked in successful case */ |
| 10265 | return 0; |
| 10266 | out_unlock: |
| 10267 | rtnl_unlock(); |
| 10268 | return err; |
| 10269 | } |
| 10270 | |
| 10271 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 10272 | struct netlink_callback *cb) |
| 10273 | { |
| 10274 | struct cfg80211_registered_device *rdev; |
| 10275 | struct wireless_dev *wdev; |
| 10276 | unsigned int vcmd_idx; |
| 10277 | const struct wiphy_vendor_command *vcmd; |
| 10278 | void *data; |
| 10279 | int data_len; |
| 10280 | int err; |
| 10281 | struct nlattr *vendor_data; |
| 10282 | |
| 10283 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 10284 | if (err) |
| 10285 | return err; |
| 10286 | |
| 10287 | vcmd_idx = cb->args[2]; |
| 10288 | data = (void *)cb->args[3]; |
| 10289 | data_len = cb->args[4]; |
| 10290 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 10291 | |
| 10292 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10293 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10294 | if (!wdev) |
| 10295 | return -EINVAL; |
| 10296 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10297 | !wdev->netdev) |
| 10298 | return -EINVAL; |
| 10299 | |
| 10300 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10301 | if (wdev->netdev && |
| 10302 | !netif_running(wdev->netdev)) |
| 10303 | return -ENETDOWN; |
| 10304 | if (!wdev->netdev && !wdev->p2p_started) |
| 10305 | return -ENETDOWN; |
| 10306 | } |
| 10307 | } |
| 10308 | |
| 10309 | while (1) { |
| 10310 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10311 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10312 | NL80211_CMD_VENDOR); |
| 10313 | if (!hdr) |
| 10314 | break; |
| 10315 | |
| 10316 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10317 | (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 10318 | wdev_id(wdev)))) { |
| 10319 | genlmsg_cancel(skb, hdr); |
| 10320 | break; |
| 10321 | } |
| 10322 | |
| 10323 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 10324 | if (!vendor_data) { |
| 10325 | genlmsg_cancel(skb, hdr); |
| 10326 | break; |
| 10327 | } |
| 10328 | |
| 10329 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 10330 | (unsigned long *)&cb->args[5]); |
| 10331 | nla_nest_end(skb, vendor_data); |
| 10332 | |
| 10333 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10334 | genlmsg_cancel(skb, hdr); |
| 10335 | break; |
| 10336 | } else if (err) { |
| 10337 | genlmsg_cancel(skb, hdr); |
| 10338 | goto out; |
| 10339 | } |
| 10340 | |
| 10341 | genlmsg_end(skb, hdr); |
| 10342 | } |
| 10343 | |
| 10344 | err = skb->len; |
| 10345 | out: |
| 10346 | rtnl_unlock(); |
| 10347 | return err; |
| 10348 | } |
| 10349 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10350 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 10351 | enum nl80211_commands cmd, |
| 10352 | enum nl80211_attrs attr, |
| 10353 | int approxlen) |
| 10354 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10355 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10356 | |
| 10357 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 10358 | return NULL; |
| 10359 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10360 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10361 | rdev->cur_cmd_info->snd_portid, |
| 10362 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10363 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10364 | } |
| 10365 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 10366 | |
| 10367 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 10368 | { |
| 10369 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10370 | void *hdr = ((void **)skb->cb)[1]; |
| 10371 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10372 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10373 | /* clear CB data for netlink core to own from now on */ |
| 10374 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10375 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10376 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 10377 | kfree_skb(skb); |
| 10378 | return -EINVAL; |
| 10379 | } |
| 10380 | |
| 10381 | nla_nest_end(skb, data); |
| 10382 | genlmsg_end(skb, hdr); |
| 10383 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 10384 | } |
| 10385 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 10386 | |
| 10387 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10388 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 10389 | struct genl_info *info) |
| 10390 | { |
| 10391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10392 | struct cfg80211_qos_map *qos_map = NULL; |
| 10393 | struct net_device *dev = info->user_ptr[1]; |
| 10394 | u8 *pos, len, num_des, des_len, des; |
| 10395 | int ret; |
| 10396 | |
| 10397 | if (!rdev->ops->set_qos_map) |
| 10398 | return -EOPNOTSUPP; |
| 10399 | |
| 10400 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10401 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10402 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10403 | |
| 10404 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10405 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10406 | return -EINVAL; |
| 10407 | |
| 10408 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10409 | if (!qos_map) |
| 10410 | return -ENOMEM; |
| 10411 | |
| 10412 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10413 | if (num_des) { |
| 10414 | des_len = num_des * |
| 10415 | sizeof(struct cfg80211_dscp_exception); |
| 10416 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10417 | qos_map->num_des = num_des; |
| 10418 | for (des = 0; des < num_des; des++) { |
| 10419 | if (qos_map->dscp_exception[des].up > 7) { |
| 10420 | kfree(qos_map); |
| 10421 | return -EINVAL; |
| 10422 | } |
| 10423 | } |
| 10424 | pos += des_len; |
| 10425 | } |
| 10426 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10427 | } |
| 10428 | |
| 10429 | wdev_lock(dev->ieee80211_ptr); |
| 10430 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10431 | if (!ret) |
| 10432 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10433 | wdev_unlock(dev->ieee80211_ptr); |
| 10434 | |
| 10435 | kfree(qos_map); |
| 10436 | return ret; |
| 10437 | } |
| 10438 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10439 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10440 | { |
| 10441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10442 | struct net_device *dev = info->user_ptr[1]; |
| 10443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10444 | const u8 *peer; |
| 10445 | u8 tsid, up; |
| 10446 | u16 admitted_time = 0; |
| 10447 | int err; |
| 10448 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10449 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10450 | return -EOPNOTSUPP; |
| 10451 | |
| 10452 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10453 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10454 | return -EINVAL; |
| 10455 | |
| 10456 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10457 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10458 | return -EINVAL; |
| 10459 | |
| 10460 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10461 | if (up >= IEEE80211_NUM_UPS) |
| 10462 | return -EINVAL; |
| 10463 | |
| 10464 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10465 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10466 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10467 | * need more attributes for that (e.g. BA session requirement); |
| 10468 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10469 | */ |
| 10470 | return -EINVAL; |
| 10471 | } |
| 10472 | |
| 10473 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10474 | |
| 10475 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10476 | admitted_time = |
| 10477 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10478 | if (!admitted_time) |
| 10479 | return -EINVAL; |
| 10480 | } |
| 10481 | |
| 10482 | wdev_lock(wdev); |
| 10483 | switch (wdev->iftype) { |
| 10484 | case NL80211_IFTYPE_STATION: |
| 10485 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10486 | if (wdev->current_bss) |
| 10487 | break; |
| 10488 | err = -ENOTCONN; |
| 10489 | goto out; |
| 10490 | default: |
| 10491 | err = -EOPNOTSUPP; |
| 10492 | goto out; |
| 10493 | } |
| 10494 | |
| 10495 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10496 | |
| 10497 | out: |
| 10498 | wdev_unlock(wdev); |
| 10499 | return err; |
| 10500 | } |
| 10501 | |
| 10502 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10503 | { |
| 10504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10505 | struct net_device *dev = info->user_ptr[1]; |
| 10506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10507 | const u8 *peer; |
| 10508 | u8 tsid; |
| 10509 | int err; |
| 10510 | |
| 10511 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10512 | return -EINVAL; |
| 10513 | |
| 10514 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10515 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10516 | |
| 10517 | wdev_lock(wdev); |
| 10518 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10519 | wdev_unlock(wdev); |
| 10520 | |
| 10521 | return err; |
| 10522 | } |
| 10523 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10524 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10525 | struct genl_info *info) |
| 10526 | { |
| 10527 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10528 | struct net_device *dev = info->user_ptr[1]; |
| 10529 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10530 | struct cfg80211_chan_def chandef = {}; |
| 10531 | const u8 *addr; |
| 10532 | u8 oper_class; |
| 10533 | int err; |
| 10534 | |
| 10535 | if (!rdev->ops->tdls_channel_switch || |
| 10536 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10537 | return -EOPNOTSUPP; |
| 10538 | |
| 10539 | switch (dev->ieee80211_ptr->iftype) { |
| 10540 | case NL80211_IFTYPE_STATION: |
| 10541 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10542 | break; |
| 10543 | default: |
| 10544 | return -EOPNOTSUPP; |
| 10545 | } |
| 10546 | |
| 10547 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10548 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10549 | return -EINVAL; |
| 10550 | |
| 10551 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10552 | if (err) |
| 10553 | return err; |
| 10554 | |
| 10555 | /* |
| 10556 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10557 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10558 | * specification is not defined for them. |
| 10559 | */ |
| 10560 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 10561 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10562 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10563 | return -EINVAL; |
| 10564 | |
| 10565 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10566 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10567 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10568 | return -EINVAL; |
| 10569 | |
| 10570 | /* don't allow switching to DFS channels */ |
| 10571 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10572 | return -EINVAL; |
| 10573 | |
| 10574 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10575 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10576 | |
| 10577 | wdev_lock(wdev); |
| 10578 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10579 | wdev_unlock(wdev); |
| 10580 | |
| 10581 | return err; |
| 10582 | } |
| 10583 | |
| 10584 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10585 | struct genl_info *info) |
| 10586 | { |
| 10587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10588 | struct net_device *dev = info->user_ptr[1]; |
| 10589 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10590 | const u8 *addr; |
| 10591 | |
| 10592 | if (!rdev->ops->tdls_channel_switch || |
| 10593 | !rdev->ops->tdls_cancel_channel_switch || |
| 10594 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10595 | return -EOPNOTSUPP; |
| 10596 | |
| 10597 | switch (dev->ieee80211_ptr->iftype) { |
| 10598 | case NL80211_IFTYPE_STATION: |
| 10599 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10600 | break; |
| 10601 | default: |
| 10602 | return -EOPNOTSUPP; |
| 10603 | } |
| 10604 | |
| 10605 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10606 | return -EINVAL; |
| 10607 | |
| 10608 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10609 | |
| 10610 | wdev_lock(wdev); |
| 10611 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10612 | wdev_unlock(wdev); |
| 10613 | |
| 10614 | return 0; |
| 10615 | } |
| 10616 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10617 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10618 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10619 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10620 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10621 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10622 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10623 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10624 | /* 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] | 10625 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10626 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10627 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10628 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10629 | 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] | 10630 | struct genl_info *info) |
| 10631 | { |
| 10632 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10633 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10634 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10635 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10636 | |
| 10637 | if (rtnl) |
| 10638 | rtnl_lock(); |
| 10639 | |
| 10640 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10641 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10642 | if (IS_ERR(rdev)) { |
| 10643 | if (rtnl) |
| 10644 | rtnl_unlock(); |
| 10645 | return PTR_ERR(rdev); |
| 10646 | } |
| 10647 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10648 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10649 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10650 | ASSERT_RTNL(); |
| 10651 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10652 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10653 | info->attrs); |
| 10654 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10655 | if (rtnl) |
| 10656 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10657 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10658 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10659 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10660 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10661 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10662 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10663 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10664 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10665 | if (rtnl) |
| 10666 | rtnl_unlock(); |
| 10667 | return -EINVAL; |
| 10668 | } |
| 10669 | |
| 10670 | info->user_ptr[1] = dev; |
| 10671 | } else { |
| 10672 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10673 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10674 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10675 | if (dev) { |
| 10676 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10677 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10678 | if (rtnl) |
| 10679 | rtnl_unlock(); |
| 10680 | return -ENETDOWN; |
| 10681 | } |
| 10682 | |
| 10683 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10684 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10685 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10686 | if (rtnl) |
| 10687 | rtnl_unlock(); |
| 10688 | return -ENETDOWN; |
| 10689 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10690 | } |
| 10691 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10692 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10693 | } |
| 10694 | |
| 10695 | return 0; |
| 10696 | } |
| 10697 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10698 | 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] | 10699 | struct genl_info *info) |
| 10700 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10701 | if (info->user_ptr[1]) { |
| 10702 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10703 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10704 | |
| 10705 | if (wdev->netdev) |
| 10706 | dev_put(wdev->netdev); |
| 10707 | } else { |
| 10708 | dev_put(info->user_ptr[1]); |
| 10709 | } |
| 10710 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10711 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10712 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10713 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10714 | |
| 10715 | /* If needed, clear the netlink message payload from the SKB |
| 10716 | * as it might contain key data that shouldn't stick around on |
| 10717 | * the heap after the SKB is freed. The netlink message header |
| 10718 | * is still needed for further processing, so leave it intact. |
| 10719 | */ |
| 10720 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10721 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10722 | |
| 10723 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10724 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10725 | } |
| 10726 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10727 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10728 | { |
| 10729 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10730 | .doit = nl80211_get_wiphy, |
| 10731 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10732 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10733 | .policy = nl80211_policy, |
| 10734 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10735 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10736 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10737 | }, |
| 10738 | { |
| 10739 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10740 | .doit = nl80211_set_wiphy, |
| 10741 | .policy = nl80211_policy, |
| 10742 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10743 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10744 | }, |
| 10745 | { |
| 10746 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10747 | .doit = nl80211_get_interface, |
| 10748 | .dumpit = nl80211_dump_interface, |
| 10749 | .policy = nl80211_policy, |
| 10750 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10751 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10752 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10753 | }, |
| 10754 | { |
| 10755 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10756 | .doit = nl80211_set_interface, |
| 10757 | .policy = nl80211_policy, |
| 10758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10759 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10760 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10761 | }, |
| 10762 | { |
| 10763 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10764 | .doit = nl80211_new_interface, |
| 10765 | .policy = nl80211_policy, |
| 10766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10767 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10768 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10769 | }, |
| 10770 | { |
| 10771 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10772 | .doit = nl80211_del_interface, |
| 10773 | .policy = nl80211_policy, |
| 10774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10775 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10776 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10777 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10778 | { |
| 10779 | .cmd = NL80211_CMD_GET_KEY, |
| 10780 | .doit = nl80211_get_key, |
| 10781 | .policy = nl80211_policy, |
| 10782 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10784 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10785 | }, |
| 10786 | { |
| 10787 | .cmd = NL80211_CMD_SET_KEY, |
| 10788 | .doit = nl80211_set_key, |
| 10789 | .policy = nl80211_policy, |
| 10790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10792 | NL80211_FLAG_NEED_RTNL | |
| 10793 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10794 | }, |
| 10795 | { |
| 10796 | .cmd = NL80211_CMD_NEW_KEY, |
| 10797 | .doit = nl80211_new_key, |
| 10798 | .policy = nl80211_policy, |
| 10799 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10801 | NL80211_FLAG_NEED_RTNL | |
| 10802 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10803 | }, |
| 10804 | { |
| 10805 | .cmd = NL80211_CMD_DEL_KEY, |
| 10806 | .doit = nl80211_del_key, |
| 10807 | .policy = nl80211_policy, |
| 10808 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10809 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10810 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10811 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10812 | { |
| 10813 | .cmd = NL80211_CMD_SET_BEACON, |
| 10814 | .policy = nl80211_policy, |
| 10815 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10816 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10817 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10818 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10819 | }, |
| 10820 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10821 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10822 | .policy = nl80211_policy, |
| 10823 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10824 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10825 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10826 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10827 | }, |
| 10828 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10829 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10830 | .policy = nl80211_policy, |
| 10831 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10832 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10833 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10834 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10835 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10836 | { |
| 10837 | .cmd = NL80211_CMD_GET_STATION, |
| 10838 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10839 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10840 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10841 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10842 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10843 | }, |
| 10844 | { |
| 10845 | .cmd = NL80211_CMD_SET_STATION, |
| 10846 | .doit = nl80211_set_station, |
| 10847 | .policy = nl80211_policy, |
| 10848 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10849 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10850 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10851 | }, |
| 10852 | { |
| 10853 | .cmd = NL80211_CMD_NEW_STATION, |
| 10854 | .doit = nl80211_new_station, |
| 10855 | .policy = nl80211_policy, |
| 10856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10858 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10859 | }, |
| 10860 | { |
| 10861 | .cmd = NL80211_CMD_DEL_STATION, |
| 10862 | .doit = nl80211_del_station, |
| 10863 | .policy = nl80211_policy, |
| 10864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10866 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10867 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10868 | { |
| 10869 | .cmd = NL80211_CMD_GET_MPATH, |
| 10870 | .doit = nl80211_get_mpath, |
| 10871 | .dumpit = nl80211_dump_mpath, |
| 10872 | .policy = nl80211_policy, |
| 10873 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10874 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10875 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10876 | }, |
| 10877 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10878 | .cmd = NL80211_CMD_GET_MPP, |
| 10879 | .doit = nl80211_get_mpp, |
| 10880 | .dumpit = nl80211_dump_mpp, |
| 10881 | .policy = nl80211_policy, |
| 10882 | .flags = GENL_ADMIN_PERM, |
| 10883 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10884 | NL80211_FLAG_NEED_RTNL, |
| 10885 | }, |
| 10886 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10887 | .cmd = NL80211_CMD_SET_MPATH, |
| 10888 | .doit = nl80211_set_mpath, |
| 10889 | .policy = nl80211_policy, |
| 10890 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10891 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10892 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10893 | }, |
| 10894 | { |
| 10895 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10896 | .doit = nl80211_new_mpath, |
| 10897 | .policy = nl80211_policy, |
| 10898 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10899 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10900 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10901 | }, |
| 10902 | { |
| 10903 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10904 | .doit = nl80211_del_mpath, |
| 10905 | .policy = nl80211_policy, |
| 10906 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10907 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10908 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10909 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10910 | { |
| 10911 | .cmd = NL80211_CMD_SET_BSS, |
| 10912 | .doit = nl80211_set_bss, |
| 10913 | .policy = nl80211_policy, |
| 10914 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10916 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10917 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10918 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10919 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10920 | .doit = nl80211_get_reg_do, |
| 10921 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10922 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10923 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10924 | /* can be retrieved by unprivileged users */ |
| 10925 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 10926 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10927 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10928 | .cmd = NL80211_CMD_SET_REG, |
| 10929 | .doit = nl80211_set_reg, |
| 10930 | .policy = nl80211_policy, |
| 10931 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10932 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10933 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 10934 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10935 | { |
| 10936 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10937 | .doit = nl80211_req_set_reg, |
| 10938 | .policy = nl80211_policy, |
| 10939 | .flags = GENL_ADMIN_PERM, |
| 10940 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10941 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10942 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10943 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10944 | .policy = nl80211_policy, |
| 10945 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10947 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10948 | }, |
| 10949 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10950 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10951 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10952 | .policy = nl80211_policy, |
| 10953 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10955 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10956 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10957 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10958 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10959 | .doit = nl80211_trigger_scan, |
| 10960 | .policy = nl80211_policy, |
| 10961 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10962 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10963 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10964 | }, |
| 10965 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 10966 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 10967 | .doit = nl80211_abort_scan, |
| 10968 | .policy = nl80211_policy, |
| 10969 | .flags = GENL_ADMIN_PERM, |
| 10970 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10971 | NL80211_FLAG_NEED_RTNL, |
| 10972 | }, |
| 10973 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10974 | .cmd = NL80211_CMD_GET_SCAN, |
| 10975 | .policy = nl80211_policy, |
| 10976 | .dumpit = nl80211_dump_scan, |
| 10977 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10978 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10979 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10980 | .doit = nl80211_start_sched_scan, |
| 10981 | .policy = nl80211_policy, |
| 10982 | .flags = GENL_ADMIN_PERM, |
| 10983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10984 | NL80211_FLAG_NEED_RTNL, |
| 10985 | }, |
| 10986 | { |
| 10987 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10988 | .doit = nl80211_stop_sched_scan, |
| 10989 | .policy = nl80211_policy, |
| 10990 | .flags = GENL_ADMIN_PERM, |
| 10991 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10992 | NL80211_FLAG_NEED_RTNL, |
| 10993 | }, |
| 10994 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10995 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10996 | .doit = nl80211_authenticate, |
| 10997 | .policy = nl80211_policy, |
| 10998 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11000 | NL80211_FLAG_NEED_RTNL | |
| 11001 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11002 | }, |
| 11003 | { |
| 11004 | .cmd = NL80211_CMD_ASSOCIATE, |
| 11005 | .doit = nl80211_associate, |
| 11006 | .policy = nl80211_policy, |
| 11007 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11008 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11009 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11010 | }, |
| 11011 | { |
| 11012 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 11013 | .doit = nl80211_deauthenticate, |
| 11014 | .policy = nl80211_policy, |
| 11015 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11016 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11017 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11018 | }, |
| 11019 | { |
| 11020 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 11021 | .doit = nl80211_disassociate, |
| 11022 | .policy = nl80211_policy, |
| 11023 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11025 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11026 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11027 | { |
| 11028 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 11029 | .doit = nl80211_join_ibss, |
| 11030 | .policy = nl80211_policy, |
| 11031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11033 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11034 | }, |
| 11035 | { |
| 11036 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 11037 | .doit = nl80211_leave_ibss, |
| 11038 | .policy = nl80211_policy, |
| 11039 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11041 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11042 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11043 | #ifdef CONFIG_NL80211_TESTMODE |
| 11044 | { |
| 11045 | .cmd = NL80211_CMD_TESTMODE, |
| 11046 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 11047 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11048 | .policy = nl80211_policy, |
| 11049 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11050 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11051 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11052 | }, |
| 11053 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11054 | { |
| 11055 | .cmd = NL80211_CMD_CONNECT, |
| 11056 | .doit = nl80211_connect, |
| 11057 | .policy = nl80211_policy, |
| 11058 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11060 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11061 | }, |
| 11062 | { |
| 11063 | .cmd = NL80211_CMD_DISCONNECT, |
| 11064 | .doit = nl80211_disconnect, |
| 11065 | .policy = nl80211_policy, |
| 11066 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11068 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11069 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11070 | { |
| 11071 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 11072 | .doit = nl80211_wiphy_netns, |
| 11073 | .policy = nl80211_policy, |
| 11074 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11075 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11076 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11077 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 11078 | { |
| 11079 | .cmd = NL80211_CMD_GET_SURVEY, |
| 11080 | .policy = nl80211_policy, |
| 11081 | .dumpit = nl80211_dump_survey, |
| 11082 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11083 | { |
| 11084 | .cmd = NL80211_CMD_SET_PMKSA, |
| 11085 | .doit = nl80211_setdel_pmksa, |
| 11086 | .policy = nl80211_policy, |
| 11087 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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 | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11090 | }, |
| 11091 | { |
| 11092 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 11093 | .doit = nl80211_setdel_pmksa, |
| 11094 | .policy = nl80211_policy, |
| 11095 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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 | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11098 | }, |
| 11099 | { |
| 11100 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 11101 | .doit = nl80211_flush_pmksa, |
| 11102 | .policy = nl80211_policy, |
| 11103 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11105 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11106 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11107 | { |
| 11108 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 11109 | .doit = nl80211_remain_on_channel, |
| 11110 | .policy = nl80211_policy, |
| 11111 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11112 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11113 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11114 | }, |
| 11115 | { |
| 11116 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 11117 | .doit = nl80211_cancel_remain_on_channel, |
| 11118 | .policy = nl80211_policy, |
| 11119 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11120 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11121 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11122 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11123 | { |
| 11124 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 11125 | .doit = nl80211_set_tx_bitrate_mask, |
| 11126 | .policy = nl80211_policy, |
| 11127 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11128 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11129 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11130 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11131 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11132 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 11133 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11134 | .policy = nl80211_policy, |
| 11135 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11136 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11137 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11138 | }, |
| 11139 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11140 | .cmd = NL80211_CMD_FRAME, |
| 11141 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11142 | .policy = nl80211_policy, |
| 11143 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11144 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11145 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11146 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11147 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11148 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 11149 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 11150 | .policy = nl80211_policy, |
| 11151 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11152 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11153 | NL80211_FLAG_NEED_RTNL, |
| 11154 | }, |
| 11155 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11156 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 11157 | .doit = nl80211_set_power_save, |
| 11158 | .policy = nl80211_policy, |
| 11159 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11160 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11161 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11162 | }, |
| 11163 | { |
| 11164 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 11165 | .doit = nl80211_get_power_save, |
| 11166 | .policy = nl80211_policy, |
| 11167 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11168 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11169 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11170 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11171 | { |
| 11172 | .cmd = NL80211_CMD_SET_CQM, |
| 11173 | .doit = nl80211_set_cqm, |
| 11174 | .policy = nl80211_policy, |
| 11175 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11176 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11177 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11178 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11179 | { |
| 11180 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 11181 | .doit = nl80211_set_channel, |
| 11182 | .policy = nl80211_policy, |
| 11183 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11184 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11185 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11186 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11187 | { |
| 11188 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 11189 | .doit = nl80211_set_wds_peer, |
| 11190 | .policy = nl80211_policy, |
| 11191 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 11192 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11193 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11194 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11195 | { |
| 11196 | .cmd = NL80211_CMD_JOIN_MESH, |
| 11197 | .doit = nl80211_join_mesh, |
| 11198 | .policy = nl80211_policy, |
| 11199 | .flags = GENL_ADMIN_PERM, |
| 11200 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11201 | NL80211_FLAG_NEED_RTNL, |
| 11202 | }, |
| 11203 | { |
| 11204 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 11205 | .doit = nl80211_leave_mesh, |
| 11206 | .policy = nl80211_policy, |
| 11207 | .flags = GENL_ADMIN_PERM, |
| 11208 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11209 | NL80211_FLAG_NEED_RTNL, |
| 11210 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11211 | { |
| 11212 | .cmd = NL80211_CMD_JOIN_OCB, |
| 11213 | .doit = nl80211_join_ocb, |
| 11214 | .policy = nl80211_policy, |
| 11215 | .flags = GENL_ADMIN_PERM, |
| 11216 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11217 | NL80211_FLAG_NEED_RTNL, |
| 11218 | }, |
| 11219 | { |
| 11220 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 11221 | .doit = nl80211_leave_ocb, |
| 11222 | .policy = nl80211_policy, |
| 11223 | .flags = GENL_ADMIN_PERM, |
| 11224 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11225 | NL80211_FLAG_NEED_RTNL, |
| 11226 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11227 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11228 | { |
| 11229 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 11230 | .doit = nl80211_get_wowlan, |
| 11231 | .policy = nl80211_policy, |
| 11232 | /* can be retrieved by unprivileged users */ |
| 11233 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11234 | NL80211_FLAG_NEED_RTNL, |
| 11235 | }, |
| 11236 | { |
| 11237 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 11238 | .doit = nl80211_set_wowlan, |
| 11239 | .policy = nl80211_policy, |
| 11240 | .flags = GENL_ADMIN_PERM, |
| 11241 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11242 | NL80211_FLAG_NEED_RTNL, |
| 11243 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11244 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11245 | { |
| 11246 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 11247 | .doit = nl80211_set_rekey_data, |
| 11248 | .policy = nl80211_policy, |
| 11249 | .flags = GENL_ADMIN_PERM, |
| 11250 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11251 | NL80211_FLAG_NEED_RTNL | |
| 11252 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11253 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11254 | { |
| 11255 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 11256 | .doit = nl80211_tdls_mgmt, |
| 11257 | .policy = nl80211_policy, |
| 11258 | .flags = GENL_ADMIN_PERM, |
| 11259 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11260 | NL80211_FLAG_NEED_RTNL, |
| 11261 | }, |
| 11262 | { |
| 11263 | .cmd = NL80211_CMD_TDLS_OPER, |
| 11264 | .doit = nl80211_tdls_oper, |
| 11265 | .policy = nl80211_policy, |
| 11266 | .flags = GENL_ADMIN_PERM, |
| 11267 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11268 | NL80211_FLAG_NEED_RTNL, |
| 11269 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11270 | { |
| 11271 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 11272 | .doit = nl80211_register_unexpected_frame, |
| 11273 | .policy = nl80211_policy, |
| 11274 | .flags = GENL_ADMIN_PERM, |
| 11275 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11276 | NL80211_FLAG_NEED_RTNL, |
| 11277 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11278 | { |
| 11279 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 11280 | .doit = nl80211_probe_client, |
| 11281 | .policy = nl80211_policy, |
| 11282 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11283 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11284 | NL80211_FLAG_NEED_RTNL, |
| 11285 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11286 | { |
| 11287 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 11288 | .doit = nl80211_register_beacons, |
| 11289 | .policy = nl80211_policy, |
| 11290 | .flags = GENL_ADMIN_PERM, |
| 11291 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11292 | NL80211_FLAG_NEED_RTNL, |
| 11293 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11294 | { |
| 11295 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 11296 | .doit = nl80211_set_noack_map, |
| 11297 | .policy = nl80211_policy, |
| 11298 | .flags = GENL_ADMIN_PERM, |
| 11299 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11300 | NL80211_FLAG_NEED_RTNL, |
| 11301 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11302 | { |
| 11303 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 11304 | .doit = nl80211_start_p2p_device, |
| 11305 | .policy = nl80211_policy, |
| 11306 | .flags = GENL_ADMIN_PERM, |
| 11307 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11308 | NL80211_FLAG_NEED_RTNL, |
| 11309 | }, |
| 11310 | { |
| 11311 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 11312 | .doit = nl80211_stop_p2p_device, |
| 11313 | .policy = nl80211_policy, |
| 11314 | .flags = GENL_ADMIN_PERM, |
| 11315 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11316 | NL80211_FLAG_NEED_RTNL, |
| 11317 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11318 | { |
| 11319 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 11320 | .doit = nl80211_set_mcast_rate, |
| 11321 | .policy = nl80211_policy, |
| 11322 | .flags = GENL_ADMIN_PERM, |
| 11323 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11324 | NL80211_FLAG_NEED_RTNL, |
| 11325 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11326 | { |
| 11327 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 11328 | .doit = nl80211_set_mac_acl, |
| 11329 | .policy = nl80211_policy, |
| 11330 | .flags = GENL_ADMIN_PERM, |
| 11331 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11332 | NL80211_FLAG_NEED_RTNL, |
| 11333 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11334 | { |
| 11335 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 11336 | .doit = nl80211_start_radar_detection, |
| 11337 | .policy = nl80211_policy, |
| 11338 | .flags = GENL_ADMIN_PERM, |
| 11339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11340 | NL80211_FLAG_NEED_RTNL, |
| 11341 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11342 | { |
| 11343 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 11344 | .doit = nl80211_get_protocol_features, |
| 11345 | .policy = nl80211_policy, |
| 11346 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11347 | { |
| 11348 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 11349 | .doit = nl80211_update_ft_ies, |
| 11350 | .policy = nl80211_policy, |
| 11351 | .flags = GENL_ADMIN_PERM, |
| 11352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11353 | NL80211_FLAG_NEED_RTNL, |
| 11354 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11355 | { |
| 11356 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 11357 | .doit = nl80211_crit_protocol_start, |
| 11358 | .policy = nl80211_policy, |
| 11359 | .flags = GENL_ADMIN_PERM, |
| 11360 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11361 | NL80211_FLAG_NEED_RTNL, |
| 11362 | }, |
| 11363 | { |
| 11364 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 11365 | .doit = nl80211_crit_protocol_stop, |
| 11366 | .policy = nl80211_policy, |
| 11367 | .flags = GENL_ADMIN_PERM, |
| 11368 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11369 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11370 | }, |
| 11371 | { |
| 11372 | .cmd = NL80211_CMD_GET_COALESCE, |
| 11373 | .doit = nl80211_get_coalesce, |
| 11374 | .policy = nl80211_policy, |
| 11375 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11376 | NL80211_FLAG_NEED_RTNL, |
| 11377 | }, |
| 11378 | { |
| 11379 | .cmd = NL80211_CMD_SET_COALESCE, |
| 11380 | .doit = nl80211_set_coalesce, |
| 11381 | .policy = nl80211_policy, |
| 11382 | .flags = GENL_ADMIN_PERM, |
| 11383 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11384 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11385 | }, |
| 11386 | { |
| 11387 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 11388 | .doit = nl80211_channel_switch, |
| 11389 | .policy = nl80211_policy, |
| 11390 | .flags = GENL_ADMIN_PERM, |
| 11391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11392 | NL80211_FLAG_NEED_RTNL, |
| 11393 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11394 | { |
| 11395 | .cmd = NL80211_CMD_VENDOR, |
| 11396 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11397 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11398 | .policy = nl80211_policy, |
| 11399 | .flags = GENL_ADMIN_PERM, |
| 11400 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11401 | NL80211_FLAG_NEED_RTNL, |
| 11402 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11403 | { |
| 11404 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11405 | .doit = nl80211_set_qos_map, |
| 11406 | .policy = nl80211_policy, |
| 11407 | .flags = GENL_ADMIN_PERM, |
| 11408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11409 | NL80211_FLAG_NEED_RTNL, |
| 11410 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11411 | { |
| 11412 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11413 | .doit = nl80211_add_tx_ts, |
| 11414 | .policy = nl80211_policy, |
| 11415 | .flags = GENL_ADMIN_PERM, |
| 11416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11417 | NL80211_FLAG_NEED_RTNL, |
| 11418 | }, |
| 11419 | { |
| 11420 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11421 | .doit = nl80211_del_tx_ts, |
| 11422 | .policy = nl80211_policy, |
| 11423 | .flags = GENL_ADMIN_PERM, |
| 11424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11425 | NL80211_FLAG_NEED_RTNL, |
| 11426 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11427 | { |
| 11428 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11429 | .doit = nl80211_tdls_channel_switch, |
| 11430 | .policy = nl80211_policy, |
| 11431 | .flags = GENL_ADMIN_PERM, |
| 11432 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11433 | NL80211_FLAG_NEED_RTNL, |
| 11434 | }, |
| 11435 | { |
| 11436 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11437 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11438 | .policy = nl80211_policy, |
| 11439 | .flags = GENL_ADMIN_PERM, |
| 11440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11441 | NL80211_FLAG_NEED_RTNL, |
| 11442 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11443 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11444 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11445 | /* notification functions */ |
| 11446 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11447 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11448 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11449 | { |
| 11450 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11451 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11452 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11453 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11454 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11455 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11457 | if (!msg) |
| 11458 | return; |
| 11459 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11460 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11461 | nlmsg_free(msg); |
| 11462 | return; |
| 11463 | } |
| 11464 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11465 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11466 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11467 | } |
| 11468 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11469 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11470 | struct cfg80211_registered_device *rdev) |
| 11471 | { |
| 11472 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11473 | struct nlattr *nest; |
| 11474 | int i; |
| 11475 | |
| 11476 | if (WARN_ON(!req)) |
| 11477 | return 0; |
| 11478 | |
| 11479 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11480 | if (!nest) |
| 11481 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11482 | for (i = 0; i < req->n_ssids; i++) { |
| 11483 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11484 | goto nla_put_failure; |
| 11485 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11486 | nla_nest_end(msg, nest); |
| 11487 | |
| 11488 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11489 | if (!nest) |
| 11490 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11491 | for (i = 0; i < req->n_channels; i++) { |
| 11492 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11493 | goto nla_put_failure; |
| 11494 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11495 | nla_nest_end(msg, nest); |
| 11496 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11497 | if (req->ie && |
| 11498 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11499 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11500 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11501 | if (req->flags && |
| 11502 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11503 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11504 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11505 | return 0; |
| 11506 | nla_put_failure: |
| 11507 | return -ENOBUFS; |
| 11508 | } |
| 11509 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11510 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11511 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11512 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11513 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11514 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11515 | { |
| 11516 | void *hdr; |
| 11517 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11518 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11519 | if (!hdr) |
| 11520 | return -1; |
| 11521 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11523 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11524 | wdev->netdev->ifindex)) || |
| 11525 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11526 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11527 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11528 | /* ignore errors and send incomplete event anyway */ |
| 11529 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11530 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11531 | genlmsg_end(msg, hdr); |
| 11532 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11533 | |
| 11534 | nla_put_failure: |
| 11535 | genlmsg_cancel(msg, hdr); |
| 11536 | return -EMSGSIZE; |
| 11537 | } |
| 11538 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11539 | static int |
| 11540 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11541 | struct cfg80211_registered_device *rdev, |
| 11542 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11543 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [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); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [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) || |
| 11552 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11553 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11554 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11555 | genlmsg_end(msg, hdr); |
| 11556 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11557 | |
| 11558 | nla_put_failure: |
| 11559 | genlmsg_cancel(msg, hdr); |
| 11560 | return -EMSGSIZE; |
| 11561 | } |
| 11562 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11563 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11564 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11565 | { |
| 11566 | struct sk_buff *msg; |
| 11567 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11568 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11569 | if (!msg) |
| 11570 | return; |
| 11571 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11572 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11573 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11574 | nlmsg_free(msg); |
| 11575 | return; |
| 11576 | } |
| 11577 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11578 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11579 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11580 | } |
| 11581 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11582 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11583 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11584 | { |
| 11585 | struct sk_buff *msg; |
| 11586 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11588 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11589 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11590 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11591 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11592 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11593 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11594 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11595 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11596 | } |
| 11597 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11598 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11599 | } |
| 11600 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11601 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11602 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11603 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11604 | if (!msg) |
| 11605 | return; |
| 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 | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11609 | } |
| 11610 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11611 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11612 | struct net_device *netdev) |
| 11613 | { |
| 11614 | struct sk_buff *msg; |
| 11615 | |
| 11616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11617 | if (!msg) |
| 11618 | return; |
| 11619 | |
| 11620 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11621 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11622 | nlmsg_free(msg); |
| 11623 | return; |
| 11624 | } |
| 11625 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11626 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11627 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11628 | } |
| 11629 | |
| 11630 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11631 | struct net_device *netdev, u32 cmd) |
| 11632 | { |
| 11633 | struct sk_buff *msg; |
| 11634 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11636 | if (!msg) |
| 11637 | return; |
| 11638 | |
| 11639 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11640 | nlmsg_free(msg); |
| 11641 | return; |
| 11642 | } |
| 11643 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11644 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11645 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11646 | } |
| 11647 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11648 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11649 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11650 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11651 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11652 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11653 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11655 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11656 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11657 | NL80211_REGDOM_TYPE_WORLD)) |
| 11658 | goto nla_put_failure; |
| 11659 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11660 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11661 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11662 | goto nla_put_failure; |
| 11663 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11664 | request->intersect) { |
| 11665 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11666 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11667 | goto nla_put_failure; |
| 11668 | } else { |
| 11669 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11670 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11671 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11672 | request->alpha2)) |
| 11673 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11674 | } |
| 11675 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11676 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11677 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11678 | |
| 11679 | if (wiphy && |
| 11680 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11681 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 11682 | |
| 11683 | if (wiphy && |
| 11684 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 11685 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 11686 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11687 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11688 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11689 | return true; |
| 11690 | |
| 11691 | nla_put_failure: |
| 11692 | return false; |
| 11693 | } |
| 11694 | |
| 11695 | /* |
| 11696 | * This can happen on global regulatory changes or device specific settings |
| 11697 | * based on custom regulatory domains. |
| 11698 | */ |
| 11699 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11700 | struct regulatory_request *request) |
| 11701 | { |
| 11702 | struct sk_buff *msg; |
| 11703 | void *hdr; |
| 11704 | |
| 11705 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11706 | if (!msg) |
| 11707 | return; |
| 11708 | |
| 11709 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11710 | if (!hdr) { |
| 11711 | nlmsg_free(msg); |
| 11712 | return; |
| 11713 | } |
| 11714 | |
| 11715 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11716 | goto nla_put_failure; |
| 11717 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11718 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11719 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11720 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11721 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11722 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11723 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11724 | |
| 11725 | return; |
| 11726 | |
| 11727 | nla_put_failure: |
| 11728 | genlmsg_cancel(msg, hdr); |
| 11729 | nlmsg_free(msg); |
| 11730 | } |
| 11731 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11732 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11733 | struct net_device *netdev, |
| 11734 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11735 | enum nl80211_commands cmd, gfp_t gfp, |
| 11736 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11737 | { |
| 11738 | struct sk_buff *msg; |
| 11739 | void *hdr; |
| 11740 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11741 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11742 | if (!msg) |
| 11743 | return; |
| 11744 | |
| 11745 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11746 | if (!hdr) { |
| 11747 | nlmsg_free(msg); |
| 11748 | return; |
| 11749 | } |
| 11750 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11751 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11752 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11753 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11754 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11755 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11756 | if (uapsd_queues >= 0) { |
| 11757 | struct nlattr *nla_wmm = |
| 11758 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11759 | if (!nla_wmm) |
| 11760 | goto nla_put_failure; |
| 11761 | |
| 11762 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11763 | uapsd_queues)) |
| 11764 | goto nla_put_failure; |
| 11765 | |
| 11766 | nla_nest_end(msg, nla_wmm); |
| 11767 | } |
| 11768 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11769 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11770 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11771 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11772 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11773 | return; |
| 11774 | |
| 11775 | nla_put_failure: |
| 11776 | genlmsg_cancel(msg, hdr); |
| 11777 | nlmsg_free(msg); |
| 11778 | } |
| 11779 | |
| 11780 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11781 | struct net_device *netdev, const u8 *buf, |
| 11782 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11783 | { |
| 11784 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11785 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11786 | } |
| 11787 | |
| 11788 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11789 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11790 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11791 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11792 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11793 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11794 | } |
| 11795 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11796 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11797 | struct net_device *netdev, const u8 *buf, |
| 11798 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11799 | { |
| 11800 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11801 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11802 | } |
| 11803 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11804 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11805 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11806 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11807 | { |
| 11808 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11809 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11810 | } |
| 11811 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11812 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11813 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11814 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11815 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11816 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11817 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11818 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11819 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11820 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11821 | if (WARN_ON(len < 2)) |
| 11822 | return; |
| 11823 | |
| 11824 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11825 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11826 | else |
| 11827 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11828 | |
| 11829 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11830 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11831 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11832 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11833 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11834 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11835 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11836 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11837 | { |
| 11838 | struct sk_buff *msg; |
| 11839 | void *hdr; |
| 11840 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11842 | if (!msg) |
| 11843 | return; |
| 11844 | |
| 11845 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11846 | if (!hdr) { |
| 11847 | nlmsg_free(msg); |
| 11848 | return; |
| 11849 | } |
| 11850 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11851 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11852 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11853 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11854 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11855 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11856 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11857 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11858 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11859 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11860 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11861 | return; |
| 11862 | |
| 11863 | nla_put_failure: |
| 11864 | genlmsg_cancel(msg, hdr); |
| 11865 | nlmsg_free(msg); |
| 11866 | } |
| 11867 | |
| 11868 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11869 | struct net_device *netdev, const u8 *addr, |
| 11870 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11871 | { |
| 11872 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11873 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11874 | } |
| 11875 | |
| 11876 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11877 | struct net_device *netdev, const u8 *addr, |
| 11878 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11879 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11880 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11881 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11882 | } |
| 11883 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11884 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11885 | struct net_device *netdev, const u8 *bssid, |
| 11886 | const u8 *req_ie, size_t req_ie_len, |
| 11887 | const u8 *resp_ie, size_t resp_ie_len, |
| 11888 | u16 status, gfp_t gfp) |
| 11889 | { |
| 11890 | struct sk_buff *msg; |
| 11891 | void *hdr; |
| 11892 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11893 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11894 | if (!msg) |
| 11895 | return; |
| 11896 | |
| 11897 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11898 | if (!hdr) { |
| 11899 | nlmsg_free(msg); |
| 11900 | return; |
| 11901 | } |
| 11902 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11903 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11904 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11905 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11906 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11907 | (req_ie && |
| 11908 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11909 | (resp_ie && |
| 11910 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11911 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11912 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11913 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11914 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11915 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11916 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11917 | return; |
| 11918 | |
| 11919 | nla_put_failure: |
| 11920 | genlmsg_cancel(msg, hdr); |
| 11921 | nlmsg_free(msg); |
| 11922 | |
| 11923 | } |
| 11924 | |
| 11925 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11926 | struct net_device *netdev, const u8 *bssid, |
| 11927 | const u8 *req_ie, size_t req_ie_len, |
| 11928 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11929 | { |
| 11930 | struct sk_buff *msg; |
| 11931 | void *hdr; |
| 11932 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11933 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11934 | if (!msg) |
| 11935 | return; |
| 11936 | |
| 11937 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11938 | if (!hdr) { |
| 11939 | nlmsg_free(msg); |
| 11940 | return; |
| 11941 | } |
| 11942 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11943 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11944 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11945 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11946 | (req_ie && |
| 11947 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11948 | (resp_ie && |
| 11949 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11950 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11951 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11952 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11953 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11954 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11955 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11956 | return; |
| 11957 | |
| 11958 | nla_put_failure: |
| 11959 | genlmsg_cancel(msg, hdr); |
| 11960 | nlmsg_free(msg); |
| 11961 | |
| 11962 | } |
| 11963 | |
| 11964 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11965 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11966 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11967 | { |
| 11968 | struct sk_buff *msg; |
| 11969 | void *hdr; |
| 11970 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11972 | if (!msg) |
| 11973 | return; |
| 11974 | |
| 11975 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11976 | if (!hdr) { |
| 11977 | nlmsg_free(msg); |
| 11978 | return; |
| 11979 | } |
| 11980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11981 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11982 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11983 | (from_ap && reason && |
| 11984 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11985 | (from_ap && |
| 11986 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11987 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11988 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11989 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11990 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11991 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11992 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11993 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11994 | return; |
| 11995 | |
| 11996 | nla_put_failure: |
| 11997 | genlmsg_cancel(msg, hdr); |
| 11998 | nlmsg_free(msg); |
| 11999 | |
| 12000 | } |
| 12001 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12002 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 12003 | struct net_device *netdev, const u8 *bssid, |
| 12004 | gfp_t gfp) |
| 12005 | { |
| 12006 | struct sk_buff *msg; |
| 12007 | void *hdr; |
| 12008 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12010 | if (!msg) |
| 12011 | return; |
| 12012 | |
| 12013 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 12014 | if (!hdr) { |
| 12015 | nlmsg_free(msg); |
| 12016 | return; |
| 12017 | } |
| 12018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12019 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12020 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12021 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12022 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12023 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12024 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12025 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12026 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12027 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12028 | return; |
| 12029 | |
| 12030 | nla_put_failure: |
| 12031 | genlmsg_cancel(msg, hdr); |
| 12032 | nlmsg_free(msg); |
| 12033 | } |
| 12034 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12035 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 12036 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12037 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12038 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12039 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12040 | struct sk_buff *msg; |
| 12041 | void *hdr; |
| 12042 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12043 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 12044 | return; |
| 12045 | |
| 12046 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 12047 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12049 | if (!msg) |
| 12050 | return; |
| 12051 | |
| 12052 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 12053 | if (!hdr) { |
| 12054 | nlmsg_free(msg); |
| 12055 | return; |
| 12056 | } |
| 12057 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12058 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12059 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12060 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12061 | (ie_len && ie && |
| 12062 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 12063 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12064 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12065 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12066 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12067 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12068 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12069 | return; |
| 12070 | |
| 12071 | nla_put_failure: |
| 12072 | genlmsg_cancel(msg, hdr); |
| 12073 | nlmsg_free(msg); |
| 12074 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12075 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12076 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12077 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 12078 | struct net_device *netdev, const u8 *addr, |
| 12079 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12080 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12081 | { |
| 12082 | struct sk_buff *msg; |
| 12083 | void *hdr; |
| 12084 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12085 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12086 | if (!msg) |
| 12087 | return; |
| 12088 | |
| 12089 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 12090 | if (!hdr) { |
| 12091 | nlmsg_free(msg); |
| 12092 | return; |
| 12093 | } |
| 12094 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12095 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12096 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12097 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 12098 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 12099 | (key_id != -1 && |
| 12100 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 12101 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 12102 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12103 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12104 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12105 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12106 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12107 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12108 | return; |
| 12109 | |
| 12110 | nla_put_failure: |
| 12111 | genlmsg_cancel(msg, hdr); |
| 12112 | nlmsg_free(msg); |
| 12113 | } |
| 12114 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12115 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 12116 | struct ieee80211_channel *channel_before, |
| 12117 | struct ieee80211_channel *channel_after) |
| 12118 | { |
| 12119 | struct sk_buff *msg; |
| 12120 | void *hdr; |
| 12121 | struct nlattr *nl_freq; |
| 12122 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12123 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12124 | if (!msg) |
| 12125 | return; |
| 12126 | |
| 12127 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 12128 | if (!hdr) { |
| 12129 | nlmsg_free(msg); |
| 12130 | return; |
| 12131 | } |
| 12132 | |
| 12133 | /* |
| 12134 | * Since we are applying the beacon hint to a wiphy we know its |
| 12135 | * wiphy_idx is valid |
| 12136 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12137 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 12138 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12139 | |
| 12140 | /* Before */ |
| 12141 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 12142 | if (!nl_freq) |
| 12143 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12144 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12145 | goto nla_put_failure; |
| 12146 | nla_nest_end(msg, nl_freq); |
| 12147 | |
| 12148 | /* After */ |
| 12149 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 12150 | if (!nl_freq) |
| 12151 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12152 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12153 | goto nla_put_failure; |
| 12154 | nla_nest_end(msg, nl_freq); |
| 12155 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12156 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12157 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12158 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12159 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12160 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12161 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12162 | |
| 12163 | return; |
| 12164 | |
| 12165 | nla_put_failure: |
| 12166 | genlmsg_cancel(msg, hdr); |
| 12167 | nlmsg_free(msg); |
| 12168 | } |
| 12169 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12170 | static void nl80211_send_remain_on_chan_event( |
| 12171 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12172 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12173 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12174 | unsigned int duration, gfp_t gfp) |
| 12175 | { |
| 12176 | struct sk_buff *msg; |
| 12177 | void *hdr; |
| 12178 | |
| 12179 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12180 | if (!msg) |
| 12181 | return; |
| 12182 | |
| 12183 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12184 | if (!hdr) { |
| 12185 | nlmsg_free(msg); |
| 12186 | return; |
| 12187 | } |
| 12188 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12189 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12190 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12191 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 12192 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12193 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12194 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 12195 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12196 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 12197 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12198 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12199 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 12200 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 12201 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12202 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12203 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12204 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12205 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12206 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12207 | return; |
| 12208 | |
| 12209 | nla_put_failure: |
| 12210 | genlmsg_cancel(msg, hdr); |
| 12211 | nlmsg_free(msg); |
| 12212 | } |
| 12213 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12214 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 12215 | struct ieee80211_channel *chan, |
| 12216 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12217 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12218 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12219 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12220 | |
| 12221 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12222 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12223 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12224 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12225 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12226 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12227 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12228 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 12229 | struct ieee80211_channel *chan, |
| 12230 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12231 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12232 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12233 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12234 | |
| 12235 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12236 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12237 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12238 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12239 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12240 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12241 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 12242 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12243 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12244 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12245 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12246 | struct sk_buff *msg; |
| 12247 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12248 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 12249 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12250 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12251 | if (!msg) |
| 12252 | return; |
| 12253 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12254 | 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] | 12255 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12256 | nlmsg_free(msg); |
| 12257 | return; |
| 12258 | } |
| 12259 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12260 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12261 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12262 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12263 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12264 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12265 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 12266 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12267 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12268 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12269 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12270 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12271 | struct station_info empty_sinfo = {}; |
| 12272 | |
| 12273 | if (!sinfo) |
| 12274 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12275 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12276 | trace_cfg80211_del_sta(dev, mac_addr); |
| 12277 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12278 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12279 | if (!msg) |
| 12280 | return; |
| 12281 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12282 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 12283 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12284 | nlmsg_free(msg); |
| 12285 | return; |
| 12286 | } |
| 12287 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12288 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12289 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12290 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12291 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12292 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12293 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 12294 | enum nl80211_connect_failed_reason reason, |
| 12295 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [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); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12299 | struct sk_buff *msg; |
| 12300 | void *hdr; |
| 12301 | |
| 12302 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 12303 | if (!msg) |
| 12304 | return; |
| 12305 | |
| 12306 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 12307 | if (!hdr) { |
| 12308 | nlmsg_free(msg); |
| 12309 | return; |
| 12310 | } |
| 12311 | |
| 12312 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12313 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 12314 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 12315 | goto nla_put_failure; |
| 12316 | |
| 12317 | genlmsg_end(msg, hdr); |
| 12318 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12319 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12320 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12321 | return; |
| 12322 | |
| 12323 | nla_put_failure: |
| 12324 | genlmsg_cancel(msg, hdr); |
| 12325 | nlmsg_free(msg); |
| 12326 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12327 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12328 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12329 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 12330 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12331 | { |
| 12332 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12333 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12334 | struct sk_buff *msg; |
| 12335 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12336 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12337 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12338 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12339 | return false; |
| 12340 | |
| 12341 | msg = nlmsg_new(100, gfp); |
| 12342 | if (!msg) |
| 12343 | return true; |
| 12344 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12345 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12346 | if (!hdr) { |
| 12347 | nlmsg_free(msg); |
| 12348 | return true; |
| 12349 | } |
| 12350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12351 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12352 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12353 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12354 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12355 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12356 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12357 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12358 | return true; |
| 12359 | |
| 12360 | nla_put_failure: |
| 12361 | genlmsg_cancel(msg, hdr); |
| 12362 | nlmsg_free(msg); |
| 12363 | return true; |
| 12364 | } |
| 12365 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12366 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 12367 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12368 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12369 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12370 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12371 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12372 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 12373 | |
| 12374 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12375 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 12376 | trace_cfg80211_return_bool(false); |
| 12377 | return false; |
| 12378 | } |
| 12379 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 12380 | addr, gfp); |
| 12381 | trace_cfg80211_return_bool(ret); |
| 12382 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12383 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12384 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 12385 | |
| 12386 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 12387 | const u8 *addr, gfp_t gfp) |
| 12388 | { |
| 12389 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12390 | bool ret; |
| 12391 | |
| 12392 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 12393 | |
| 12394 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12395 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 12396 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 12397 | trace_cfg80211_return_bool(false); |
| 12398 | return false; |
| 12399 | } |
| 12400 | ret = __nl80211_unexpected_frame(dev, |
| 12401 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12402 | addr, gfp); |
| 12403 | trace_cfg80211_return_bool(ret); |
| 12404 | return ret; |
| 12405 | } |
| 12406 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12407 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12408 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12409 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12410 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12411 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12412 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12413 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12414 | struct sk_buff *msg; |
| 12415 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12416 | |
| 12417 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12418 | if (!msg) |
| 12419 | return -ENOMEM; |
| 12420 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12421 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12422 | if (!hdr) { |
| 12423 | nlmsg_free(msg); |
| 12424 | return -ENOMEM; |
| 12425 | } |
| 12426 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12427 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12428 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12429 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12430 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12431 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12432 | (sig_dbm && |
| 12433 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12434 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12435 | (flags && |
| 12436 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12437 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12438 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12439 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12440 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12441 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12442 | |
| 12443 | nla_put_failure: |
| 12444 | genlmsg_cancel(msg, hdr); |
| 12445 | nlmsg_free(msg); |
| 12446 | return -ENOBUFS; |
| 12447 | } |
| 12448 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12449 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12450 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12451 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12452 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12454 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12455 | struct sk_buff *msg; |
| 12456 | void *hdr; |
| 12457 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12458 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12459 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12461 | if (!msg) |
| 12462 | return; |
| 12463 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12464 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12465 | if (!hdr) { |
| 12466 | nlmsg_free(msg); |
| 12467 | return; |
| 12468 | } |
| 12469 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12470 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12471 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12472 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12473 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12474 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12475 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12476 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12477 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12478 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12479 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12480 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12481 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12482 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12483 | return; |
| 12484 | |
| 12485 | nla_put_failure: |
| 12486 | genlmsg_cancel(msg, hdr); |
| 12487 | nlmsg_free(msg); |
| 12488 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12489 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12490 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12491 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12492 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12493 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12494 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12495 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12496 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12497 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12498 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12499 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12500 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12501 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12502 | cb = (void **)msg->cb; |
| 12503 | |
| 12504 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12505 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12506 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12507 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12508 | } |
| 12509 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12510 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12511 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12512 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12513 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12514 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12515 | goto nla_put_failure; |
| 12516 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12517 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12518 | if (!cb[1]) |
| 12519 | goto nla_put_failure; |
| 12520 | |
| 12521 | cb[2] = rdev; |
| 12522 | |
| 12523 | return msg; |
| 12524 | nla_put_failure: |
| 12525 | nlmsg_free(msg); |
| 12526 | return NULL; |
| 12527 | } |
| 12528 | |
| 12529 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12530 | { |
| 12531 | void **cb = (void **)msg->cb; |
| 12532 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12533 | |
| 12534 | nla_nest_end(msg, cb[1]); |
| 12535 | genlmsg_end(msg, cb[0]); |
| 12536 | |
| 12537 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12538 | |
| 12539 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12540 | NL80211_MCGRP_MLME, gfp); |
| 12541 | } |
| 12542 | |
| 12543 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12544 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12545 | gfp_t gfp) |
| 12546 | { |
| 12547 | struct sk_buff *msg; |
| 12548 | |
| 12549 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12550 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12551 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12552 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12553 | return; |
| 12554 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12555 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12556 | if (!msg) |
| 12557 | return; |
| 12558 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12559 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12560 | rssi_event)) |
| 12561 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12562 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12563 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12564 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12565 | return; |
| 12566 | |
| 12567 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12568 | nlmsg_free(msg); |
| 12569 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12570 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12571 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12572 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12573 | const u8 *peer, u32 num_packets, |
| 12574 | u32 rate, u32 intvl, gfp_t gfp) |
| 12575 | { |
| 12576 | struct sk_buff *msg; |
| 12577 | |
| 12578 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12579 | if (!msg) |
| 12580 | return; |
| 12581 | |
| 12582 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12583 | goto nla_put_failure; |
| 12584 | |
| 12585 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12586 | goto nla_put_failure; |
| 12587 | |
| 12588 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12589 | goto nla_put_failure; |
| 12590 | |
| 12591 | cfg80211_send_cqm(msg, gfp); |
| 12592 | return; |
| 12593 | |
| 12594 | nla_put_failure: |
| 12595 | nlmsg_free(msg); |
| 12596 | } |
| 12597 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12598 | |
| 12599 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12600 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12601 | { |
| 12602 | struct sk_buff *msg; |
| 12603 | |
| 12604 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12605 | |
| 12606 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12607 | if (!msg) |
| 12608 | return; |
| 12609 | |
| 12610 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12611 | goto nla_put_failure; |
| 12612 | |
| 12613 | cfg80211_send_cqm(msg, gfp); |
| 12614 | return; |
| 12615 | |
| 12616 | nla_put_failure: |
| 12617 | nlmsg_free(msg); |
| 12618 | } |
| 12619 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12620 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12621 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12622 | { |
| 12623 | struct sk_buff *msg; |
| 12624 | |
| 12625 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12626 | if (!msg) |
| 12627 | return; |
| 12628 | |
| 12629 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12630 | goto nla_put_failure; |
| 12631 | |
| 12632 | cfg80211_send_cqm(msg, gfp); |
| 12633 | return; |
| 12634 | |
| 12635 | nla_put_failure: |
| 12636 | nlmsg_free(msg); |
| 12637 | } |
| 12638 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12639 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12640 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12641 | struct net_device *netdev, const u8 *bssid, |
| 12642 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12643 | { |
| 12644 | struct sk_buff *msg; |
| 12645 | struct nlattr *rekey_attr; |
| 12646 | void *hdr; |
| 12647 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12649 | if (!msg) |
| 12650 | return; |
| 12651 | |
| 12652 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12653 | if (!hdr) { |
| 12654 | nlmsg_free(msg); |
| 12655 | return; |
| 12656 | } |
| 12657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12658 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12659 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12660 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12661 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12662 | |
| 12663 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12664 | if (!rekey_attr) |
| 12665 | goto nla_put_failure; |
| 12666 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12667 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12668 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12669 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12670 | |
| 12671 | nla_nest_end(msg, rekey_attr); |
| 12672 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12673 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12674 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12675 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12676 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12677 | return; |
| 12678 | |
| 12679 | nla_put_failure: |
| 12680 | genlmsg_cancel(msg, hdr); |
| 12681 | nlmsg_free(msg); |
| 12682 | } |
| 12683 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12684 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12685 | const u8 *replay_ctr, gfp_t gfp) |
| 12686 | { |
| 12687 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12688 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12689 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12690 | |
| 12691 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12692 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12693 | } |
| 12694 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12695 | |
| 12696 | static void |
| 12697 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12698 | struct net_device *netdev, int index, |
| 12699 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12700 | { |
| 12701 | struct sk_buff *msg; |
| 12702 | struct nlattr *attr; |
| 12703 | void *hdr; |
| 12704 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12705 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12706 | if (!msg) |
| 12707 | return; |
| 12708 | |
| 12709 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12710 | if (!hdr) { |
| 12711 | nlmsg_free(msg); |
| 12712 | return; |
| 12713 | } |
| 12714 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12715 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12716 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12717 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12718 | |
| 12719 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12720 | if (!attr) |
| 12721 | goto nla_put_failure; |
| 12722 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12723 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12724 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12725 | (preauth && |
| 12726 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12727 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12728 | |
| 12729 | nla_nest_end(msg, attr); |
| 12730 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12731 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12732 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12733 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12734 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12735 | return; |
| 12736 | |
| 12737 | nla_put_failure: |
| 12738 | genlmsg_cancel(msg, hdr); |
| 12739 | nlmsg_free(msg); |
| 12740 | } |
| 12741 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12742 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12743 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12744 | { |
| 12745 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12746 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12747 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12748 | |
| 12749 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12750 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12751 | } |
| 12752 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12753 | |
| 12754 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12755 | struct net_device *netdev, |
| 12756 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12757 | gfp_t gfp, |
| 12758 | enum nl80211_commands notif, |
| 12759 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12760 | { |
| 12761 | struct sk_buff *msg; |
| 12762 | void *hdr; |
| 12763 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12765 | if (!msg) |
| 12766 | return; |
| 12767 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12768 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12769 | if (!hdr) { |
| 12770 | nlmsg_free(msg); |
| 12771 | return; |
| 12772 | } |
| 12773 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12774 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12775 | goto nla_put_failure; |
| 12776 | |
| 12777 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12778 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12779 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12780 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12781 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12782 | goto nla_put_failure; |
| 12783 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12784 | genlmsg_end(msg, hdr); |
| 12785 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12786 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12787 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12788 | return; |
| 12789 | |
| 12790 | nla_put_failure: |
| 12791 | genlmsg_cancel(msg, hdr); |
| 12792 | nlmsg_free(msg); |
| 12793 | } |
| 12794 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12795 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12796 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12797 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12798 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12799 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12800 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12801 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12802 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12803 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12804 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12805 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12806 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12807 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12808 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12809 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12810 | } |
| 12811 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12812 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12813 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12814 | struct cfg80211_chan_def *chandef, |
| 12815 | u8 count) |
| 12816 | { |
| 12817 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12818 | struct wiphy *wiphy = wdev->wiphy; |
| 12819 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12820 | |
| 12821 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12822 | |
| 12823 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12824 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12825 | } |
| 12826 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12827 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12828 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12829 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12830 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12831 | enum nl80211_radar_event event, |
| 12832 | struct net_device *netdev, gfp_t gfp) |
| 12833 | { |
| 12834 | struct sk_buff *msg; |
| 12835 | void *hdr; |
| 12836 | |
| 12837 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12838 | if (!msg) |
| 12839 | return; |
| 12840 | |
| 12841 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12842 | if (!hdr) { |
| 12843 | nlmsg_free(msg); |
| 12844 | return; |
| 12845 | } |
| 12846 | |
| 12847 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12848 | goto nla_put_failure; |
| 12849 | |
| 12850 | /* NOP and radar events don't need a netdev parameter */ |
| 12851 | if (netdev) { |
| 12852 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12853 | |
| 12854 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12855 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12856 | goto nla_put_failure; |
| 12857 | } |
| 12858 | |
| 12859 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12860 | goto nla_put_failure; |
| 12861 | |
| 12862 | if (nl80211_send_chandef(msg, chandef)) |
| 12863 | goto nla_put_failure; |
| 12864 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12865 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12866 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12867 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12868 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12869 | return; |
| 12870 | |
| 12871 | nla_put_failure: |
| 12872 | genlmsg_cancel(msg, hdr); |
| 12873 | nlmsg_free(msg); |
| 12874 | } |
| 12875 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12876 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12877 | u64 cookie, bool acked, gfp_t gfp) |
| 12878 | { |
| 12879 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12880 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12881 | struct sk_buff *msg; |
| 12882 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12883 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12884 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12885 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12887 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12888 | if (!msg) |
| 12889 | return; |
| 12890 | |
| 12891 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12892 | if (!hdr) { |
| 12893 | nlmsg_free(msg); |
| 12894 | return; |
| 12895 | } |
| 12896 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12897 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12898 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12899 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12900 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12901 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12902 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12903 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12904 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12905 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12906 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12907 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12908 | return; |
| 12909 | |
| 12910 | nla_put_failure: |
| 12911 | genlmsg_cancel(msg, hdr); |
| 12912 | nlmsg_free(msg); |
| 12913 | } |
| 12914 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12915 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12916 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12917 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12918 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12919 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12920 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12921 | struct sk_buff *msg; |
| 12922 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12923 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12924 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12925 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12926 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12927 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12928 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12929 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12930 | if (!msg) { |
| 12931 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12932 | return; |
| 12933 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12934 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12936 | if (!hdr) |
| 12937 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12938 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12939 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12940 | (freq && |
| 12941 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12942 | (sig_dbm && |
| 12943 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12944 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12945 | goto nla_put_failure; |
| 12946 | |
| 12947 | genlmsg_end(msg, hdr); |
| 12948 | |
| 12949 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12950 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12951 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12952 | return; |
| 12953 | |
| 12954 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12955 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12956 | if (hdr) |
| 12957 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12958 | nlmsg_free(msg); |
| 12959 | } |
| 12960 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12961 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12962 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12963 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12964 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12965 | { |
| 12966 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12967 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12968 | int i, j; |
| 12969 | |
| 12970 | nl_results = nla_nest_start( |
| 12971 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12972 | if (!nl_results) |
| 12973 | return -EMSGSIZE; |
| 12974 | |
| 12975 | for (i = 0; i < nd->n_matches; i++) { |
| 12976 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12977 | |
| 12978 | nl_match = nla_nest_start(msg, i); |
| 12979 | if (!nl_match) |
| 12980 | break; |
| 12981 | |
| 12982 | /* The SSID attribute is optional in nl80211, but for |
| 12983 | * simplicity reasons it's always present in the |
| 12984 | * cfg80211 structure. If a driver can't pass the |
| 12985 | * SSID, that needs to be changed. A zero length SSID |
| 12986 | * is still a valid SSID (wildcard), so it cannot be |
| 12987 | * used for this purpose. |
| 12988 | */ |
| 12989 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12990 | match->ssid.ssid)) { |
| 12991 | nla_nest_cancel(msg, nl_match); |
| 12992 | goto out; |
| 12993 | } |
| 12994 | |
| 12995 | if (match->n_channels) { |
| 12996 | nl_freqs = nla_nest_start( |
| 12997 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12998 | if (!nl_freqs) { |
| 12999 | nla_nest_cancel(msg, nl_match); |
| 13000 | goto out; |
| 13001 | } |
| 13002 | |
| 13003 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 13004 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13005 | nla_nest_cancel(msg, nl_freqs); |
| 13006 | nla_nest_cancel(msg, nl_match); |
| 13007 | goto out; |
| 13008 | } |
| 13009 | } |
| 13010 | |
| 13011 | nla_nest_end(msg, nl_freqs); |
| 13012 | } |
| 13013 | |
| 13014 | nla_nest_end(msg, nl_match); |
| 13015 | } |
| 13016 | |
| 13017 | out: |
| 13018 | nla_nest_end(msg, nl_results); |
| 13019 | return 0; |
| 13020 | } |
| 13021 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13022 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 13023 | struct cfg80211_wowlan_wakeup *wakeup, |
| 13024 | gfp_t gfp) |
| 13025 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13026 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13027 | struct sk_buff *msg; |
| 13028 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13029 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13030 | |
| 13031 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 13032 | |
| 13033 | if (wakeup) |
| 13034 | size += wakeup->packet_present_len; |
| 13035 | |
| 13036 | msg = nlmsg_new(size, gfp); |
| 13037 | if (!msg) |
| 13038 | return; |
| 13039 | |
| 13040 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 13041 | if (!hdr) |
| 13042 | goto free_msg; |
| 13043 | |
| 13044 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13045 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13046 | goto free_msg; |
| 13047 | |
| 13048 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13049 | wdev->netdev->ifindex)) |
| 13050 | goto free_msg; |
| 13051 | |
| 13052 | if (wakeup) { |
| 13053 | struct nlattr *reasons; |
| 13054 | |
| 13055 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 13056 | if (!reasons) |
| 13057 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13058 | |
| 13059 | if (wakeup->disconnect && |
| 13060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 13061 | goto free_msg; |
| 13062 | if (wakeup->magic_pkt && |
| 13063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 13064 | goto free_msg; |
| 13065 | if (wakeup->gtk_rekey_failure && |
| 13066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 13067 | goto free_msg; |
| 13068 | if (wakeup->eap_identity_req && |
| 13069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 13070 | goto free_msg; |
| 13071 | if (wakeup->four_way_handshake && |
| 13072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 13073 | goto free_msg; |
| 13074 | if (wakeup->rfkill_release && |
| 13075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 13076 | goto free_msg; |
| 13077 | |
| 13078 | if (wakeup->pattern_idx >= 0 && |
| 13079 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 13080 | wakeup->pattern_idx)) |
| 13081 | goto free_msg; |
| 13082 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13083 | if (wakeup->tcp_match && |
| 13084 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 13085 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13086 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13087 | if (wakeup->tcp_connlost && |
| 13088 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 13089 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13090 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13091 | if (wakeup->tcp_nomoretokens && |
| 13092 | nla_put_flag(msg, |
| 13093 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 13094 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13095 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13096 | if (wakeup->packet) { |
| 13097 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 13098 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 13099 | |
| 13100 | if (!wakeup->packet_80211) { |
| 13101 | pkt_attr = |
| 13102 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 13103 | len_attr = |
| 13104 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 13105 | } |
| 13106 | |
| 13107 | if (wakeup->packet_len && |
| 13108 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 13109 | goto free_msg; |
| 13110 | |
| 13111 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 13112 | wakeup->packet)) |
| 13113 | goto free_msg; |
| 13114 | } |
| 13115 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13116 | if (wakeup->net_detect && |
| 13117 | cfg80211_net_detect_results(msg, wakeup)) |
| 13118 | goto free_msg; |
| 13119 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13120 | nla_nest_end(msg, reasons); |
| 13121 | } |
| 13122 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13123 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13124 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13125 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13126 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13127 | return; |
| 13128 | |
| 13129 | free_msg: |
| 13130 | nlmsg_free(msg); |
| 13131 | } |
| 13132 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 13133 | #endif |
| 13134 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13135 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 13136 | enum nl80211_tdls_operation oper, |
| 13137 | u16 reason_code, gfp_t gfp) |
| 13138 | { |
| 13139 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13140 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13141 | struct sk_buff *msg; |
| 13142 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13143 | |
| 13144 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 13145 | reason_code); |
| 13146 | |
| 13147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13148 | if (!msg) |
| 13149 | return; |
| 13150 | |
| 13151 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 13152 | if (!hdr) { |
| 13153 | nlmsg_free(msg); |
| 13154 | return; |
| 13155 | } |
| 13156 | |
| 13157 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13158 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13159 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 13160 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 13161 | (reason_code > 0 && |
| 13162 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 13163 | goto nla_put_failure; |
| 13164 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13165 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13166 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13167 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13168 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13169 | return; |
| 13170 | |
| 13171 | nla_put_failure: |
| 13172 | genlmsg_cancel(msg, hdr); |
| 13173 | nlmsg_free(msg); |
| 13174 | } |
| 13175 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 13176 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13177 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 13178 | unsigned long state, |
| 13179 | void *_notify) |
| 13180 | { |
| 13181 | struct netlink_notify *notify = _notify; |
| 13182 | struct cfg80211_registered_device *rdev; |
| 13183 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13184 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13185 | |
| 13186 | if (state != NETLINK_URELEASE) |
| 13187 | return NOTIFY_DONE; |
| 13188 | |
| 13189 | rcu_read_lock(); |
| 13190 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13191 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13192 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13193 | bool schedule_scan_stop = false; |
| 13194 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 13195 | rcu_dereference(rdev->sched_scan_req); |
| 13196 | |
| 13197 | if (sched_scan_req && notify->portid && |
| 13198 | sched_scan_req->owner_nlportid == notify->portid) |
| 13199 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13200 | |
| 13201 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13202 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13203 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13204 | if (wdev->owner_nlportid == notify->portid) |
| 13205 | schedule_destroy_work = true; |
| 13206 | } |
| 13207 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13208 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13209 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 13210 | list) { |
| 13211 | if (reg->nlportid == notify->portid) { |
| 13212 | list_del(®->list); |
| 13213 | kfree(reg); |
| 13214 | break; |
| 13215 | } |
| 13216 | } |
| 13217 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13218 | |
| 13219 | if (schedule_destroy_work) { |
| 13220 | struct cfg80211_iface_destroy *destroy; |
| 13221 | |
| 13222 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 13223 | if (destroy) { |
| 13224 | destroy->nlportid = notify->portid; |
| 13225 | spin_lock(&rdev->destroy_list_lock); |
| 13226 | list_add(&destroy->list, &rdev->destroy_list); |
| 13227 | spin_unlock(&rdev->destroy_list_lock); |
| 13228 | schedule_work(&rdev->destroy_work); |
| 13229 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13230 | } else if (schedule_scan_stop) { |
| 13231 | sched_scan_req->owner_nlportid = 0; |
| 13232 | |
| 13233 | if (rdev->ops->sched_scan_stop && |
| 13234 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 13235 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13236 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13237 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13238 | |
| 13239 | rcu_read_unlock(); |
| 13240 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 13241 | /* |
| 13242 | * It is possible that the user space process that is controlling the |
| 13243 | * indoor setting disappeared, so notify the regulatory core. |
| 13244 | */ |
| 13245 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 13246 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13247 | } |
| 13248 | |
| 13249 | static struct notifier_block nl80211_netlink_notifier = { |
| 13250 | .notifier_call = nl80211_netlink_notify, |
| 13251 | }; |
| 13252 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13253 | void cfg80211_ft_event(struct net_device *netdev, |
| 13254 | struct cfg80211_ft_event_params *ft_event) |
| 13255 | { |
| 13256 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13257 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13258 | struct sk_buff *msg; |
| 13259 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13260 | |
| 13261 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 13262 | |
| 13263 | if (!ft_event->target_ap) |
| 13264 | return; |
| 13265 | |
| 13266 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13267 | if (!msg) |
| 13268 | return; |
| 13269 | |
| 13270 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13271 | if (!hdr) |
| 13272 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13273 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13274 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13275 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13276 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 13277 | goto out; |
| 13278 | |
| 13279 | if (ft_event->ies && |
| 13280 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 13281 | goto out; |
| 13282 | if (ft_event->ric_ies && |
| 13283 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 13284 | ft_event->ric_ies)) |
| 13285 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13286 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13287 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13288 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13289 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13290 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13291 | return; |
| 13292 | out: |
| 13293 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13294 | } |
| 13295 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 13296 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13297 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 13298 | { |
| 13299 | struct cfg80211_registered_device *rdev; |
| 13300 | struct sk_buff *msg; |
| 13301 | void *hdr; |
| 13302 | u32 nlportid; |
| 13303 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13304 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13305 | if (!rdev->crit_proto_nlportid) |
| 13306 | return; |
| 13307 | |
| 13308 | nlportid = rdev->crit_proto_nlportid; |
| 13309 | rdev->crit_proto_nlportid = 0; |
| 13310 | |
| 13311 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13312 | if (!msg) |
| 13313 | return; |
| 13314 | |
| 13315 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 13316 | if (!hdr) |
| 13317 | goto nla_put_failure; |
| 13318 | |
| 13319 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13320 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13321 | goto nla_put_failure; |
| 13322 | |
| 13323 | genlmsg_end(msg, hdr); |
| 13324 | |
| 13325 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 13326 | return; |
| 13327 | |
| 13328 | nla_put_failure: |
| 13329 | if (hdr) |
| 13330 | genlmsg_cancel(msg, hdr); |
| 13331 | nlmsg_free(msg); |
| 13332 | |
| 13333 | } |
| 13334 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 13335 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13336 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 13337 | { |
| 13338 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13339 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13340 | struct sk_buff *msg; |
| 13341 | void *hdr; |
| 13342 | |
| 13343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13344 | if (!msg) |
| 13345 | return; |
| 13346 | |
| 13347 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 13348 | if (!hdr) |
| 13349 | goto out; |
| 13350 | |
| 13351 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13352 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 13353 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 13354 | goto out; |
| 13355 | |
| 13356 | genlmsg_end(msg, hdr); |
| 13357 | |
| 13358 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 13359 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13360 | return; |
| 13361 | out: |
| 13362 | nlmsg_free(msg); |
| 13363 | } |
| 13364 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13365 | /* initialisation/exit functions */ |
| 13366 | |
| 13367 | int nl80211_init(void) |
| 13368 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 13369 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13370 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13371 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 13372 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13373 | if (err) |
| 13374 | return err; |
| 13375 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13376 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 13377 | if (err) |
| 13378 | goto err_out; |
| 13379 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13380 | return 0; |
| 13381 | err_out: |
| 13382 | genl_unregister_family(&nl80211_fam); |
| 13383 | return err; |
| 13384 | } |
| 13385 | |
| 13386 | void nl80211_exit(void) |
| 13387 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13388 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13389 | genl_unregister_family(&nl80211_fam); |
| 13390 | } |