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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | #include <linux/if_ether.h> |
| 14 | #include <linux/ieee80211.h> |
| 15 | #include <linux/nl80211.h> |
| 16 | #include <linux/rtnetlink.h> |
| 17 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 19 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 20 | #include <net/genetlink.h> |
| 21 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 22 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 23 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 26 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 27 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 28 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 30 | struct genl_info *info, |
| 31 | struct cfg80211_crypto_settings *settings, |
| 32 | int cipher_limit); |
| 33 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 34 | 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] | 35 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 36 | 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] | 37 | struct genl_info *info); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
| 40 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 43 | .hdrsize = 0, /* no private header */ |
| 44 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 45 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 46 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 47 | .pre_doit = nl80211_pre_doit, |
| 48 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 51 | /* multicast groups */ |
| 52 | enum nl80211_multicast_groups { |
| 53 | NL80211_MCGRP_CONFIG, |
| 54 | NL80211_MCGRP_SCAN, |
| 55 | NL80211_MCGRP_REGULATORY, |
| 56 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 59 | }; |
| 60 | |
| 61 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 69 | #endif |
| 70 | }; |
| 71 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 72 | /* returns ERR_PTR values */ |
| 73 | static struct wireless_dev * |
| 74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 76 | struct cfg80211_registered_device *rdev; |
| 77 | struct wireless_dev *result = NULL; |
| 78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 80 | u64 wdev_id; |
| 81 | int wiphy_idx = -1; |
| 82 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 83 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 84 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 86 | if (!have_ifidx && !have_wdev_id) |
| 87 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | if (have_ifidx) |
| 90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 91 | if (have_wdev_id) { |
| 92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 93 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 97 | struct wireless_dev *wdev; |
| 98 | |
| 99 | if (wiphy_net(&rdev->wiphy) != netns) |
| 100 | continue; |
| 101 | |
| 102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 103 | continue; |
| 104 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 106 | if (have_ifidx && wdev->netdev && |
| 107 | wdev->netdev->ifindex == ifidx) { |
| 108 | result = wdev; |
| 109 | break; |
| 110 | } |
| 111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 112 | result = wdev; |
| 113 | break; |
| 114 | } |
| 115 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 116 | |
| 117 | if (result) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | if (result) |
| 122 | return result; |
| 123 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 124 | } |
| 125 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 128 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 130 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 132 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 133 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | !attrs[NL80211_ATTR_IFINDEX] && |
| 136 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 137 | return ERR_PTR(-EINVAL); |
| 138 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 142 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 143 | if (attrs[NL80211_ATTR_WDEV]) { |
| 144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 145 | struct wireless_dev *wdev; |
| 146 | bool found = false; |
| 147 | |
| 148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 149 | if (tmp) { |
| 150 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 152 | if (wdev->identifier != (u32)wdev_id) |
| 153 | continue; |
| 154 | found = true; |
| 155 | break; |
| 156 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 157 | |
| 158 | if (!found) |
| 159 | tmp = NULL; |
| 160 | |
| 161 | if (rdev && tmp != rdev) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | rdev = tmp; |
| 164 | } |
| 165 | } |
| 166 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 169 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 170 | if (netdev) { |
| 171 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 172 | tmp = wiphy_to_rdev( |
| 173 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 174 | else |
| 175 | tmp = NULL; |
| 176 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 177 | /* not wireless device -- return error */ |
| 178 | if (!tmp) |
| 179 | return ERR_PTR(-EINVAL); |
| 180 | |
| 181 | /* mismatch -- return error */ |
| 182 | if (rdev && tmp != rdev) |
| 183 | return ERR_PTR(-EINVAL); |
| 184 | |
| 185 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 189 | if (!rdev) |
| 190 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 192 | if (netns != wiphy_net(&rdev->wiphy)) |
| 193 | return ERR_PTR(-ENODEV); |
| 194 | |
| 195 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* |
| 199 | * This function returns a pointer to the driver |
| 200 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | * |
| 202 | * The result of this can be a PTR_ERR and hence must |
| 203 | * be checked with IS_ERR() for errors. |
| 204 | */ |
| 205 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 207 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 211 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 215 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 217 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 223 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 230 | |
| 231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 234 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 240 | .len = WLAN_MAX_KEY_LEN }, |
| 241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 246 | |
| 247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
| 251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 257 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 267 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 272 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 277 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 279 | |
| 280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 282 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 285 | |
| 286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 287 | .len = IEEE80211_MAX_SSID_LEN }, |
| 288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_STA_FLAGS2] = { |
| 294 | .len = sizeof(struct nl80211_sta_flag_update), |
| 295 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 305 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
| 332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 345 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 349 | .len = NL80211_HT_CAPABILITY_LEN |
| 350 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 368 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 369 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 372 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 402 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 403 | }; |
| 404 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 405 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 406 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 407 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 409 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 410 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 411 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 412 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 413 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 414 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 415 | }; |
| 416 | |
| 417 | /* policy for the key default flags */ |
| 418 | static const struct nla_policy |
| 419 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 420 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 421 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 422 | }; |
| 423 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 424 | /* policy for WoWLAN attributes */ |
| 425 | static const struct nla_policy |
| 426 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 427 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 430 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 431 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 432 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 433 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 434 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 435 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 436 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | static const struct nla_policy |
| 440 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 441 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 442 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 443 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 444 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 445 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 448 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 449 | }, |
| 450 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 451 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 452 | }, |
| 453 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 454 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 455 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 456 | }; |
| 457 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 458 | /* policy for coalesce rule attributes */ |
| 459 | static const struct nla_policy |
| 460 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 461 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 462 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 463 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 464 | }; |
| 465 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 466 | /* policy for GTK rekey offload attributes */ |
| 467 | static const struct nla_policy |
| 468 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 469 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 470 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 471 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 472 | }; |
| 473 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 474 | static const struct nla_policy |
| 475 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 476 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 477 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 478 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 479 | }; |
| 480 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 481 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 482 | struct netlink_callback *cb, |
| 483 | struct cfg80211_registered_device **rdev, |
| 484 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 485 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 486 | int err; |
| 487 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 488 | rtnl_lock(); |
| 489 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 490 | if (!cb->args[0]) { |
| 491 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 492 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 493 | nl80211_policy); |
| 494 | if (err) |
| 495 | goto out_unlock; |
| 496 | |
| 497 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 498 | nl80211_fam.attrbuf); |
| 499 | if (IS_ERR(*wdev)) { |
| 500 | err = PTR_ERR(*wdev); |
| 501 | goto out_unlock; |
| 502 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 503 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 504 | /* 0 is the first index - add 1 to parse only once */ |
| 505 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | cb->args[1] = (*wdev)->identifier; |
| 507 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 508 | /* subtract the 1 again here */ |
| 509 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 510 | struct wireless_dev *tmp; |
| 511 | |
| 512 | if (!wiphy) { |
| 513 | err = -ENODEV; |
| 514 | goto out_unlock; |
| 515 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 516 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 517 | *wdev = NULL; |
| 518 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 519 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 520 | if (tmp->identifier == cb->args[1]) { |
| 521 | *wdev = tmp; |
| 522 | break; |
| 523 | } |
| 524 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 525 | |
| 526 | if (!*wdev) { |
| 527 | err = -ENODEV; |
| 528 | goto out_unlock; |
| 529 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 532 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 533 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 534 | rtnl_unlock(); |
| 535 | return err; |
| 536 | } |
| 537 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 538 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 539 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 540 | rtnl_unlock(); |
| 541 | } |
| 542 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 543 | /* IE validation */ |
| 544 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 545 | { |
| 546 | const u8 *pos; |
| 547 | int len; |
| 548 | |
| 549 | if (!attr) |
| 550 | return true; |
| 551 | |
| 552 | pos = nla_data(attr); |
| 553 | len = nla_len(attr); |
| 554 | |
| 555 | while (len) { |
| 556 | u8 elemlen; |
| 557 | |
| 558 | if (len < 2) |
| 559 | return false; |
| 560 | len -= 2; |
| 561 | |
| 562 | elemlen = pos[1]; |
| 563 | if (elemlen > len) |
| 564 | return false; |
| 565 | |
| 566 | len -= elemlen; |
| 567 | pos += 2 + elemlen; |
| 568 | } |
| 569 | |
| 570 | return true; |
| 571 | } |
| 572 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 573 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 574 | 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] | 575 | int flags, u8 cmd) |
| 576 | { |
| 577 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 578 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 579 | } |
| 580 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 581 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 582 | struct ieee80211_channel *chan, |
| 583 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 584 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 585 | /* Some channels must be completely excluded from the |
| 586 | * list to protect old user-space tools from breaking |
| 587 | */ |
| 588 | if (!large && chan->flags & |
| 589 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 590 | return 0; |
| 591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 593 | chan->center_freq)) |
| 594 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 595 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 596 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 597 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 598 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 599 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 601 | goto nla_put_failure; |
| 602 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 603 | goto nla_put_failure; |
| 604 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 605 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 606 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 607 | goto nla_put_failure; |
| 608 | if (large) { |
| 609 | u32 time; |
| 610 | |
| 611 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 612 | |
| 613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 614 | chan->dfs_state)) |
| 615 | goto nla_put_failure; |
| 616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 617 | time)) |
| 618 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 619 | if (nla_put_u32(msg, |
| 620 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 621 | chan->dfs_cac_ms)) |
| 622 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 623 | } |
| 624 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 625 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 626 | if (large) { |
| 627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 629 | goto nla_put_failure; |
| 630 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 632 | goto nla_put_failure; |
| 633 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 635 | goto nla_put_failure; |
| 636 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 638 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 639 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 641 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 642 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 644 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 645 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 647 | goto nla_put_failure; |
| 648 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 649 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 650 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 651 | } |
| 652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 653 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 654 | DBM_TO_MBM(chan->max_power))) |
| 655 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 656 | |
| 657 | return 0; |
| 658 | |
| 659 | nla_put_failure: |
| 660 | return -ENOBUFS; |
| 661 | } |
| 662 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | /* netlink command implementations */ |
| 664 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 665 | struct key_parse { |
| 666 | struct key_params p; |
| 667 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 668 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 669 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 670 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 674 | { |
| 675 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 676 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 677 | nl80211_key_policy); |
| 678 | if (err) |
| 679 | return err; |
| 680 | |
| 681 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 682 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 683 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 684 | if (k->def) { |
| 685 | k->def_uni = true; |
| 686 | k->def_multi = true; |
| 687 | } |
| 688 | if (k->defmgmt) |
| 689 | k->def_multi = true; |
| 690 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 691 | if (tb[NL80211_KEY_IDX]) |
| 692 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 693 | |
| 694 | if (tb[NL80211_KEY_DATA]) { |
| 695 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 696 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 697 | } |
| 698 | |
| 699 | if (tb[NL80211_KEY_SEQ]) { |
| 700 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 701 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 702 | } |
| 703 | |
| 704 | if (tb[NL80211_KEY_CIPHER]) |
| 705 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 706 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 707 | if (tb[NL80211_KEY_TYPE]) { |
| 708 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 709 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 710 | return -EINVAL; |
| 711 | } |
| 712 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 713 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 714 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 715 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 716 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 717 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 718 | if (err) |
| 719 | return err; |
| 720 | |
| 721 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 722 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 723 | } |
| 724 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 729 | { |
| 730 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 731 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 732 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 733 | } |
| 734 | |
| 735 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 736 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 737 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 738 | } |
| 739 | |
| 740 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 741 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 742 | |
| 743 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 744 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 745 | |
| 746 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 747 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 748 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 749 | if (k->def) { |
| 750 | k->def_uni = true; |
| 751 | k->def_multi = true; |
| 752 | } |
| 753 | if (k->defmgmt) |
| 754 | k->def_multi = true; |
| 755 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 756 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 757 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 758 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 759 | return -EINVAL; |
| 760 | } |
| 761 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 762 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 763 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 764 | int err = nla_parse_nested( |
| 765 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 766 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 767 | nl80211_key_default_policy); |
| 768 | if (err) |
| 769 | return err; |
| 770 | |
| 771 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 772 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 773 | } |
| 774 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 779 | { |
| 780 | int err; |
| 781 | |
| 782 | memset(k, 0, sizeof(*k)); |
| 783 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 784 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 785 | |
| 786 | if (info->attrs[NL80211_ATTR_KEY]) |
| 787 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 788 | else |
| 789 | err = nl80211_parse_key_old(info, k); |
| 790 | |
| 791 | if (err) |
| 792 | return err; |
| 793 | |
| 794 | if (k->def && k->defmgmt) |
| 795 | return -EINVAL; |
| 796 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 797 | if (k->defmgmt) { |
| 798 | if (k->def_uni || !k->def_multi) |
| 799 | return -EINVAL; |
| 800 | } |
| 801 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 802 | if (k->idx != -1) { |
| 803 | if (k->defmgmt) { |
| 804 | if (k->idx < 4 || k->idx > 5) |
| 805 | return -EINVAL; |
| 806 | } else if (k->def) { |
| 807 | if (k->idx < 0 || k->idx > 3) |
| 808 | return -EINVAL; |
| 809 | } else { |
| 810 | if (k->idx < 0 || k->idx > 5) |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | static struct cfg80211_cached_keys * |
| 819 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 820 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | { |
| 822 | struct key_parse parse; |
| 823 | struct nlattr *key; |
| 824 | struct cfg80211_cached_keys *result; |
| 825 | int rem, err, def = 0; |
| 826 | |
| 827 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 828 | if (!result) |
| 829 | return ERR_PTR(-ENOMEM); |
| 830 | |
| 831 | result->def = -1; |
| 832 | result->defmgmt = -1; |
| 833 | |
| 834 | nla_for_each_nested(key, keys, rem) { |
| 835 | memset(&parse, 0, sizeof(parse)); |
| 836 | parse.idx = -1; |
| 837 | |
| 838 | err = nl80211_parse_key_new(key, &parse); |
| 839 | if (err) |
| 840 | goto error; |
| 841 | err = -EINVAL; |
| 842 | if (!parse.p.key) |
| 843 | goto error; |
| 844 | if (parse.idx < 0 || parse.idx > 4) |
| 845 | goto error; |
| 846 | if (parse.def) { |
| 847 | if (def) |
| 848 | goto error; |
| 849 | def = 1; |
| 850 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 851 | if (!parse.def_uni || !parse.def_multi) |
| 852 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 853 | } else if (parse.defmgmt) |
| 854 | goto error; |
| 855 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 856 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 857 | if (err) |
| 858 | goto error; |
| 859 | result->params[parse.idx].cipher = parse.p.cipher; |
| 860 | result->params[parse.idx].key_len = parse.p.key_len; |
| 861 | result->params[parse.idx].key = result->data[parse.idx]; |
| 862 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 863 | |
| 864 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 865 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 866 | if (no_ht) |
| 867 | *no_ht = true; |
| 868 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | return result; |
| 872 | error: |
| 873 | kfree(result); |
| 874 | return ERR_PTR(err); |
| 875 | } |
| 876 | |
| 877 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 878 | { |
| 879 | ASSERT_WDEV_LOCK(wdev); |
| 880 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 881 | switch (wdev->iftype) { |
| 882 | case NL80211_IFTYPE_AP: |
| 883 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 884 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 885 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 886 | break; |
| 887 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 888 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 889 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 890 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 891 | return -ENOLINK; |
| 892 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 893 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 894 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 895 | case NL80211_IFTYPE_MONITOR: |
| 896 | case NL80211_IFTYPE_P2P_DEVICE: |
| 897 | case NL80211_IFTYPE_WDS: |
| 898 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 899 | return -EINVAL; |
| 900 | } |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 905 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 906 | struct nlattr *tb) |
| 907 | { |
| 908 | struct ieee80211_channel *chan; |
| 909 | |
| 910 | if (tb == NULL) |
| 911 | return NULL; |
| 912 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 913 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 914 | return NULL; |
| 915 | return chan; |
| 916 | } |
| 917 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 918 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 919 | { |
| 920 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 921 | int i; |
| 922 | |
| 923 | if (!nl_modes) |
| 924 | goto nla_put_failure; |
| 925 | |
| 926 | i = 0; |
| 927 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 928 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 929 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 930 | ifmodes >>= 1; |
| 931 | i++; |
| 932 | } |
| 933 | |
| 934 | nla_nest_end(msg, nl_modes); |
| 935 | return 0; |
| 936 | |
| 937 | nla_put_failure: |
| 938 | return -ENOBUFS; |
| 939 | } |
| 940 | |
| 941 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 942 | struct sk_buff *msg, |
| 943 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 944 | { |
| 945 | struct nlattr *nl_combis; |
| 946 | int i, j; |
| 947 | |
| 948 | nl_combis = nla_nest_start(msg, |
| 949 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 950 | if (!nl_combis) |
| 951 | goto nla_put_failure; |
| 952 | |
| 953 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 954 | const struct ieee80211_iface_combination *c; |
| 955 | struct nlattr *nl_combi, *nl_limits; |
| 956 | |
| 957 | c = &wiphy->iface_combinations[i]; |
| 958 | |
| 959 | nl_combi = nla_nest_start(msg, i + 1); |
| 960 | if (!nl_combi) |
| 961 | goto nla_put_failure; |
| 962 | |
| 963 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 964 | if (!nl_limits) |
| 965 | goto nla_put_failure; |
| 966 | |
| 967 | for (j = 0; j < c->n_limits; j++) { |
| 968 | struct nlattr *nl_limit; |
| 969 | |
| 970 | nl_limit = nla_nest_start(msg, j + 1); |
| 971 | if (!nl_limit) |
| 972 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 973 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 974 | c->limits[j].max)) |
| 975 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 976 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 977 | c->limits[j].types)) |
| 978 | goto nla_put_failure; |
| 979 | nla_nest_end(msg, nl_limit); |
| 980 | } |
| 981 | |
| 982 | nla_nest_end(msg, nl_limits); |
| 983 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 984 | if (c->beacon_int_infra_match && |
| 985 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 986 | goto nla_put_failure; |
| 987 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 988 | c->num_different_channels) || |
| 989 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 990 | c->max_interfaces)) |
| 991 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 992 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 993 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 994 | c->radar_detect_widths) || |
| 995 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 996 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 997 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 998 | |
| 999 | nla_nest_end(msg, nl_combi); |
| 1000 | } |
| 1001 | |
| 1002 | nla_nest_end(msg, nl_combis); |
| 1003 | |
| 1004 | return 0; |
| 1005 | nla_put_failure: |
| 1006 | return -ENOBUFS; |
| 1007 | } |
| 1008 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1009 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1010 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1011 | struct sk_buff *msg) |
| 1012 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1013 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1014 | struct nlattr *nl_tcp; |
| 1015 | |
| 1016 | if (!tcp) |
| 1017 | return 0; |
| 1018 | |
| 1019 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1020 | if (!nl_tcp) |
| 1021 | return -ENOBUFS; |
| 1022 | |
| 1023 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1024 | tcp->data_payload_max)) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1028 | tcp->data_payload_max)) |
| 1029 | return -ENOBUFS; |
| 1030 | |
| 1031 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1032 | return -ENOBUFS; |
| 1033 | |
| 1034 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1035 | sizeof(*tcp->tok), tcp->tok)) |
| 1036 | return -ENOBUFS; |
| 1037 | |
| 1038 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1039 | tcp->data_interval_max)) |
| 1040 | return -ENOBUFS; |
| 1041 | |
| 1042 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1043 | tcp->wake_payload_max)) |
| 1044 | return -ENOBUFS; |
| 1045 | |
| 1046 | nla_nest_end(msg, nl_tcp); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1051 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1052 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1053 | { |
| 1054 | struct nlattr *nl_wowlan; |
| 1055 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1056 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1057 | return 0; |
| 1058 | |
| 1059 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1060 | if (!nl_wowlan) |
| 1061 | return -ENOBUFS; |
| 1062 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1075 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1077 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1079 | return -ENOBUFS; |
| 1080 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1081 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1082 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1083 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1084 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1085 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1086 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1087 | }; |
| 1088 | |
| 1089 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1090 | sizeof(pat), &pat)) |
| 1091 | return -ENOBUFS; |
| 1092 | } |
| 1093 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1094 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1095 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1096 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1097 | return -ENOBUFS; |
| 1098 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1099 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1100 | return -ENOBUFS; |
| 1101 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1102 | nla_nest_end(msg, nl_wowlan); |
| 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | #endif |
| 1107 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1108 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1109 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1110 | { |
| 1111 | struct nl80211_coalesce_rule_support rule; |
| 1112 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1113 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1114 | return 0; |
| 1115 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1116 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1117 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1118 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1119 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1120 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1121 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1122 | |
| 1123 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1124 | return -ENOBUFS; |
| 1125 | |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1129 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1130 | struct ieee80211_supported_band *sband) |
| 1131 | { |
| 1132 | struct nlattr *nl_rates, *nl_rate; |
| 1133 | struct ieee80211_rate *rate; |
| 1134 | int i; |
| 1135 | |
| 1136 | /* add HT info */ |
| 1137 | if (sband->ht_cap.ht_supported && |
| 1138 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1139 | sizeof(sband->ht_cap.mcs), |
| 1140 | &sband->ht_cap.mcs) || |
| 1141 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1142 | sband->ht_cap.cap) || |
| 1143 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1144 | sband->ht_cap.ampdu_factor) || |
| 1145 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1146 | sband->ht_cap.ampdu_density))) |
| 1147 | return -ENOBUFS; |
| 1148 | |
| 1149 | /* add VHT info */ |
| 1150 | if (sband->vht_cap.vht_supported && |
| 1151 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1152 | sizeof(sband->vht_cap.vht_mcs), |
| 1153 | &sband->vht_cap.vht_mcs) || |
| 1154 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1155 | sband->vht_cap.cap))) |
| 1156 | return -ENOBUFS; |
| 1157 | |
| 1158 | /* add bitrates */ |
| 1159 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1160 | if (!nl_rates) |
| 1161 | return -ENOBUFS; |
| 1162 | |
| 1163 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1164 | nl_rate = nla_nest_start(msg, i); |
| 1165 | if (!nl_rate) |
| 1166 | return -ENOBUFS; |
| 1167 | |
| 1168 | rate = &sband->bitrates[i]; |
| 1169 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1170 | rate->bitrate)) |
| 1171 | return -ENOBUFS; |
| 1172 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1173 | nla_put_flag(msg, |
| 1174 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1175 | return -ENOBUFS; |
| 1176 | |
| 1177 | nla_nest_end(msg, nl_rate); |
| 1178 | } |
| 1179 | |
| 1180 | nla_nest_end(msg, nl_rates); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int |
| 1186 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1187 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1188 | { |
| 1189 | u16 stypes; |
| 1190 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1191 | enum nl80211_iftype ift; |
| 1192 | int i; |
| 1193 | |
| 1194 | if (!mgmt_stypes) |
| 1195 | return 0; |
| 1196 | |
| 1197 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1198 | if (!nl_ifs) |
| 1199 | return -ENOBUFS; |
| 1200 | |
| 1201 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1202 | nl_ftypes = nla_nest_start(msg, ift); |
| 1203 | if (!nl_ftypes) |
| 1204 | return -ENOBUFS; |
| 1205 | i = 0; |
| 1206 | stypes = mgmt_stypes[ift].tx; |
| 1207 | while (stypes) { |
| 1208 | if ((stypes & 1) && |
| 1209 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1210 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1211 | return -ENOBUFS; |
| 1212 | stypes >>= 1; |
| 1213 | i++; |
| 1214 | } |
| 1215 | nla_nest_end(msg, nl_ftypes); |
| 1216 | } |
| 1217 | |
| 1218 | nla_nest_end(msg, nl_ifs); |
| 1219 | |
| 1220 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1221 | if (!nl_ifs) |
| 1222 | return -ENOBUFS; |
| 1223 | |
| 1224 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1225 | nl_ftypes = nla_nest_start(msg, ift); |
| 1226 | if (!nl_ftypes) |
| 1227 | return -ENOBUFS; |
| 1228 | i = 0; |
| 1229 | stypes = mgmt_stypes[ift].rx; |
| 1230 | while (stypes) { |
| 1231 | if ((stypes & 1) && |
| 1232 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1233 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1234 | return -ENOBUFS; |
| 1235 | stypes >>= 1; |
| 1236 | i++; |
| 1237 | } |
| 1238 | nla_nest_end(msg, nl_ftypes); |
| 1239 | } |
| 1240 | nla_nest_end(msg, nl_ifs); |
| 1241 | |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1245 | struct nl80211_dump_wiphy_state { |
| 1246 | s64 filter_wiphy; |
| 1247 | long start; |
| 1248 | long split_start, band_start, chan_start; |
| 1249 | bool split; |
| 1250 | }; |
| 1251 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1252 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1253 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1254 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1255 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1256 | { |
| 1257 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1258 | struct nlattr *nl_bands, *nl_band; |
| 1259 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1260 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1261 | enum ieee80211_band band; |
| 1262 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1263 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1264 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1265 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1266 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1267 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1268 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1269 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | return -ENOBUFS; |
| 1271 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1272 | if (WARN_ON(!state)) |
| 1273 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1274 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1275 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1276 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1278 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1280 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1281 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1282 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1283 | goto finish; |
| 1284 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1285 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | case 0: |
| 1287 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1291 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1294 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1304 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1307 | goto nla_put_failure; |
| 1308 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1311 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1312 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1314 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1317 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1318 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1320 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1323 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1324 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1325 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1326 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1327 | state->split_start++; |
| 1328 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | break; |
| 1330 | case 1: |
| 1331 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1332 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1333 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1334 | goto nla_put_failure; |
| 1335 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1336 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1337 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1338 | goto nla_put_failure; |
| 1339 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1340 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1342 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1343 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1345 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1347 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1348 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1349 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1350 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1352 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1354 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1355 | if ((rdev->wiphy.available_antennas_tx || |
| 1356 | rdev->wiphy.available_antennas_rx) && |
| 1357 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | u32 tx_ant = 0, rx_ant = 0; |
| 1359 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1360 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | if (!res) { |
| 1362 | if (nla_put_u32(msg, |
| 1363 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1364 | tx_ant) || |
| 1365 | nla_put_u32(msg, |
| 1366 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1367 | rx_ant)) |
| 1368 | goto nla_put_failure; |
| 1369 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1372 | state->split_start++; |
| 1373 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | break; |
| 1375 | case 2: |
| 1376 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1377 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1379 | state->split_start++; |
| 1380 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1381 | break; |
| 1382 | case 3: |
| 1383 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1384 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1385 | goto nla_put_failure; |
| 1386 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1387 | for (band = state->band_start; |
| 1388 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1389 | struct ieee80211_supported_band *sband; |
| 1390 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1391 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1392 | |
| 1393 | if (!sband) |
| 1394 | continue; |
| 1395 | |
| 1396 | nl_band = nla_nest_start(msg, band); |
| 1397 | if (!nl_band) |
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 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1401 | case 0: |
| 1402 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1403 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1404 | state->chan_start++; |
| 1405 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | default: |
| 1408 | /* add frequencies */ |
| 1409 | nl_freqs = nla_nest_start( |
| 1410 | msg, NL80211_BAND_ATTR_FREQS); |
| 1411 | if (!nl_freqs) |
| 1412 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1413 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1414 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1415 | i < sband->n_channels; |
| 1416 | i++) { |
| 1417 | nl_freq = nla_nest_start(msg, i); |
| 1418 | if (!nl_freq) |
| 1419 | goto nla_put_failure; |
| 1420 | |
| 1421 | chan = &sband->channels[i]; |
| 1422 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1423 | if (nl80211_msg_put_channel( |
| 1424 | msg, chan, |
| 1425 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | goto nla_put_failure; |
| 1427 | |
| 1428 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1429 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1430 | break; |
| 1431 | } |
| 1432 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1433 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | nla_nest_end(msg, nl_freqs); |
| 1437 | } |
| 1438 | |
| 1439 | nla_nest_end(msg, nl_band); |
| 1440 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1441 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1443 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | band--; |
| 1445 | break; |
| 1446 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1447 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1449 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1451 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1453 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1454 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1455 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1456 | if (state->band_start == 0 && state->chan_start == 0) |
| 1457 | state->split_start++; |
| 1458 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1459 | break; |
| 1460 | case 4: |
| 1461 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1462 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1463 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | |
| 1465 | i = 0; |
| 1466 | #define CMD(op, n) \ |
| 1467 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1468 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | i++; \ |
| 1470 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1471 | goto nla_put_failure; \ |
| 1472 | } \ |
| 1473 | } while (0) |
| 1474 | |
| 1475 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1476 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1477 | CMD(add_key, NEW_KEY); |
| 1478 | CMD(start_ap, START_AP); |
| 1479 | CMD(add_station, NEW_STATION); |
| 1480 | CMD(add_mpath, NEW_MPATH); |
| 1481 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1482 | CMD(change_bss, SET_BSS); |
| 1483 | CMD(auth, AUTHENTICATE); |
| 1484 | CMD(assoc, ASSOCIATE); |
| 1485 | CMD(deauth, DEAUTHENTICATE); |
| 1486 | CMD(disassoc, DISASSOCIATE); |
| 1487 | CMD(join_ibss, JOIN_IBSS); |
| 1488 | CMD(join_mesh, JOIN_MESH); |
| 1489 | CMD(set_pmksa, SET_PMKSA); |
| 1490 | CMD(del_pmksa, DEL_PMKSA); |
| 1491 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1492 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1494 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1495 | CMD(mgmt_tx, FRAME); |
| 1496 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1497 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | i++; |
| 1499 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1500 | goto nla_put_failure; |
| 1501 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1503 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1504 | i++; |
| 1505 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1506 | goto nla_put_failure; |
| 1507 | } |
| 1508 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1509 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1511 | CMD(tdls_oper, TDLS_OPER); |
| 1512 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1513 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1515 | CMD(probe_client, PROBE_CLIENT); |
| 1516 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1517 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | i++; |
| 1519 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1520 | goto nla_put_failure; |
| 1521 | } |
| 1522 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1523 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1524 | #ifdef CONFIG_NL80211_TESTMODE |
| 1525 | CMD(testmode_cmd, TESTMODE); |
| 1526 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1527 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1528 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1529 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1530 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1531 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1532 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1533 | if (rdev->wiphy.features & |
| 1534 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1535 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1536 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1537 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1538 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1539 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1540 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | i++; |
| 1542 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1543 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1546 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1547 | i++; |
| 1548 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1549 | goto nla_put_failure; |
| 1550 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1551 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1553 | state->split_start++; |
| 1554 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1555 | break; |
| 1556 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1557 | if (rdev->ops->remain_on_channel && |
| 1558 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | nla_put_u32(msg, |
| 1560 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1561 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1562 | goto nla_put_failure; |
| 1563 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1564 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1566 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1567 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1569 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1570 | state->split_start++; |
| 1571 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | break; |
| 1573 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1574 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1575 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1576 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1577 | state->split_start++; |
| 1578 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1579 | break; |
| 1580 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1581 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | #endif |
| 1583 | case 7: |
| 1584 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1586 | goto nla_put_failure; |
| 1587 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1589 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1591 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1592 | state->split_start++; |
| 1593 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | break; |
| 1595 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1596 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1598 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1599 | goto nla_put_failure; |
| 1600 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1601 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1602 | /* |
| 1603 | * We can only add the per-channel limit information if the |
| 1604 | * dump is split, otherwise it makes it too big. Therefore |
| 1605 | * only advertise it in that case. |
| 1606 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1607 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1608 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1609 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1610 | goto nla_put_failure; |
| 1611 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1612 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1614 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1615 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | goto nla_put_failure; |
| 1617 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1618 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1619 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1620 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1621 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | goto nla_put_failure; |
| 1623 | |
| 1624 | /* |
| 1625 | * Any information below this point is only available to |
| 1626 | * applications that can deal with it being split. This |
| 1627 | * helps ensure that newly added capabilities don't break |
| 1628 | * older tools by overrunning their buffers. |
| 1629 | * |
| 1630 | * We still increment split_start so that in the split |
| 1631 | * case we'll continue with more data in the next round, |
| 1632 | * but break unconditionally so unsplit data stops here. |
| 1633 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1634 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1635 | break; |
| 1636 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1637 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1638 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1639 | rdev->wiphy.extended_capabilities_len, |
| 1640 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1641 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1642 | rdev->wiphy.extended_capabilities_len, |
| 1643 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1644 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1647 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1648 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1649 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1650 | goto nla_put_failure; |
| 1651 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1652 | state->split_start++; |
| 1653 | break; |
| 1654 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1655 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1656 | goto nla_put_failure; |
| 1657 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1658 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1659 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1660 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1661 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1662 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1663 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1664 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1665 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1666 | goto nla_put_failure; |
| 1667 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1668 | state->split_start++; |
| 1669 | break; |
| 1670 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1672 | const struct nl80211_vendor_cmd_info *info; |
| 1673 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1674 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1675 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1676 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1677 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1678 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1680 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1681 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1682 | goto nla_put_failure; |
| 1683 | } |
| 1684 | nla_nest_end(msg, nested); |
| 1685 | } |
| 1686 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1687 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1688 | const struct nl80211_vendor_cmd_info *info; |
| 1689 | struct nlattr *nested; |
| 1690 | |
| 1691 | nested = nla_nest_start(msg, |
| 1692 | NL80211_ATTR_VENDOR_EVENTS); |
| 1693 | if (!nested) |
| 1694 | goto nla_put_failure; |
| 1695 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1696 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1697 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1698 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1699 | goto nla_put_failure; |
| 1700 | } |
| 1701 | nla_nest_end(msg, nested); |
| 1702 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1703 | state->split_start++; |
| 1704 | break; |
| 1705 | case 12: |
| 1706 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1707 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1708 | rdev->wiphy.max_num_csa_counters)) |
| 1709 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1710 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1711 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1712 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1713 | goto nla_put_failure; |
| 1714 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1715 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1716 | sizeof(rdev->wiphy.ext_features), |
| 1717 | rdev->wiphy.ext_features)) |
| 1718 | goto nla_put_failure; |
| 1719 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1720 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1721 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1722 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1723 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1724 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1725 | genlmsg_end(msg, hdr); |
| 1726 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1727 | |
| 1728 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1729 | genlmsg_cancel(msg, hdr); |
| 1730 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1731 | } |
| 1732 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1733 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1734 | struct netlink_callback *cb, |
| 1735 | struct nl80211_dump_wiphy_state *state) |
| 1736 | { |
| 1737 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1738 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1739 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1740 | /* ignore parse errors for backward compatibility */ |
| 1741 | if (ret) |
| 1742 | return 0; |
| 1743 | |
| 1744 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1745 | if (tb[NL80211_ATTR_WIPHY]) |
| 1746 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1747 | if (tb[NL80211_ATTR_WDEV]) |
| 1748 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1749 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1750 | struct net_device *netdev; |
| 1751 | struct cfg80211_registered_device *rdev; |
| 1752 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1753 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1754 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1755 | if (!netdev) |
| 1756 | return -ENODEV; |
| 1757 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1758 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1759 | netdev->ieee80211_ptr->wiphy); |
| 1760 | state->filter_wiphy = rdev->wiphy_idx; |
| 1761 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1767 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1768 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1769 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1770 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1771 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1772 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1773 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1774 | if (!state) { |
| 1775 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1776 | if (!state) { |
| 1777 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1778 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1779 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1780 | state->filter_wiphy = -1; |
| 1781 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1782 | if (ret) { |
| 1783 | kfree(state); |
| 1784 | rtnl_unlock(); |
| 1785 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1786 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1787 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1790 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1791 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1792 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1793 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1794 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1795 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1796 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1797 | continue; |
| 1798 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1799 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1800 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1801 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1802 | NETLINK_CB(cb->skb).portid, |
| 1803 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1804 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1805 | if (ret < 0) { |
| 1806 | /* |
| 1807 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1808 | * or EMSGSIZE returned), this SKB is still |
| 1809 | * empty (so it's not too big because another |
| 1810 | * wiphy dataset is already in the skb) and |
| 1811 | * we've not tried to adjust the dump allocation |
| 1812 | * yet ... then adjust the alloc size to be |
| 1813 | * bigger, and return 1 but with the empty skb. |
| 1814 | * This results in an empty message being RX'ed |
| 1815 | * in userspace, but that is ignored. |
| 1816 | * |
| 1817 | * We can then retry with the larger buffer. |
| 1818 | */ |
| 1819 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1820 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1821 | cb->min_dump_alloc < 4096) { |
| 1822 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1823 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1824 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1825 | return 1; |
| 1826 | } |
| 1827 | idx--; |
| 1828 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1829 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1830 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1831 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1832 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1833 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1835 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1836 | |
| 1837 | return skb->len; |
| 1838 | } |
| 1839 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1840 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1841 | { |
| 1842 | kfree((void *)cb->args[0]); |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1846 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1847 | { |
| 1848 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1850 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1851 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1852 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1853 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1854 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1855 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1856 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1857 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1858 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1859 | nlmsg_free(msg); |
| 1860 | return -ENOBUFS; |
| 1861 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1862 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1863 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1866 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1867 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1868 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1869 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1870 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1871 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1872 | }; |
| 1873 | |
| 1874 | static int parse_txq_params(struct nlattr *tb[], |
| 1875 | struct ieee80211_txq_params *txq_params) |
| 1876 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1877 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1878 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1879 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1880 | return -EINVAL; |
| 1881 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1882 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1883 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1884 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1885 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1886 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1887 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1888 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1889 | return -EINVAL; |
| 1890 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1891 | return 0; |
| 1892 | } |
| 1893 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1894 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1895 | { |
| 1896 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1897 | * You can only set the channel explicitly for WDS interfaces, |
| 1898 | * all others have their channel managed via their respective |
| 1899 | * "establish a connection" command (connect, join, ...) |
| 1900 | * |
| 1901 | * For AP/GO and mesh mode, the channel can be set with the |
| 1902 | * channel userspace API, but is only stored and passed to the |
| 1903 | * low-level driver when the AP starts or the mesh is joined. |
| 1904 | * This is for backward compatibility, userspace can also give |
| 1905 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1906 | * |
| 1907 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1908 | * whatever else is going on, so they have their own special |
| 1909 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1910 | */ |
| 1911 | return !wdev || |
| 1912 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1913 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1914 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1915 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1916 | } |
| 1917 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1918 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1919 | struct genl_info *info, |
| 1920 | struct cfg80211_chan_def *chandef) |
| 1921 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1922 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1923 | |
| 1924 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1925 | return -EINVAL; |
| 1926 | |
| 1927 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1928 | |
| 1929 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1930 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1931 | chandef->center_freq1 = control_freq; |
| 1932 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1933 | |
| 1934 | /* Primary channel not allowed */ |
| 1935 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1936 | return -EINVAL; |
| 1937 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1938 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1939 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1940 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1941 | chantype = nla_get_u32( |
| 1942 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1943 | |
| 1944 | switch (chantype) { |
| 1945 | case NL80211_CHAN_NO_HT: |
| 1946 | case NL80211_CHAN_HT20: |
| 1947 | case NL80211_CHAN_HT40PLUS: |
| 1948 | case NL80211_CHAN_HT40MINUS: |
| 1949 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1950 | chantype); |
| 1951 | break; |
| 1952 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1953 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1954 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1955 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1956 | chandef->width = |
| 1957 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1958 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1959 | chandef->center_freq1 = |
| 1960 | nla_get_u32( |
| 1961 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1962 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1963 | chandef->center_freq2 = |
| 1964 | nla_get_u32( |
| 1965 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1966 | } |
| 1967 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1968 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1969 | return -EINVAL; |
| 1970 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1971 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1972 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1973 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1974 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1975 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1976 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1977 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1978 | return -EINVAL; |
| 1979 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1980 | return 0; |
| 1981 | } |
| 1982 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1983 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1984 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1985 | struct genl_info *info) |
| 1986 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1987 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1988 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1989 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1990 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1991 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1992 | if (dev) |
| 1993 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1994 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1995 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1996 | if (wdev) |
| 1997 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1998 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1999 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2000 | if (result) |
| 2001 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2003 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2004 | case NL80211_IFTYPE_AP: |
| 2005 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2006 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2007 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2008 | result = -EINVAL; |
| 2009 | break; |
| 2010 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2011 | if (wdev->beacon_interval) { |
| 2012 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2013 | !(rdev->wiphy.features & |
| 2014 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2015 | result = -EBUSY; |
| 2016 | break; |
| 2017 | } |
| 2018 | |
| 2019 | /* Only allow dynamic channel width changes */ |
| 2020 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2021 | result = -EBUSY; |
| 2022 | break; |
| 2023 | } |
| 2024 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2025 | if (result) |
| 2026 | break; |
| 2027 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2028 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2029 | result = 0; |
| 2030 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2031 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2032 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2033 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2034 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2035 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2036 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2037 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2038 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2039 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2040 | |
| 2041 | return result; |
| 2042 | } |
| 2043 | |
| 2044 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2045 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2047 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2048 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2049 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2050 | } |
| 2051 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2052 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2053 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2055 | struct net_device *dev = info->user_ptr[1]; |
| 2056 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2057 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2058 | |
| 2059 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2060 | return -EINVAL; |
| 2061 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2062 | if (netif_running(dev)) |
| 2063 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2064 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2065 | if (!rdev->ops->set_wds_peer) |
| 2066 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2067 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2068 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2069 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2070 | |
| 2071 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2072 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2076 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2077 | { |
| 2078 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2079 | struct net_device *netdev = NULL; |
| 2080 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2081 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2082 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2083 | u32 changed; |
| 2084 | u8 retry_short = 0, retry_long = 0; |
| 2085 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2086 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2087 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2088 | ASSERT_RTNL(); |
| 2089 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2090 | /* |
| 2091 | * Try to find the wiphy and netdev. Normally this |
| 2092 | * function shouldn't need the netdev, but this is |
| 2093 | * done for backward compatibility -- previously |
| 2094 | * setting the channel was done per wiphy, but now |
| 2095 | * it is per netdev. Previous userland like hostapd |
| 2096 | * also passed a netdev to set_wiphy, so that it is |
| 2097 | * possible to let that go to the right netdev! |
| 2098 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2099 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2100 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2101 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2102 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2103 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2104 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2105 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2106 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2107 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2108 | } |
| 2109 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2110 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2111 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2112 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2113 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2114 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2115 | wdev = NULL; |
| 2116 | netdev = NULL; |
| 2117 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2118 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2120 | |
| 2121 | /* |
| 2122 | * end workaround code, by now the rdev is available |
| 2123 | * and locked, and wdev may or may not be NULL. |
| 2124 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2125 | |
| 2126 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2127 | result = cfg80211_dev_rename( |
| 2128 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2129 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2130 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2131 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2132 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2134 | struct ieee80211_txq_params txq_params; |
| 2135 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2136 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2137 | if (!rdev->ops->set_txq_params) |
| 2138 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2139 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2140 | if (!netdev) |
| 2141 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2142 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2143 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2144 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2145 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2146 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2147 | if (!netif_running(netdev)) |
| 2148 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2149 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2150 | nla_for_each_nested(nl_txq_params, |
| 2151 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2152 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2153 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2154 | nla_data(nl_txq_params), |
| 2155 | nla_len(nl_txq_params), |
| 2156 | txq_params_policy); |
| 2157 | if (result) |
| 2158 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2159 | result = parse_txq_params(tb, &txq_params); |
| 2160 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2161 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2162 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2163 | result = rdev_set_txq_params(rdev, netdev, |
| 2164 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2165 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2166 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2170 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2171 | result = __nl80211_set_channel( |
| 2172 | rdev, |
| 2173 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2174 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2175 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2176 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2177 | } |
| 2178 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2179 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2180 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2181 | enum nl80211_tx_power_setting type; |
| 2182 | int idx, mbm = 0; |
| 2183 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2184 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2185 | txp_wdev = NULL; |
| 2186 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2187 | if (!rdev->ops->set_tx_power) |
| 2188 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2189 | |
| 2190 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2191 | type = nla_get_u32(info->attrs[idx]); |
| 2192 | |
| 2193 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2194 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2195 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2196 | |
| 2197 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2198 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2199 | mbm = nla_get_u32(info->attrs[idx]); |
| 2200 | } |
| 2201 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2202 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2203 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2204 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2205 | } |
| 2206 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2207 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2208 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2209 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2210 | if ((!rdev->wiphy.available_antennas_tx && |
| 2211 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2212 | !rdev->ops->set_antenna) |
| 2213 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2214 | |
| 2215 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2216 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2217 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2218 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2219 | * available antenna masks, except for the "all" mask */ |
| 2220 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2221 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2222 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2223 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2224 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2225 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2226 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2227 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2228 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2229 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2230 | } |
| 2231 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2232 | changed = 0; |
| 2233 | |
| 2234 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2235 | retry_short = nla_get_u8( |
| 2236 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2237 | if (retry_short == 0) |
| 2238 | return -EINVAL; |
| 2239 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2240 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2241 | } |
| 2242 | |
| 2243 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2244 | retry_long = nla_get_u8( |
| 2245 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2246 | if (retry_long == 0) |
| 2247 | return -EINVAL; |
| 2248 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2249 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2250 | } |
| 2251 | |
| 2252 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2253 | frag_threshold = nla_get_u32( |
| 2254 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2255 | if (frag_threshold < 256) |
| 2256 | return -EINVAL; |
| 2257 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2258 | if (frag_threshold != (u32) -1) { |
| 2259 | /* |
| 2260 | * Fragments (apart from the last one) are required to |
| 2261 | * have even length. Make the fragmentation code |
| 2262 | * simpler by stripping LSB should someone try to use |
| 2263 | * odd threshold value. |
| 2264 | */ |
| 2265 | frag_threshold &= ~0x1; |
| 2266 | } |
| 2267 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2268 | } |
| 2269 | |
| 2270 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2271 | rts_threshold = nla_get_u32( |
| 2272 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2273 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2274 | } |
| 2275 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2276 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2277 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2278 | return -EINVAL; |
| 2279 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2280 | coverage_class = nla_get_u8( |
| 2281 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2282 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2283 | } |
| 2284 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2285 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2286 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2287 | return -EOPNOTSUPP; |
| 2288 | |
| 2289 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2290 | } |
| 2291 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2292 | if (changed) { |
| 2293 | u8 old_retry_short, old_retry_long; |
| 2294 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2295 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2296 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2297 | if (!rdev->ops->set_wiphy_params) |
| 2298 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2299 | |
| 2300 | old_retry_short = rdev->wiphy.retry_short; |
| 2301 | old_retry_long = rdev->wiphy.retry_long; |
| 2302 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2303 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2304 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2305 | |
| 2306 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2307 | rdev->wiphy.retry_short = retry_short; |
| 2308 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2309 | rdev->wiphy.retry_long = retry_long; |
| 2310 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2311 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2312 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2313 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2314 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2315 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2316 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2317 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2318 | if (result) { |
| 2319 | rdev->wiphy.retry_short = old_retry_short; |
| 2320 | rdev->wiphy.retry_long = old_retry_long; |
| 2321 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2322 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2323 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2324 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2325 | } |
| 2326 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2327 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2328 | } |
| 2329 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2330 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2331 | { |
| 2332 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2333 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2334 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2335 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2336 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2337 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2338 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2339 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2340 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2341 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2343 | chandef->chan->center_freq)) |
| 2344 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2345 | switch (chandef->width) { |
| 2346 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2347 | case NL80211_CHAN_WIDTH_20: |
| 2348 | case NL80211_CHAN_WIDTH_40: |
| 2349 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2350 | cfg80211_get_chandef_type(chandef))) |
| 2351 | return -ENOBUFS; |
| 2352 | break; |
| 2353 | default: |
| 2354 | break; |
| 2355 | } |
| 2356 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2357 | return -ENOBUFS; |
| 2358 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2359 | return -ENOBUFS; |
| 2360 | if (chandef->center_freq2 && |
| 2361 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2362 | return -ENOBUFS; |
| 2363 | return 0; |
| 2364 | } |
| 2365 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2366 | 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] | 2367 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2368 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2369 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2370 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2371 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2372 | void *hdr; |
| 2373 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2374 | if (removal) |
| 2375 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2376 | |
| 2377 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2378 | if (!hdr) |
| 2379 | return -1; |
| 2380 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2381 | if (dev && |
| 2382 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2383 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2384 | goto nla_put_failure; |
| 2385 | |
| 2386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2387 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2388 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2391 | rdev->devlist_generation ^ |
| 2392 | (cfg80211_rdev_list_generation << 2))) |
| 2393 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2394 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2395 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2396 | int ret; |
| 2397 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2398 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2399 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2400 | if (ret == 0) { |
| 2401 | if (nl80211_send_chandef(msg, &chandef)) |
| 2402 | goto nla_put_failure; |
| 2403 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2404 | } |
| 2405 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2406 | if (wdev->ssid_len) { |
| 2407 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2408 | goto nla_put_failure; |
| 2409 | } |
| 2410 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2411 | genlmsg_end(msg, hdr); |
| 2412 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2413 | |
| 2414 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2415 | genlmsg_cancel(msg, hdr); |
| 2416 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2420 | { |
| 2421 | int wp_idx = 0; |
| 2422 | int if_idx = 0; |
| 2423 | int wp_start = cb->args[0]; |
| 2424 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2425 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | struct wireless_dev *wdev; |
| 2427 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2428 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2429 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2430 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2431 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2432 | if (wp_idx < wp_start) { |
| 2433 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2435 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2436 | if_idx = 0; |
| 2437 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2438 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2439 | if (if_idx < if_start) { |
| 2440 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2441 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2442 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2443 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2444 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2445 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2446 | goto out; |
| 2447 | } |
| 2448 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2449 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2450 | |
| 2451 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2452 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2453 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2454 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2455 | |
| 2456 | cb->args[0] = wp_idx; |
| 2457 | cb->args[1] = if_idx; |
| 2458 | |
| 2459 | return skb->len; |
| 2460 | } |
| 2461 | |
| 2462 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2463 | { |
| 2464 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2466 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2469 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2472 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2473 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2474 | nlmsg_free(msg); |
| 2475 | return -ENOBUFS; |
| 2476 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2477 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2478 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2479 | } |
| 2480 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2481 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2482 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2483 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2484 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2485 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2486 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2487 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2488 | }; |
| 2489 | |
| 2490 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2491 | { |
| 2492 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2493 | int flag; |
| 2494 | |
| 2495 | *mntrflags = 0; |
| 2496 | |
| 2497 | if (!nla) |
| 2498 | return -EINVAL; |
| 2499 | |
| 2500 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2501 | nla, mntr_flags_policy)) |
| 2502 | return -EINVAL; |
| 2503 | |
| 2504 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2505 | if (flags[flag]) |
| 2506 | *mntrflags |= (1<<flag); |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2511 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2512 | struct net_device *netdev, u8 use_4addr, |
| 2513 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2514 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2515 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2516 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2517 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2518 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2519 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2520 | |
| 2521 | switch (iftype) { |
| 2522 | case NL80211_IFTYPE_AP_VLAN: |
| 2523 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2524 | return 0; |
| 2525 | break; |
| 2526 | case NL80211_IFTYPE_STATION: |
| 2527 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2528 | return 0; |
| 2529 | break; |
| 2530 | default: |
| 2531 | break; |
| 2532 | } |
| 2533 | |
| 2534 | return -EOPNOTSUPP; |
| 2535 | } |
| 2536 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2537 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2538 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2540 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2541 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2542 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2543 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2544 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2545 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2546 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2547 | memset(¶ms, 0, sizeof(params)); |
| 2548 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2549 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2550 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2551 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2552 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2553 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2554 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2555 | if (ntype > NL80211_IFTYPE_MAX) |
| 2556 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2557 | } |
| 2558 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2559 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2560 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2561 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2563 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2564 | if (netif_running(dev)) |
| 2565 | return -EBUSY; |
| 2566 | |
| 2567 | wdev_lock(wdev); |
| 2568 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2569 | IEEE80211_MAX_MESH_ID_LEN); |
| 2570 | wdev->mesh_id_up_len = |
| 2571 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2572 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2573 | wdev->mesh_id_up_len); |
| 2574 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2575 | } |
| 2576 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2577 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2578 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2579 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2580 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2581 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2583 | } else { |
| 2584 | params.use_4addr = -1; |
| 2585 | } |
| 2586 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2587 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2588 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2589 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2590 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2591 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2592 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2593 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2594 | |
| 2595 | flags = &_flags; |
| 2596 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2597 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2598 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2599 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2600 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2601 | return -EOPNOTSUPP; |
| 2602 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2603 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2604 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2605 | else |
| 2606 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2607 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2608 | if (!err && params.use_4addr != -1) |
| 2609 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2610 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2611 | return err; |
| 2612 | } |
| 2613 | |
| 2614 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2617 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2618 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2619 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2620 | int err; |
| 2621 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2622 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2623 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2624 | /* to avoid failing a new interface creation due to pending removal */ |
| 2625 | cfg80211_destroy_ifaces(rdev); |
| 2626 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2627 | memset(¶ms, 0, sizeof(params)); |
| 2628 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2629 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2630 | return -EINVAL; |
| 2631 | |
| 2632 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2633 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2634 | if (type > NL80211_IFTYPE_MAX) |
| 2635 | return -EINVAL; |
| 2636 | } |
| 2637 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2638 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2639 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2640 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2641 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2642 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2643 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2644 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2645 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2646 | ETH_ALEN); |
| 2647 | if (!is_valid_ether_addr(params.macaddr)) |
| 2648 | return -EADDRNOTAVAIL; |
| 2649 | } |
| 2650 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2651 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2652 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2653 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2654 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2655 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2656 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2657 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2658 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2659 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2660 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2661 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2662 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2663 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2664 | return -EOPNOTSUPP; |
| 2665 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2667 | if (!msg) |
| 2668 | return -ENOMEM; |
| 2669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2670 | wdev = rdev_add_virtual_intf(rdev, |
| 2671 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2672 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2673 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2674 | if (WARN_ON(!wdev)) { |
| 2675 | nlmsg_free(msg); |
| 2676 | return -EPROTO; |
| 2677 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2678 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2679 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2680 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2681 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2682 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2683 | wdev->owner_nlportid = info->snd_portid; |
| 2684 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2685 | switch (type) { |
| 2686 | case NL80211_IFTYPE_MESH_POINT: |
| 2687 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2688 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2689 | wdev_lock(wdev); |
| 2690 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2691 | IEEE80211_MAX_MESH_ID_LEN); |
| 2692 | wdev->mesh_id_up_len = |
| 2693 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2694 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2695 | wdev->mesh_id_up_len); |
| 2696 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2697 | break; |
| 2698 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2699 | /* |
| 2700 | * P2P Device doesn't have a netdev, so doesn't go |
| 2701 | * through the netdev notifier and must be added here |
| 2702 | */ |
| 2703 | mutex_init(&wdev->mtx); |
| 2704 | INIT_LIST_HEAD(&wdev->event_list); |
| 2705 | spin_lock_init(&wdev->event_lock); |
| 2706 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2707 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2708 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2709 | wdev->identifier = ++rdev->wdev_id; |
| 2710 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2711 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2712 | break; |
| 2713 | default: |
| 2714 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2717 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2718 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2719 | nlmsg_free(msg); |
| 2720 | return -ENOBUFS; |
| 2721 | } |
| 2722 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2723 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2724 | if (event) { |
| 2725 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2726 | rdev, wdev, false) < 0) { |
| 2727 | nlmsg_free(event); |
| 2728 | goto out; |
| 2729 | } |
| 2730 | |
| 2731 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2732 | event, 0, NL80211_MCGRP_CONFIG, |
| 2733 | GFP_KERNEL); |
| 2734 | } |
| 2735 | |
| 2736 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2737 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2743 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2744 | struct sk_buff *msg; |
| 2745 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | if (!rdev->ops->del_virtual_intf) |
| 2748 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2749 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2751 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2752 | nlmsg_free(msg); |
| 2753 | msg = NULL; |
| 2754 | } |
| 2755 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2756 | /* |
| 2757 | * If we remove a wireless device without a netdev then clear |
| 2758 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2759 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2760 | * since the wdev has been freed, unlike with a netdev where |
| 2761 | * we need the dev_put() for the netdev to really be freed. |
| 2762 | */ |
| 2763 | if (!wdev->netdev) |
| 2764 | info->user_ptr[1] = NULL; |
| 2765 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2766 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2767 | if (status >= 0 && msg) |
| 2768 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2769 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2770 | GFP_KERNEL); |
| 2771 | else |
| 2772 | nlmsg_free(msg); |
| 2773 | |
| 2774 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2775 | } |
| 2776 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2777 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2778 | { |
| 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2780 | struct net_device *dev = info->user_ptr[1]; |
| 2781 | u16 noack_map; |
| 2782 | |
| 2783 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2784 | return -EINVAL; |
| 2785 | |
| 2786 | if (!rdev->ops->set_noack_map) |
| 2787 | return -EOPNOTSUPP; |
| 2788 | |
| 2789 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2790 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2791 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2792 | } |
| 2793 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2794 | struct get_key_cookie { |
| 2795 | struct sk_buff *msg; |
| 2796 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2797 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2798 | }; |
| 2799 | |
| 2800 | static void get_key_callback(void *c, struct key_params *params) |
| 2801 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2802 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2803 | struct get_key_cookie *cookie = c; |
| 2804 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2805 | if ((params->key && |
| 2806 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2807 | params->key_len, params->key)) || |
| 2808 | (params->seq && |
| 2809 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2810 | params->seq_len, params->seq)) || |
| 2811 | (params->cipher && |
| 2812 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2813 | params->cipher))) |
| 2814 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2815 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2816 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2817 | if (!key) |
| 2818 | goto nla_put_failure; |
| 2819 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2820 | if ((params->key && |
| 2821 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2822 | params->key_len, params->key)) || |
| 2823 | (params->seq && |
| 2824 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2825 | params->seq_len, params->seq)) || |
| 2826 | (params->cipher && |
| 2827 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2828 | params->cipher))) |
| 2829 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2830 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2831 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2832 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2833 | |
| 2834 | nla_nest_end(cookie->msg, key); |
| 2835 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | return; |
| 2837 | nla_put_failure: |
| 2838 | cookie->error = 1; |
| 2839 | } |
| 2840 | |
| 2841 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2842 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2844 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2845 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2847 | const u8 *mac_addr = NULL; |
| 2848 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2849 | struct get_key_cookie cookie = { |
| 2850 | .error = 0, |
| 2851 | }; |
| 2852 | void *hdr; |
| 2853 | struct sk_buff *msg; |
| 2854 | |
| 2855 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2856 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2857 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2858 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2859 | return -EINVAL; |
| 2860 | |
| 2861 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2862 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2863 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2864 | pairwise = !!mac_addr; |
| 2865 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2866 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2867 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2868 | return -EINVAL; |
| 2869 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2870 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2871 | return -EINVAL; |
| 2872 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2873 | } |
| 2874 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | if (!rdev->ops->get_key) |
| 2876 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2877 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 2878 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2879 | return -ENOENT; |
| 2880 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2881 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2882 | if (!msg) |
| 2883 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2884 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2885 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2886 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2887 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2888 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2889 | |
| 2890 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2891 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2893 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2894 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2895 | goto nla_put_failure; |
| 2896 | if (mac_addr && |
| 2897 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2898 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2899 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2900 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2901 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2902 | |
| 2903 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2904 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2905 | |
| 2906 | if (cookie.error) |
| 2907 | goto nla_put_failure; |
| 2908 | |
| 2909 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2910 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2911 | |
| 2912 | nla_put_failure: |
| 2913 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2914 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2916 | return err; |
| 2917 | } |
| 2918 | |
| 2919 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2920 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2922 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2923 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2924 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2925 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2926 | err = nl80211_parse_key(info, &key); |
| 2927 | if (err) |
| 2928 | return err; |
| 2929 | |
| 2930 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2931 | return -EINVAL; |
| 2932 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2933 | /* only support setting default key */ |
| 2934 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2935 | return -EINVAL; |
| 2936 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2937 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2938 | |
| 2939 | if (key.def) { |
| 2940 | if (!rdev->ops->set_default_key) { |
| 2941 | err = -EOPNOTSUPP; |
| 2942 | goto out; |
| 2943 | } |
| 2944 | |
| 2945 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2946 | if (err) |
| 2947 | goto out; |
| 2948 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2949 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2950 | key.def_uni, key.def_multi); |
| 2951 | |
| 2952 | if (err) |
| 2953 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2954 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2955 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2956 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2957 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2958 | } else { |
| 2959 | if (key.def_uni || !key.def_multi) { |
| 2960 | err = -EINVAL; |
| 2961 | goto out; |
| 2962 | } |
| 2963 | |
| 2964 | if (!rdev->ops->set_default_mgmt_key) { |
| 2965 | err = -EOPNOTSUPP; |
| 2966 | goto out; |
| 2967 | } |
| 2968 | |
| 2969 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2970 | if (err) |
| 2971 | goto out; |
| 2972 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2973 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2974 | if (err) |
| 2975 | goto out; |
| 2976 | |
| 2977 | #ifdef CONFIG_CFG80211_WEXT |
| 2978 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2979 | #endif |
| 2980 | } |
| 2981 | |
| 2982 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2983 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2984 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2985 | return err; |
| 2986 | } |
| 2987 | |
| 2988 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2991 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2992 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2993 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2994 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2995 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2996 | err = nl80211_parse_key(info, &key); |
| 2997 | if (err) |
| 2998 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2999 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3000 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3001 | return -EINVAL; |
| 3002 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3003 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3004 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3005 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3006 | if (key.type == -1) { |
| 3007 | if (mac_addr) |
| 3008 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3009 | else |
| 3010 | key.type = NL80211_KEYTYPE_GROUP; |
| 3011 | } |
| 3012 | |
| 3013 | /* for now */ |
| 3014 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3015 | key.type != NL80211_KEYTYPE_GROUP) |
| 3016 | return -EINVAL; |
| 3017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3018 | if (!rdev->ops->add_key) |
| 3019 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3020 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3021 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3022 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3023 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3024 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3025 | |
| 3026 | wdev_lock(dev->ieee80211_ptr); |
| 3027 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3028 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3029 | err = rdev_add_key(rdev, dev, key.idx, |
| 3030 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3031 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3032 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3033 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3034 | return err; |
| 3035 | } |
| 3036 | |
| 3037 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3038 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3039 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3040 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3041 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3042 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3043 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3044 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3045 | err = nl80211_parse_key(info, &key); |
| 3046 | if (err) |
| 3047 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3048 | |
| 3049 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3050 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3051 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3052 | if (key.type == -1) { |
| 3053 | if (mac_addr) |
| 3054 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3055 | else |
| 3056 | key.type = NL80211_KEYTYPE_GROUP; |
| 3057 | } |
| 3058 | |
| 3059 | /* for now */ |
| 3060 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3061 | key.type != NL80211_KEYTYPE_GROUP) |
| 3062 | return -EINVAL; |
| 3063 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3064 | if (!rdev->ops->del_key) |
| 3065 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3066 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3067 | wdev_lock(dev->ieee80211_ptr); |
| 3068 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3069 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3070 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3071 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3072 | err = -ENOENT; |
| 3073 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3074 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3075 | err = rdev_del_key(rdev, dev, key.idx, |
| 3076 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3077 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3078 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3079 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3080 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3081 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3082 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3083 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3084 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3085 | } |
| 3086 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3087 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3088 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3089 | return err; |
| 3090 | } |
| 3091 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3092 | /* This function returns an error or the number of nested attributes */ |
| 3093 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3094 | { |
| 3095 | struct nlattr *attr; |
| 3096 | int n_entries = 0, tmp; |
| 3097 | |
| 3098 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3099 | if (nla_len(attr) != ETH_ALEN) |
| 3100 | return -EINVAL; |
| 3101 | |
| 3102 | n_entries++; |
| 3103 | } |
| 3104 | |
| 3105 | return n_entries; |
| 3106 | } |
| 3107 | |
| 3108 | /* |
| 3109 | * This function parses ACL information and allocates memory for ACL data. |
| 3110 | * On successful return, the calling function is responsible to free the |
| 3111 | * ACL buffer returned by this function. |
| 3112 | */ |
| 3113 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3114 | struct genl_info *info) |
| 3115 | { |
| 3116 | enum nl80211_acl_policy acl_policy; |
| 3117 | struct nlattr *attr; |
| 3118 | struct cfg80211_acl_data *acl; |
| 3119 | int i = 0, n_entries, tmp; |
| 3120 | |
| 3121 | if (!wiphy->max_acl_mac_addrs) |
| 3122 | return ERR_PTR(-EOPNOTSUPP); |
| 3123 | |
| 3124 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3125 | return ERR_PTR(-EINVAL); |
| 3126 | |
| 3127 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3128 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3129 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3130 | return ERR_PTR(-EINVAL); |
| 3131 | |
| 3132 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3133 | return ERR_PTR(-EINVAL); |
| 3134 | |
| 3135 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3136 | if (n_entries < 0) |
| 3137 | return ERR_PTR(n_entries); |
| 3138 | |
| 3139 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3140 | return ERR_PTR(-ENOTSUPP); |
| 3141 | |
| 3142 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3143 | GFP_KERNEL); |
| 3144 | if (!acl) |
| 3145 | return ERR_PTR(-ENOMEM); |
| 3146 | |
| 3147 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3148 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3149 | i++; |
| 3150 | } |
| 3151 | |
| 3152 | acl->n_acl_entries = n_entries; |
| 3153 | acl->acl_policy = acl_policy; |
| 3154 | |
| 3155 | return acl; |
| 3156 | } |
| 3157 | |
| 3158 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3159 | { |
| 3160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3161 | struct net_device *dev = info->user_ptr[1]; |
| 3162 | struct cfg80211_acl_data *acl; |
| 3163 | int err; |
| 3164 | |
| 3165 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3166 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3167 | return -EOPNOTSUPP; |
| 3168 | |
| 3169 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3170 | return -EINVAL; |
| 3171 | |
| 3172 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3173 | if (IS_ERR(acl)) |
| 3174 | return PTR_ERR(acl); |
| 3175 | |
| 3176 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3177 | |
| 3178 | kfree(acl); |
| 3179 | |
| 3180 | return err; |
| 3181 | } |
| 3182 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3183 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3184 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3185 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3186 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3187 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3188 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3189 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3190 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3191 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3192 | return -EINVAL; |
| 3193 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3194 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3195 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3196 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3197 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3198 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3199 | if (!bcn->head_len) |
| 3200 | return -EINVAL; |
| 3201 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3202 | } |
| 3203 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3204 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3205 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3206 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3207 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3208 | } |
| 3209 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3210 | if (!haveinfo) |
| 3211 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3212 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3213 | if (attrs[NL80211_ATTR_IE]) { |
| 3214 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3215 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3216 | } |
| 3217 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3218 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3219 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3220 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3221 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3222 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3223 | } |
| 3224 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3225 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3226 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3227 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3228 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3229 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3230 | } |
| 3231 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3232 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3233 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3234 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3235 | } |
| 3236 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3237 | return 0; |
| 3238 | } |
| 3239 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3240 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3241 | struct cfg80211_ap_settings *params) |
| 3242 | { |
| 3243 | struct wireless_dev *wdev; |
| 3244 | bool ret = false; |
| 3245 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3246 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3247 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3248 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3249 | continue; |
| 3250 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3251 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3252 | continue; |
| 3253 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3254 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3255 | ret = true; |
| 3256 | break; |
| 3257 | } |
| 3258 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3259 | return ret; |
| 3260 | } |
| 3261 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3262 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3263 | enum nl80211_auth_type auth_type, |
| 3264 | enum nl80211_commands cmd) |
| 3265 | { |
| 3266 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3267 | return false; |
| 3268 | |
| 3269 | switch (cmd) { |
| 3270 | case NL80211_CMD_AUTHENTICATE: |
| 3271 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3272 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3273 | return false; |
| 3274 | return true; |
| 3275 | case NL80211_CMD_CONNECT: |
| 3276 | case NL80211_CMD_START_AP: |
| 3277 | /* SAE not supported yet */ |
| 3278 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3279 | return false; |
| 3280 | return true; |
| 3281 | default: |
| 3282 | return false; |
| 3283 | } |
| 3284 | } |
| 3285 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3286 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3287 | { |
| 3288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3289 | struct net_device *dev = info->user_ptr[1]; |
| 3290 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3291 | struct cfg80211_ap_settings params; |
| 3292 | int err; |
| 3293 | |
| 3294 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3295 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3296 | return -EOPNOTSUPP; |
| 3297 | |
| 3298 | if (!rdev->ops->start_ap) |
| 3299 | return -EOPNOTSUPP; |
| 3300 | |
| 3301 | if (wdev->beacon_interval) |
| 3302 | return -EALREADY; |
| 3303 | |
| 3304 | memset(¶ms, 0, sizeof(params)); |
| 3305 | |
| 3306 | /* these are required for START_AP */ |
| 3307 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3308 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3309 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3310 | return -EINVAL; |
| 3311 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3312 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3313 | if (err) |
| 3314 | return err; |
| 3315 | |
| 3316 | params.beacon_interval = |
| 3317 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3318 | params.dtim_period = |
| 3319 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3320 | |
| 3321 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3322 | if (err) |
| 3323 | return err; |
| 3324 | |
| 3325 | /* |
| 3326 | * In theory, some of these attributes should be required here |
| 3327 | * but since they were not used when the command was originally |
| 3328 | * added, keep them optional for old user space programs to let |
| 3329 | * them continue to work with drivers that do not need the |
| 3330 | * additional information -- drivers must check! |
| 3331 | */ |
| 3332 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3333 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3334 | params.ssid_len = |
| 3335 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3336 | if (params.ssid_len == 0 || |
| 3337 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3338 | return -EINVAL; |
| 3339 | } |
| 3340 | |
| 3341 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3342 | params.hidden_ssid = nla_get_u32( |
| 3343 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3344 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3345 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3346 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3347 | return -EINVAL; |
| 3348 | } |
| 3349 | |
| 3350 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3351 | |
| 3352 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3353 | params.auth_type = nla_get_u32( |
| 3354 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3355 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3356 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3357 | return -EINVAL; |
| 3358 | } else |
| 3359 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3360 | |
| 3361 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3362 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3363 | if (err) |
| 3364 | return err; |
| 3365 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3366 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3367 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3368 | return -EOPNOTSUPP; |
| 3369 | params.inactivity_timeout = nla_get_u16( |
| 3370 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3371 | } |
| 3372 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3373 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3374 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3375 | return -EINVAL; |
| 3376 | params.p2p_ctwindow = |
| 3377 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3378 | if (params.p2p_ctwindow > 127) |
| 3379 | return -EINVAL; |
| 3380 | if (params.p2p_ctwindow != 0 && |
| 3381 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3382 | return -EINVAL; |
| 3383 | } |
| 3384 | |
| 3385 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3386 | u8 tmp; |
| 3387 | |
| 3388 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3389 | return -EINVAL; |
| 3390 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3391 | if (tmp > 1) |
| 3392 | return -EINVAL; |
| 3393 | params.p2p_opp_ps = tmp; |
| 3394 | if (params.p2p_opp_ps != 0 && |
| 3395 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3396 | return -EINVAL; |
| 3397 | } |
| 3398 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3399 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3400 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3401 | if (err) |
| 3402 | return err; |
| 3403 | } else if (wdev->preset_chandef.chan) { |
| 3404 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3405 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3406 | return -EINVAL; |
| 3407 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3408 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3409 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3410 | return -EINVAL; |
| 3411 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3412 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3413 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3414 | if (IS_ERR(params.acl)) |
| 3415 | return PTR_ERR(params.acl); |
| 3416 | } |
| 3417 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3418 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3419 | params.smps_mode = |
| 3420 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3421 | switch (params.smps_mode) { |
| 3422 | case NL80211_SMPS_OFF: |
| 3423 | break; |
| 3424 | case NL80211_SMPS_STATIC: |
| 3425 | if (!(rdev->wiphy.features & |
| 3426 | NL80211_FEATURE_STATIC_SMPS)) |
| 3427 | return -EINVAL; |
| 3428 | break; |
| 3429 | case NL80211_SMPS_DYNAMIC: |
| 3430 | if (!(rdev->wiphy.features & |
| 3431 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3432 | return -EINVAL; |
| 3433 | break; |
| 3434 | default: |
| 3435 | return -EINVAL; |
| 3436 | } |
| 3437 | } else { |
| 3438 | params.smps_mode = NL80211_SMPS_OFF; |
| 3439 | } |
| 3440 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3441 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3442 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3443 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3444 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3445 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3446 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3447 | wdev->ssid_len = params.ssid_len; |
| 3448 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3449 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3450 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3451 | |
| 3452 | kfree(params.acl); |
| 3453 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3454 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3455 | } |
| 3456 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3457 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3458 | { |
| 3459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3460 | struct net_device *dev = info->user_ptr[1]; |
| 3461 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3462 | struct cfg80211_beacon_data params; |
| 3463 | int err; |
| 3464 | |
| 3465 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3466 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3467 | return -EOPNOTSUPP; |
| 3468 | |
| 3469 | if (!rdev->ops->change_beacon) |
| 3470 | return -EOPNOTSUPP; |
| 3471 | |
| 3472 | if (!wdev->beacon_interval) |
| 3473 | return -EINVAL; |
| 3474 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3475 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3476 | if (err) |
| 3477 | return err; |
| 3478 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3479 | wdev_lock(wdev); |
| 3480 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3481 | wdev_unlock(wdev); |
| 3482 | |
| 3483 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | 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] | 3487 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3489 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3490 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3491 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3492 | } |
| 3493 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3494 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3495 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3496 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3497 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3498 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3499 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3500 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3501 | }; |
| 3502 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3503 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3504 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3505 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3506 | { |
| 3507 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3508 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3509 | int flag; |
| 3510 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3511 | /* |
| 3512 | * Try parsing the new attribute first so userspace |
| 3513 | * can specify both for older kernels. |
| 3514 | */ |
| 3515 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3516 | if (nla) { |
| 3517 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3518 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3519 | sta_flags = nla_data(nla); |
| 3520 | params->sta_flags_mask = sta_flags->mask; |
| 3521 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3522 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3523 | if ((params->sta_flags_mask | |
| 3524 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3525 | return -EINVAL; |
| 3526 | return 0; |
| 3527 | } |
| 3528 | |
| 3529 | /* if present, parse the old attribute */ |
| 3530 | |
| 3531 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3532 | if (!nla) |
| 3533 | return 0; |
| 3534 | |
| 3535 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3536 | nla, sta_flags_policy)) |
| 3537 | return -EINVAL; |
| 3538 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3539 | /* |
| 3540 | * Only allow certain flags for interface types so that |
| 3541 | * other attributes are silently ignored. Remember that |
| 3542 | * this is backward compatibility code with old userspace |
| 3543 | * and shouldn't be hit in other cases anyway. |
| 3544 | */ |
| 3545 | switch (iftype) { |
| 3546 | case NL80211_IFTYPE_AP: |
| 3547 | case NL80211_IFTYPE_AP_VLAN: |
| 3548 | case NL80211_IFTYPE_P2P_GO: |
| 3549 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3550 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3551 | BIT(NL80211_STA_FLAG_WME) | |
| 3552 | BIT(NL80211_STA_FLAG_MFP); |
| 3553 | break; |
| 3554 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3555 | case NL80211_IFTYPE_STATION: |
| 3556 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3557 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3558 | break; |
| 3559 | case NL80211_IFTYPE_MESH_POINT: |
| 3560 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3561 | BIT(NL80211_STA_FLAG_MFP) | |
| 3562 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3563 | default: |
| 3564 | return -EINVAL; |
| 3565 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3566 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3567 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3568 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3569 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3570 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3571 | /* no longer support new API additions in old API */ |
| 3572 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3573 | return -EINVAL; |
| 3574 | } |
| 3575 | } |
| 3576 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3577 | return 0; |
| 3578 | } |
| 3579 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3580 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3581 | int attr) |
| 3582 | { |
| 3583 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3584 | u32 bitrate; |
| 3585 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3586 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3587 | |
| 3588 | rate = nla_nest_start(msg, attr); |
| 3589 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3590 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3591 | |
| 3592 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3593 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3594 | /* report 16-bit bitrate only if we can */ |
| 3595 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3596 | if (bitrate > 0 && |
| 3597 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3598 | return false; |
| 3599 | if (bitrate_compat > 0 && |
| 3600 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3601 | return false; |
| 3602 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3603 | switch (info->bw) { |
| 3604 | case RATE_INFO_BW_5: |
| 3605 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3606 | break; |
| 3607 | case RATE_INFO_BW_10: |
| 3608 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3609 | break; |
| 3610 | default: |
| 3611 | WARN_ON(1); |
| 3612 | /* fall through */ |
| 3613 | case RATE_INFO_BW_20: |
| 3614 | rate_flg = 0; |
| 3615 | break; |
| 3616 | case RATE_INFO_BW_40: |
| 3617 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3618 | break; |
| 3619 | case RATE_INFO_BW_80: |
| 3620 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3621 | break; |
| 3622 | case RATE_INFO_BW_160: |
| 3623 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3624 | break; |
| 3625 | } |
| 3626 | |
| 3627 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3628 | return false; |
| 3629 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3630 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3631 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3632 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3633 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3634 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3635 | return false; |
| 3636 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3637 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3638 | return false; |
| 3639 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3640 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3641 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3642 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3643 | return false; |
| 3644 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3645 | |
| 3646 | nla_nest_end(msg, rate); |
| 3647 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3648 | } |
| 3649 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3650 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3651 | int id) |
| 3652 | { |
| 3653 | void *attr; |
| 3654 | int i = 0; |
| 3655 | |
| 3656 | if (!mask) |
| 3657 | return true; |
| 3658 | |
| 3659 | attr = nla_nest_start(msg, id); |
| 3660 | if (!attr) |
| 3661 | return false; |
| 3662 | |
| 3663 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3664 | if (!(mask & BIT(i))) |
| 3665 | continue; |
| 3666 | |
| 3667 | if (nla_put_u8(msg, i, signal[i])) |
| 3668 | return false; |
| 3669 | } |
| 3670 | |
| 3671 | nla_nest_end(msg, attr); |
| 3672 | |
| 3673 | return true; |
| 3674 | } |
| 3675 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3676 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3677 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3678 | struct cfg80211_registered_device *rdev, |
| 3679 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3680 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3681 | { |
| 3682 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3683 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3684 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3685 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3686 | if (!hdr) |
| 3687 | return -1; |
| 3688 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3689 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3690 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3691 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3692 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3693 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3694 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3695 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3696 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3697 | |
| 3698 | #define PUT_SINFO(attr, memb, type) do { \ |
| 3699 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ |
| 3700 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3701 | sinfo->memb)) \ |
| 3702 | goto nla_put_failure; \ |
| 3703 | } while (0) |
| 3704 | |
| 3705 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3706 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3707 | |
| 3708 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3709 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3710 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3711 | (u32)sinfo->rx_bytes)) |
| 3712 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3713 | |
| 3714 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3715 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3716 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3717 | (u32)sinfo->tx_bytes)) |
| 3718 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3719 | |
| 3720 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); |
| 3721 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); |
| 3722 | PUT_SINFO(LLID, llid, u16); |
| 3723 | PUT_SINFO(PLID, plid, u16); |
| 3724 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
| 3725 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3726 | switch (rdev->wiphy.signal_type) { |
| 3727 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3728 | PUT_SINFO(SIGNAL, signal, u8); |
| 3729 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3730 | break; |
| 3731 | default: |
| 3732 | break; |
| 3733 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3734 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3735 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3736 | sinfo->chain_signal, |
| 3737 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3738 | goto nla_put_failure; |
| 3739 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3740 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3741 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3742 | sinfo->chain_signal_avg, |
| 3743 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3744 | goto nla_put_failure; |
| 3745 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3746 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3747 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3748 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3749 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3750 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3751 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3752 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3753 | NL80211_STA_INFO_RX_BITRATE)) |
| 3754 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3755 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3756 | |
| 3757 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3758 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3759 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3760 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3761 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3762 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3763 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3764 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3765 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3766 | |
| 3767 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3768 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3769 | if (!bss_param) |
| 3770 | goto nla_put_failure; |
| 3771 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3772 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3773 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3774 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3775 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3776 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3777 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3778 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3779 | sinfo->bss_param.dtim_period) || |
| 3780 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3781 | sinfo->bss_param.beacon_interval)) |
| 3782 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3783 | |
| 3784 | nla_nest_end(msg, bss_param); |
| 3785 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3786 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3787 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3788 | sizeof(struct nl80211_sta_flag_update), |
| 3789 | &sinfo->sta_flags)) |
| 3790 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3791 | |
| 3792 | PUT_SINFO(T_OFFSET, t_offset, u64); |
| 3793 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3794 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
| 3795 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3796 | |
| 3797 | #undef PUT_SINFO |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3798 | |
| 3799 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3800 | struct nlattr *tidsattr; |
| 3801 | int tid; |
| 3802 | |
| 3803 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3804 | if (!tidsattr) |
| 3805 | goto nla_put_failure; |
| 3806 | |
| 3807 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3808 | struct cfg80211_tid_stats *tidstats; |
| 3809 | struct nlattr *tidattr; |
| 3810 | |
| 3811 | tidstats = &sinfo->pertid[tid]; |
| 3812 | |
| 3813 | if (!tidstats->filled) |
| 3814 | continue; |
| 3815 | |
| 3816 | tidattr = nla_nest_start(msg, tid + 1); |
| 3817 | if (!tidattr) |
| 3818 | goto nla_put_failure; |
| 3819 | |
| 3820 | #define PUT_TIDVAL(attr, memb, type) do { \ |
| 3821 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
| 3822 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ |
| 3823 | tidstats->memb)) \ |
| 3824 | goto nla_put_failure; \ |
| 3825 | } while (0) |
| 3826 | |
| 3827 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); |
| 3828 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); |
| 3829 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); |
| 3830 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); |
| 3831 | |
| 3832 | #undef PUT_TIDVAL |
| 3833 | nla_nest_end(msg, tidattr); |
| 3834 | } |
| 3835 | |
| 3836 | nla_nest_end(msg, tidsattr); |
| 3837 | } |
| 3838 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3839 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3840 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3841 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3842 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3843 | sinfo->assoc_req_ies)) |
| 3844 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3845 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3846 | genlmsg_end(msg, hdr); |
| 3847 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3848 | |
| 3849 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3850 | genlmsg_cancel(msg, hdr); |
| 3851 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3852 | } |
| 3853 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3854 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3855 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3856 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3857 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3858 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3859 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3860 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3861 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3862 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3863 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3864 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3865 | if (err) |
| 3866 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3867 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3868 | if (!wdev->netdev) { |
| 3869 | err = -EINVAL; |
| 3870 | goto out_err; |
| 3871 | } |
| 3872 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3873 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3874 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3875 | goto out_err; |
| 3876 | } |
| 3877 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3878 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3879 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3880 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3881 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3882 | if (err == -ENOENT) |
| 3883 | break; |
| 3884 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3885 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3886 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3887 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3888 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3889 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3890 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3891 | &sinfo) < 0) |
| 3892 | goto out; |
| 3893 | |
| 3894 | sta_idx++; |
| 3895 | } |
| 3896 | |
| 3897 | |
| 3898 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3899 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3900 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3901 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3902 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3903 | |
| 3904 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3905 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3906 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3907 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3910 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3911 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3912 | struct sk_buff *msg; |
| 3913 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3914 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3915 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3916 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3917 | |
| 3918 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3919 | return -EINVAL; |
| 3920 | |
| 3921 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3922 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3923 | if (!rdev->ops->get_station) |
| 3924 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3925 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3926 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3927 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3928 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3929 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3930 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3931 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3932 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3933 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3934 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 3935 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3936 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3937 | nlmsg_free(msg); |
| 3938 | return -ENOBUFS; |
| 3939 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3940 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3941 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3942 | } |
| 3943 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3944 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3945 | struct station_parameters *params, |
| 3946 | enum cfg80211_station_type statype) |
| 3947 | { |
| 3948 | if (params->listen_interval != -1) |
| 3949 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3950 | if (params->aid && |
| 3951 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3952 | return -EINVAL; |
| 3953 | |
| 3954 | /* When you run into this, adjust the code below for the new flag */ |
| 3955 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3956 | |
| 3957 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3958 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3959 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3960 | /* |
| 3961 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3962 | * code doesn't have the bug of including TDLS in the |
| 3963 | * mask everywhere. |
| 3964 | */ |
| 3965 | if (params->sta_flags_mask & |
| 3966 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3967 | BIT(NL80211_STA_FLAG_MFP) | |
| 3968 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3969 | return -EINVAL; |
| 3970 | break; |
| 3971 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3972 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3973 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3974 | return -EINVAL; |
| 3975 | /* ignore since it can't change */ |
| 3976 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3977 | break; |
| 3978 | default: |
| 3979 | /* disallow mesh-specific things */ |
| 3980 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3981 | return -EINVAL; |
| 3982 | if (params->local_pm) |
| 3983 | return -EINVAL; |
| 3984 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3985 | return -EINVAL; |
| 3986 | } |
| 3987 | |
| 3988 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3989 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3990 | /* TDLS can't be set, ... */ |
| 3991 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3992 | return -EINVAL; |
| 3993 | /* |
| 3994 | * ... but don't bother the driver with it. This works around |
| 3995 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3996 | * TLDS_PEER flag in the mask even for AP mode. |
| 3997 | */ |
| 3998 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3999 | } |
| 4000 | |
| 4001 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 4002 | /* reject other things that can't change */ |
| 4003 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4004 | return -EINVAL; |
| 4005 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4006 | return -EINVAL; |
| 4007 | if (params->supported_rates) |
| 4008 | return -EINVAL; |
| 4009 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4010 | return -EINVAL; |
| 4011 | } |
| 4012 | |
| 4013 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 4014 | if (params->vlan) |
| 4015 | return -EINVAL; |
| 4016 | } |
| 4017 | |
| 4018 | switch (statype) { |
| 4019 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4020 | /* Use this only for authorizing/unauthorizing a station */ |
| 4021 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4022 | return -EOPNOTSUPP; |
| 4023 | break; |
| 4024 | case CFG80211_STA_AP_CLIENT: |
| 4025 | /* accept only the listed bits */ |
| 4026 | if (params->sta_flags_mask & |
| 4027 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4028 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4029 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4030 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4031 | BIT(NL80211_STA_FLAG_WME) | |
| 4032 | BIT(NL80211_STA_FLAG_MFP))) |
| 4033 | return -EINVAL; |
| 4034 | |
| 4035 | /* but authenticated/associated only if driver handles it */ |
| 4036 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4037 | params->sta_flags_mask & |
| 4038 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4039 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4040 | return -EINVAL; |
| 4041 | break; |
| 4042 | case CFG80211_STA_IBSS: |
| 4043 | case CFG80211_STA_AP_STA: |
| 4044 | /* reject any changes other than AUTHORIZED */ |
| 4045 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4046 | return -EINVAL; |
| 4047 | break; |
| 4048 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4049 | /* reject any changes other than AUTHORIZED or WME */ |
| 4050 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4051 | BIT(NL80211_STA_FLAG_WME))) |
| 4052 | return -EINVAL; |
| 4053 | /* force (at least) rates when authorizing */ |
| 4054 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4055 | !params->supported_rates) |
| 4056 | return -EINVAL; |
| 4057 | break; |
| 4058 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4059 | /* reject any changes */ |
| 4060 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4061 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4062 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4063 | return -EINVAL; |
| 4064 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4065 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4066 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4067 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4068 | return -EINVAL; |
| 4069 | break; |
| 4070 | } |
| 4071 | |
| 4072 | return 0; |
| 4073 | } |
| 4074 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4075 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4076 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4077 | * 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] | 4078 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4079 | static struct net_device *get_vlan(struct genl_info *info, |
| 4080 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4081 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4082 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4083 | struct net_device *v; |
| 4084 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4085 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4086 | if (!vlanattr) |
| 4087 | return NULL; |
| 4088 | |
| 4089 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4090 | if (!v) |
| 4091 | return ERR_PTR(-ENODEV); |
| 4092 | |
| 4093 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4094 | ret = -EINVAL; |
| 4095 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4096 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4097 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4098 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4099 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4100 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4101 | ret = -EINVAL; |
| 4102 | goto error; |
| 4103 | } |
| 4104 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4105 | if (!netif_running(v)) { |
| 4106 | ret = -ENETDOWN; |
| 4107 | goto error; |
| 4108 | } |
| 4109 | |
| 4110 | return v; |
| 4111 | error: |
| 4112 | dev_put(v); |
| 4113 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4116 | static const struct nla_policy |
| 4117 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4118 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4119 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4120 | }; |
| 4121 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4122 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4123 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4124 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4125 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4126 | struct nlattr *nla; |
| 4127 | int err; |
| 4128 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4129 | /* parse WME attributes if present */ |
| 4130 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4131 | return 0; |
| 4132 | |
| 4133 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4134 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4135 | nl80211_sta_wme_policy); |
| 4136 | if (err) |
| 4137 | return err; |
| 4138 | |
| 4139 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4140 | params->uapsd_queues = nla_get_u8( |
| 4141 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4142 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4143 | return -EINVAL; |
| 4144 | |
| 4145 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4146 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4147 | |
| 4148 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4149 | return -EINVAL; |
| 4150 | |
| 4151 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4152 | |
| 4153 | return 0; |
| 4154 | } |
| 4155 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4156 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4157 | struct station_parameters *params) |
| 4158 | { |
| 4159 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4160 | params->supported_channels = |
| 4161 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4162 | params->supported_channels_len = |
| 4163 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4164 | /* |
| 4165 | * Need to include at least one (first channel, number of |
| 4166 | * channels) tuple for each subband, and must have proper |
| 4167 | * tuples for the rest of the data as well. |
| 4168 | */ |
| 4169 | if (params->supported_channels_len < 2) |
| 4170 | return -EINVAL; |
| 4171 | if (params->supported_channels_len % 2) |
| 4172 | return -EINVAL; |
| 4173 | } |
| 4174 | |
| 4175 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4176 | params->supported_oper_classes = |
| 4177 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4178 | params->supported_oper_classes_len = |
| 4179 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4180 | /* |
| 4181 | * The value of the Length field of the Supported Operating |
| 4182 | * Classes element is between 2 and 253. |
| 4183 | */ |
| 4184 | if (params->supported_oper_classes_len < 2 || |
| 4185 | params->supported_oper_classes_len > 253) |
| 4186 | return -EINVAL; |
| 4187 | } |
| 4188 | return 0; |
| 4189 | } |
| 4190 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4191 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4192 | struct station_parameters *params) |
| 4193 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4194 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4195 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4196 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4197 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4198 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4199 | params->ht_capa = |
| 4200 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4201 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4202 | params->vht_capa = |
| 4203 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4204 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4205 | err = nl80211_parse_sta_channel_info(info, params); |
| 4206 | if (err) |
| 4207 | return err; |
| 4208 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4209 | return nl80211_parse_sta_wme(info, params); |
| 4210 | } |
| 4211 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4212 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4215 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4216 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4217 | u8 *mac_addr; |
| 4218 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4219 | |
| 4220 | memset(¶ms, 0, sizeof(params)); |
| 4221 | |
| 4222 | params.listen_interval = -1; |
| 4223 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4224 | if (!rdev->ops->change_station) |
| 4225 | return -EOPNOTSUPP; |
| 4226 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4227 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4228 | return -EINVAL; |
| 4229 | |
| 4230 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4231 | return -EINVAL; |
| 4232 | |
| 4233 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4234 | |
| 4235 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4236 | params.supported_rates = |
| 4237 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4238 | params.supported_rates_len = |
| 4239 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4240 | } |
| 4241 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4242 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4243 | params.capability = |
| 4244 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4245 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4246 | } |
| 4247 | |
| 4248 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4249 | params.ext_capab = |
| 4250 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4251 | params.ext_capab_len = |
| 4252 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4253 | } |
| 4254 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4255 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4256 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4257 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4258 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4259 | return -EINVAL; |
| 4260 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4261 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4262 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4263 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4264 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4265 | return -EINVAL; |
| 4266 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4267 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4268 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4269 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4270 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4271 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4272 | return -EINVAL; |
| 4273 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4274 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4275 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4276 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4277 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4278 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4279 | |
| 4280 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4281 | pm > NL80211_MESH_POWER_MAX) |
| 4282 | return -EINVAL; |
| 4283 | |
| 4284 | params.local_pm = pm; |
| 4285 | } |
| 4286 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4287 | /* Include parameters for TDLS peer (will check later) */ |
| 4288 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4289 | if (err) |
| 4290 | return err; |
| 4291 | |
| 4292 | params.vlan = get_vlan(info, rdev); |
| 4293 | if (IS_ERR(params.vlan)) |
| 4294 | return PTR_ERR(params.vlan); |
| 4295 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4296 | switch (dev->ieee80211_ptr->iftype) { |
| 4297 | case NL80211_IFTYPE_AP: |
| 4298 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4299 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4300 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4301 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4302 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4303 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4304 | break; |
| 4305 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4306 | err = -EOPNOTSUPP; |
| 4307 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4308 | } |
| 4309 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4310 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4311 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4312 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4313 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4314 | if (params.vlan) |
| 4315 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4316 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4317 | return err; |
| 4318 | } |
| 4319 | |
| 4320 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4321 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4323 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4324 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4325 | struct station_parameters params; |
| 4326 | u8 *mac_addr = NULL; |
| 4327 | |
| 4328 | memset(¶ms, 0, sizeof(params)); |
| 4329 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4330 | if (!rdev->ops->add_station) |
| 4331 | return -EOPNOTSUPP; |
| 4332 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4333 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4334 | return -EINVAL; |
| 4335 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4336 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4337 | return -EINVAL; |
| 4338 | |
| 4339 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4340 | return -EINVAL; |
| 4341 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4342 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4343 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4344 | return -EINVAL; |
| 4345 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4346 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4347 | params.supported_rates = |
| 4348 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4349 | params.supported_rates_len = |
| 4350 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4351 | params.listen_interval = |
| 4352 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4353 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4354 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4355 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4356 | else |
| 4357 | 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] | 4358 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4359 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4360 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4361 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4362 | params.capability = |
| 4363 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4364 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4365 | } |
| 4366 | |
| 4367 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4368 | params.ext_capab = |
| 4369 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4370 | params.ext_capab_len = |
| 4371 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4372 | } |
| 4373 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4374 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4375 | params.ht_capa = |
| 4376 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4377 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4378 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4379 | params.vht_capa = |
| 4380 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4381 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4382 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4383 | params.opmode_notif_used = true; |
| 4384 | params.opmode_notif = |
| 4385 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4386 | } |
| 4387 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4388 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4389 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4390 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4391 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4392 | return -EINVAL; |
| 4393 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4394 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4395 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4396 | if (err) |
| 4397 | return err; |
| 4398 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4399 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4400 | if (err) |
| 4401 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4402 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4403 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4404 | return -EINVAL; |
| 4405 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4406 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4407 | * as userspace might just pass through the capabilities from the IEs |
| 4408 | * directly, rather than enforcing this restriction and returning an |
| 4409 | * error in this case. |
| 4410 | */ |
| 4411 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4412 | params.ht_capa = NULL; |
| 4413 | params.vht_capa = NULL; |
| 4414 | } |
| 4415 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4416 | /* When you run into this, adjust the code below for the new flag */ |
| 4417 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4418 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4419 | switch (dev->ieee80211_ptr->iftype) { |
| 4420 | case NL80211_IFTYPE_AP: |
| 4421 | case NL80211_IFTYPE_AP_VLAN: |
| 4422 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4423 | /* ignore WME attributes if iface/sta is not capable */ |
| 4424 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4425 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4426 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4427 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4428 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4429 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4430 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4431 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4432 | /* but don't bother the driver with it */ |
| 4433 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4434 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4435 | /* allow authenticated/associated only if driver handles it */ |
| 4436 | if (!(rdev->wiphy.features & |
| 4437 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4438 | params.sta_flags_mask & |
| 4439 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4440 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4441 | return -EINVAL; |
| 4442 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4443 | /* must be last in here for error handling */ |
| 4444 | params.vlan = get_vlan(info, rdev); |
| 4445 | if (IS_ERR(params.vlan)) |
| 4446 | return PTR_ERR(params.vlan); |
| 4447 | break; |
| 4448 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4449 | /* ignore uAPSD data */ |
| 4450 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4451 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4452 | /* associated is disallowed */ |
| 4453 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4454 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4455 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4456 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4457 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4458 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4459 | break; |
| 4460 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4461 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4462 | /* ignore uAPSD data */ |
| 4463 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4464 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4465 | /* these are disallowed */ |
| 4466 | if (params.sta_flags_mask & |
| 4467 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4468 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4469 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4470 | /* Only TDLS peers can be added */ |
| 4471 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4472 | return -EINVAL; |
| 4473 | /* Can only add if TDLS ... */ |
| 4474 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4475 | return -EOPNOTSUPP; |
| 4476 | /* ... with external setup is supported */ |
| 4477 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4478 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4479 | /* |
| 4480 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4481 | * as authorized, but it shouldn't yet be. |
| 4482 | */ |
| 4483 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4484 | break; |
| 4485 | default: |
| 4486 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4487 | } |
| 4488 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4489 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4490 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4491 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4492 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4493 | if (params.vlan) |
| 4494 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4495 | return err; |
| 4496 | } |
| 4497 | |
| 4498 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4499 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4501 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4502 | struct station_del_parameters params; |
| 4503 | |
| 4504 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4505 | |
| 4506 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4507 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4508 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4509 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4510 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4511 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4512 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4513 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4515 | if (!rdev->ops->del_station) |
| 4516 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4517 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4518 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4519 | params.subtype = |
| 4520 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4521 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4522 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4523 | return -EINVAL; |
| 4524 | } else { |
| 4525 | /* Default to Deauthentication frame */ |
| 4526 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4527 | } |
| 4528 | |
| 4529 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4530 | params.reason_code = |
| 4531 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4532 | if (params.reason_code == 0) |
| 4533 | return -EINVAL; /* 0 is reserved */ |
| 4534 | } else { |
| 4535 | /* Default to reason code 2 */ |
| 4536 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4537 | } |
| 4538 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4539 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4542 | 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] | 4543 | int flags, struct net_device *dev, |
| 4544 | u8 *dst, u8 *next_hop, |
| 4545 | struct mpath_info *pinfo) |
| 4546 | { |
| 4547 | void *hdr; |
| 4548 | struct nlattr *pinfoattr; |
| 4549 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4550 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4551 | if (!hdr) |
| 4552 | return -1; |
| 4553 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4554 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4555 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4556 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4557 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4558 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4559 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4560 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4561 | if (!pinfoattr) |
| 4562 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4563 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4564 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4565 | pinfo->frame_qlen)) |
| 4566 | goto nla_put_failure; |
| 4567 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4568 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4569 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4570 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4571 | pinfo->metric)) || |
| 4572 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4573 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4574 | pinfo->exptime)) || |
| 4575 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4576 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4577 | pinfo->flags)) || |
| 4578 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4579 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4580 | pinfo->discovery_timeout)) || |
| 4581 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4582 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4583 | pinfo->discovery_retries))) |
| 4584 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4585 | |
| 4586 | nla_nest_end(msg, pinfoattr); |
| 4587 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4588 | genlmsg_end(msg, hdr); |
| 4589 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4590 | |
| 4591 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4592 | genlmsg_cancel(msg, hdr); |
| 4593 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4597 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4598 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4599 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4600 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4601 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4602 | u8 dst[ETH_ALEN]; |
| 4603 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4604 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4605 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4606 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4607 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4608 | if (err) |
| 4609 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4610 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4611 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4612 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4613 | goto out_err; |
| 4614 | } |
| 4615 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4616 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4617 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4618 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4619 | } |
| 4620 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4621 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4622 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4623 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4624 | if (err == -ENOENT) |
| 4625 | break; |
| 4626 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4627 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4628 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4629 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4630 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4631 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4632 | &pinfo) < 0) |
| 4633 | goto out; |
| 4634 | |
| 4635 | path_idx++; |
| 4636 | } |
| 4637 | |
| 4638 | |
| 4639 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4640 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4641 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4642 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4643 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4644 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4648 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4650 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4651 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4652 | struct mpath_info pinfo; |
| 4653 | struct sk_buff *msg; |
| 4654 | u8 *dst = NULL; |
| 4655 | u8 next_hop[ETH_ALEN]; |
| 4656 | |
| 4657 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4658 | |
| 4659 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4660 | return -EINVAL; |
| 4661 | |
| 4662 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4664 | if (!rdev->ops->get_mpath) |
| 4665 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4668 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4670 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4671 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4672 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4673 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4675 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4676 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4677 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4678 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4679 | dev, dst, next_hop, &pinfo) < 0) { |
| 4680 | nlmsg_free(msg); |
| 4681 | return -ENOBUFS; |
| 4682 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4683 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4684 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4688 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4690 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4691 | u8 *dst = NULL; |
| 4692 | u8 *next_hop = NULL; |
| 4693 | |
| 4694 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4695 | return -EINVAL; |
| 4696 | |
| 4697 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4698 | return -EINVAL; |
| 4699 | |
| 4700 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4701 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4702 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4703 | if (!rdev->ops->change_mpath) |
| 4704 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4705 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4706 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4707 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4708 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4709 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4710 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4711 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4712 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4715 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4716 | u8 *dst = NULL; |
| 4717 | u8 *next_hop = NULL; |
| 4718 | |
| 4719 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4720 | return -EINVAL; |
| 4721 | |
| 4722 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4723 | return -EINVAL; |
| 4724 | |
| 4725 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4726 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4727 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4728 | if (!rdev->ops->add_mpath) |
| 4729 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4731 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4732 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4733 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4734 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4738 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4740 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4741 | u8 *dst = NULL; |
| 4742 | |
| 4743 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4744 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4746 | if (!rdev->ops->del_mpath) |
| 4747 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4748 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4749 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4750 | } |
| 4751 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4752 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4753 | { |
| 4754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4755 | int err; |
| 4756 | struct net_device *dev = info->user_ptr[1]; |
| 4757 | struct mpath_info pinfo; |
| 4758 | struct sk_buff *msg; |
| 4759 | u8 *dst = NULL; |
| 4760 | u8 mpp[ETH_ALEN]; |
| 4761 | |
| 4762 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4763 | |
| 4764 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4765 | return -EINVAL; |
| 4766 | |
| 4767 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4768 | |
| 4769 | if (!rdev->ops->get_mpp) |
| 4770 | return -EOPNOTSUPP; |
| 4771 | |
| 4772 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4773 | return -EOPNOTSUPP; |
| 4774 | |
| 4775 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4776 | if (err) |
| 4777 | return err; |
| 4778 | |
| 4779 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4780 | if (!msg) |
| 4781 | return -ENOMEM; |
| 4782 | |
| 4783 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4784 | dev, dst, mpp, &pinfo) < 0) { |
| 4785 | nlmsg_free(msg); |
| 4786 | return -ENOBUFS; |
| 4787 | } |
| 4788 | |
| 4789 | return genlmsg_reply(msg, info); |
| 4790 | } |
| 4791 | |
| 4792 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4793 | struct netlink_callback *cb) |
| 4794 | { |
| 4795 | struct mpath_info pinfo; |
| 4796 | struct cfg80211_registered_device *rdev; |
| 4797 | struct wireless_dev *wdev; |
| 4798 | u8 dst[ETH_ALEN]; |
| 4799 | u8 mpp[ETH_ALEN]; |
| 4800 | int path_idx = cb->args[2]; |
| 4801 | int err; |
| 4802 | |
| 4803 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4804 | if (err) |
| 4805 | return err; |
| 4806 | |
| 4807 | if (!rdev->ops->dump_mpp) { |
| 4808 | err = -EOPNOTSUPP; |
| 4809 | goto out_err; |
| 4810 | } |
| 4811 | |
| 4812 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4813 | err = -EOPNOTSUPP; |
| 4814 | goto out_err; |
| 4815 | } |
| 4816 | |
| 4817 | while (1) { |
| 4818 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4819 | mpp, &pinfo); |
| 4820 | if (err == -ENOENT) |
| 4821 | break; |
| 4822 | if (err) |
| 4823 | goto out_err; |
| 4824 | |
| 4825 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4826 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4827 | wdev->netdev, dst, mpp, |
| 4828 | &pinfo) < 0) |
| 4829 | goto out; |
| 4830 | |
| 4831 | path_idx++; |
| 4832 | } |
| 4833 | |
| 4834 | out: |
| 4835 | cb->args[2] = path_idx; |
| 4836 | err = skb->len; |
| 4837 | out_err: |
| 4838 | nl80211_finish_wdev_dump(rdev); |
| 4839 | return err; |
| 4840 | } |
| 4841 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4842 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4843 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4845 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4846 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4847 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4848 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4849 | |
| 4850 | memset(¶ms, 0, sizeof(params)); |
| 4851 | /* default to not changing parameters */ |
| 4852 | params.use_cts_prot = -1; |
| 4853 | params.use_short_preamble = -1; |
| 4854 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4855 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4856 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4857 | params.p2p_ctwindow = -1; |
| 4858 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4859 | |
| 4860 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4861 | params.use_cts_prot = |
| 4862 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4863 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4864 | params.use_short_preamble = |
| 4865 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4866 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4867 | params.use_short_slot_time = |
| 4868 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4869 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4870 | params.basic_rates = |
| 4871 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4872 | params.basic_rates_len = |
| 4873 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4874 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4875 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4876 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4877 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4878 | params.ht_opmode = |
| 4879 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4880 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4881 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4883 | return -EINVAL; |
| 4884 | params.p2p_ctwindow = |
| 4885 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4886 | if (params.p2p_ctwindow < 0) |
| 4887 | return -EINVAL; |
| 4888 | if (params.p2p_ctwindow != 0 && |
| 4889 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4890 | return -EINVAL; |
| 4891 | } |
| 4892 | |
| 4893 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4894 | u8 tmp; |
| 4895 | |
| 4896 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4897 | return -EINVAL; |
| 4898 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4899 | if (tmp > 1) |
| 4900 | return -EINVAL; |
| 4901 | params.p2p_opp_ps = tmp; |
| 4902 | if (params.p2p_opp_ps && |
| 4903 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4904 | return -EINVAL; |
| 4905 | } |
| 4906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4907 | if (!rdev->ops->change_bss) |
| 4908 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4909 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4910 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4911 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4912 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4913 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4914 | wdev_lock(wdev); |
| 4915 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4916 | wdev_unlock(wdev); |
| 4917 | |
| 4918 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4919 | } |
| 4920 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4921 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4922 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4923 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4924 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4925 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4926 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4927 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4928 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4929 | }; |
| 4930 | |
| 4931 | static int parse_reg_rule(struct nlattr *tb[], |
| 4932 | struct ieee80211_reg_rule *reg_rule) |
| 4933 | { |
| 4934 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4935 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4936 | |
| 4937 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4938 | return -EINVAL; |
| 4939 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4940 | return -EINVAL; |
| 4941 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4942 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4943 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4944 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4945 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4946 | return -EINVAL; |
| 4947 | |
| 4948 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4949 | |
| 4950 | freq_range->start_freq_khz = |
| 4951 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4952 | freq_range->end_freq_khz = |
| 4953 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4954 | freq_range->max_bandwidth_khz = |
| 4955 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4956 | |
| 4957 | power_rule->max_eirp = |
| 4958 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4959 | |
| 4960 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4961 | power_rule->max_antenna_gain = |
| 4962 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4963 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4964 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4965 | reg_rule->dfs_cac_ms = |
| 4966 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4967 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4968 | return 0; |
| 4969 | } |
| 4970 | |
| 4971 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4972 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4973 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4974 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4975 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4976 | u32 owner_nlportid; |
| 4977 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4978 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4979 | /* |
| 4980 | * You should only get this when cfg80211 hasn't yet initialized |
| 4981 | * completely when built-in to the kernel right between the time |
| 4982 | * window between nl80211_init() and regulatory_init(), if that is |
| 4983 | * even possible. |
| 4984 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4985 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4986 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4987 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4988 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4989 | user_reg_hint_type = |
| 4990 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4991 | else |
| 4992 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4993 | |
| 4994 | switch (user_reg_hint_type) { |
| 4995 | case NL80211_USER_REG_HINT_USER: |
| 4996 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4997 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4998 | return -EINVAL; |
| 4999 | |
| 5000 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5001 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5002 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5003 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5004 | owner_nlportid = info->snd_portid; |
| 5005 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5006 | } else { |
| 5007 | owner_nlportid = 0; |
| 5008 | is_indoor = true; |
| 5009 | } |
| 5010 | |
| 5011 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5012 | default: |
| 5013 | return -EINVAL; |
| 5014 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5017 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5018 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5019 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5022 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5023 | struct mesh_config cur_params; |
| 5024 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5025 | void *hdr; |
| 5026 | struct nlattr *pinfoattr; |
| 5027 | struct sk_buff *msg; |
| 5028 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5029 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5030 | return -EOPNOTSUPP; |
| 5031 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5032 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5033 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5034 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5035 | wdev_lock(wdev); |
| 5036 | /* If not connected, get default parameters */ |
| 5037 | if (!wdev->mesh_id_len) |
| 5038 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5039 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5040 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5041 | wdev_unlock(wdev); |
| 5042 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5043 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5044 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5045 | |
| 5046 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5047 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5048 | if (!msg) |
| 5049 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5050 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5051 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5052 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5053 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5054 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5055 | if (!pinfoattr) |
| 5056 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5057 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5058 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5059 | cur_params.dot11MeshRetryTimeout) || |
| 5060 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5061 | cur_params.dot11MeshConfirmTimeout) || |
| 5062 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5063 | cur_params.dot11MeshHoldingTimeout) || |
| 5064 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5065 | cur_params.dot11MeshMaxPeerLinks) || |
| 5066 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5067 | cur_params.dot11MeshMaxRetries) || |
| 5068 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5069 | cur_params.dot11MeshTTL) || |
| 5070 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5071 | cur_params.element_ttl) || |
| 5072 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5073 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5074 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5075 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5076 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5077 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5078 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5079 | cur_params.path_refresh_time) || |
| 5080 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5081 | cur_params.min_discovery_timeout) || |
| 5082 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5083 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5084 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5085 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5086 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5087 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5088 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5089 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5090 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5091 | cur_params.dot11MeshHWMPRootMode) || |
| 5092 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5093 | cur_params.dot11MeshHWMPRannInterval) || |
| 5094 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5095 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5096 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5097 | cur_params.dot11MeshForwarding) || |
| 5098 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5099 | cur_params.rssi_threshold) || |
| 5100 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5101 | cur_params.ht_opmode) || |
| 5102 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5103 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5104 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5105 | cur_params.dot11MeshHWMProotInterval) || |
| 5106 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5107 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5108 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5109 | cur_params.power_mode) || |
| 5110 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5111 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5112 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5113 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5114 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5115 | nla_nest_end(msg, pinfoattr); |
| 5116 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5118 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5119 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5120 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5121 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5122 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5123 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5126 | 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] | 5127 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5128 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5129 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5130 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5131 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5132 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5133 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5134 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5135 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5136 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5137 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5138 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5139 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5140 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5141 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5142 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5143 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5144 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5145 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5146 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5147 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5148 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5149 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5150 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5151 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5152 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5153 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5154 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5155 | }; |
| 5156 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5157 | static const struct nla_policy |
| 5158 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5159 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5160 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5161 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5162 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5163 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5164 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5165 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5166 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5167 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5168 | }; |
| 5169 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5170 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5171 | struct mesh_config *cfg, |
| 5172 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5173 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5174 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5175 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5176 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5177 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5178 | do { \ |
| 5179 | if (tb[attr]) { \ |
| 5180 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5181 | return -EINVAL; \ |
| 5182 | cfg->param = fn(tb[attr]); \ |
| 5183 | mask |= (1 << (attr - 1)); \ |
| 5184 | } \ |
| 5185 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5186 | |
| 5187 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5188 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5189 | return -EINVAL; |
| 5190 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5191 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5192 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5193 | return -EINVAL; |
| 5194 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5195 | /* This makes sure that there aren't more than 32 mesh config |
| 5196 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5197 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5198 | |
| 5199 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5200 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5201 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5202 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5203 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5204 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5205 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5207 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5208 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5210 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5211 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5213 | mask, NL80211_MESHCONF_MAX_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, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5216 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5217 | 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] | 5218 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5219 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5221 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5222 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5223 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5224 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5225 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5226 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5227 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5228 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5229 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5230 | 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] | 5231 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5232 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5233 | 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] | 5234 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5235 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5237 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5238 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5239 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5240 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5241 | 1, 65535, mask, |
| 5242 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5243 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5245 | 1, 65535, mask, |
| 5246 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5247 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5248 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5249 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5250 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5251 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5252 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5253 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5254 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5255 | nla_get_u8); |
| 5256 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5257 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5258 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5259 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5260 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5261 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5262 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5263 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5264 | mask, NL80211_MESHCONF_FORWARDING, |
| 5265 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5266 | 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] | 5267 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5268 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5269 | 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] | 5270 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5271 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5272 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5273 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5274 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5275 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5276 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5277 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5278 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5279 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5280 | dot11MeshHWMPconfirmationInterval, |
| 5281 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5282 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5283 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5284 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5285 | NL80211_MESH_POWER_ACTIVE, |
| 5286 | NL80211_MESH_POWER_MAX, |
| 5287 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5288 | nla_get_u32); |
| 5289 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5290 | 0, 65535, mask, |
| 5291 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5292 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5293 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5294 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5295 | if (mask_out) |
| 5296 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5297 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5298 | return 0; |
| 5299 | |
| 5300 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5301 | } |
| 5302 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5303 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5304 | struct mesh_setup *setup) |
| 5305 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5307 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5308 | |
| 5309 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5310 | return -EINVAL; |
| 5311 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5312 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5313 | nl80211_mesh_setup_params_policy)) |
| 5314 | return -EINVAL; |
| 5315 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5316 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5317 | setup->sync_method = |
| 5318 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5319 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5320 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5321 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5322 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5323 | setup->path_sel_proto = |
| 5324 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5325 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5326 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5327 | |
| 5328 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5329 | setup->path_metric = |
| 5330 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5331 | IEEE80211_PATH_METRIC_VENDOR : |
| 5332 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5333 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5334 | |
| 5335 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5336 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5337 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5338 | if (!is_valid_ie_attr(ieattr)) |
| 5339 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5340 | setup->ie = nla_data(ieattr); |
| 5341 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5342 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5343 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5344 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5345 | return -EINVAL; |
| 5346 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5347 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5348 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5349 | if (setup->is_secure) |
| 5350 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5351 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5352 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5353 | if (!setup->user_mpm) |
| 5354 | return -EINVAL; |
| 5355 | setup->auth_id = |
| 5356 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5357 | } |
| 5358 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5359 | return 0; |
| 5360 | } |
| 5361 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5362 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5363 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5364 | { |
| 5365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5366 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5367 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5368 | struct mesh_config cfg; |
| 5369 | u32 mask; |
| 5370 | int err; |
| 5371 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5372 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5373 | return -EOPNOTSUPP; |
| 5374 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5375 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5376 | return -EOPNOTSUPP; |
| 5377 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5378 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5379 | if (err) |
| 5380 | return err; |
| 5381 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5382 | wdev_lock(wdev); |
| 5383 | if (!wdev->mesh_id_len) |
| 5384 | err = -ENOLINK; |
| 5385 | |
| 5386 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5387 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5388 | |
| 5389 | wdev_unlock(wdev); |
| 5390 | |
| 5391 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5392 | } |
| 5393 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5394 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5395 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5396 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5397 | struct nlattr *nl_reg_rules; |
| 5398 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5399 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5400 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5401 | (regdom->dfs_region && |
| 5402 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5403 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5404 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5405 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5406 | if (!nl_reg_rules) |
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 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5409 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5410 | struct nlattr *nl_reg_rule; |
| 5411 | const struct ieee80211_reg_rule *reg_rule; |
| 5412 | const struct ieee80211_freq_range *freq_range; |
| 5413 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5414 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5415 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5416 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5417 | freq_range = ®_rule->freq_range; |
| 5418 | power_rule = ®_rule->power_rule; |
| 5419 | |
| 5420 | nl_reg_rule = nla_nest_start(msg, i); |
| 5421 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5422 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5423 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5424 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5425 | if (!max_bandwidth_khz) |
| 5426 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5427 | reg_rule); |
| 5428 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5429 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5430 | reg_rule->flags) || |
| 5431 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5432 | freq_range->start_freq_khz) || |
| 5433 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5434 | freq_range->end_freq_khz) || |
| 5435 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5436 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5437 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5438 | power_rule->max_antenna_gain) || |
| 5439 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5440 | power_rule->max_eirp) || |
| 5441 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5442 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5443 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5444 | |
| 5445 | nla_nest_end(msg, nl_reg_rule); |
| 5446 | } |
| 5447 | |
| 5448 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5449 | return 0; |
| 5450 | |
| 5451 | nla_put_failure: |
| 5452 | return -EMSGSIZE; |
| 5453 | } |
| 5454 | |
| 5455 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5456 | { |
| 5457 | const struct ieee80211_regdomain *regdom = NULL; |
| 5458 | struct cfg80211_registered_device *rdev; |
| 5459 | struct wiphy *wiphy = NULL; |
| 5460 | struct sk_buff *msg; |
| 5461 | void *hdr; |
| 5462 | |
| 5463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5464 | if (!msg) |
| 5465 | return -ENOBUFS; |
| 5466 | |
| 5467 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5468 | NL80211_CMD_GET_REG); |
| 5469 | if (!hdr) |
| 5470 | goto put_failure; |
| 5471 | |
| 5472 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5473 | bool self_managed; |
| 5474 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5475 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5476 | if (IS_ERR(rdev)) { |
| 5477 | nlmsg_free(msg); |
| 5478 | return PTR_ERR(rdev); |
| 5479 | } |
| 5480 | |
| 5481 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5482 | self_managed = wiphy->regulatory_flags & |
| 5483 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5484 | regdom = get_wiphy_regdom(wiphy); |
| 5485 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5486 | /* a self-managed-reg device must have a private regdom */ |
| 5487 | if (WARN_ON(!regdom && self_managed)) { |
| 5488 | nlmsg_free(msg); |
| 5489 | return -EINVAL; |
| 5490 | } |
| 5491 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5492 | if (regdom && |
| 5493 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5494 | goto nla_put_failure; |
| 5495 | } |
| 5496 | |
| 5497 | if (!wiphy && reg_last_request_cell_base() && |
| 5498 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5499 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5500 | goto nla_put_failure; |
| 5501 | |
| 5502 | rcu_read_lock(); |
| 5503 | |
| 5504 | if (!regdom) |
| 5505 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5506 | |
| 5507 | if (nl80211_put_regdom(regdom, msg)) |
| 5508 | goto nla_put_failure_rcu; |
| 5509 | |
| 5510 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5511 | |
| 5512 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5513 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5514 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5515 | nla_put_failure_rcu: |
| 5516 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5517 | nla_put_failure: |
| 5518 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5519 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5520 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5521 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5522 | } |
| 5523 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5524 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5525 | u32 seq, int flags, struct wiphy *wiphy, |
| 5526 | const struct ieee80211_regdomain *regdom) |
| 5527 | { |
| 5528 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5529 | NL80211_CMD_GET_REG); |
| 5530 | |
| 5531 | if (!hdr) |
| 5532 | return -1; |
| 5533 | |
| 5534 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5535 | |
| 5536 | if (nl80211_put_regdom(regdom, msg)) |
| 5537 | goto nla_put_failure; |
| 5538 | |
| 5539 | if (!wiphy && reg_last_request_cell_base() && |
| 5540 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5541 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5542 | goto nla_put_failure; |
| 5543 | |
| 5544 | if (wiphy && |
| 5545 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5546 | goto nla_put_failure; |
| 5547 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5548 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5549 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5550 | goto nla_put_failure; |
| 5551 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5552 | genlmsg_end(msg, hdr); |
| 5553 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5554 | |
| 5555 | nla_put_failure: |
| 5556 | genlmsg_cancel(msg, hdr); |
| 5557 | return -EMSGSIZE; |
| 5558 | } |
| 5559 | |
| 5560 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5561 | struct netlink_callback *cb) |
| 5562 | { |
| 5563 | const struct ieee80211_regdomain *regdom = NULL; |
| 5564 | struct cfg80211_registered_device *rdev; |
| 5565 | int err, reg_idx, start = cb->args[2]; |
| 5566 | |
| 5567 | rtnl_lock(); |
| 5568 | |
| 5569 | if (cfg80211_regdomain && start == 0) { |
| 5570 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5571 | NLM_F_MULTI, NULL, |
| 5572 | rtnl_dereference(cfg80211_regdomain)); |
| 5573 | if (err < 0) |
| 5574 | goto out_err; |
| 5575 | } |
| 5576 | |
| 5577 | /* the global regdom is idx 0 */ |
| 5578 | reg_idx = 1; |
| 5579 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5580 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5581 | if (!regdom) |
| 5582 | continue; |
| 5583 | |
| 5584 | if (++reg_idx <= start) |
| 5585 | continue; |
| 5586 | |
| 5587 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5588 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5589 | if (err < 0) { |
| 5590 | reg_idx--; |
| 5591 | break; |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | cb->args[2] = reg_idx; |
| 5596 | err = skb->len; |
| 5597 | out_err: |
| 5598 | rtnl_unlock(); |
| 5599 | return err; |
| 5600 | } |
| 5601 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5602 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5603 | { |
| 5604 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5605 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5606 | char *alpha2; |
| 5607 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5608 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5609 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5610 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5611 | |
| 5612 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5613 | return -EINVAL; |
| 5614 | |
| 5615 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5616 | return -EINVAL; |
| 5617 | |
| 5618 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5619 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5620 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5621 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5622 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5623 | 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] | 5624 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5625 | num_rules++; |
| 5626 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5627 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5628 | } |
| 5629 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5630 | if (!reg_is_valid_request(alpha2)) |
| 5631 | return -EINVAL; |
| 5632 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5633 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5634 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5635 | |
| 5636 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5637 | if (!rd) |
| 5638 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5639 | |
| 5640 | rd->n_reg_rules = num_rules; |
| 5641 | rd->alpha2[0] = alpha2[0]; |
| 5642 | rd->alpha2[1] = alpha2[1]; |
| 5643 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5644 | /* |
| 5645 | * Disable DFS master mode if the DFS region was |
| 5646 | * not supported or known on this kernel. |
| 5647 | */ |
| 5648 | if (reg_supported_dfs_region(dfs_region)) |
| 5649 | rd->dfs_region = dfs_region; |
| 5650 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5651 | 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] | 5652 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5653 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5654 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5655 | reg_rule_policy); |
| 5656 | if (r) |
| 5657 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5658 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5659 | if (r) |
| 5660 | goto bad_reg; |
| 5661 | |
| 5662 | rule_idx++; |
| 5663 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5664 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5665 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5666 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5667 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5668 | } |
| 5669 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 5670 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5671 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5672 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5673 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5674 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5675 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5676 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5677 | } |
| 5678 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5679 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5680 | { |
| 5681 | struct nlattr *attr1, *attr2; |
| 5682 | int n_channels = 0, tmp1, tmp2; |
| 5683 | |
| 5684 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5685 | n_channels++; |
| 5686 | /* |
| 5687 | * Some hardware has a limited channel list for |
| 5688 | * scanning, and it is pretty much nonsensical |
| 5689 | * to scan for a channel twice, so disallow that |
| 5690 | * and don't require drivers to check that the |
| 5691 | * channel list they get isn't longer than what |
| 5692 | * they can scan, as long as they can scan all |
| 5693 | * the channels they registered at once. |
| 5694 | */ |
| 5695 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5696 | if (attr1 != attr2 && |
| 5697 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5698 | return 0; |
| 5699 | } |
| 5700 | |
| 5701 | return n_channels; |
| 5702 | } |
| 5703 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5704 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5705 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5706 | { |
| 5707 | int i; |
| 5708 | |
| 5709 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 5710 | eth_zero_addr(mac_addr); |
| 5711 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5712 | mac_addr[0] = 0x2; |
| 5713 | mac_addr_mask[0] = 0x3; |
| 5714 | |
| 5715 | return 0; |
| 5716 | } |
| 5717 | |
| 5718 | /* need both or none */ |
| 5719 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5720 | return -EINVAL; |
| 5721 | |
| 5722 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5723 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5724 | |
| 5725 | /* don't allow or configure an mcast address */ |
| 5726 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5727 | is_multicast_ether_addr(mac_addr)) |
| 5728 | return -EINVAL; |
| 5729 | |
| 5730 | /* |
| 5731 | * allow users to pass a MAC address that has bits set outside |
| 5732 | * of the mask, but don't bother drivers with having to deal |
| 5733 | * with such bits |
| 5734 | */ |
| 5735 | for (i = 0; i < ETH_ALEN; i++) |
| 5736 | mac_addr[i] &= mac_addr_mask[i]; |
| 5737 | |
| 5738 | return 0; |
| 5739 | } |
| 5740 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5741 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5742 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5744 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5745 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5746 | struct nlattr *attr; |
| 5747 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5748 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5749 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5750 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5751 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5752 | return -EINVAL; |
| 5753 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5754 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5756 | if (!rdev->ops->scan) |
| 5757 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5758 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5759 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5760 | err = -EBUSY; |
| 5761 | goto unlock; |
| 5762 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5763 | |
| 5764 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5765 | n_channels = validate_scan_freqs( |
| 5766 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5767 | if (!n_channels) { |
| 5768 | err = -EINVAL; |
| 5769 | goto unlock; |
| 5770 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5771 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5772 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5776 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5777 | n_ssids++; |
| 5778 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5779 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5780 | err = -EINVAL; |
| 5781 | goto unlock; |
| 5782 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5783 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5784 | if (info->attrs[NL80211_ATTR_IE]) |
| 5785 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5786 | else |
| 5787 | ie_len = 0; |
| 5788 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5789 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5790 | err = -EINVAL; |
| 5791 | goto unlock; |
| 5792 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5793 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5794 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5795 | + sizeof(*request->ssids) * n_ssids |
| 5796 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5797 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5798 | if (!request) { |
| 5799 | err = -ENOMEM; |
| 5800 | goto unlock; |
| 5801 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5803 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5804 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5805 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5806 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5807 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5808 | request->ie = (void *)(request->ssids + n_ssids); |
| 5809 | else |
| 5810 | request->ie = (void *)(request->channels + n_channels); |
| 5811 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5812 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5813 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5814 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5815 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5816 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5817 | struct ieee80211_channel *chan; |
| 5818 | |
| 5819 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5820 | |
| 5821 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5822 | err = -EINVAL; |
| 5823 | goto out_free; |
| 5824 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5825 | |
| 5826 | /* ignore disabled channels */ |
| 5827 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5828 | continue; |
| 5829 | |
| 5830 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5831 | i++; |
| 5832 | } |
| 5833 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5834 | enum ieee80211_band band; |
| 5835 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5836 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5837 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5838 | int j; |
| 5839 | if (!wiphy->bands[band]) |
| 5840 | continue; |
| 5841 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5842 | struct ieee80211_channel *chan; |
| 5843 | |
| 5844 | chan = &wiphy->bands[band]->channels[j]; |
| 5845 | |
| 5846 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5847 | continue; |
| 5848 | |
| 5849 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5850 | i++; |
| 5851 | } |
| 5852 | } |
| 5853 | } |
| 5854 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5855 | if (!i) { |
| 5856 | err = -EINVAL; |
| 5857 | goto out_free; |
| 5858 | } |
| 5859 | |
| 5860 | request->n_channels = i; |
| 5861 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5863 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5864 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5865 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5866 | err = -EINVAL; |
| 5867 | goto out_free; |
| 5868 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5869 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5871 | i++; |
| 5872 | } |
| 5873 | } |
| 5874 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5875 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5876 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5877 | memcpy((void *)request->ie, |
| 5878 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5879 | request->ie_len); |
| 5880 | } |
| 5881 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5882 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5883 | if (wiphy->bands[i]) |
| 5884 | request->rates[i] = |
| 5885 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5886 | |
| 5887 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5888 | nla_for_each_nested(attr, |
| 5889 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5890 | tmp) { |
| 5891 | enum ieee80211_band band = nla_type(attr); |
| 5892 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5893 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5894 | err = -EINVAL; |
| 5895 | goto out_free; |
| 5896 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5897 | |
| 5898 | if (!wiphy->bands[band]) |
| 5899 | continue; |
| 5900 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5901 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5902 | nla_data(attr), |
| 5903 | nla_len(attr), |
| 5904 | &request->rates[band]); |
| 5905 | if (err) |
| 5906 | goto out_free; |
| 5907 | } |
| 5908 | } |
| 5909 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5910 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5911 | request->flags = nla_get_u32( |
| 5912 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5913 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5914 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5915 | err = -EOPNOTSUPP; |
| 5916 | goto out_free; |
| 5917 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5918 | |
| 5919 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5920 | if (!(wiphy->features & |
| 5921 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5922 | err = -EOPNOTSUPP; |
| 5923 | goto out_free; |
| 5924 | } |
| 5925 | |
| 5926 | if (wdev->current_bss) { |
| 5927 | err = -EOPNOTSUPP; |
| 5928 | goto out_free; |
| 5929 | } |
| 5930 | |
| 5931 | err = nl80211_parse_random_mac(info->attrs, |
| 5932 | request->mac_addr, |
| 5933 | request->mac_addr_mask); |
| 5934 | if (err) |
| 5935 | goto out_free; |
| 5936 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5937 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5938 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5939 | request->no_cck = |
| 5940 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5941 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5942 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5943 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5944 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5945 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5946 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5947 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5948 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5949 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5950 | nl80211_send_scan_start(rdev, wdev); |
| 5951 | if (wdev->netdev) |
| 5952 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5953 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5954 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5955 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5956 | kfree(request); |
| 5957 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5958 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5959 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5960 | return err; |
| 5961 | } |
| 5962 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5963 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5964 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5965 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5966 | { |
| 5967 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5968 | struct nlattr *attr; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5969 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5970 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5971 | enum ieee80211_band band; |
| 5972 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5973 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5974 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5975 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5976 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 5977 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5978 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5979 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5980 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5981 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5982 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5983 | if (interval == 0) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5984 | return ERR_PTR(-EINVAL); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5985 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5986 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5987 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5988 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5989 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5990 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5991 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5992 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5993 | } |
| 5994 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5995 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5996 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5997 | tmp) |
| 5998 | n_ssids++; |
| 5999 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6000 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6001 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6002 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6003 | /* |
| 6004 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6005 | * the old implementation, matchsets containing only the RSSI attribute |
| 6006 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6007 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6008 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6009 | * older userspace that treated a matchset with only the RSSI as the |
| 6010 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6011 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6012 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6013 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6014 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6015 | tmp) { |
| 6016 | struct nlattr *rssi; |
| 6017 | |
| 6018 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6019 | nla_data(attr), nla_len(attr), |
| 6020 | nl80211_match_policy); |
| 6021 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6022 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6023 | /* add other standalone attributes here */ |
| 6024 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6025 | n_match_sets++; |
| 6026 | continue; |
| 6027 | } |
| 6028 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6029 | if (rssi) |
| 6030 | default_match_rssi = nla_get_s32(rssi); |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | /* However, if there's no other matchset, add the RSSI one */ |
| 6035 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6036 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6037 | |
| 6038 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6039 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6040 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6041 | if (attrs[NL80211_ATTR_IE]) |
| 6042 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6043 | else |
| 6044 | ie_len = 0; |
| 6045 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6046 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6047 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6048 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6049 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6050 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6051 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6052 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6053 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6054 | if (!request) |
| 6055 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6056 | |
| 6057 | if (n_ssids) |
| 6058 | request->ssids = (void *)&request->channels[n_channels]; |
| 6059 | request->n_ssids = n_ssids; |
| 6060 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6061 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6062 | request->ie = (void *)(request->ssids + n_ssids); |
| 6063 | else |
| 6064 | request->ie = (void *)(request->channels + n_channels); |
| 6065 | } |
| 6066 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6067 | if (n_match_sets) { |
| 6068 | if (request->ie) |
| 6069 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6070 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6071 | request->match_sets = |
| 6072 | (void *)(request->ssids + n_ssids); |
| 6073 | else |
| 6074 | request->match_sets = |
| 6075 | (void *)(request->channels + n_channels); |
| 6076 | } |
| 6077 | request->n_match_sets = n_match_sets; |
| 6078 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6079 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6080 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6081 | /* user specified, bail out if channel not found */ |
| 6082 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6083 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6084 | tmp) { |
| 6085 | struct ieee80211_channel *chan; |
| 6086 | |
| 6087 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6088 | |
| 6089 | if (!chan) { |
| 6090 | err = -EINVAL; |
| 6091 | goto out_free; |
| 6092 | } |
| 6093 | |
| 6094 | /* ignore disabled channels */ |
| 6095 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6096 | continue; |
| 6097 | |
| 6098 | request->channels[i] = chan; |
| 6099 | i++; |
| 6100 | } |
| 6101 | } else { |
| 6102 | /* all channels */ |
| 6103 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6104 | int j; |
| 6105 | if (!wiphy->bands[band]) |
| 6106 | continue; |
| 6107 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6108 | struct ieee80211_channel *chan; |
| 6109 | |
| 6110 | chan = &wiphy->bands[band]->channels[j]; |
| 6111 | |
| 6112 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6113 | continue; |
| 6114 | |
| 6115 | request->channels[i] = chan; |
| 6116 | i++; |
| 6117 | } |
| 6118 | } |
| 6119 | } |
| 6120 | |
| 6121 | if (!i) { |
| 6122 | err = -EINVAL; |
| 6123 | goto out_free; |
| 6124 | } |
| 6125 | |
| 6126 | request->n_channels = i; |
| 6127 | |
| 6128 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6129 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 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) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6132 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6133 | err = -EINVAL; |
| 6134 | goto out_free; |
| 6135 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6136 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6137 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6138 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6139 | i++; |
| 6140 | } |
| 6141 | } |
| 6142 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6143 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6144 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6145 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6146 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6147 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6148 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6149 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6150 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6151 | nla_data(attr), nla_len(attr), |
| 6152 | nl80211_match_policy); |
| 6153 | if (err) |
| 6154 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6155 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6156 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6157 | if (WARN_ON(i >= n_match_sets)) { |
| 6158 | /* this indicates a programming error, |
| 6159 | * the loop above should have verified |
| 6160 | * things properly |
| 6161 | */ |
| 6162 | err = -EINVAL; |
| 6163 | goto out_free; |
| 6164 | } |
| 6165 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6166 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6167 | err = -EINVAL; |
| 6168 | goto out_free; |
| 6169 | } |
| 6170 | memcpy(request->match_sets[i].ssid.ssid, |
| 6171 | nla_data(ssid), nla_len(ssid)); |
| 6172 | request->match_sets[i].ssid.ssid_len = |
| 6173 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6174 | /* special attribute - old implemenation w/a */ |
| 6175 | request->match_sets[i].rssi_thold = |
| 6176 | default_match_rssi; |
| 6177 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6178 | if (rssi) |
| 6179 | request->match_sets[i].rssi_thold = |
| 6180 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6181 | } |
| 6182 | i++; |
| 6183 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6184 | |
| 6185 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6186 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6187 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6188 | |
| 6189 | request->min_rssi_thold = INT_MAX; |
| 6190 | for (i = 0; i < n_match_sets; i++) |
| 6191 | request->min_rssi_thold = |
| 6192 | min(request->match_sets[i].rssi_thold, |
| 6193 | request->min_rssi_thold); |
| 6194 | } else { |
| 6195 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6196 | } |
| 6197 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6198 | if (ie_len) { |
| 6199 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6200 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6201 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6202 | request->ie_len); |
| 6203 | } |
| 6204 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6205 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6206 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6207 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6208 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6209 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6210 | err = -EOPNOTSUPP; |
| 6211 | goto out_free; |
| 6212 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6213 | |
| 6214 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6215 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6216 | |
| 6217 | if (!wdev) /* must be net-detect */ |
| 6218 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6219 | |
| 6220 | if (!(wiphy->features & flg)) { |
| 6221 | err = -EOPNOTSUPP; |
| 6222 | goto out_free; |
| 6223 | } |
| 6224 | |
| 6225 | if (wdev && wdev->current_bss) { |
| 6226 | err = -EOPNOTSUPP; |
| 6227 | goto out_free; |
| 6228 | } |
| 6229 | |
| 6230 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6231 | request->mac_addr_mask); |
| 6232 | if (err) |
| 6233 | goto out_free; |
| 6234 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6235 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6236 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6237 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6238 | request->delay = |
| 6239 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6240 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 6241 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6242 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6243 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6244 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6245 | |
| 6246 | out_free: |
| 6247 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6248 | return ERR_PTR(err); |
| 6249 | } |
| 6250 | |
| 6251 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6252 | struct genl_info *info) |
| 6253 | { |
| 6254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6255 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6256 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6257 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6258 | int err; |
| 6259 | |
| 6260 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6261 | !rdev->ops->sched_scan_start) |
| 6262 | return -EOPNOTSUPP; |
| 6263 | |
| 6264 | if (rdev->sched_scan_req) |
| 6265 | return -EINPROGRESS; |
| 6266 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6267 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6268 | info->attrs); |
| 6269 | |
| 6270 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6271 | if (err) |
| 6272 | goto out_err; |
| 6273 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6274 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6275 | if (err) |
| 6276 | goto out_free; |
| 6277 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6278 | sched_scan_req->dev = dev; |
| 6279 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6280 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6281 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6282 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6283 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6284 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6285 | |
| 6286 | nl80211_send_sched_scan(rdev, dev, |
| 6287 | NL80211_CMD_START_SCHED_SCAN); |
| 6288 | return 0; |
| 6289 | |
| 6290 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6291 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6292 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6293 | return err; |
| 6294 | } |
| 6295 | |
| 6296 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6297 | struct genl_info *info) |
| 6298 | { |
| 6299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6300 | |
| 6301 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6302 | !rdev->ops->sched_scan_stop) |
| 6303 | return -EOPNOTSUPP; |
| 6304 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6305 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6306 | } |
| 6307 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6308 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6309 | struct genl_info *info) |
| 6310 | { |
| 6311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6312 | struct net_device *dev = info->user_ptr[1]; |
| 6313 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6314 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6315 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6316 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6317 | int err; |
| 6318 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6319 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6320 | if (dfs_region == NL80211_DFS_UNSET) |
| 6321 | return -EINVAL; |
| 6322 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6323 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6324 | if (err) |
| 6325 | return err; |
| 6326 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6327 | if (netif_carrier_ok(dev)) |
| 6328 | return -EBUSY; |
| 6329 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6330 | if (wdev->cac_started) |
| 6331 | return -EBUSY; |
| 6332 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6333 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6334 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6335 | if (err < 0) |
| 6336 | return err; |
| 6337 | |
| 6338 | if (err == 0) |
| 6339 | return -EINVAL; |
| 6340 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6341 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6342 | return -EINVAL; |
| 6343 | |
| 6344 | if (!rdev->ops->start_radar_detection) |
| 6345 | return -EOPNOTSUPP; |
| 6346 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6347 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6348 | if (WARN_ON(!cac_time_ms)) |
| 6349 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6350 | |
| 6351 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6352 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6353 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6354 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6355 | wdev->cac_started = true; |
| 6356 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6357 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6358 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6359 | return err; |
| 6360 | } |
| 6361 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6362 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6363 | { |
| 6364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6365 | struct net_device *dev = info->user_ptr[1]; |
| 6366 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6367 | struct cfg80211_csa_settings params; |
| 6368 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6369 | * function is called under RTNL lock, so this should not be a problem. |
| 6370 | */ |
| 6371 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6372 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6373 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6374 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6375 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6376 | |
| 6377 | if (!rdev->ops->channel_switch || |
| 6378 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6379 | return -EOPNOTSUPP; |
| 6380 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6381 | switch (dev->ieee80211_ptr->iftype) { |
| 6382 | case NL80211_IFTYPE_AP: |
| 6383 | case NL80211_IFTYPE_P2P_GO: |
| 6384 | need_new_beacon = true; |
| 6385 | |
| 6386 | /* useless if AP is not running */ |
| 6387 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6388 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6389 | break; |
| 6390 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6391 | if (!wdev->ssid_len) |
| 6392 | return -ENOTCONN; |
| 6393 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6394 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6395 | if (!wdev->mesh_id_len) |
| 6396 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6397 | break; |
| 6398 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6399 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6400 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6401 | |
| 6402 | memset(¶ms, 0, sizeof(params)); |
| 6403 | |
| 6404 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6405 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6406 | return -EINVAL; |
| 6407 | |
| 6408 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6409 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6410 | return -EINVAL; |
| 6411 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6412 | /* Even though the attribute is u32, the specification says |
| 6413 | * u8, so let's make sure we don't overflow. |
| 6414 | */ |
| 6415 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6416 | if (cs_count > 255) |
| 6417 | return -EINVAL; |
| 6418 | |
| 6419 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6420 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6421 | if (!need_new_beacon) |
| 6422 | goto skip_beacons; |
| 6423 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6424 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6425 | if (err) |
| 6426 | return err; |
| 6427 | |
| 6428 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6429 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6430 | nl80211_policy); |
| 6431 | if (err) |
| 6432 | return err; |
| 6433 | |
| 6434 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6435 | if (err) |
| 6436 | return err; |
| 6437 | |
| 6438 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6439 | return -EINVAL; |
| 6440 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6441 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6442 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6443 | return -EINVAL; |
| 6444 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6445 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6446 | if (rdev->wiphy.max_num_csa_counters && |
| 6447 | (params.n_counter_offsets_beacon > |
| 6448 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6449 | return -EINVAL; |
| 6450 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6451 | params.counter_offsets_beacon = |
| 6452 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6453 | |
| 6454 | /* sanity checks - counters should fit and be the same */ |
| 6455 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6456 | u16 offset = params.counter_offsets_beacon[i]; |
| 6457 | |
| 6458 | if (offset >= params.beacon_csa.tail_len) |
| 6459 | return -EINVAL; |
| 6460 | |
| 6461 | if (params.beacon_csa.tail[offset] != params.count) |
| 6462 | return -EINVAL; |
| 6463 | } |
| 6464 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6465 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6466 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6467 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6468 | return -EINVAL; |
| 6469 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6470 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6471 | if (rdev->wiphy.max_num_csa_counters && |
| 6472 | (params.n_counter_offsets_beacon > |
| 6473 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6474 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6475 | |
| 6476 | params.counter_offsets_presp = |
| 6477 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6478 | |
| 6479 | /* sanity checks - counters should fit and be the same */ |
| 6480 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6481 | u16 offset = params.counter_offsets_presp[i]; |
| 6482 | |
| 6483 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6484 | return -EINVAL; |
| 6485 | |
| 6486 | if (params.beacon_csa.probe_resp[offset] != |
| 6487 | params.count) |
| 6488 | return -EINVAL; |
| 6489 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6490 | } |
| 6491 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6492 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6493 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6494 | if (err) |
| 6495 | return err; |
| 6496 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 6497 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 6498 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6499 | return -EINVAL; |
| 6500 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6501 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6502 | ¶ms.chandef, |
| 6503 | wdev->iftype); |
| 6504 | if (err < 0) |
| 6505 | return err; |
| 6506 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6507 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6508 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6509 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6510 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6511 | params.block_tx = true; |
| 6512 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6513 | wdev_lock(wdev); |
| 6514 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6515 | wdev_unlock(wdev); |
| 6516 | |
| 6517 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6518 | } |
| 6519 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6520 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6521 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6522 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6523 | struct wireless_dev *wdev, |
| 6524 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6525 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6526 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6527 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6528 | void *hdr; |
| 6529 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6530 | |
| 6531 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6533 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6534 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6535 | if (!hdr) |
| 6536 | return -1; |
| 6537 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6538 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6539 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6540 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6541 | goto nla_put_failure; |
| 6542 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6543 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6544 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6545 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6546 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6547 | |
| 6548 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6549 | if (!bss) |
| 6550 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6551 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6552 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6553 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6554 | |
| 6555 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6556 | /* indicate whether we have probe response data or not */ |
| 6557 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6558 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6559 | goto fail_unlock_rcu; |
| 6560 | |
| 6561 | /* this pointer prefers to be pointed to probe response data |
| 6562 | * but is always valid |
| 6563 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6564 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6565 | if (ies) { |
| 6566 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6567 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6568 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6569 | ies->len, ies->data)) |
| 6570 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6571 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6572 | |
| 6573 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6574 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6575 | if (ies && ies->from_beacon) { |
| 6576 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6577 | goto fail_unlock_rcu; |
| 6578 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6579 | ies->len, ies->data)) |
| 6580 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6581 | } |
| 6582 | rcu_read_unlock(); |
| 6583 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6584 | if (res->beacon_interval && |
| 6585 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6586 | goto nla_put_failure; |
| 6587 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6588 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6589 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6590 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6591 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6592 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6593 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6594 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6595 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6596 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6597 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6598 | break; |
| 6599 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6600 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6601 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6602 | break; |
| 6603 | default: |
| 6604 | break; |
| 6605 | } |
| 6606 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6607 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6608 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6609 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6610 | if (intbss == wdev->current_bss && |
| 6611 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6612 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6613 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6614 | break; |
| 6615 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6616 | if (intbss == wdev->current_bss && |
| 6617 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6618 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6619 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6620 | break; |
| 6621 | default: |
| 6622 | break; |
| 6623 | } |
| 6624 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6625 | nla_nest_end(msg, bss); |
| 6626 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6627 | genlmsg_end(msg, hdr); |
| 6628 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6629 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6630 | fail_unlock_rcu: |
| 6631 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6632 | nla_put_failure: |
| 6633 | genlmsg_cancel(msg, hdr); |
| 6634 | return -EMSGSIZE; |
| 6635 | } |
| 6636 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6637 | 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] | 6638 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6639 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6640 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6641 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6642 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6643 | int err; |
| 6644 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6645 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6646 | if (err) |
| 6647 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6648 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6649 | wdev_lock(wdev); |
| 6650 | spin_lock_bh(&rdev->bss_lock); |
| 6651 | cfg80211_bss_expire(rdev); |
| 6652 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6653 | cb->seq = rdev->bss_generation; |
| 6654 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6655 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6656 | if (++idx <= start) |
| 6657 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6658 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6659 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6660 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6661 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6662 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6663 | } |
| 6664 | } |
| 6665 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6666 | spin_unlock_bh(&rdev->bss_lock); |
| 6667 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6668 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6669 | cb->args[2] = idx; |
| 6670 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6671 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6672 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6673 | } |
| 6674 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6675 | 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] | 6676 | int flags, struct net_device *dev, |
| 6677 | bool allow_radio_stats, |
| 6678 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6679 | { |
| 6680 | void *hdr; |
| 6681 | struct nlattr *infoattr; |
| 6682 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6683 | /* skip radio stats if userspace didn't request them */ |
| 6684 | if (!survey->channel && !allow_radio_stats) |
| 6685 | return 0; |
| 6686 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6687 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6688 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6689 | if (!hdr) |
| 6690 | return -ENOMEM; |
| 6691 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6692 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6693 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6694 | |
| 6695 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6696 | if (!infoattr) |
| 6697 | goto nla_put_failure; |
| 6698 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6699 | if (survey->channel && |
| 6700 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6701 | survey->channel->center_freq)) |
| 6702 | goto nla_put_failure; |
| 6703 | |
| 6704 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6705 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6706 | goto nla_put_failure; |
| 6707 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6708 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6709 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6710 | if ((survey->filled & SURVEY_INFO_TIME) && |
| 6711 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, |
| 6712 | survey->time)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6713 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6714 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
| 6715 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 6716 | survey->time_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6717 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6718 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
| 6719 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 6720 | survey->time_ext_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6721 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6722 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
| 6723 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 6724 | survey->time_rx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6725 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6726 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
| 6727 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 6728 | survey->time_tx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6729 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 6730 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
| 6731 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 6732 | survey->time_scan)) |
| 6733 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6734 | |
| 6735 | nla_nest_end(msg, infoattr); |
| 6736 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6737 | genlmsg_end(msg, hdr); |
| 6738 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6739 | |
| 6740 | nla_put_failure: |
| 6741 | genlmsg_cancel(msg, hdr); |
| 6742 | return -EMSGSIZE; |
| 6743 | } |
| 6744 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6745 | 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] | 6746 | { |
| 6747 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6748 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6749 | struct wireless_dev *wdev; |
| 6750 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6751 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6752 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6753 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6754 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6755 | if (res) |
| 6756 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6757 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6758 | /* prepare_wdev_dump parsed the attributes */ |
| 6759 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 6760 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6761 | if (!wdev->netdev) { |
| 6762 | res = -EINVAL; |
| 6763 | goto out_err; |
| 6764 | } |
| 6765 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6766 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6767 | res = -EOPNOTSUPP; |
| 6768 | goto out_err; |
| 6769 | } |
| 6770 | |
| 6771 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6772 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6773 | if (res == -ENOENT) |
| 6774 | break; |
| 6775 | if (res) |
| 6776 | goto out_err; |
| 6777 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6778 | /* don't send disabled channels, but do send non-channel data */ |
| 6779 | if (survey.channel && |
| 6780 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6781 | survey_idx++; |
| 6782 | continue; |
| 6783 | } |
| 6784 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6785 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6786 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6787 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6788 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6789 | goto out; |
| 6790 | survey_idx++; |
| 6791 | } |
| 6792 | |
| 6793 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6794 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6795 | res = skb->len; |
| 6796 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6797 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6798 | return res; |
| 6799 | } |
| 6800 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6801 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6802 | { |
| 6803 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6804 | NL80211_WPA_VERSION_2)); |
| 6805 | } |
| 6806 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6807 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6808 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6809 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6810 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6811 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6812 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6813 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6814 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6815 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6816 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6817 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6818 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6819 | return -EINVAL; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6822 | return -EINVAL; |
| 6823 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6824 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6825 | return -EINVAL; |
| 6826 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6827 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6828 | return -EINVAL; |
| 6829 | |
| 6830 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6831 | return -EINVAL; |
| 6832 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6833 | err = nl80211_parse_key(info, &key); |
| 6834 | if (err) |
| 6835 | return err; |
| 6836 | |
| 6837 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6838 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6839 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6840 | if (!key.p.key || !key.p.key_len) |
| 6841 | return -EINVAL; |
| 6842 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6843 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6844 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6845 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6846 | return -EINVAL; |
| 6847 | if (key.idx > 4) |
| 6848 | return -EINVAL; |
| 6849 | } else { |
| 6850 | key.p.key_len = 0; |
| 6851 | key.p.key = NULL; |
| 6852 | } |
| 6853 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6854 | if (key.idx >= 0) { |
| 6855 | int i; |
| 6856 | bool ok = false; |
| 6857 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6858 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6859 | ok = true; |
| 6860 | break; |
| 6861 | } |
| 6862 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6863 | if (!ok) |
| 6864 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6865 | } |
| 6866 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6867 | if (!rdev->ops->auth) |
| 6868 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6869 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6870 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6871 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6872 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6873 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6874 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6875 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6876 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6877 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6878 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6879 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6880 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6881 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6882 | |
| 6883 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6884 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6885 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6886 | } |
| 6887 | |
| 6888 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6889 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6890 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6891 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6892 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6893 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6894 | return -EINVAL; |
| 6895 | |
| 6896 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6897 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6898 | return -EINVAL; |
| 6899 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6900 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6901 | /* need to include at least Auth Transaction and Status Code */ |
| 6902 | if (sae_data_len < 4) |
| 6903 | return -EINVAL; |
| 6904 | } |
| 6905 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6906 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6907 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6908 | /* |
| 6909 | * Since we no longer track auth state, ignore |
| 6910 | * requests to only change local state. |
| 6911 | */ |
| 6912 | if (local_state_change) |
| 6913 | return 0; |
| 6914 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6915 | wdev_lock(dev->ieee80211_ptr); |
| 6916 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6917 | ssid, ssid_len, ie, ie_len, |
| 6918 | key.p.key, key.p.key_len, key.idx, |
| 6919 | sae_data, sae_data_len); |
| 6920 | wdev_unlock(dev->ieee80211_ptr); |
| 6921 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6922 | } |
| 6923 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6924 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6925 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6926 | struct cfg80211_crypto_settings *settings, |
| 6927 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6928 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6929 | memset(settings, 0, sizeof(*settings)); |
| 6930 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6931 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6932 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6933 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6934 | u16 proto; |
| 6935 | proto = nla_get_u16( |
| 6936 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6937 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6938 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6939 | proto != ETH_P_PAE) |
| 6940 | return -EINVAL; |
| 6941 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6942 | settings->control_port_no_encrypt = true; |
| 6943 | } else |
| 6944 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6945 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6946 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6947 | void *data; |
| 6948 | int len, i; |
| 6949 | |
| 6950 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6951 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6952 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6953 | |
| 6954 | if (len % sizeof(u32)) |
| 6955 | return -EINVAL; |
| 6956 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6957 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6958 | return -EINVAL; |
| 6959 | |
| 6960 | memcpy(settings->ciphers_pairwise, data, len); |
| 6961 | |
| 6962 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6963 | if (!cfg80211_supported_cipher_suite( |
| 6964 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6965 | settings->ciphers_pairwise[i])) |
| 6966 | return -EINVAL; |
| 6967 | } |
| 6968 | |
| 6969 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6970 | settings->cipher_group = |
| 6971 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6972 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6973 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6974 | return -EINVAL; |
| 6975 | } |
| 6976 | |
| 6977 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6978 | settings->wpa_versions = |
| 6979 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6980 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6981 | return -EINVAL; |
| 6982 | } |
| 6983 | |
| 6984 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6985 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6986 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6987 | |
| 6988 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6989 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6990 | settings->n_akm_suites = len / sizeof(u32); |
| 6991 | |
| 6992 | if (len % sizeof(u32)) |
| 6993 | return -EINVAL; |
| 6994 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6995 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6996 | return -EINVAL; |
| 6997 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6998 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | return 0; |
| 7002 | } |
| 7003 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7004 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7005 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7007 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7008 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7009 | struct cfg80211_assoc_request req = {}; |
| 7010 | const u8 *bssid, *ssid; |
| 7011 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7012 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7013 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7014 | return -EINVAL; |
| 7015 | |
| 7016 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7017 | !info->attrs[NL80211_ATTR_SSID] || |
| 7018 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7019 | return -EINVAL; |
| 7020 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7021 | if (!rdev->ops->assoc) |
| 7022 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7023 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7024 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7025 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7026 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7027 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7028 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7029 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7030 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7031 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7032 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7033 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7034 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7035 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7036 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7037 | |
| 7038 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7039 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7040 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7041 | } |
| 7042 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7043 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7044 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7045 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7046 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7047 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7048 | else if (mfp != NL80211_MFP_NO) |
| 7049 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7050 | } |
| 7051 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7052 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7053 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7054 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7055 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7056 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7057 | |
| 7058 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7059 | memcpy(&req.ht_capa_mask, |
| 7060 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7061 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7062 | |
| 7063 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7064 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7065 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7066 | memcpy(&req.ht_capa, |
| 7067 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7068 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7069 | } |
| 7070 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7071 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7072 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7073 | |
| 7074 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7075 | memcpy(&req.vht_capa_mask, |
| 7076 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7077 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7078 | |
| 7079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7080 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7081 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7082 | memcpy(&req.vht_capa, |
| 7083 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7084 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7085 | } |
| 7086 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7087 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7088 | if (!(rdev->wiphy.features & |
| 7089 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7090 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7091 | return -EINVAL; |
| 7092 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7093 | } |
| 7094 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7095 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7096 | if (!err) { |
| 7097 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7098 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7099 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7100 | wdev_unlock(dev->ieee80211_ptr); |
| 7101 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7102 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7103 | return err; |
| 7104 | } |
| 7105 | |
| 7106 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7107 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7109 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7110 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7111 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7112 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7113 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7114 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7115 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7116 | return -EINVAL; |
| 7117 | |
| 7118 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7119 | return -EINVAL; |
| 7120 | |
| 7121 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7122 | return -EINVAL; |
| 7123 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7124 | if (!rdev->ops->deauth) |
| 7125 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7126 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7127 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7128 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7129 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7130 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7131 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7132 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7133 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7134 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7135 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7136 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7137 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7138 | |
| 7139 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7140 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7141 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7142 | } |
| 7143 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7144 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7145 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7146 | wdev_lock(dev->ieee80211_ptr); |
| 7147 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7148 | local_state_change); |
| 7149 | wdev_unlock(dev->ieee80211_ptr); |
| 7150 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7151 | } |
| 7152 | |
| 7153 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7154 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7156 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7157 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7158 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7159 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7160 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7161 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7162 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7163 | return -EINVAL; |
| 7164 | |
| 7165 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7166 | return -EINVAL; |
| 7167 | |
| 7168 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7169 | return -EINVAL; |
| 7170 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7171 | if (!rdev->ops->disassoc) |
| 7172 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7173 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7174 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7175 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7176 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7177 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7178 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7179 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7180 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7181 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7182 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7183 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7184 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7185 | |
| 7186 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7187 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7188 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7189 | } |
| 7190 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7191 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7192 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7193 | wdev_lock(dev->ieee80211_ptr); |
| 7194 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7195 | local_state_change); |
| 7196 | wdev_unlock(dev->ieee80211_ptr); |
| 7197 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7198 | } |
| 7199 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7200 | static bool |
| 7201 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7202 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7203 | int rateval) |
| 7204 | { |
| 7205 | struct wiphy *wiphy = &rdev->wiphy; |
| 7206 | bool found = false; |
| 7207 | int band, i; |
| 7208 | |
| 7209 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7210 | struct ieee80211_supported_band *sband; |
| 7211 | |
| 7212 | sband = wiphy->bands[band]; |
| 7213 | if (!sband) |
| 7214 | continue; |
| 7215 | |
| 7216 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7217 | if (sband->bitrates[i].bitrate == rateval) { |
| 7218 | mcast_rate[band] = i + 1; |
| 7219 | found = true; |
| 7220 | break; |
| 7221 | } |
| 7222 | } |
| 7223 | } |
| 7224 | |
| 7225 | return found; |
| 7226 | } |
| 7227 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7228 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7231 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7232 | struct cfg80211_ibss_params ibss; |
| 7233 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7234 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7235 | int err; |
| 7236 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7237 | memset(&ibss, 0, sizeof(ibss)); |
| 7238 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7239 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7240 | return -EINVAL; |
| 7241 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7242 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7243 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7244 | return -EINVAL; |
| 7245 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7246 | ibss.beacon_interval = 100; |
| 7247 | |
| 7248 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7249 | ibss.beacon_interval = |
| 7250 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7251 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7252 | return -EINVAL; |
| 7253 | } |
| 7254 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7255 | if (!rdev->ops->join_ibss) |
| 7256 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7258 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7259 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7260 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7261 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7262 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7263 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7264 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7265 | |
| 7266 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7267 | return -EINVAL; |
| 7268 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7269 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7270 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7271 | |
| 7272 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7273 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7274 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7275 | } |
| 7276 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7277 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7278 | if (err) |
| 7279 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7280 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7281 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7282 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7283 | return -EINVAL; |
| 7284 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7285 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7286 | case NL80211_CHAN_WIDTH_5: |
| 7287 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7288 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7289 | break; |
| 7290 | case NL80211_CHAN_WIDTH_20: |
| 7291 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7292 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7293 | return -EINVAL; |
| 7294 | break; |
| 7295 | case NL80211_CHAN_WIDTH_80: |
| 7296 | case NL80211_CHAN_WIDTH_80P80: |
| 7297 | case NL80211_CHAN_WIDTH_160: |
| 7298 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7299 | return -EINVAL; |
| 7300 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7301 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7302 | return -EINVAL; |
| 7303 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7304 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7305 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7306 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7307 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7308 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7309 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7310 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7311 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7312 | u8 *rates = |
| 7313 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7314 | int n_rates = |
| 7315 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7316 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7317 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7318 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7319 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7320 | &ibss.basic_rates); |
| 7321 | if (err) |
| 7322 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7323 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7324 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7325 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7326 | memcpy(&ibss.ht_capa_mask, |
| 7327 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7328 | sizeof(ibss.ht_capa_mask)); |
| 7329 | |
| 7330 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7331 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7332 | return -EINVAL; |
| 7333 | memcpy(&ibss.ht_capa, |
| 7334 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7335 | sizeof(ibss.ht_capa)); |
| 7336 | } |
| 7337 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7338 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7339 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7340 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7341 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7343 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7344 | bool no_ht = false; |
| 7345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7346 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7347 | info->attrs[NL80211_ATTR_KEYS], |
| 7348 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7349 | if (IS_ERR(connkeys)) |
| 7350 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7351 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7352 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7353 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7354 | kfree(connkeys); |
| 7355 | return -EINVAL; |
| 7356 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7357 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7358 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7359 | ibss.control_port = |
| 7360 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7361 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7362 | ibss.userspace_handles_dfs = |
| 7363 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7365 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7366 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7367 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7368 | return err; |
| 7369 | } |
| 7370 | |
| 7371 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7372 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7374 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7376 | if (!rdev->ops->leave_ibss) |
| 7377 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7378 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7380 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7382 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7383 | } |
| 7384 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7385 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7386 | { |
| 7387 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7388 | struct net_device *dev = info->user_ptr[1]; |
| 7389 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7390 | u32 nla_rate; |
| 7391 | int err; |
| 7392 | |
| 7393 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7394 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7395 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7396 | return -EOPNOTSUPP; |
| 7397 | |
| 7398 | if (!rdev->ops->set_mcast_rate) |
| 7399 | return -EOPNOTSUPP; |
| 7400 | |
| 7401 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7402 | |
| 7403 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7404 | return -EINVAL; |
| 7405 | |
| 7406 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7407 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7408 | return -EINVAL; |
| 7409 | |
| 7410 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7411 | |
| 7412 | return err; |
| 7413 | } |
| 7414 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7415 | static struct sk_buff * |
| 7416 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7417 | struct wireless_dev *wdev, int approxlen, |
| 7418 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7419 | enum nl80211_attrs attr, |
| 7420 | const struct nl80211_vendor_cmd_info *info, |
| 7421 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7422 | { |
| 7423 | struct sk_buff *skb; |
| 7424 | void *hdr; |
| 7425 | struct nlattr *data; |
| 7426 | |
| 7427 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7428 | if (!skb) |
| 7429 | return NULL; |
| 7430 | |
| 7431 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7432 | if (!hdr) { |
| 7433 | kfree_skb(skb); |
| 7434 | return NULL; |
| 7435 | } |
| 7436 | |
| 7437 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7438 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7439 | |
| 7440 | if (info) { |
| 7441 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7442 | info->vendor_id)) |
| 7443 | goto nla_put_failure; |
| 7444 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7445 | info->subcmd)) |
| 7446 | goto nla_put_failure; |
| 7447 | } |
| 7448 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7449 | if (wdev) { |
| 7450 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 7451 | wdev_id(wdev))) |
| 7452 | goto nla_put_failure; |
| 7453 | if (wdev->netdev && |
| 7454 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7455 | wdev->netdev->ifindex)) |
| 7456 | goto nla_put_failure; |
| 7457 | } |
| 7458 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7459 | data = nla_nest_start(skb, attr); |
| 7460 | |
| 7461 | ((void **)skb->cb)[0] = rdev; |
| 7462 | ((void **)skb->cb)[1] = hdr; |
| 7463 | ((void **)skb->cb)[2] = data; |
| 7464 | |
| 7465 | return skb; |
| 7466 | |
| 7467 | nla_put_failure: |
| 7468 | kfree_skb(skb); |
| 7469 | return NULL; |
| 7470 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7471 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7472 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7473 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7474 | enum nl80211_commands cmd, |
| 7475 | enum nl80211_attrs attr, |
| 7476 | int vendor_event_idx, |
| 7477 | int approxlen, gfp_t gfp) |
| 7478 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7479 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7480 | const struct nl80211_vendor_cmd_info *info; |
| 7481 | |
| 7482 | switch (cmd) { |
| 7483 | case NL80211_CMD_TESTMODE: |
| 7484 | if (WARN_ON(vendor_event_idx != -1)) |
| 7485 | return NULL; |
| 7486 | info = NULL; |
| 7487 | break; |
| 7488 | case NL80211_CMD_VENDOR: |
| 7489 | if (WARN_ON(vendor_event_idx < 0 || |
| 7490 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7491 | return NULL; |
| 7492 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7493 | break; |
| 7494 | default: |
| 7495 | WARN_ON(1); |
| 7496 | return NULL; |
| 7497 | } |
| 7498 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7499 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7500 | cmd, attr, info, gfp); |
| 7501 | } |
| 7502 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7503 | |
| 7504 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7505 | { |
| 7506 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7507 | void *hdr = ((void **)skb->cb)[1]; |
| 7508 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7509 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7510 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7511 | /* clear CB data for netlink core to own from now on */ |
| 7512 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7513 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7514 | nla_nest_end(skb, data); |
| 7515 | genlmsg_end(skb, hdr); |
| 7516 | |
| 7517 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7518 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7519 | |
| 7520 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7521 | mcgrp, gfp); |
| 7522 | } |
| 7523 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7524 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7525 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7526 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7527 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7529 | struct wireless_dev *wdev = |
| 7530 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7531 | int err; |
| 7532 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7533 | if (!rdev->ops->testmode_cmd) |
| 7534 | return -EOPNOTSUPP; |
| 7535 | |
| 7536 | if (IS_ERR(wdev)) { |
| 7537 | err = PTR_ERR(wdev); |
| 7538 | if (err != -EINVAL) |
| 7539 | return err; |
| 7540 | wdev = NULL; |
| 7541 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7542 | return -EINVAL; |
| 7543 | } |
| 7544 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7545 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7546 | return -EINVAL; |
| 7547 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7548 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7549 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7550 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7551 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7552 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7553 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7554 | return err; |
| 7555 | } |
| 7556 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7557 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7558 | struct netlink_callback *cb) |
| 7559 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7560 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7561 | int err; |
| 7562 | long phy_idx; |
| 7563 | void *data = NULL; |
| 7564 | int data_len = 0; |
| 7565 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7566 | rtnl_lock(); |
| 7567 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7568 | if (cb->args[0]) { |
| 7569 | /* |
| 7570 | * 0 is a valid index, but not valid for args[0], |
| 7571 | * so we need to offset by 1. |
| 7572 | */ |
| 7573 | phy_idx = cb->args[0] - 1; |
| 7574 | } else { |
| 7575 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7576 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7577 | nl80211_policy); |
| 7578 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7579 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7580 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7581 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7582 | nl80211_fam.attrbuf); |
| 7583 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7584 | err = PTR_ERR(rdev); |
| 7585 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7586 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7587 | phy_idx = rdev->wiphy_idx; |
| 7588 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7589 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7590 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7591 | cb->args[1] = |
| 7592 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7593 | } |
| 7594 | |
| 7595 | if (cb->args[1]) { |
| 7596 | data = nla_data((void *)cb->args[1]); |
| 7597 | data_len = nla_len((void *)cb->args[1]); |
| 7598 | } |
| 7599 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7600 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7601 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7602 | err = -ENOENT; |
| 7603 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7604 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7605 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7606 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7607 | err = -EOPNOTSUPP; |
| 7608 | goto out_err; |
| 7609 | } |
| 7610 | |
| 7611 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7612 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7613 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7614 | NL80211_CMD_TESTMODE); |
| 7615 | struct nlattr *tmdata; |
| 7616 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7617 | if (!hdr) |
| 7618 | break; |
| 7619 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7620 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7621 | genlmsg_cancel(skb, hdr); |
| 7622 | break; |
| 7623 | } |
| 7624 | |
| 7625 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7626 | if (!tmdata) { |
| 7627 | genlmsg_cancel(skb, hdr); |
| 7628 | break; |
| 7629 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7630 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7631 | nla_nest_end(skb, tmdata); |
| 7632 | |
| 7633 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7634 | genlmsg_cancel(skb, hdr); |
| 7635 | break; |
| 7636 | } else if (err) { |
| 7637 | genlmsg_cancel(skb, hdr); |
| 7638 | goto out_err; |
| 7639 | } |
| 7640 | |
| 7641 | genlmsg_end(skb, hdr); |
| 7642 | } |
| 7643 | |
| 7644 | err = skb->len; |
| 7645 | /* see above */ |
| 7646 | cb->args[0] = phy_idx + 1; |
| 7647 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7648 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7649 | return err; |
| 7650 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7651 | #endif |
| 7652 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7653 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7656 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7657 | struct cfg80211_connect_params connect; |
| 7658 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7659 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7660 | int err; |
| 7661 | |
| 7662 | memset(&connect, 0, sizeof(connect)); |
| 7663 | |
| 7664 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7665 | return -EINVAL; |
| 7666 | |
| 7667 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7668 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7669 | return -EINVAL; |
| 7670 | |
| 7671 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7672 | connect.auth_type = |
| 7673 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7674 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7675 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7676 | return -EINVAL; |
| 7677 | } else |
| 7678 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7679 | |
| 7680 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7681 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7682 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7683 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7684 | if (err) |
| 7685 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7686 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7687 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7688 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7689 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7690 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7691 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7692 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7693 | connect.bg_scan_period = -1; |
| 7694 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7695 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7696 | connect.bg_scan_period = |
| 7697 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7698 | } |
| 7699 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7700 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7701 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7702 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7703 | connect.bssid_hint = |
| 7704 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7705 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7706 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7707 | |
| 7708 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7709 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7710 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7711 | } |
| 7712 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7713 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7714 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7715 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7716 | connect.mfp != NL80211_MFP_NO) |
| 7717 | return -EINVAL; |
| 7718 | } else { |
| 7719 | connect.mfp = NL80211_MFP_NO; |
| 7720 | } |
| 7721 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7722 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7723 | connect.channel = nl80211_get_valid_chan( |
| 7724 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7725 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7726 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7727 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7728 | connect.channel_hint = nl80211_get_valid_chan( |
| 7729 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7730 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7731 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7732 | } |
| 7733 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7734 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7735 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7736 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7737 | if (IS_ERR(connkeys)) |
| 7738 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7739 | } |
| 7740 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7741 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7742 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7743 | |
| 7744 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7745 | memcpy(&connect.ht_capa_mask, |
| 7746 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7747 | sizeof(connect.ht_capa_mask)); |
| 7748 | |
| 7749 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7750 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7751 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7752 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7753 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7754 | memcpy(&connect.ht_capa, |
| 7755 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7756 | sizeof(connect.ht_capa)); |
| 7757 | } |
| 7758 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7759 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7760 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7761 | |
| 7762 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7763 | memcpy(&connect.vht_capa_mask, |
| 7764 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7765 | sizeof(connect.vht_capa_mask)); |
| 7766 | |
| 7767 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7768 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7769 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7770 | return -EINVAL; |
| 7771 | } |
| 7772 | memcpy(&connect.vht_capa, |
| 7773 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7774 | sizeof(connect.vht_capa)); |
| 7775 | } |
| 7776 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7777 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7778 | if (!(rdev->wiphy.features & |
| 7779 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7780 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7781 | return -EINVAL; |
| 7782 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7783 | } |
| 7784 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7785 | wdev_lock(dev->ieee80211_ptr); |
| 7786 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7787 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7788 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7789 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7790 | return err; |
| 7791 | } |
| 7792 | |
| 7793 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7794 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7795 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7796 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7797 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7798 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7799 | |
| 7800 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7801 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7802 | else |
| 7803 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7804 | |
| 7805 | if (reason == 0) |
| 7806 | return -EINVAL; |
| 7807 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7809 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7810 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7811 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7812 | wdev_lock(dev->ieee80211_ptr); |
| 7813 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7814 | wdev_unlock(dev->ieee80211_ptr); |
| 7815 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7816 | } |
| 7817 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7818 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7819 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7821 | struct net *net; |
| 7822 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7823 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 7824 | if (info->attrs[NL80211_ATTR_PID]) { |
| 7825 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7826 | |
| 7827 | net = get_net_ns_by_pid(pid); |
| 7828 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 7829 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 7830 | |
| 7831 | net = get_net_ns_by_fd(fd); |
| 7832 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7833 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 7834 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7836 | if (IS_ERR(net)) |
| 7837 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7838 | |
| 7839 | err = 0; |
| 7840 | |
| 7841 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7842 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7843 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7844 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7845 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7846 | return err; |
| 7847 | } |
| 7848 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7849 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7850 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7852 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7853 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7854 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7855 | struct cfg80211_pmksa pmksa; |
| 7856 | |
| 7857 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7858 | |
| 7859 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7860 | return -EINVAL; |
| 7861 | |
| 7862 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7863 | return -EINVAL; |
| 7864 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7865 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7866 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 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 | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7871 | |
| 7872 | switch (info->genlhdr->cmd) { |
| 7873 | case NL80211_CMD_SET_PMKSA: |
| 7874 | rdev_ops = rdev->ops->set_pmksa; |
| 7875 | break; |
| 7876 | case NL80211_CMD_DEL_PMKSA: |
| 7877 | rdev_ops = rdev->ops->del_pmksa; |
| 7878 | break; |
| 7879 | default: |
| 7880 | WARN_ON(1); |
| 7881 | break; |
| 7882 | } |
| 7883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7884 | if (!rdev_ops) |
| 7885 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7887 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7888 | } |
| 7889 | |
| 7890 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7893 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7894 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7895 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7896 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7897 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7898 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7899 | if (!rdev->ops->flush_pmksa) |
| 7900 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7901 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7902 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7903 | } |
| 7904 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7905 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7906 | { |
| 7907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7908 | struct net_device *dev = info->user_ptr[1]; |
| 7909 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7910 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7911 | u16 status_code; |
| 7912 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7913 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7914 | |
| 7915 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7916 | !rdev->ops->tdls_mgmt) |
| 7917 | return -EOPNOTSUPP; |
| 7918 | |
| 7919 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7920 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7921 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7922 | !info->attrs[NL80211_ATTR_IE] || |
| 7923 | !info->attrs[NL80211_ATTR_MAC]) |
| 7924 | return -EINVAL; |
| 7925 | |
| 7926 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7927 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7928 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7929 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7930 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7931 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7932 | peer_capability = |
| 7933 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7934 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7935 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7936 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7937 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7938 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7939 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7940 | } |
| 7941 | |
| 7942 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7943 | { |
| 7944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7945 | struct net_device *dev = info->user_ptr[1]; |
| 7946 | enum nl80211_tdls_operation operation; |
| 7947 | u8 *peer; |
| 7948 | |
| 7949 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7950 | !rdev->ops->tdls_oper) |
| 7951 | return -EOPNOTSUPP; |
| 7952 | |
| 7953 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7954 | !info->attrs[NL80211_ATTR_MAC]) |
| 7955 | return -EINVAL; |
| 7956 | |
| 7957 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7958 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7959 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7960 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7961 | } |
| 7962 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7963 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7964 | struct genl_info *info) |
| 7965 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7967 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7968 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7969 | struct sk_buff *msg; |
| 7970 | void *hdr; |
| 7971 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7972 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7973 | int err; |
| 7974 | |
| 7975 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7976 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7977 | return -EINVAL; |
| 7978 | |
| 7979 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7980 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7981 | if (!rdev->ops->remain_on_channel || |
| 7982 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7983 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7984 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7985 | /* |
| 7986 | * We should be on that channel for at least a minimum amount of |
| 7987 | * time (10ms) but no longer than the driver supports. |
| 7988 | */ |
| 7989 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7990 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7991 | return -EINVAL; |
| 7992 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7993 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7994 | if (err) |
| 7995 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7996 | |
| 7997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7998 | if (!msg) |
| 7999 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8000 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8001 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8002 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8003 | if (!hdr) { |
| 8004 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8005 | goto free_msg; |
| 8006 | } |
| 8007 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8008 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8009 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8010 | |
| 8011 | if (err) |
| 8012 | goto free_msg; |
| 8013 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8014 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8015 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8016 | |
| 8017 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8018 | |
| 8019 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8020 | |
| 8021 | nla_put_failure: |
| 8022 | err = -ENOBUFS; |
| 8023 | free_msg: |
| 8024 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8025 | return err; |
| 8026 | } |
| 8027 | |
| 8028 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8029 | struct genl_info *info) |
| 8030 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8032 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8033 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8034 | |
| 8035 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8036 | return -EINVAL; |
| 8037 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8038 | if (!rdev->ops->cancel_remain_on_channel) |
| 8039 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8040 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8041 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8042 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8043 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8044 | } |
| 8045 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8046 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8047 | u8 *rates, u8 rates_len) |
| 8048 | { |
| 8049 | u8 i; |
| 8050 | u32 mask = 0; |
| 8051 | |
| 8052 | for (i = 0; i < rates_len; i++) { |
| 8053 | int rate = (rates[i] & 0x7f) * 5; |
| 8054 | int ridx; |
| 8055 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8056 | struct ieee80211_rate *srate = |
| 8057 | &sband->bitrates[ridx]; |
| 8058 | if (rate == srate->bitrate) { |
| 8059 | mask |= 1 << ridx; |
| 8060 | break; |
| 8061 | } |
| 8062 | } |
| 8063 | if (ridx == sband->n_bitrates) |
| 8064 | return 0; /* rate not found */ |
| 8065 | } |
| 8066 | |
| 8067 | return mask; |
| 8068 | } |
| 8069 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8070 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8071 | u8 *rates, u8 rates_len, |
| 8072 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8073 | { |
| 8074 | u8 i; |
| 8075 | |
| 8076 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8077 | |
| 8078 | for (i = 0; i < rates_len; i++) { |
| 8079 | int ridx, rbit; |
| 8080 | |
| 8081 | ridx = rates[i] / 8; |
| 8082 | rbit = BIT(rates[i] % 8); |
| 8083 | |
| 8084 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8085 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8086 | return false; |
| 8087 | |
| 8088 | /* check availability */ |
| 8089 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8090 | mcs[ridx] |= rbit; |
| 8091 | else |
| 8092 | return false; |
| 8093 | } |
| 8094 | |
| 8095 | return true; |
| 8096 | } |
| 8097 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8098 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8099 | { |
| 8100 | u16 mcs_mask = 0; |
| 8101 | |
| 8102 | switch (vht_mcs_map) { |
| 8103 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8104 | break; |
| 8105 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8106 | mcs_mask = 0x00FF; |
| 8107 | break; |
| 8108 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8109 | mcs_mask = 0x01FF; |
| 8110 | break; |
| 8111 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8112 | mcs_mask = 0x03FF; |
| 8113 | break; |
| 8114 | default: |
| 8115 | break; |
| 8116 | } |
| 8117 | |
| 8118 | return mcs_mask; |
| 8119 | } |
| 8120 | |
| 8121 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8122 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8123 | { |
| 8124 | u8 nss; |
| 8125 | |
| 8126 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8127 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8128 | vht_mcs_map >>= 2; |
| 8129 | } |
| 8130 | } |
| 8131 | |
| 8132 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8133 | struct nl80211_txrate_vht *txrate, |
| 8134 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8135 | { |
| 8136 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8137 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8138 | u8 i; |
| 8139 | |
| 8140 | if (!sband->vht_cap.vht_supported) |
| 8141 | return false; |
| 8142 | |
| 8143 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8144 | |
| 8145 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8146 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8147 | |
| 8148 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8149 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8150 | mcs[i] = txrate->mcs[i]; |
| 8151 | else |
| 8152 | return false; |
| 8153 | } |
| 8154 | |
| 8155 | return true; |
| 8156 | } |
| 8157 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8158 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8159 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8160 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8161 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8162 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8163 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8164 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8165 | }; |
| 8166 | |
| 8167 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8168 | struct genl_info *info) |
| 8169 | { |
| 8170 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8172 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8173 | int rem, i; |
| 8174 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8175 | struct nlattr *tx_rates; |
| 8176 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8177 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8178 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8179 | if (!rdev->ops->set_bitrate_mask) |
| 8180 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8181 | |
| 8182 | memset(&mask, 0, sizeof(mask)); |
| 8183 | /* Default to all rates enabled */ |
| 8184 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8185 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8186 | |
| 8187 | if (!sband) |
| 8188 | continue; |
| 8189 | |
| 8190 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8191 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8192 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8193 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8194 | |
| 8195 | if (!sband->vht_cap.vht_supported) |
| 8196 | continue; |
| 8197 | |
| 8198 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8199 | 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] | 8200 | } |
| 8201 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8202 | /* if no rates are given set it back to the defaults */ |
| 8203 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8204 | goto out; |
| 8205 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8206 | /* |
| 8207 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8208 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8209 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8210 | 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] | 8211 | 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] | 8212 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8213 | int err; |
| 8214 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8216 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8217 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8218 | if (sband == NULL) |
| 8219 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8220 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8221 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8222 | if (err) |
| 8223 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8224 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8225 | mask.control[band].legacy = rateset_to_mask( |
| 8226 | sband, |
| 8227 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8228 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8229 | if ((mask.control[band].legacy == 0) && |
| 8230 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8231 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8232 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8233 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8234 | if (!ht_rateset_to_mask( |
| 8235 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8236 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8237 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8238 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8239 | return -EINVAL; |
| 8240 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8241 | if (tb[NL80211_TXRATE_VHT]) { |
| 8242 | if (!vht_set_mcs_mask( |
| 8243 | sband, |
| 8244 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8245 | mask.control[band].vht_mcs)) |
| 8246 | return -EINVAL; |
| 8247 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8248 | if (tb[NL80211_TXRATE_GI]) { |
| 8249 | mask.control[band].gi = |
| 8250 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8251 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8252 | return -EINVAL; |
| 8253 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8254 | |
| 8255 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8256 | /* don't allow empty legacy rates if HT or VHT |
| 8257 | * are not even supported. |
| 8258 | */ |
| 8259 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8260 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8261 | return -EINVAL; |
| 8262 | |
| 8263 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8264 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8265 | goto out; |
| 8266 | |
| 8267 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8268 | if (mask.control[band].vht_mcs[i]) |
| 8269 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8270 | |
| 8271 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8272 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8273 | } |
| 8274 | } |
| 8275 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8276 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8277 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8278 | } |
| 8279 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8280 | 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] | 8281 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8283 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8284 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8285 | |
| 8286 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8287 | return -EINVAL; |
| 8288 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8289 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8290 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8291 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8292 | switch (wdev->iftype) { |
| 8293 | case NL80211_IFTYPE_STATION: |
| 8294 | case NL80211_IFTYPE_ADHOC: |
| 8295 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8296 | case NL80211_IFTYPE_AP: |
| 8297 | case NL80211_IFTYPE_AP_VLAN: |
| 8298 | case NL80211_IFTYPE_MESH_POINT: |
| 8299 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8300 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8301 | break; |
| 8302 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8303 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8304 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8305 | |
| 8306 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8307 | if (!rdev->ops->mgmt_tx) |
| 8308 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8309 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8310 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8311 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8312 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8313 | } |
| 8314 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8315 | 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] | 8316 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8318 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8319 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8320 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8321 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8322 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8323 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8324 | struct cfg80211_mgmt_tx_params params = { |
| 8325 | .dont_wait_for_ack = |
| 8326 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8327 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8328 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8329 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8330 | return -EINVAL; |
| 8331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8332 | if (!rdev->ops->mgmt_tx) |
| 8333 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8334 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8335 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8336 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8337 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8338 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8339 | case NL80211_IFTYPE_STATION: |
| 8340 | case NL80211_IFTYPE_ADHOC: |
| 8341 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8342 | case NL80211_IFTYPE_AP: |
| 8343 | case NL80211_IFTYPE_AP_VLAN: |
| 8344 | case NL80211_IFTYPE_MESH_POINT: |
| 8345 | case NL80211_IFTYPE_P2P_GO: |
| 8346 | break; |
| 8347 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8348 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8349 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8350 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8351 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8352 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8353 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8354 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8355 | |
| 8356 | /* |
| 8357 | * We should wait on the channel for at least a minimum amount |
| 8358 | * of time (10ms) but no longer than the driver supports. |
| 8359 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8360 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8361 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8362 | return -EINVAL; |
| 8363 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8364 | } |
| 8365 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8366 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8367 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8368 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8369 | return -EINVAL; |
| 8370 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8371 | 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] | 8372 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8373 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8374 | * the driver. The latter will use the current one |
| 8375 | */ |
| 8376 | chandef.chan = NULL; |
| 8377 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8378 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8379 | if (err) |
| 8380 | return err; |
| 8381 | } |
| 8382 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8383 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8384 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8385 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8386 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8387 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8388 | |
| 8389 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8390 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8391 | int i; |
| 8392 | |
| 8393 | if (len % sizeof(u16)) |
| 8394 | return -EINVAL; |
| 8395 | |
| 8396 | params.n_csa_offsets = len / sizeof(u16); |
| 8397 | params.csa_offsets = |
| 8398 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8399 | |
| 8400 | /* check that all the offsets fit the frame */ |
| 8401 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8402 | if (params.csa_offsets[i] >= params.len) |
| 8403 | return -EINVAL; |
| 8404 | } |
| 8405 | } |
| 8406 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8407 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8409 | if (!msg) |
| 8410 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8411 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8412 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8413 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8414 | if (!hdr) { |
| 8415 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8416 | goto free_msg; |
| 8417 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8418 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8419 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8420 | params.chan = chandef.chan; |
| 8421 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8422 | if (err) |
| 8423 | goto free_msg; |
| 8424 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8425 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8426 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8427 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8428 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8429 | genlmsg_end(msg, hdr); |
| 8430 | return genlmsg_reply(msg, info); |
| 8431 | } |
| 8432 | |
| 8433 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8434 | |
| 8435 | nla_put_failure: |
| 8436 | err = -ENOBUFS; |
| 8437 | free_msg: |
| 8438 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8439 | return err; |
| 8440 | } |
| 8441 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8442 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8443 | { |
| 8444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8445 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8446 | u64 cookie; |
| 8447 | |
| 8448 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8449 | return -EINVAL; |
| 8450 | |
| 8451 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8452 | return -EOPNOTSUPP; |
| 8453 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8454 | switch (wdev->iftype) { |
| 8455 | case NL80211_IFTYPE_STATION: |
| 8456 | case NL80211_IFTYPE_ADHOC: |
| 8457 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8458 | case NL80211_IFTYPE_AP: |
| 8459 | case NL80211_IFTYPE_AP_VLAN: |
| 8460 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8461 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8462 | break; |
| 8463 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8464 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8465 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8466 | |
| 8467 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8468 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8469 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8470 | } |
| 8471 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8472 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8475 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8476 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8477 | u8 ps_state; |
| 8478 | bool state; |
| 8479 | int err; |
| 8480 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8481 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8482 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8483 | |
| 8484 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8486 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8487 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8488 | |
| 8489 | wdev = dev->ieee80211_ptr; |
| 8490 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | if (!rdev->ops->set_power_mgmt) |
| 8492 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8493 | |
| 8494 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8495 | |
| 8496 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8497 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8498 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8499 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8500 | if (!err) |
| 8501 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8502 | return err; |
| 8503 | } |
| 8504 | |
| 8505 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8508 | enum nl80211_ps_state ps_state; |
| 8509 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8510 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8511 | struct sk_buff *msg; |
| 8512 | void *hdr; |
| 8513 | int err; |
| 8514 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8515 | wdev = dev->ieee80211_ptr; |
| 8516 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8517 | if (!rdev->ops->set_power_mgmt) |
| 8518 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8519 | |
| 8520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8521 | if (!msg) |
| 8522 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8523 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8524 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8525 | NL80211_CMD_GET_POWER_SAVE); |
| 8526 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8527 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8528 | goto free_msg; |
| 8529 | } |
| 8530 | |
| 8531 | if (wdev->ps) |
| 8532 | ps_state = NL80211_PS_ENABLED; |
| 8533 | else |
| 8534 | ps_state = NL80211_PS_DISABLED; |
| 8535 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8536 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8537 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8538 | |
| 8539 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8540 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8542 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8543 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8544 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8545 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8546 | return err; |
| 8547 | } |
| 8548 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8549 | static const struct nla_policy |
| 8550 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8551 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8552 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8553 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8554 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8555 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8556 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8557 | }; |
| 8558 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8559 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8560 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8561 | { |
| 8562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8563 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8565 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8566 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8567 | return -EINVAL; |
| 8568 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8569 | if (!rdev->ops->set_cqm_txe_config) |
| 8570 | return -EOPNOTSUPP; |
| 8571 | |
| 8572 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8573 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8574 | return -EOPNOTSUPP; |
| 8575 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8576 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8577 | } |
| 8578 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8579 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8580 | s32 threshold, u32 hysteresis) |
| 8581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8583 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8584 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8585 | |
| 8586 | if (threshold > 0) |
| 8587 | return -EINVAL; |
| 8588 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8589 | /* disabling - hysteresis should also be zero then */ |
| 8590 | if (threshold == 0) |
| 8591 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8592 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8593 | if (!rdev->ops->set_cqm_rssi_config) |
| 8594 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8595 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8596 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8597 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8598 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8599 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8600 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8601 | } |
| 8602 | |
| 8603 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8604 | { |
| 8605 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8606 | struct nlattr *cqm; |
| 8607 | int err; |
| 8608 | |
| 8609 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8610 | if (!cqm) |
| 8611 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8612 | |
| 8613 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8614 | nl80211_attr_cqm_policy); |
| 8615 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8616 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8617 | |
| 8618 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8619 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8620 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8621 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8622 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8623 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8624 | } |
| 8625 | |
| 8626 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8627 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8628 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8629 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8630 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8631 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8632 | |
| 8633 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8634 | } |
| 8635 | |
| 8636 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8637 | } |
| 8638 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8639 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8640 | { |
| 8641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8642 | struct net_device *dev = info->user_ptr[1]; |
| 8643 | struct ocb_setup setup = {}; |
| 8644 | int err; |
| 8645 | |
| 8646 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8647 | if (err) |
| 8648 | return err; |
| 8649 | |
| 8650 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8651 | } |
| 8652 | |
| 8653 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8654 | { |
| 8655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8656 | struct net_device *dev = info->user_ptr[1]; |
| 8657 | |
| 8658 | return cfg80211_leave_ocb(rdev, dev); |
| 8659 | } |
| 8660 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8661 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8662 | { |
| 8663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8664 | struct net_device *dev = info->user_ptr[1]; |
| 8665 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8666 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8667 | int err; |
| 8668 | |
| 8669 | /* start with default */ |
| 8670 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8671 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8672 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8673 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8674 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8675 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8676 | if (err) |
| 8677 | return err; |
| 8678 | } |
| 8679 | |
| 8680 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8681 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8682 | return -EINVAL; |
| 8683 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8684 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8685 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8686 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8687 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8688 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8689 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8690 | return -EINVAL; |
| 8691 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8692 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8693 | setup.beacon_interval = |
| 8694 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8695 | if (setup.beacon_interval < 10 || |
| 8696 | setup.beacon_interval > 10000) |
| 8697 | return -EINVAL; |
| 8698 | } |
| 8699 | |
| 8700 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8701 | setup.dtim_period = |
| 8702 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8703 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8704 | return -EINVAL; |
| 8705 | } |
| 8706 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8707 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8708 | /* parse additional setup parameters if given */ |
| 8709 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8710 | if (err) |
| 8711 | return err; |
| 8712 | } |
| 8713 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8714 | if (setup.user_mpm) |
| 8715 | cfg.auto_open_plinks = false; |
| 8716 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8717 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8718 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8719 | if (err) |
| 8720 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8721 | } else { |
| 8722 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8723 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8724 | } |
| 8725 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8726 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8727 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8728 | int n_rates = |
| 8729 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8730 | struct ieee80211_supported_band *sband; |
| 8731 | |
| 8732 | if (!setup.chandef.chan) |
| 8733 | return -EINVAL; |
| 8734 | |
| 8735 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8736 | |
| 8737 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8738 | &setup.basic_rates); |
| 8739 | if (err) |
| 8740 | return err; |
| 8741 | } |
| 8742 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8743 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8744 | } |
| 8745 | |
| 8746 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8747 | { |
| 8748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8749 | struct net_device *dev = info->user_ptr[1]; |
| 8750 | |
| 8751 | return cfg80211_leave_mesh(rdev, dev); |
| 8752 | } |
| 8753 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8754 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8755 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8756 | struct cfg80211_registered_device *rdev) |
| 8757 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8758 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8759 | struct nlattr *nl_pats, *nl_pat; |
| 8760 | int i, pat_len; |
| 8761 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8762 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8763 | return 0; |
| 8764 | |
| 8765 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8766 | if (!nl_pats) |
| 8767 | return -ENOBUFS; |
| 8768 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8769 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8770 | nl_pat = nla_nest_start(msg, i + 1); |
| 8771 | if (!nl_pat) |
| 8772 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8773 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8774 | 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] | 8775 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8776 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8777 | wowlan->patterns[i].pattern) || |
| 8778 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8779 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8780 | return -ENOBUFS; |
| 8781 | nla_nest_end(msg, nl_pat); |
| 8782 | } |
| 8783 | nla_nest_end(msg, nl_pats); |
| 8784 | |
| 8785 | return 0; |
| 8786 | } |
| 8787 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8788 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8789 | struct cfg80211_wowlan_tcp *tcp) |
| 8790 | { |
| 8791 | struct nlattr *nl_tcp; |
| 8792 | |
| 8793 | if (!tcp) |
| 8794 | return 0; |
| 8795 | |
| 8796 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8797 | if (!nl_tcp) |
| 8798 | return -ENOBUFS; |
| 8799 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 8800 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8801 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8802 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8803 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8804 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8805 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8806 | tcp->payload_len, tcp->payload) || |
| 8807 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8808 | tcp->data_interval) || |
| 8809 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8810 | tcp->wake_len, tcp->wake_data) || |
| 8811 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8812 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8813 | return -ENOBUFS; |
| 8814 | |
| 8815 | if (tcp->payload_seq.len && |
| 8816 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8817 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8818 | return -ENOBUFS; |
| 8819 | |
| 8820 | if (tcp->payload_tok.len && |
| 8821 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8822 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8823 | &tcp->payload_tok)) |
| 8824 | return -ENOBUFS; |
| 8825 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8826 | nla_nest_end(msg, nl_tcp); |
| 8827 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8828 | return 0; |
| 8829 | } |
| 8830 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8831 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 8832 | struct cfg80211_sched_scan_request *req) |
| 8833 | { |
| 8834 | struct nlattr *nd, *freqs, *matches, *match; |
| 8835 | int i; |
| 8836 | |
| 8837 | if (!req) |
| 8838 | return 0; |
| 8839 | |
| 8840 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 8841 | if (!nd) |
| 8842 | return -ENOBUFS; |
| 8843 | |
| 8844 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) |
| 8845 | return -ENOBUFS; |
| 8846 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 8847 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 8848 | return -ENOBUFS; |
| 8849 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8850 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8851 | if (!freqs) |
| 8852 | return -ENOBUFS; |
| 8853 | |
| 8854 | for (i = 0; i < req->n_channels; i++) |
| 8855 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 8856 | |
| 8857 | nla_nest_end(msg, freqs); |
| 8858 | |
| 8859 | if (req->n_match_sets) { |
| 8860 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 8861 | for (i = 0; i < req->n_match_sets; i++) { |
| 8862 | match = nla_nest_start(msg, i); |
| 8863 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 8864 | req->match_sets[i].ssid.ssid_len, |
| 8865 | req->match_sets[i].ssid.ssid); |
| 8866 | nla_nest_end(msg, match); |
| 8867 | } |
| 8868 | nla_nest_end(msg, matches); |
| 8869 | } |
| 8870 | |
| 8871 | nla_nest_end(msg, nd); |
| 8872 | |
| 8873 | return 0; |
| 8874 | } |
| 8875 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8876 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8877 | { |
| 8878 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8879 | struct sk_buff *msg; |
| 8880 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8881 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8882 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8883 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8884 | return -EOPNOTSUPP; |
| 8885 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8886 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8887 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8888 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8889 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8890 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8891 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8892 | } |
| 8893 | |
| 8894 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8895 | if (!msg) |
| 8896 | return -ENOMEM; |
| 8897 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8898 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8899 | NL80211_CMD_GET_WOWLAN); |
| 8900 | if (!hdr) |
| 8901 | goto nla_put_failure; |
| 8902 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8903 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8904 | struct nlattr *nl_wowlan; |
| 8905 | |
| 8906 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8907 | if (!nl_wowlan) |
| 8908 | goto nla_put_failure; |
| 8909 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8910 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8911 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8912 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8913 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8914 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8915 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8916 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8917 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8918 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8919 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8920 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8921 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8922 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8923 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8924 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8925 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8926 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8927 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8928 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8929 | if (nl80211_send_wowlan_tcp(msg, |
| 8930 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8931 | goto nla_put_failure; |
| 8932 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8933 | if (nl80211_send_wowlan_nd( |
| 8934 | msg, |
| 8935 | rdev->wiphy.wowlan_config->nd_config)) |
| 8936 | goto nla_put_failure; |
| 8937 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8938 | nla_nest_end(msg, nl_wowlan); |
| 8939 | } |
| 8940 | |
| 8941 | genlmsg_end(msg, hdr); |
| 8942 | return genlmsg_reply(msg, info); |
| 8943 | |
| 8944 | nla_put_failure: |
| 8945 | nlmsg_free(msg); |
| 8946 | return -ENOBUFS; |
| 8947 | } |
| 8948 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8949 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8950 | struct nlattr *attr, |
| 8951 | struct cfg80211_wowlan *trig) |
| 8952 | { |
| 8953 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8954 | struct cfg80211_wowlan_tcp *cfg; |
| 8955 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8956 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8957 | u32 size; |
| 8958 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8959 | int err, port; |
| 8960 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8961 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8962 | return -EINVAL; |
| 8963 | |
| 8964 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8965 | nla_data(attr), nla_len(attr), |
| 8966 | nl80211_wowlan_tcp_policy); |
| 8967 | if (err) |
| 8968 | return err; |
| 8969 | |
| 8970 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8971 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8972 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8973 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8974 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8975 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8976 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8977 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8978 | return -EINVAL; |
| 8979 | |
| 8980 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8981 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8982 | return -EINVAL; |
| 8983 | |
| 8984 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8985 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8986 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8987 | return -EINVAL; |
| 8988 | |
| 8989 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8990 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8991 | return -EINVAL; |
| 8992 | |
| 8993 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8994 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8995 | return -EINVAL; |
| 8996 | |
| 8997 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8998 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8999 | |
| 9000 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9001 | tokens_size = tokln - sizeof(*tok); |
| 9002 | |
| 9003 | if (!tok->len || tokens_size % tok->len) |
| 9004 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9005 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9006 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9007 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9008 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9009 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9010 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9011 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9012 | return -EINVAL; |
| 9013 | if (tok->offset + tok->len > data_size) |
| 9014 | return -EINVAL; |
| 9015 | } |
| 9016 | |
| 9017 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9018 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9019 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9020 | return -EINVAL; |
| 9021 | if (seq->len == 0 || seq->len > 4) |
| 9022 | return -EINVAL; |
| 9023 | if (seq->len + seq->offset > data_size) |
| 9024 | return -EINVAL; |
| 9025 | } |
| 9026 | |
| 9027 | size = sizeof(*cfg); |
| 9028 | size += data_size; |
| 9029 | size += wake_size + wake_mask_size; |
| 9030 | size += tokens_size; |
| 9031 | |
| 9032 | cfg = kzalloc(size, GFP_KERNEL); |
| 9033 | if (!cfg) |
| 9034 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9035 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9036 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9037 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9038 | ETH_ALEN); |
| 9039 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9040 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9041 | else |
| 9042 | port = 0; |
| 9043 | #ifdef CONFIG_INET |
| 9044 | /* allocate a socket and port for it and use it */ |
| 9045 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9046 | IPPROTO_TCP, &cfg->sock, 1); |
| 9047 | if (err) { |
| 9048 | kfree(cfg); |
| 9049 | return err; |
| 9050 | } |
| 9051 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9052 | sock_release(cfg->sock); |
| 9053 | kfree(cfg); |
| 9054 | return -EADDRINUSE; |
| 9055 | } |
| 9056 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9057 | #else |
| 9058 | if (!port) { |
| 9059 | kfree(cfg); |
| 9060 | return -EINVAL; |
| 9061 | } |
| 9062 | cfg->src_port = port; |
| 9063 | #endif |
| 9064 | |
| 9065 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9066 | cfg->payload_len = data_size; |
| 9067 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9068 | memcpy((void *)cfg->payload, |
| 9069 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9070 | data_size); |
| 9071 | if (seq) |
| 9072 | cfg->payload_seq = *seq; |
| 9073 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9074 | cfg->wake_len = wake_size; |
| 9075 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9076 | memcpy((void *)cfg->wake_data, |
| 9077 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9078 | wake_size); |
| 9079 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9080 | data_size + wake_size; |
| 9081 | memcpy((void *)cfg->wake_mask, |
| 9082 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9083 | wake_mask_size); |
| 9084 | if (tok) { |
| 9085 | cfg->tokens_size = tokens_size; |
| 9086 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9087 | } |
| 9088 | |
| 9089 | trig->tcp = cfg; |
| 9090 | |
| 9091 | return 0; |
| 9092 | } |
| 9093 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9094 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9095 | const struct wiphy_wowlan_support *wowlan, |
| 9096 | struct nlattr *attr, |
| 9097 | struct cfg80211_wowlan *trig) |
| 9098 | { |
| 9099 | struct nlattr **tb; |
| 9100 | int err; |
| 9101 | |
| 9102 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9103 | if (!tb) |
| 9104 | return -ENOMEM; |
| 9105 | |
| 9106 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9107 | err = -EOPNOTSUPP; |
| 9108 | goto out; |
| 9109 | } |
| 9110 | |
| 9111 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9112 | nla_data(attr), nla_len(attr), |
| 9113 | nl80211_policy); |
| 9114 | if (err) |
| 9115 | goto out; |
| 9116 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9117 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9118 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9119 | if (err) |
| 9120 | trig->nd_config = NULL; |
| 9121 | |
| 9122 | out: |
| 9123 | kfree(tb); |
| 9124 | return err; |
| 9125 | } |
| 9126 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9127 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9128 | { |
| 9129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9130 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9131 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9132 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9133 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9134 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9135 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9136 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9137 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9138 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9139 | return -EOPNOTSUPP; |
| 9140 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9141 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9142 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9143 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9144 | goto set_wakeup; |
| 9145 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9146 | |
| 9147 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9148 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9149 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9150 | nl80211_wowlan_policy); |
| 9151 | if (err) |
| 9152 | return err; |
| 9153 | |
| 9154 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9155 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9156 | return -EINVAL; |
| 9157 | new_triggers.any = true; |
| 9158 | } |
| 9159 | |
| 9160 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9161 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9162 | return -EINVAL; |
| 9163 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9164 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9165 | } |
| 9166 | |
| 9167 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9168 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9169 | return -EINVAL; |
| 9170 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9171 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9172 | } |
| 9173 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9174 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9175 | return -EINVAL; |
| 9176 | |
| 9177 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9178 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9179 | return -EINVAL; |
| 9180 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9181 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9182 | } |
| 9183 | |
| 9184 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9185 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9186 | return -EINVAL; |
| 9187 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9188 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9189 | } |
| 9190 | |
| 9191 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9192 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9193 | return -EINVAL; |
| 9194 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9195 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9196 | } |
| 9197 | |
| 9198 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9199 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9200 | return -EINVAL; |
| 9201 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9202 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9203 | } |
| 9204 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9205 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9206 | struct nlattr *pat; |
| 9207 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9208 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9209 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9210 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9211 | regular = true; |
| 9212 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9213 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9214 | rem) |
| 9215 | n_patterns++; |
| 9216 | if (n_patterns > wowlan->n_patterns) |
| 9217 | return -EINVAL; |
| 9218 | |
| 9219 | new_triggers.patterns = kcalloc(n_patterns, |
| 9220 | sizeof(new_triggers.patterns[0]), |
| 9221 | GFP_KERNEL); |
| 9222 | if (!new_triggers.patterns) |
| 9223 | return -ENOMEM; |
| 9224 | |
| 9225 | new_triggers.n_patterns = n_patterns; |
| 9226 | i = 0; |
| 9227 | |
| 9228 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9229 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9230 | u8 *mask_pat; |
| 9231 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9232 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9233 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9234 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9235 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9236 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9237 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9238 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9239 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9240 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9241 | goto error; |
| 9242 | if (pat_len > wowlan->pattern_max_len || |
| 9243 | pat_len < wowlan->pattern_min_len) |
| 9244 | goto error; |
| 9245 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9246 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9247 | pkt_offset = 0; |
| 9248 | else |
| 9249 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9250 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9251 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9252 | goto error; |
| 9253 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9254 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9255 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9256 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9257 | err = -ENOMEM; |
| 9258 | goto error; |
| 9259 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9260 | new_triggers.patterns[i].mask = mask_pat; |
| 9261 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9262 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9263 | mask_pat += mask_len; |
| 9264 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9265 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9266 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9267 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9268 | pat_len); |
| 9269 | i++; |
| 9270 | } |
| 9271 | } |
| 9272 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9273 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9274 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9275 | err = nl80211_parse_wowlan_tcp( |
| 9276 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9277 | &new_triggers); |
| 9278 | if (err) |
| 9279 | goto error; |
| 9280 | } |
| 9281 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9282 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9283 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9284 | err = nl80211_parse_wowlan_nd( |
| 9285 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9286 | &new_triggers); |
| 9287 | if (err) |
| 9288 | goto error; |
| 9289 | } |
| 9290 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9291 | /* The 'any' trigger means the device continues operating more or less |
| 9292 | * as in its normal operation mode and wakes up the host on most of the |
| 9293 | * normal interrupts (like packet RX, ...) |
| 9294 | * It therefore makes little sense to combine with the more constrained |
| 9295 | * wakeup trigger modes. |
| 9296 | */ |
| 9297 | if (new_triggers.any && regular) { |
| 9298 | err = -EINVAL; |
| 9299 | goto error; |
| 9300 | } |
| 9301 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9302 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9303 | if (!ntrig) { |
| 9304 | err = -ENOMEM; |
| 9305 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9306 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9307 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9308 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9309 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9310 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9311 | if (rdev->ops->set_wakeup && |
| 9312 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9313 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9314 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9315 | return 0; |
| 9316 | error: |
| 9317 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9318 | kfree(new_triggers.patterns[i].mask); |
| 9319 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9320 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9321 | sock_release(new_triggers.tcp->sock); |
| 9322 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9323 | return err; |
| 9324 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9325 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9326 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9327 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9328 | struct cfg80211_registered_device *rdev) |
| 9329 | { |
| 9330 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9331 | int i, j, pat_len; |
| 9332 | struct cfg80211_coalesce_rules *rule; |
| 9333 | |
| 9334 | if (!rdev->coalesce->n_rules) |
| 9335 | return 0; |
| 9336 | |
| 9337 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9338 | if (!nl_rules) |
| 9339 | return -ENOBUFS; |
| 9340 | |
| 9341 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9342 | nl_rule = nla_nest_start(msg, i + 1); |
| 9343 | if (!nl_rule) |
| 9344 | return -ENOBUFS; |
| 9345 | |
| 9346 | rule = &rdev->coalesce->rules[i]; |
| 9347 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9348 | rule->delay)) |
| 9349 | return -ENOBUFS; |
| 9350 | |
| 9351 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9352 | rule->condition)) |
| 9353 | return -ENOBUFS; |
| 9354 | |
| 9355 | nl_pats = nla_nest_start(msg, |
| 9356 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9357 | if (!nl_pats) |
| 9358 | return -ENOBUFS; |
| 9359 | |
| 9360 | for (j = 0; j < rule->n_patterns; j++) { |
| 9361 | nl_pat = nla_nest_start(msg, j + 1); |
| 9362 | if (!nl_pat) |
| 9363 | return -ENOBUFS; |
| 9364 | pat_len = rule->patterns[j].pattern_len; |
| 9365 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9366 | DIV_ROUND_UP(pat_len, 8), |
| 9367 | rule->patterns[j].mask) || |
| 9368 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9369 | rule->patterns[j].pattern) || |
| 9370 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9371 | rule->patterns[j].pkt_offset)) |
| 9372 | return -ENOBUFS; |
| 9373 | nla_nest_end(msg, nl_pat); |
| 9374 | } |
| 9375 | nla_nest_end(msg, nl_pats); |
| 9376 | nla_nest_end(msg, nl_rule); |
| 9377 | } |
| 9378 | nla_nest_end(msg, nl_rules); |
| 9379 | |
| 9380 | return 0; |
| 9381 | } |
| 9382 | |
| 9383 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9384 | { |
| 9385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9386 | struct sk_buff *msg; |
| 9387 | void *hdr; |
| 9388 | |
| 9389 | if (!rdev->wiphy.coalesce) |
| 9390 | return -EOPNOTSUPP; |
| 9391 | |
| 9392 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9393 | if (!msg) |
| 9394 | return -ENOMEM; |
| 9395 | |
| 9396 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9397 | NL80211_CMD_GET_COALESCE); |
| 9398 | if (!hdr) |
| 9399 | goto nla_put_failure; |
| 9400 | |
| 9401 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9402 | goto nla_put_failure; |
| 9403 | |
| 9404 | genlmsg_end(msg, hdr); |
| 9405 | return genlmsg_reply(msg, info); |
| 9406 | |
| 9407 | nla_put_failure: |
| 9408 | nlmsg_free(msg); |
| 9409 | return -ENOBUFS; |
| 9410 | } |
| 9411 | |
| 9412 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9413 | { |
| 9414 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9415 | int i, j; |
| 9416 | struct cfg80211_coalesce_rules *rule; |
| 9417 | |
| 9418 | if (!coalesce) |
| 9419 | return; |
| 9420 | |
| 9421 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9422 | rule = &coalesce->rules[i]; |
| 9423 | for (j = 0; j < rule->n_patterns; j++) |
| 9424 | kfree(rule->patterns[j].mask); |
| 9425 | kfree(rule->patterns); |
| 9426 | } |
| 9427 | kfree(coalesce->rules); |
| 9428 | kfree(coalesce); |
| 9429 | rdev->coalesce = NULL; |
| 9430 | } |
| 9431 | |
| 9432 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9433 | struct nlattr *rule, |
| 9434 | struct cfg80211_coalesce_rules *new_rule) |
| 9435 | { |
| 9436 | int err, i; |
| 9437 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9438 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9439 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9440 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9441 | |
| 9442 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9443 | nla_len(rule), nl80211_coalesce_policy); |
| 9444 | if (err) |
| 9445 | return err; |
| 9446 | |
| 9447 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9448 | new_rule->delay = |
| 9449 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9450 | if (new_rule->delay > coalesce->max_delay) |
| 9451 | return -EINVAL; |
| 9452 | |
| 9453 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9454 | new_rule->condition = |
| 9455 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9456 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9457 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9458 | return -EINVAL; |
| 9459 | |
| 9460 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9461 | return -EINVAL; |
| 9462 | |
| 9463 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9464 | rem) |
| 9465 | n_patterns++; |
| 9466 | if (n_patterns > coalesce->n_patterns) |
| 9467 | return -EINVAL; |
| 9468 | |
| 9469 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9470 | GFP_KERNEL); |
| 9471 | if (!new_rule->patterns) |
| 9472 | return -ENOMEM; |
| 9473 | |
| 9474 | new_rule->n_patterns = n_patterns; |
| 9475 | i = 0; |
| 9476 | |
| 9477 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9478 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9479 | u8 *mask_pat; |
| 9480 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9481 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9482 | nla_len(pat), NULL); |
| 9483 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9484 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9485 | return -EINVAL; |
| 9486 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9487 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9488 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9489 | return -EINVAL; |
| 9490 | if (pat_len > coalesce->pattern_max_len || |
| 9491 | pat_len < coalesce->pattern_min_len) |
| 9492 | return -EINVAL; |
| 9493 | |
| 9494 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9495 | pkt_offset = 0; |
| 9496 | else |
| 9497 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9498 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9499 | return -EINVAL; |
| 9500 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9501 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9502 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9503 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9504 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9505 | |
| 9506 | new_rule->patterns[i].mask = mask_pat; |
| 9507 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9508 | mask_len); |
| 9509 | |
| 9510 | mask_pat += mask_len; |
| 9511 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9512 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9513 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9514 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9515 | i++; |
| 9516 | } |
| 9517 | |
| 9518 | return 0; |
| 9519 | } |
| 9520 | |
| 9521 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9522 | { |
| 9523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9524 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9525 | struct cfg80211_coalesce new_coalesce = {}; |
| 9526 | struct cfg80211_coalesce *n_coalesce; |
| 9527 | int err, rem_rule, n_rules = 0, i, j; |
| 9528 | struct nlattr *rule; |
| 9529 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9530 | |
| 9531 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9532 | return -EOPNOTSUPP; |
| 9533 | |
| 9534 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9535 | cfg80211_rdev_free_coalesce(rdev); |
| 9536 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9537 | return 0; |
| 9538 | } |
| 9539 | |
| 9540 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9541 | rem_rule) |
| 9542 | n_rules++; |
| 9543 | if (n_rules > coalesce->n_rules) |
| 9544 | return -EINVAL; |
| 9545 | |
| 9546 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9547 | GFP_KERNEL); |
| 9548 | if (!new_coalesce.rules) |
| 9549 | return -ENOMEM; |
| 9550 | |
| 9551 | new_coalesce.n_rules = n_rules; |
| 9552 | i = 0; |
| 9553 | |
| 9554 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9555 | rem_rule) { |
| 9556 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9557 | &new_coalesce.rules[i]); |
| 9558 | if (err) |
| 9559 | goto error; |
| 9560 | |
| 9561 | i++; |
| 9562 | } |
| 9563 | |
| 9564 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9565 | if (err) |
| 9566 | goto error; |
| 9567 | |
| 9568 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9569 | if (!n_coalesce) { |
| 9570 | err = -ENOMEM; |
| 9571 | goto error; |
| 9572 | } |
| 9573 | cfg80211_rdev_free_coalesce(rdev); |
| 9574 | rdev->coalesce = n_coalesce; |
| 9575 | |
| 9576 | return 0; |
| 9577 | error: |
| 9578 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9579 | tmp_rule = &new_coalesce.rules[i]; |
| 9580 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9581 | kfree(tmp_rule->patterns[j].mask); |
| 9582 | kfree(tmp_rule->patterns); |
| 9583 | } |
| 9584 | kfree(new_coalesce.rules); |
| 9585 | |
| 9586 | return err; |
| 9587 | } |
| 9588 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9589 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9590 | { |
| 9591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9592 | struct net_device *dev = info->user_ptr[1]; |
| 9593 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9594 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9595 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9596 | int err; |
| 9597 | |
| 9598 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9599 | return -EINVAL; |
| 9600 | |
| 9601 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9602 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9603 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9604 | nl80211_rekey_policy); |
| 9605 | if (err) |
| 9606 | return err; |
| 9607 | |
| 9608 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9609 | return -ERANGE; |
| 9610 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9611 | return -ERANGE; |
| 9612 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9613 | return -ERANGE; |
| 9614 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9615 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9616 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9617 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9618 | |
| 9619 | wdev_lock(wdev); |
| 9620 | if (!wdev->current_bss) { |
| 9621 | err = -ENOTCONN; |
| 9622 | goto out; |
| 9623 | } |
| 9624 | |
| 9625 | if (!rdev->ops->set_rekey_data) { |
| 9626 | err = -EOPNOTSUPP; |
| 9627 | goto out; |
| 9628 | } |
| 9629 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9630 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9631 | out: |
| 9632 | wdev_unlock(wdev); |
| 9633 | return err; |
| 9634 | } |
| 9635 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9636 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9637 | struct genl_info *info) |
| 9638 | { |
| 9639 | struct net_device *dev = info->user_ptr[1]; |
| 9640 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9641 | |
| 9642 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9643 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9644 | return -EINVAL; |
| 9645 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9646 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9647 | return -EBUSY; |
| 9648 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9649 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9650 | return 0; |
| 9651 | } |
| 9652 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9653 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9654 | struct genl_info *info) |
| 9655 | { |
| 9656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9657 | struct net_device *dev = info->user_ptr[1]; |
| 9658 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9659 | struct sk_buff *msg; |
| 9660 | void *hdr; |
| 9661 | const u8 *addr; |
| 9662 | u64 cookie; |
| 9663 | int err; |
| 9664 | |
| 9665 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9666 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9667 | return -EOPNOTSUPP; |
| 9668 | |
| 9669 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9670 | return -EINVAL; |
| 9671 | |
| 9672 | if (!rdev->ops->probe_client) |
| 9673 | return -EOPNOTSUPP; |
| 9674 | |
| 9675 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9676 | if (!msg) |
| 9677 | return -ENOMEM; |
| 9678 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9679 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9680 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9681 | if (!hdr) { |
| 9682 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9683 | goto free_msg; |
| 9684 | } |
| 9685 | |
| 9686 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9687 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9688 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9689 | if (err) |
| 9690 | goto free_msg; |
| 9691 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9692 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9693 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9694 | |
| 9695 | genlmsg_end(msg, hdr); |
| 9696 | |
| 9697 | return genlmsg_reply(msg, info); |
| 9698 | |
| 9699 | nla_put_failure: |
| 9700 | err = -ENOBUFS; |
| 9701 | free_msg: |
| 9702 | nlmsg_free(msg); |
| 9703 | return err; |
| 9704 | } |
| 9705 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9706 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9707 | { |
| 9708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9709 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9710 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9711 | |
| 9712 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9713 | return -EOPNOTSUPP; |
| 9714 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9715 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9716 | if (!nreg) |
| 9717 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9718 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9719 | /* First, check if already registered. */ |
| 9720 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9721 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9722 | if (reg->nlportid == info->snd_portid) { |
| 9723 | rv = -EALREADY; |
| 9724 | goto out_err; |
| 9725 | } |
| 9726 | } |
| 9727 | /* Add it to the list */ |
| 9728 | nreg->nlportid = info->snd_portid; |
| 9729 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9730 | |
| 9731 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9732 | |
| 9733 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9734 | out_err: |
| 9735 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9736 | kfree(nreg); |
| 9737 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9738 | } |
| 9739 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9740 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9741 | { |
| 9742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9743 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9744 | int err; |
| 9745 | |
| 9746 | if (!rdev->ops->start_p2p_device) |
| 9747 | return -EOPNOTSUPP; |
| 9748 | |
| 9749 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9750 | return -EOPNOTSUPP; |
| 9751 | |
| 9752 | if (wdev->p2p_started) |
| 9753 | return 0; |
| 9754 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9755 | if (rfkill_blocked(rdev->rfkill)) |
| 9756 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9757 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9758 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9759 | if (err) |
| 9760 | return err; |
| 9761 | |
| 9762 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9763 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9764 | |
| 9765 | return 0; |
| 9766 | } |
| 9767 | |
| 9768 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9769 | { |
| 9770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9771 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9772 | |
| 9773 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9774 | return -EOPNOTSUPP; |
| 9775 | |
| 9776 | if (!rdev->ops->stop_p2p_device) |
| 9777 | return -EOPNOTSUPP; |
| 9778 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9779 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9780 | |
| 9781 | return 0; |
| 9782 | } |
| 9783 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9784 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9785 | struct genl_info *info) |
| 9786 | { |
| 9787 | void *hdr; |
| 9788 | struct sk_buff *msg; |
| 9789 | |
| 9790 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9791 | if (!msg) |
| 9792 | return -ENOMEM; |
| 9793 | |
| 9794 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9795 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9796 | if (!hdr) |
| 9797 | goto nla_put_failure; |
| 9798 | |
| 9799 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9800 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9801 | goto nla_put_failure; |
| 9802 | |
| 9803 | genlmsg_end(msg, hdr); |
| 9804 | return genlmsg_reply(msg, info); |
| 9805 | |
| 9806 | nla_put_failure: |
| 9807 | kfree_skb(msg); |
| 9808 | return -ENOBUFS; |
| 9809 | } |
| 9810 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9811 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9812 | { |
| 9813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9814 | struct cfg80211_update_ft_ies_params ft_params; |
| 9815 | struct net_device *dev = info->user_ptr[1]; |
| 9816 | |
| 9817 | if (!rdev->ops->update_ft_ies) |
| 9818 | return -EOPNOTSUPP; |
| 9819 | |
| 9820 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9821 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9822 | return -EINVAL; |
| 9823 | |
| 9824 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9825 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9826 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9827 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9828 | |
| 9829 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9830 | } |
| 9831 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9832 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9833 | struct genl_info *info) |
| 9834 | { |
| 9835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9836 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9837 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9838 | u16 duration; |
| 9839 | int ret; |
| 9840 | |
| 9841 | if (!rdev->ops->crit_proto_start) |
| 9842 | return -EOPNOTSUPP; |
| 9843 | |
| 9844 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9845 | return -EINVAL; |
| 9846 | |
| 9847 | if (rdev->crit_proto_nlportid) |
| 9848 | return -EBUSY; |
| 9849 | |
| 9850 | /* determine protocol if provided */ |
| 9851 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9852 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9853 | |
| 9854 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9855 | return -EINVAL; |
| 9856 | |
| 9857 | /* timeout must be provided */ |
| 9858 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9859 | return -EINVAL; |
| 9860 | |
| 9861 | duration = |
| 9862 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9863 | |
| 9864 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9865 | return -ERANGE; |
| 9866 | |
| 9867 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9868 | if (!ret) |
| 9869 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9870 | |
| 9871 | return ret; |
| 9872 | } |
| 9873 | |
| 9874 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9875 | struct genl_info *info) |
| 9876 | { |
| 9877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9878 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9879 | |
| 9880 | if (!rdev->ops->crit_proto_stop) |
| 9881 | return -EOPNOTSUPP; |
| 9882 | |
| 9883 | if (rdev->crit_proto_nlportid) { |
| 9884 | rdev->crit_proto_nlportid = 0; |
| 9885 | rdev_crit_proto_stop(rdev, wdev); |
| 9886 | } |
| 9887 | return 0; |
| 9888 | } |
| 9889 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9890 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9891 | { |
| 9892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9893 | struct wireless_dev *wdev = |
| 9894 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9895 | int i, err; |
| 9896 | u32 vid, subcmd; |
| 9897 | |
| 9898 | if (!rdev->wiphy.vendor_commands) |
| 9899 | return -EOPNOTSUPP; |
| 9900 | |
| 9901 | if (IS_ERR(wdev)) { |
| 9902 | err = PTR_ERR(wdev); |
| 9903 | if (err != -EINVAL) |
| 9904 | return err; |
| 9905 | wdev = NULL; |
| 9906 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9907 | return -EINVAL; |
| 9908 | } |
| 9909 | |
| 9910 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9911 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9912 | return -EINVAL; |
| 9913 | |
| 9914 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9915 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9916 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9917 | const struct wiphy_vendor_command *vcmd; |
| 9918 | void *data = NULL; |
| 9919 | int len = 0; |
| 9920 | |
| 9921 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9922 | |
| 9923 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9924 | continue; |
| 9925 | |
| 9926 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9927 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9928 | if (!wdev) |
| 9929 | return -EINVAL; |
| 9930 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9931 | !wdev->netdev) |
| 9932 | return -EINVAL; |
| 9933 | |
| 9934 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9935 | if (wdev->netdev && |
| 9936 | !netif_running(wdev->netdev)) |
| 9937 | return -ENETDOWN; |
| 9938 | if (!wdev->netdev && !wdev->p2p_started) |
| 9939 | return -ENETDOWN; |
| 9940 | } |
| 9941 | } else { |
| 9942 | wdev = NULL; |
| 9943 | } |
| 9944 | |
| 9945 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9946 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9947 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9948 | } |
| 9949 | |
| 9950 | rdev->cur_cmd_info = info; |
| 9951 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9952 | data, len); |
| 9953 | rdev->cur_cmd_info = NULL; |
| 9954 | return err; |
| 9955 | } |
| 9956 | |
| 9957 | return -EOPNOTSUPP; |
| 9958 | } |
| 9959 | |
| 9960 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9961 | enum nl80211_commands cmd, |
| 9962 | enum nl80211_attrs attr, |
| 9963 | int approxlen) |
| 9964 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9965 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9966 | |
| 9967 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9968 | return NULL; |
| 9969 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9970 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9971 | rdev->cur_cmd_info->snd_portid, |
| 9972 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9973 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9974 | } |
| 9975 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9976 | |
| 9977 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9978 | { |
| 9979 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9980 | void *hdr = ((void **)skb->cb)[1]; |
| 9981 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9982 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9983 | /* clear CB data for netlink core to own from now on */ |
| 9984 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9985 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9986 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9987 | kfree_skb(skb); |
| 9988 | return -EINVAL; |
| 9989 | } |
| 9990 | |
| 9991 | nla_nest_end(skb, data); |
| 9992 | genlmsg_end(skb, hdr); |
| 9993 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9994 | } |
| 9995 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9996 | |
| 9997 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9998 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9999 | struct genl_info *info) |
| 10000 | { |
| 10001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10002 | struct cfg80211_qos_map *qos_map = NULL; |
| 10003 | struct net_device *dev = info->user_ptr[1]; |
| 10004 | u8 *pos, len, num_des, des_len, des; |
| 10005 | int ret; |
| 10006 | |
| 10007 | if (!rdev->ops->set_qos_map) |
| 10008 | return -EOPNOTSUPP; |
| 10009 | |
| 10010 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10011 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10012 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10013 | |
| 10014 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10015 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10016 | return -EINVAL; |
| 10017 | |
| 10018 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10019 | if (!qos_map) |
| 10020 | return -ENOMEM; |
| 10021 | |
| 10022 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10023 | if (num_des) { |
| 10024 | des_len = num_des * |
| 10025 | sizeof(struct cfg80211_dscp_exception); |
| 10026 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10027 | qos_map->num_des = num_des; |
| 10028 | for (des = 0; des < num_des; des++) { |
| 10029 | if (qos_map->dscp_exception[des].up > 7) { |
| 10030 | kfree(qos_map); |
| 10031 | return -EINVAL; |
| 10032 | } |
| 10033 | } |
| 10034 | pos += des_len; |
| 10035 | } |
| 10036 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10037 | } |
| 10038 | |
| 10039 | wdev_lock(dev->ieee80211_ptr); |
| 10040 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10041 | if (!ret) |
| 10042 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10043 | wdev_unlock(dev->ieee80211_ptr); |
| 10044 | |
| 10045 | kfree(qos_map); |
| 10046 | return ret; |
| 10047 | } |
| 10048 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10049 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10050 | { |
| 10051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10052 | struct net_device *dev = info->user_ptr[1]; |
| 10053 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10054 | const u8 *peer; |
| 10055 | u8 tsid, up; |
| 10056 | u16 admitted_time = 0; |
| 10057 | int err; |
| 10058 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10059 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10060 | return -EOPNOTSUPP; |
| 10061 | |
| 10062 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10063 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10064 | return -EINVAL; |
| 10065 | |
| 10066 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10067 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10068 | return -EINVAL; |
| 10069 | |
| 10070 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10071 | if (up >= IEEE80211_NUM_UPS) |
| 10072 | return -EINVAL; |
| 10073 | |
| 10074 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10075 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10076 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10077 | * need more attributes for that (e.g. BA session requirement); |
| 10078 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10079 | */ |
| 10080 | return -EINVAL; |
| 10081 | } |
| 10082 | |
| 10083 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10084 | |
| 10085 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10086 | admitted_time = |
| 10087 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10088 | if (!admitted_time) |
| 10089 | return -EINVAL; |
| 10090 | } |
| 10091 | |
| 10092 | wdev_lock(wdev); |
| 10093 | switch (wdev->iftype) { |
| 10094 | case NL80211_IFTYPE_STATION: |
| 10095 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10096 | if (wdev->current_bss) |
| 10097 | break; |
| 10098 | err = -ENOTCONN; |
| 10099 | goto out; |
| 10100 | default: |
| 10101 | err = -EOPNOTSUPP; |
| 10102 | goto out; |
| 10103 | } |
| 10104 | |
| 10105 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10106 | |
| 10107 | out: |
| 10108 | wdev_unlock(wdev); |
| 10109 | return err; |
| 10110 | } |
| 10111 | |
| 10112 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10113 | { |
| 10114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10115 | struct net_device *dev = info->user_ptr[1]; |
| 10116 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10117 | const u8 *peer; |
| 10118 | u8 tsid; |
| 10119 | int err; |
| 10120 | |
| 10121 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10122 | return -EINVAL; |
| 10123 | |
| 10124 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10125 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10126 | |
| 10127 | wdev_lock(wdev); |
| 10128 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10129 | wdev_unlock(wdev); |
| 10130 | |
| 10131 | return err; |
| 10132 | } |
| 10133 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10134 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10135 | struct genl_info *info) |
| 10136 | { |
| 10137 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10138 | struct net_device *dev = info->user_ptr[1]; |
| 10139 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10140 | struct cfg80211_chan_def chandef = {}; |
| 10141 | const u8 *addr; |
| 10142 | u8 oper_class; |
| 10143 | int err; |
| 10144 | |
| 10145 | if (!rdev->ops->tdls_channel_switch || |
| 10146 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10147 | return -EOPNOTSUPP; |
| 10148 | |
| 10149 | switch (dev->ieee80211_ptr->iftype) { |
| 10150 | case NL80211_IFTYPE_STATION: |
| 10151 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10152 | break; |
| 10153 | default: |
| 10154 | return -EOPNOTSUPP; |
| 10155 | } |
| 10156 | |
| 10157 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10158 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10159 | return -EINVAL; |
| 10160 | |
| 10161 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10162 | if (err) |
| 10163 | return err; |
| 10164 | |
| 10165 | /* |
| 10166 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10167 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10168 | * specification is not defined for them. |
| 10169 | */ |
| 10170 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 10171 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10172 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10173 | return -EINVAL; |
| 10174 | |
| 10175 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10176 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10177 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10178 | return -EINVAL; |
| 10179 | |
| 10180 | /* don't allow switching to DFS channels */ |
| 10181 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10182 | return -EINVAL; |
| 10183 | |
| 10184 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10185 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10186 | |
| 10187 | wdev_lock(wdev); |
| 10188 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10189 | wdev_unlock(wdev); |
| 10190 | |
| 10191 | return err; |
| 10192 | } |
| 10193 | |
| 10194 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10195 | struct genl_info *info) |
| 10196 | { |
| 10197 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10198 | struct net_device *dev = info->user_ptr[1]; |
| 10199 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10200 | const u8 *addr; |
| 10201 | |
| 10202 | if (!rdev->ops->tdls_channel_switch || |
| 10203 | !rdev->ops->tdls_cancel_channel_switch || |
| 10204 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10205 | return -EOPNOTSUPP; |
| 10206 | |
| 10207 | switch (dev->ieee80211_ptr->iftype) { |
| 10208 | case NL80211_IFTYPE_STATION: |
| 10209 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10210 | break; |
| 10211 | default: |
| 10212 | return -EOPNOTSUPP; |
| 10213 | } |
| 10214 | |
| 10215 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10216 | return -EINVAL; |
| 10217 | |
| 10218 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10219 | |
| 10220 | wdev_lock(wdev); |
| 10221 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10222 | wdev_unlock(wdev); |
| 10223 | |
| 10224 | return 0; |
| 10225 | } |
| 10226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10227 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10228 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10229 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10230 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10231 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10232 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10233 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10234 | /* 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] | 10235 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10236 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10237 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10238 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10239 | 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] | 10240 | struct genl_info *info) |
| 10241 | { |
| 10242 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10243 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10244 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10245 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10246 | |
| 10247 | if (rtnl) |
| 10248 | rtnl_lock(); |
| 10249 | |
| 10250 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10251 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10252 | if (IS_ERR(rdev)) { |
| 10253 | if (rtnl) |
| 10254 | rtnl_unlock(); |
| 10255 | return PTR_ERR(rdev); |
| 10256 | } |
| 10257 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10258 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10259 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10260 | ASSERT_RTNL(); |
| 10261 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10262 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10263 | info->attrs); |
| 10264 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10265 | if (rtnl) |
| 10266 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10267 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10268 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10269 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10270 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10271 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10272 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10273 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10274 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10275 | if (rtnl) |
| 10276 | rtnl_unlock(); |
| 10277 | return -EINVAL; |
| 10278 | } |
| 10279 | |
| 10280 | info->user_ptr[1] = dev; |
| 10281 | } else { |
| 10282 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10283 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10284 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10285 | if (dev) { |
| 10286 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10287 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10288 | if (rtnl) |
| 10289 | rtnl_unlock(); |
| 10290 | return -ENETDOWN; |
| 10291 | } |
| 10292 | |
| 10293 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10294 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10295 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10296 | if (rtnl) |
| 10297 | rtnl_unlock(); |
| 10298 | return -ENETDOWN; |
| 10299 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10300 | } |
| 10301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10302 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10303 | } |
| 10304 | |
| 10305 | return 0; |
| 10306 | } |
| 10307 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10308 | 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] | 10309 | struct genl_info *info) |
| 10310 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10311 | if (info->user_ptr[1]) { |
| 10312 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10313 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10314 | |
| 10315 | if (wdev->netdev) |
| 10316 | dev_put(wdev->netdev); |
| 10317 | } else { |
| 10318 | dev_put(info->user_ptr[1]); |
| 10319 | } |
| 10320 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10321 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10322 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10323 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10324 | |
| 10325 | /* If needed, clear the netlink message payload from the SKB |
| 10326 | * as it might contain key data that shouldn't stick around on |
| 10327 | * the heap after the SKB is freed. The netlink message header |
| 10328 | * is still needed for further processing, so leave it intact. |
| 10329 | */ |
| 10330 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10331 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10332 | |
| 10333 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10334 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10335 | } |
| 10336 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10337 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10338 | { |
| 10339 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10340 | .doit = nl80211_get_wiphy, |
| 10341 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10342 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10343 | .policy = nl80211_policy, |
| 10344 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10345 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10346 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10347 | }, |
| 10348 | { |
| 10349 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10350 | .doit = nl80211_set_wiphy, |
| 10351 | .policy = nl80211_policy, |
| 10352 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10353 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10354 | }, |
| 10355 | { |
| 10356 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10357 | .doit = nl80211_get_interface, |
| 10358 | .dumpit = nl80211_dump_interface, |
| 10359 | .policy = nl80211_policy, |
| 10360 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10361 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10362 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10363 | }, |
| 10364 | { |
| 10365 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10366 | .doit = nl80211_set_interface, |
| 10367 | .policy = nl80211_policy, |
| 10368 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10369 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10370 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10371 | }, |
| 10372 | { |
| 10373 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10374 | .doit = nl80211_new_interface, |
| 10375 | .policy = nl80211_policy, |
| 10376 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10377 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10378 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10379 | }, |
| 10380 | { |
| 10381 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10382 | .doit = nl80211_del_interface, |
| 10383 | .policy = nl80211_policy, |
| 10384 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10385 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10386 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10387 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10388 | { |
| 10389 | .cmd = NL80211_CMD_GET_KEY, |
| 10390 | .doit = nl80211_get_key, |
| 10391 | .policy = nl80211_policy, |
| 10392 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10393 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10394 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10395 | }, |
| 10396 | { |
| 10397 | .cmd = NL80211_CMD_SET_KEY, |
| 10398 | .doit = nl80211_set_key, |
| 10399 | .policy = nl80211_policy, |
| 10400 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10401 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10402 | NL80211_FLAG_NEED_RTNL | |
| 10403 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10404 | }, |
| 10405 | { |
| 10406 | .cmd = NL80211_CMD_NEW_KEY, |
| 10407 | .doit = nl80211_new_key, |
| 10408 | .policy = nl80211_policy, |
| 10409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10411 | NL80211_FLAG_NEED_RTNL | |
| 10412 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10413 | }, |
| 10414 | { |
| 10415 | .cmd = NL80211_CMD_DEL_KEY, |
| 10416 | .doit = nl80211_del_key, |
| 10417 | .policy = nl80211_policy, |
| 10418 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10420 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10421 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10422 | { |
| 10423 | .cmd = NL80211_CMD_SET_BEACON, |
| 10424 | .policy = nl80211_policy, |
| 10425 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10426 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10428 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10429 | }, |
| 10430 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10431 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10432 | .policy = nl80211_policy, |
| 10433 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10434 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10436 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10437 | }, |
| 10438 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10439 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10440 | .policy = nl80211_policy, |
| 10441 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10442 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10444 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10445 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10446 | { |
| 10447 | .cmd = NL80211_CMD_GET_STATION, |
| 10448 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10449 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10450 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10451 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10453 | }, |
| 10454 | { |
| 10455 | .cmd = NL80211_CMD_SET_STATION, |
| 10456 | .doit = nl80211_set_station, |
| 10457 | .policy = nl80211_policy, |
| 10458 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10460 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10461 | }, |
| 10462 | { |
| 10463 | .cmd = NL80211_CMD_NEW_STATION, |
| 10464 | .doit = nl80211_new_station, |
| 10465 | .policy = nl80211_policy, |
| 10466 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10468 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10469 | }, |
| 10470 | { |
| 10471 | .cmd = NL80211_CMD_DEL_STATION, |
| 10472 | .doit = nl80211_del_station, |
| 10473 | .policy = nl80211_policy, |
| 10474 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10476 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10477 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10478 | { |
| 10479 | .cmd = NL80211_CMD_GET_MPATH, |
| 10480 | .doit = nl80211_get_mpath, |
| 10481 | .dumpit = nl80211_dump_mpath, |
| 10482 | .policy = nl80211_policy, |
| 10483 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10485 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10486 | }, |
| 10487 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10488 | .cmd = NL80211_CMD_GET_MPP, |
| 10489 | .doit = nl80211_get_mpp, |
| 10490 | .dumpit = nl80211_dump_mpp, |
| 10491 | .policy = nl80211_policy, |
| 10492 | .flags = GENL_ADMIN_PERM, |
| 10493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10494 | NL80211_FLAG_NEED_RTNL, |
| 10495 | }, |
| 10496 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10497 | .cmd = NL80211_CMD_SET_MPATH, |
| 10498 | .doit = nl80211_set_mpath, |
| 10499 | .policy = nl80211_policy, |
| 10500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10502 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10503 | }, |
| 10504 | { |
| 10505 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10506 | .doit = nl80211_new_mpath, |
| 10507 | .policy = nl80211_policy, |
| 10508 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10510 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10511 | }, |
| 10512 | { |
| 10513 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10514 | .doit = nl80211_del_mpath, |
| 10515 | .policy = nl80211_policy, |
| 10516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10518 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10519 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10520 | { |
| 10521 | .cmd = NL80211_CMD_SET_BSS, |
| 10522 | .doit = nl80211_set_bss, |
| 10523 | .policy = nl80211_policy, |
| 10524 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10526 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10527 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10528 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10529 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10530 | .doit = nl80211_get_reg_do, |
| 10531 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10532 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10533 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10534 | /* can be retrieved by unprivileged users */ |
| 10535 | }, |
| 10536 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10537 | .cmd = NL80211_CMD_SET_REG, |
| 10538 | .doit = nl80211_set_reg, |
| 10539 | .policy = nl80211_policy, |
| 10540 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10541 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10542 | }, |
| 10543 | { |
| 10544 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10545 | .doit = nl80211_req_set_reg, |
| 10546 | .policy = nl80211_policy, |
| 10547 | .flags = GENL_ADMIN_PERM, |
| 10548 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10549 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10550 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10551 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10552 | .policy = nl80211_policy, |
| 10553 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10554 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10555 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10556 | }, |
| 10557 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10558 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10559 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10560 | .policy = nl80211_policy, |
| 10561 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10563 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10564 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10565 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10566 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10567 | .doit = nl80211_trigger_scan, |
| 10568 | .policy = nl80211_policy, |
| 10569 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10570 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10571 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10572 | }, |
| 10573 | { |
| 10574 | .cmd = NL80211_CMD_GET_SCAN, |
| 10575 | .policy = nl80211_policy, |
| 10576 | .dumpit = nl80211_dump_scan, |
| 10577 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10578 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10579 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10580 | .doit = nl80211_start_sched_scan, |
| 10581 | .policy = nl80211_policy, |
| 10582 | .flags = GENL_ADMIN_PERM, |
| 10583 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10584 | NL80211_FLAG_NEED_RTNL, |
| 10585 | }, |
| 10586 | { |
| 10587 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10588 | .doit = nl80211_stop_sched_scan, |
| 10589 | .policy = nl80211_policy, |
| 10590 | .flags = GENL_ADMIN_PERM, |
| 10591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10592 | NL80211_FLAG_NEED_RTNL, |
| 10593 | }, |
| 10594 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10595 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10596 | .doit = nl80211_authenticate, |
| 10597 | .policy = nl80211_policy, |
| 10598 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10600 | NL80211_FLAG_NEED_RTNL | |
| 10601 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10602 | }, |
| 10603 | { |
| 10604 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10605 | .doit = nl80211_associate, |
| 10606 | .policy = nl80211_policy, |
| 10607 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10609 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10610 | }, |
| 10611 | { |
| 10612 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10613 | .doit = nl80211_deauthenticate, |
| 10614 | .policy = nl80211_policy, |
| 10615 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10616 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10617 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10618 | }, |
| 10619 | { |
| 10620 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10621 | .doit = nl80211_disassociate, |
| 10622 | .policy = nl80211_policy, |
| 10623 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10624 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10625 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10626 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10627 | { |
| 10628 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10629 | .doit = nl80211_join_ibss, |
| 10630 | .policy = nl80211_policy, |
| 10631 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10632 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10633 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10634 | }, |
| 10635 | { |
| 10636 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10637 | .doit = nl80211_leave_ibss, |
| 10638 | .policy = nl80211_policy, |
| 10639 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10640 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10641 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10642 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10643 | #ifdef CONFIG_NL80211_TESTMODE |
| 10644 | { |
| 10645 | .cmd = NL80211_CMD_TESTMODE, |
| 10646 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10647 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10648 | .policy = nl80211_policy, |
| 10649 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10650 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10651 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10652 | }, |
| 10653 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10654 | { |
| 10655 | .cmd = NL80211_CMD_CONNECT, |
| 10656 | .doit = nl80211_connect, |
| 10657 | .policy = nl80211_policy, |
| 10658 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10659 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10660 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10661 | }, |
| 10662 | { |
| 10663 | .cmd = NL80211_CMD_DISCONNECT, |
| 10664 | .doit = nl80211_disconnect, |
| 10665 | .policy = nl80211_policy, |
| 10666 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10667 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10668 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10669 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10670 | { |
| 10671 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10672 | .doit = nl80211_wiphy_netns, |
| 10673 | .policy = nl80211_policy, |
| 10674 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10675 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10676 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10677 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10678 | { |
| 10679 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10680 | .policy = nl80211_policy, |
| 10681 | .dumpit = nl80211_dump_survey, |
| 10682 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10683 | { |
| 10684 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10685 | .doit = nl80211_setdel_pmksa, |
| 10686 | .policy = nl80211_policy, |
| 10687 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10688 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10689 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10690 | }, |
| 10691 | { |
| 10692 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10693 | .doit = nl80211_setdel_pmksa, |
| 10694 | .policy = nl80211_policy, |
| 10695 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10696 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10697 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10698 | }, |
| 10699 | { |
| 10700 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10701 | .doit = nl80211_flush_pmksa, |
| 10702 | .policy = nl80211_policy, |
| 10703 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10704 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10705 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10706 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10707 | { |
| 10708 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10709 | .doit = nl80211_remain_on_channel, |
| 10710 | .policy = nl80211_policy, |
| 10711 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10712 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10713 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10714 | }, |
| 10715 | { |
| 10716 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10717 | .doit = nl80211_cancel_remain_on_channel, |
| 10718 | .policy = nl80211_policy, |
| 10719 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10720 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10721 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10722 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10723 | { |
| 10724 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10725 | .doit = nl80211_set_tx_bitrate_mask, |
| 10726 | .policy = nl80211_policy, |
| 10727 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10729 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10730 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10731 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10732 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10733 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10734 | .policy = nl80211_policy, |
| 10735 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10736 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10737 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10738 | }, |
| 10739 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10740 | .cmd = NL80211_CMD_FRAME, |
| 10741 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10742 | .policy = nl80211_policy, |
| 10743 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10744 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10745 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10746 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10747 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10748 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10749 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10750 | .policy = nl80211_policy, |
| 10751 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10752 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10753 | NL80211_FLAG_NEED_RTNL, |
| 10754 | }, |
| 10755 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10756 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10757 | .doit = nl80211_set_power_save, |
| 10758 | .policy = nl80211_policy, |
| 10759 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10760 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10761 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10762 | }, |
| 10763 | { |
| 10764 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10765 | .doit = nl80211_get_power_save, |
| 10766 | .policy = nl80211_policy, |
| 10767 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10768 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10769 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10770 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10771 | { |
| 10772 | .cmd = NL80211_CMD_SET_CQM, |
| 10773 | .doit = nl80211_set_cqm, |
| 10774 | .policy = nl80211_policy, |
| 10775 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10776 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10777 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10778 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10779 | { |
| 10780 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10781 | .doit = nl80211_set_channel, |
| 10782 | .policy = nl80211_policy, |
| 10783 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10784 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10785 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10786 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10787 | { |
| 10788 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10789 | .doit = nl80211_set_wds_peer, |
| 10790 | .policy = nl80211_policy, |
| 10791 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10792 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10793 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10794 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10795 | { |
| 10796 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10797 | .doit = nl80211_join_mesh, |
| 10798 | .policy = nl80211_policy, |
| 10799 | .flags = GENL_ADMIN_PERM, |
| 10800 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10801 | NL80211_FLAG_NEED_RTNL, |
| 10802 | }, |
| 10803 | { |
| 10804 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10805 | .doit = nl80211_leave_mesh, |
| 10806 | .policy = nl80211_policy, |
| 10807 | .flags = GENL_ADMIN_PERM, |
| 10808 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10809 | NL80211_FLAG_NEED_RTNL, |
| 10810 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10811 | { |
| 10812 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10813 | .doit = nl80211_join_ocb, |
| 10814 | .policy = nl80211_policy, |
| 10815 | .flags = GENL_ADMIN_PERM, |
| 10816 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10817 | NL80211_FLAG_NEED_RTNL, |
| 10818 | }, |
| 10819 | { |
| 10820 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10821 | .doit = nl80211_leave_ocb, |
| 10822 | .policy = nl80211_policy, |
| 10823 | .flags = GENL_ADMIN_PERM, |
| 10824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10825 | NL80211_FLAG_NEED_RTNL, |
| 10826 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10827 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10828 | { |
| 10829 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10830 | .doit = nl80211_get_wowlan, |
| 10831 | .policy = nl80211_policy, |
| 10832 | /* can be retrieved by unprivileged users */ |
| 10833 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10834 | NL80211_FLAG_NEED_RTNL, |
| 10835 | }, |
| 10836 | { |
| 10837 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10838 | .doit = nl80211_set_wowlan, |
| 10839 | .policy = nl80211_policy, |
| 10840 | .flags = GENL_ADMIN_PERM, |
| 10841 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10842 | NL80211_FLAG_NEED_RTNL, |
| 10843 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10844 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10845 | { |
| 10846 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10847 | .doit = nl80211_set_rekey_data, |
| 10848 | .policy = nl80211_policy, |
| 10849 | .flags = GENL_ADMIN_PERM, |
| 10850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10851 | NL80211_FLAG_NEED_RTNL | |
| 10852 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10853 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10854 | { |
| 10855 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10856 | .doit = nl80211_tdls_mgmt, |
| 10857 | .policy = nl80211_policy, |
| 10858 | .flags = GENL_ADMIN_PERM, |
| 10859 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10860 | NL80211_FLAG_NEED_RTNL, |
| 10861 | }, |
| 10862 | { |
| 10863 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10864 | .doit = nl80211_tdls_oper, |
| 10865 | .policy = nl80211_policy, |
| 10866 | .flags = GENL_ADMIN_PERM, |
| 10867 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10868 | NL80211_FLAG_NEED_RTNL, |
| 10869 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10870 | { |
| 10871 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10872 | .doit = nl80211_register_unexpected_frame, |
| 10873 | .policy = nl80211_policy, |
| 10874 | .flags = GENL_ADMIN_PERM, |
| 10875 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10876 | NL80211_FLAG_NEED_RTNL, |
| 10877 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10878 | { |
| 10879 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10880 | .doit = nl80211_probe_client, |
| 10881 | .policy = nl80211_policy, |
| 10882 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10883 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10884 | NL80211_FLAG_NEED_RTNL, |
| 10885 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10886 | { |
| 10887 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10888 | .doit = nl80211_register_beacons, |
| 10889 | .policy = nl80211_policy, |
| 10890 | .flags = GENL_ADMIN_PERM, |
| 10891 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10892 | NL80211_FLAG_NEED_RTNL, |
| 10893 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10894 | { |
| 10895 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10896 | .doit = nl80211_set_noack_map, |
| 10897 | .policy = nl80211_policy, |
| 10898 | .flags = GENL_ADMIN_PERM, |
| 10899 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10900 | NL80211_FLAG_NEED_RTNL, |
| 10901 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10902 | { |
| 10903 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10904 | .doit = nl80211_start_p2p_device, |
| 10905 | .policy = nl80211_policy, |
| 10906 | .flags = GENL_ADMIN_PERM, |
| 10907 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10908 | NL80211_FLAG_NEED_RTNL, |
| 10909 | }, |
| 10910 | { |
| 10911 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10912 | .doit = nl80211_stop_p2p_device, |
| 10913 | .policy = nl80211_policy, |
| 10914 | .flags = GENL_ADMIN_PERM, |
| 10915 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10916 | NL80211_FLAG_NEED_RTNL, |
| 10917 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10918 | { |
| 10919 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10920 | .doit = nl80211_set_mcast_rate, |
| 10921 | .policy = nl80211_policy, |
| 10922 | .flags = GENL_ADMIN_PERM, |
| 10923 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10924 | NL80211_FLAG_NEED_RTNL, |
| 10925 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10926 | { |
| 10927 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10928 | .doit = nl80211_set_mac_acl, |
| 10929 | .policy = nl80211_policy, |
| 10930 | .flags = GENL_ADMIN_PERM, |
| 10931 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10932 | NL80211_FLAG_NEED_RTNL, |
| 10933 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10934 | { |
| 10935 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10936 | .doit = nl80211_start_radar_detection, |
| 10937 | .policy = nl80211_policy, |
| 10938 | .flags = GENL_ADMIN_PERM, |
| 10939 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10940 | NL80211_FLAG_NEED_RTNL, |
| 10941 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10942 | { |
| 10943 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10944 | .doit = nl80211_get_protocol_features, |
| 10945 | .policy = nl80211_policy, |
| 10946 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10947 | { |
| 10948 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10949 | .doit = nl80211_update_ft_ies, |
| 10950 | .policy = nl80211_policy, |
| 10951 | .flags = GENL_ADMIN_PERM, |
| 10952 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10953 | NL80211_FLAG_NEED_RTNL, |
| 10954 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10955 | { |
| 10956 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10957 | .doit = nl80211_crit_protocol_start, |
| 10958 | .policy = nl80211_policy, |
| 10959 | .flags = GENL_ADMIN_PERM, |
| 10960 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10961 | NL80211_FLAG_NEED_RTNL, |
| 10962 | }, |
| 10963 | { |
| 10964 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10965 | .doit = nl80211_crit_protocol_stop, |
| 10966 | .policy = nl80211_policy, |
| 10967 | .flags = GENL_ADMIN_PERM, |
| 10968 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10969 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10970 | }, |
| 10971 | { |
| 10972 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10973 | .doit = nl80211_get_coalesce, |
| 10974 | .policy = nl80211_policy, |
| 10975 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10976 | NL80211_FLAG_NEED_RTNL, |
| 10977 | }, |
| 10978 | { |
| 10979 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10980 | .doit = nl80211_set_coalesce, |
| 10981 | .policy = nl80211_policy, |
| 10982 | .flags = GENL_ADMIN_PERM, |
| 10983 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10984 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10985 | }, |
| 10986 | { |
| 10987 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10988 | .doit = nl80211_channel_switch, |
| 10989 | .policy = nl80211_policy, |
| 10990 | .flags = GENL_ADMIN_PERM, |
| 10991 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10992 | NL80211_FLAG_NEED_RTNL, |
| 10993 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10994 | { |
| 10995 | .cmd = NL80211_CMD_VENDOR, |
| 10996 | .doit = nl80211_vendor_cmd, |
| 10997 | .policy = nl80211_policy, |
| 10998 | .flags = GENL_ADMIN_PERM, |
| 10999 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11000 | NL80211_FLAG_NEED_RTNL, |
| 11001 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11002 | { |
| 11003 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11004 | .doit = nl80211_set_qos_map, |
| 11005 | .policy = nl80211_policy, |
| 11006 | .flags = GENL_ADMIN_PERM, |
| 11007 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11008 | NL80211_FLAG_NEED_RTNL, |
| 11009 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11010 | { |
| 11011 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11012 | .doit = nl80211_add_tx_ts, |
| 11013 | .policy = nl80211_policy, |
| 11014 | .flags = GENL_ADMIN_PERM, |
| 11015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11016 | NL80211_FLAG_NEED_RTNL, |
| 11017 | }, |
| 11018 | { |
| 11019 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11020 | .doit = nl80211_del_tx_ts, |
| 11021 | .policy = nl80211_policy, |
| 11022 | .flags = GENL_ADMIN_PERM, |
| 11023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11024 | NL80211_FLAG_NEED_RTNL, |
| 11025 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11026 | { |
| 11027 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11028 | .doit = nl80211_tdls_channel_switch, |
| 11029 | .policy = nl80211_policy, |
| 11030 | .flags = GENL_ADMIN_PERM, |
| 11031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11032 | NL80211_FLAG_NEED_RTNL, |
| 11033 | }, |
| 11034 | { |
| 11035 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11036 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11037 | .policy = nl80211_policy, |
| 11038 | .flags = GENL_ADMIN_PERM, |
| 11039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11040 | NL80211_FLAG_NEED_RTNL, |
| 11041 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11042 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11043 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11044 | /* notification functions */ |
| 11045 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11046 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11047 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11048 | { |
| 11049 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11050 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11051 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11052 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11053 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11054 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11055 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11056 | if (!msg) |
| 11057 | return; |
| 11058 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11059 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11060 | nlmsg_free(msg); |
| 11061 | return; |
| 11062 | } |
| 11063 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11064 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11065 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11066 | } |
| 11067 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11068 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11069 | struct cfg80211_registered_device *rdev) |
| 11070 | { |
| 11071 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11072 | struct nlattr *nest; |
| 11073 | int i; |
| 11074 | |
| 11075 | if (WARN_ON(!req)) |
| 11076 | return 0; |
| 11077 | |
| 11078 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11079 | if (!nest) |
| 11080 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11081 | for (i = 0; i < req->n_ssids; i++) { |
| 11082 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11083 | goto nla_put_failure; |
| 11084 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11085 | nla_nest_end(msg, nest); |
| 11086 | |
| 11087 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11088 | if (!nest) |
| 11089 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11090 | for (i = 0; i < req->n_channels; i++) { |
| 11091 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11092 | goto nla_put_failure; |
| 11093 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11094 | nla_nest_end(msg, nest); |
| 11095 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11096 | if (req->ie && |
| 11097 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11098 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11099 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11100 | if (req->flags && |
| 11101 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11102 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11103 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11104 | return 0; |
| 11105 | nla_put_failure: |
| 11106 | return -ENOBUFS; |
| 11107 | } |
| 11108 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11109 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11110 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11111 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11112 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11113 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11114 | { |
| 11115 | void *hdr; |
| 11116 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11117 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11118 | if (!hdr) |
| 11119 | return -1; |
| 11120 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11121 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11122 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11123 | wdev->netdev->ifindex)) || |
| 11124 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11125 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11126 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11127 | /* ignore errors and send incomplete event anyway */ |
| 11128 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11129 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11130 | genlmsg_end(msg, hdr); |
| 11131 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11132 | |
| 11133 | nla_put_failure: |
| 11134 | genlmsg_cancel(msg, hdr); |
| 11135 | return -EMSGSIZE; |
| 11136 | } |
| 11137 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11138 | static int |
| 11139 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11140 | struct cfg80211_registered_device *rdev, |
| 11141 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11142 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11143 | { |
| 11144 | void *hdr; |
| 11145 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11146 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11147 | if (!hdr) |
| 11148 | return -1; |
| 11149 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11150 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11151 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11152 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11153 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11154 | genlmsg_end(msg, hdr); |
| 11155 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11156 | |
| 11157 | nla_put_failure: |
| 11158 | genlmsg_cancel(msg, hdr); |
| 11159 | return -EMSGSIZE; |
| 11160 | } |
| 11161 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11162 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11163 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11164 | { |
| 11165 | struct sk_buff *msg; |
| 11166 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11168 | if (!msg) |
| 11169 | return; |
| 11170 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11171 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11172 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11173 | nlmsg_free(msg); |
| 11174 | return; |
| 11175 | } |
| 11176 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11177 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11178 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11179 | } |
| 11180 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11181 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11182 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11183 | { |
| 11184 | struct sk_buff *msg; |
| 11185 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11186 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11187 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11188 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11189 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11190 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11191 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11192 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11193 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11194 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11195 | } |
| 11196 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11197 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11198 | } |
| 11199 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11200 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11201 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11202 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11203 | if (!msg) |
| 11204 | return; |
| 11205 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11206 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11207 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11208 | } |
| 11209 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11210 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11211 | struct net_device *netdev) |
| 11212 | { |
| 11213 | struct sk_buff *msg; |
| 11214 | |
| 11215 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11216 | if (!msg) |
| 11217 | return; |
| 11218 | |
| 11219 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11220 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11221 | nlmsg_free(msg); |
| 11222 | return; |
| 11223 | } |
| 11224 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11225 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11226 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11227 | } |
| 11228 | |
| 11229 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11230 | struct net_device *netdev, u32 cmd) |
| 11231 | { |
| 11232 | struct sk_buff *msg; |
| 11233 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11235 | if (!msg) |
| 11236 | return; |
| 11237 | |
| 11238 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11239 | nlmsg_free(msg); |
| 11240 | return; |
| 11241 | } |
| 11242 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11243 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11244 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11245 | } |
| 11246 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11247 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11248 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11249 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11250 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11251 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11252 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11253 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11254 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11255 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11256 | NL80211_REGDOM_TYPE_WORLD)) |
| 11257 | goto nla_put_failure; |
| 11258 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11259 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11260 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11261 | goto nla_put_failure; |
| 11262 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11263 | request->intersect) { |
| 11264 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11265 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11266 | goto nla_put_failure; |
| 11267 | } else { |
| 11268 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11269 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11270 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11271 | request->alpha2)) |
| 11272 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11273 | } |
| 11274 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11275 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11276 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11277 | |
| 11278 | if (wiphy && |
| 11279 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11280 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 11281 | |
| 11282 | if (wiphy && |
| 11283 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 11284 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 11285 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11286 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11287 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11288 | return true; |
| 11289 | |
| 11290 | nla_put_failure: |
| 11291 | return false; |
| 11292 | } |
| 11293 | |
| 11294 | /* |
| 11295 | * This can happen on global regulatory changes or device specific settings |
| 11296 | * based on custom regulatory domains. |
| 11297 | */ |
| 11298 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11299 | struct regulatory_request *request) |
| 11300 | { |
| 11301 | struct sk_buff *msg; |
| 11302 | void *hdr; |
| 11303 | |
| 11304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11305 | if (!msg) |
| 11306 | return; |
| 11307 | |
| 11308 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11309 | if (!hdr) { |
| 11310 | nlmsg_free(msg); |
| 11311 | return; |
| 11312 | } |
| 11313 | |
| 11314 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11315 | goto nla_put_failure; |
| 11316 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11317 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11318 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11319 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11320 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11321 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11322 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11323 | |
| 11324 | return; |
| 11325 | |
| 11326 | nla_put_failure: |
| 11327 | genlmsg_cancel(msg, hdr); |
| 11328 | nlmsg_free(msg); |
| 11329 | } |
| 11330 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11331 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11332 | struct net_device *netdev, |
| 11333 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11334 | enum nl80211_commands cmd, gfp_t gfp, |
| 11335 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11336 | { |
| 11337 | struct sk_buff *msg; |
| 11338 | void *hdr; |
| 11339 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11340 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11341 | if (!msg) |
| 11342 | return; |
| 11343 | |
| 11344 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11345 | if (!hdr) { |
| 11346 | nlmsg_free(msg); |
| 11347 | return; |
| 11348 | } |
| 11349 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11350 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11351 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11352 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11353 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11354 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11355 | if (uapsd_queues >= 0) { |
| 11356 | struct nlattr *nla_wmm = |
| 11357 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11358 | if (!nla_wmm) |
| 11359 | goto nla_put_failure; |
| 11360 | |
| 11361 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11362 | uapsd_queues)) |
| 11363 | goto nla_put_failure; |
| 11364 | |
| 11365 | nla_nest_end(msg, nla_wmm); |
| 11366 | } |
| 11367 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11368 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11369 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11370 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11371 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11372 | return; |
| 11373 | |
| 11374 | nla_put_failure: |
| 11375 | genlmsg_cancel(msg, hdr); |
| 11376 | nlmsg_free(msg); |
| 11377 | } |
| 11378 | |
| 11379 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11380 | struct net_device *netdev, const u8 *buf, |
| 11381 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11382 | { |
| 11383 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11384 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11385 | } |
| 11386 | |
| 11387 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11388 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11389 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11390 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11391 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11392 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11393 | } |
| 11394 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11395 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11396 | struct net_device *netdev, const u8 *buf, |
| 11397 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11398 | { |
| 11399 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11400 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11401 | } |
| 11402 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11403 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11404 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11405 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11406 | { |
| 11407 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11408 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11409 | } |
| 11410 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11411 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11412 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11413 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11414 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11415 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11416 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11417 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11418 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11419 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11420 | if (WARN_ON(len < 2)) |
| 11421 | return; |
| 11422 | |
| 11423 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11424 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11425 | else |
| 11426 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11427 | |
| 11428 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11429 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11430 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11431 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11432 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11433 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11434 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11435 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11436 | { |
| 11437 | struct sk_buff *msg; |
| 11438 | void *hdr; |
| 11439 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11441 | if (!msg) |
| 11442 | return; |
| 11443 | |
| 11444 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11445 | if (!hdr) { |
| 11446 | nlmsg_free(msg); |
| 11447 | return; |
| 11448 | } |
| 11449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11452 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11453 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11454 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11455 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11456 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11457 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11458 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11459 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11460 | return; |
| 11461 | |
| 11462 | nla_put_failure: |
| 11463 | genlmsg_cancel(msg, hdr); |
| 11464 | nlmsg_free(msg); |
| 11465 | } |
| 11466 | |
| 11467 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11468 | struct net_device *netdev, const u8 *addr, |
| 11469 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11470 | { |
| 11471 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11472 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11473 | } |
| 11474 | |
| 11475 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11476 | struct net_device *netdev, const u8 *addr, |
| 11477 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11478 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11479 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11480 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11481 | } |
| 11482 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11483 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11484 | struct net_device *netdev, const u8 *bssid, |
| 11485 | const u8 *req_ie, size_t req_ie_len, |
| 11486 | const u8 *resp_ie, size_t resp_ie_len, |
| 11487 | u16 status, gfp_t gfp) |
| 11488 | { |
| 11489 | struct sk_buff *msg; |
| 11490 | void *hdr; |
| 11491 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11492 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11493 | if (!msg) |
| 11494 | return; |
| 11495 | |
| 11496 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11497 | if (!hdr) { |
| 11498 | nlmsg_free(msg); |
| 11499 | return; |
| 11500 | } |
| 11501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11502 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11503 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11504 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11505 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11506 | (req_ie && |
| 11507 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11508 | (resp_ie && |
| 11509 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11510 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11511 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11512 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11513 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11514 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11515 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11516 | return; |
| 11517 | |
| 11518 | nla_put_failure: |
| 11519 | genlmsg_cancel(msg, hdr); |
| 11520 | nlmsg_free(msg); |
| 11521 | |
| 11522 | } |
| 11523 | |
| 11524 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11525 | struct net_device *netdev, const u8 *bssid, |
| 11526 | const u8 *req_ie, size_t req_ie_len, |
| 11527 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11528 | { |
| 11529 | struct sk_buff *msg; |
| 11530 | void *hdr; |
| 11531 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11532 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11533 | if (!msg) |
| 11534 | return; |
| 11535 | |
| 11536 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11537 | if (!hdr) { |
| 11538 | nlmsg_free(msg); |
| 11539 | return; |
| 11540 | } |
| 11541 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11543 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11544 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11545 | (req_ie && |
| 11546 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11547 | (resp_ie && |
| 11548 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11549 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11550 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11551 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11552 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11553 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11554 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11555 | return; |
| 11556 | |
| 11557 | nla_put_failure: |
| 11558 | genlmsg_cancel(msg, hdr); |
| 11559 | nlmsg_free(msg); |
| 11560 | |
| 11561 | } |
| 11562 | |
| 11563 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11564 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11565 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11566 | { |
| 11567 | struct sk_buff *msg; |
| 11568 | void *hdr; |
| 11569 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11570 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11571 | if (!msg) |
| 11572 | return; |
| 11573 | |
| 11574 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11575 | if (!hdr) { |
| 11576 | nlmsg_free(msg); |
| 11577 | return; |
| 11578 | } |
| 11579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11580 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11581 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11582 | (from_ap && reason && |
| 11583 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11584 | (from_ap && |
| 11585 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11586 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11587 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11588 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11589 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11590 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11591 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11592 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11593 | return; |
| 11594 | |
| 11595 | nla_put_failure: |
| 11596 | genlmsg_cancel(msg, hdr); |
| 11597 | nlmsg_free(msg); |
| 11598 | |
| 11599 | } |
| 11600 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11601 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 11602 | struct net_device *netdev, const u8 *bssid, |
| 11603 | gfp_t gfp) |
| 11604 | { |
| 11605 | struct sk_buff *msg; |
| 11606 | void *hdr; |
| 11607 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11609 | if (!msg) |
| 11610 | return; |
| 11611 | |
| 11612 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11613 | if (!hdr) { |
| 11614 | nlmsg_free(msg); |
| 11615 | return; |
| 11616 | } |
| 11617 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11619 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11620 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11621 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11622 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11623 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11624 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11625 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11626 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11627 | return; |
| 11628 | |
| 11629 | nla_put_failure: |
| 11630 | genlmsg_cancel(msg, hdr); |
| 11631 | nlmsg_free(msg); |
| 11632 | } |
| 11633 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11634 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11635 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11636 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11637 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11638 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11639 | struct sk_buff *msg; |
| 11640 | void *hdr; |
| 11641 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11642 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11643 | return; |
| 11644 | |
| 11645 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11646 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11647 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11648 | if (!msg) |
| 11649 | return; |
| 11650 | |
| 11651 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11652 | if (!hdr) { |
| 11653 | nlmsg_free(msg); |
| 11654 | return; |
| 11655 | } |
| 11656 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11657 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11658 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11660 | (ie_len && ie && |
| 11661 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11662 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11663 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11664 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11665 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11666 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11667 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11668 | return; |
| 11669 | |
| 11670 | nla_put_failure: |
| 11671 | genlmsg_cancel(msg, hdr); |
| 11672 | nlmsg_free(msg); |
| 11673 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11674 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11675 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11676 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11677 | struct net_device *netdev, const u8 *addr, |
| 11678 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11679 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11680 | { |
| 11681 | struct sk_buff *msg; |
| 11682 | void *hdr; |
| 11683 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11685 | if (!msg) |
| 11686 | return; |
| 11687 | |
| 11688 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11689 | if (!hdr) { |
| 11690 | nlmsg_free(msg); |
| 11691 | return; |
| 11692 | } |
| 11693 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11694 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11695 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11696 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11697 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11698 | (key_id != -1 && |
| 11699 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11700 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11701 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11702 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11703 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11704 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11705 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11706 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11707 | return; |
| 11708 | |
| 11709 | nla_put_failure: |
| 11710 | genlmsg_cancel(msg, hdr); |
| 11711 | nlmsg_free(msg); |
| 11712 | } |
| 11713 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11714 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11715 | struct ieee80211_channel *channel_before, |
| 11716 | struct ieee80211_channel *channel_after) |
| 11717 | { |
| 11718 | struct sk_buff *msg; |
| 11719 | void *hdr; |
| 11720 | struct nlattr *nl_freq; |
| 11721 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11723 | if (!msg) |
| 11724 | return; |
| 11725 | |
| 11726 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11727 | if (!hdr) { |
| 11728 | nlmsg_free(msg); |
| 11729 | return; |
| 11730 | } |
| 11731 | |
| 11732 | /* |
| 11733 | * Since we are applying the beacon hint to a wiphy we know its |
| 11734 | * wiphy_idx is valid |
| 11735 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11736 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11737 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11738 | |
| 11739 | /* Before */ |
| 11740 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11741 | if (!nl_freq) |
| 11742 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11743 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11744 | goto nla_put_failure; |
| 11745 | nla_nest_end(msg, nl_freq); |
| 11746 | |
| 11747 | /* After */ |
| 11748 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11749 | if (!nl_freq) |
| 11750 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11751 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11752 | goto nla_put_failure; |
| 11753 | nla_nest_end(msg, nl_freq); |
| 11754 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11755 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11756 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11757 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11758 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11759 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11760 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11761 | |
| 11762 | return; |
| 11763 | |
| 11764 | nla_put_failure: |
| 11765 | genlmsg_cancel(msg, hdr); |
| 11766 | nlmsg_free(msg); |
| 11767 | } |
| 11768 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11769 | static void nl80211_send_remain_on_chan_event( |
| 11770 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11771 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11772 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11773 | unsigned int duration, gfp_t gfp) |
| 11774 | { |
| 11775 | struct sk_buff *msg; |
| 11776 | void *hdr; |
| 11777 | |
| 11778 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11779 | if (!msg) |
| 11780 | return; |
| 11781 | |
| 11782 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11783 | if (!hdr) { |
| 11784 | nlmsg_free(msg); |
| 11785 | return; |
| 11786 | } |
| 11787 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11788 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11789 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11790 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11791 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11792 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11793 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11794 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11795 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11796 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11797 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11798 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11799 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11800 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11801 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11802 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11803 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11804 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11805 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11806 | return; |
| 11807 | |
| 11808 | nla_put_failure: |
| 11809 | genlmsg_cancel(msg, hdr); |
| 11810 | nlmsg_free(msg); |
| 11811 | } |
| 11812 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11813 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11814 | struct ieee80211_channel *chan, |
| 11815 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11816 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11817 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11818 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11819 | |
| 11820 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11821 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11822 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11823 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11824 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11825 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11826 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11827 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11828 | struct ieee80211_channel *chan, |
| 11829 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11830 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11831 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11832 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11833 | |
| 11834 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11835 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11836 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11837 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11838 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11839 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11840 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11841 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11842 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11843 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11844 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11845 | struct sk_buff *msg; |
| 11846 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11847 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11848 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11849 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11850 | if (!msg) |
| 11851 | return; |
| 11852 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11853 | 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] | 11854 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11855 | nlmsg_free(msg); |
| 11856 | return; |
| 11857 | } |
| 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); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11861 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11862 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11863 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11864 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 11865 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11866 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11867 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11868 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11869 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11870 | struct station_info empty_sinfo = {}; |
| 11871 | |
| 11872 | if (!sinfo) |
| 11873 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11874 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11875 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11876 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11877 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11878 | if (!msg) |
| 11879 | return; |
| 11880 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11881 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 11882 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11883 | nlmsg_free(msg); |
| 11884 | return; |
| 11885 | } |
| 11886 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11887 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11888 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11889 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11890 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11891 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11892 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11893 | enum nl80211_connect_failed_reason reason, |
| 11894 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11895 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11896 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11897 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11898 | struct sk_buff *msg; |
| 11899 | void *hdr; |
| 11900 | |
| 11901 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11902 | if (!msg) |
| 11903 | return; |
| 11904 | |
| 11905 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11906 | if (!hdr) { |
| 11907 | nlmsg_free(msg); |
| 11908 | return; |
| 11909 | } |
| 11910 | |
| 11911 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11912 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11913 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11914 | goto nla_put_failure; |
| 11915 | |
| 11916 | genlmsg_end(msg, hdr); |
| 11917 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11918 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11919 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11920 | return; |
| 11921 | |
| 11922 | nla_put_failure: |
| 11923 | genlmsg_cancel(msg, hdr); |
| 11924 | nlmsg_free(msg); |
| 11925 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11926 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11927 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11928 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11929 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11930 | { |
| 11931 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11932 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11933 | struct sk_buff *msg; |
| 11934 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11935 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11936 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11937 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11938 | return false; |
| 11939 | |
| 11940 | msg = nlmsg_new(100, gfp); |
| 11941 | if (!msg) |
| 11942 | return true; |
| 11943 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11944 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11945 | if (!hdr) { |
| 11946 | nlmsg_free(msg); |
| 11947 | return true; |
| 11948 | } |
| 11949 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11950 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11951 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11952 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11953 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11954 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11955 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11956 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11957 | return true; |
| 11958 | |
| 11959 | nla_put_failure: |
| 11960 | genlmsg_cancel(msg, hdr); |
| 11961 | nlmsg_free(msg); |
| 11962 | return true; |
| 11963 | } |
| 11964 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11965 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11966 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11967 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11968 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11969 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11970 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11971 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11972 | |
| 11973 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11974 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11975 | trace_cfg80211_return_bool(false); |
| 11976 | return false; |
| 11977 | } |
| 11978 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11979 | addr, gfp); |
| 11980 | trace_cfg80211_return_bool(ret); |
| 11981 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11982 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11983 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11984 | |
| 11985 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11986 | const u8 *addr, gfp_t gfp) |
| 11987 | { |
| 11988 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11989 | bool ret; |
| 11990 | |
| 11991 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11992 | |
| 11993 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11994 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11995 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11996 | trace_cfg80211_return_bool(false); |
| 11997 | return false; |
| 11998 | } |
| 11999 | ret = __nl80211_unexpected_frame(dev, |
| 12000 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12001 | addr, gfp); |
| 12002 | trace_cfg80211_return_bool(ret); |
| 12003 | return ret; |
| 12004 | } |
| 12005 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12006 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12007 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12008 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12009 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12010 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12011 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12012 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12013 | struct sk_buff *msg; |
| 12014 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12015 | |
| 12016 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12017 | if (!msg) |
| 12018 | return -ENOMEM; |
| 12019 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12020 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12021 | if (!hdr) { |
| 12022 | nlmsg_free(msg); |
| 12023 | return -ENOMEM; |
| 12024 | } |
| 12025 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12026 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12027 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12028 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12029 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12030 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12031 | (sig_dbm && |
| 12032 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12033 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12034 | (flags && |
| 12035 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12036 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12037 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12038 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12039 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12040 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12041 | |
| 12042 | nla_put_failure: |
| 12043 | genlmsg_cancel(msg, hdr); |
| 12044 | nlmsg_free(msg); |
| 12045 | return -ENOBUFS; |
| 12046 | } |
| 12047 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12048 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12049 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12050 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12051 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12052 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12053 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12054 | struct sk_buff *msg; |
| 12055 | void *hdr; |
| 12056 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12057 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12058 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12060 | if (!msg) |
| 12061 | return; |
| 12062 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12063 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12064 | if (!hdr) { |
| 12065 | nlmsg_free(msg); |
| 12066 | return; |
| 12067 | } |
| 12068 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12069 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12070 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12071 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12072 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12073 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12074 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12075 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12076 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12077 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12078 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12079 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12080 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12081 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12082 | return; |
| 12083 | |
| 12084 | nla_put_failure: |
| 12085 | genlmsg_cancel(msg, hdr); |
| 12086 | nlmsg_free(msg); |
| 12087 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12088 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12089 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12090 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12091 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12092 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12093 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12094 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12095 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12096 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12097 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12098 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12099 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12100 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12101 | cb = (void **)msg->cb; |
| 12102 | |
| 12103 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12104 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12105 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12106 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12107 | } |
| 12108 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12109 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12110 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12111 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12112 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12113 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12114 | goto nla_put_failure; |
| 12115 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12116 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12117 | if (!cb[1]) |
| 12118 | goto nla_put_failure; |
| 12119 | |
| 12120 | cb[2] = rdev; |
| 12121 | |
| 12122 | return msg; |
| 12123 | nla_put_failure: |
| 12124 | nlmsg_free(msg); |
| 12125 | return NULL; |
| 12126 | } |
| 12127 | |
| 12128 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12129 | { |
| 12130 | void **cb = (void **)msg->cb; |
| 12131 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12132 | |
| 12133 | nla_nest_end(msg, cb[1]); |
| 12134 | genlmsg_end(msg, cb[0]); |
| 12135 | |
| 12136 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12137 | |
| 12138 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12139 | NL80211_MCGRP_MLME, gfp); |
| 12140 | } |
| 12141 | |
| 12142 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12143 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12144 | gfp_t gfp) |
| 12145 | { |
| 12146 | struct sk_buff *msg; |
| 12147 | |
| 12148 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12149 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12150 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12151 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12152 | return; |
| 12153 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12154 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12155 | if (!msg) |
| 12156 | return; |
| 12157 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12158 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12159 | rssi_event)) |
| 12160 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12161 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12162 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12163 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12164 | return; |
| 12165 | |
| 12166 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12167 | nlmsg_free(msg); |
| 12168 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12169 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12170 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12171 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12172 | const u8 *peer, u32 num_packets, |
| 12173 | u32 rate, u32 intvl, gfp_t gfp) |
| 12174 | { |
| 12175 | struct sk_buff *msg; |
| 12176 | |
| 12177 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12178 | if (!msg) |
| 12179 | return; |
| 12180 | |
| 12181 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12182 | goto nla_put_failure; |
| 12183 | |
| 12184 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12185 | goto nla_put_failure; |
| 12186 | |
| 12187 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12188 | goto nla_put_failure; |
| 12189 | |
| 12190 | cfg80211_send_cqm(msg, gfp); |
| 12191 | return; |
| 12192 | |
| 12193 | nla_put_failure: |
| 12194 | nlmsg_free(msg); |
| 12195 | } |
| 12196 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12197 | |
| 12198 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12199 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12200 | { |
| 12201 | struct sk_buff *msg; |
| 12202 | |
| 12203 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12204 | |
| 12205 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12206 | if (!msg) |
| 12207 | return; |
| 12208 | |
| 12209 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12210 | goto nla_put_failure; |
| 12211 | |
| 12212 | cfg80211_send_cqm(msg, gfp); |
| 12213 | return; |
| 12214 | |
| 12215 | nla_put_failure: |
| 12216 | nlmsg_free(msg); |
| 12217 | } |
| 12218 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12219 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12220 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12221 | { |
| 12222 | struct sk_buff *msg; |
| 12223 | |
| 12224 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12225 | if (!msg) |
| 12226 | return; |
| 12227 | |
| 12228 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12229 | goto nla_put_failure; |
| 12230 | |
| 12231 | cfg80211_send_cqm(msg, gfp); |
| 12232 | return; |
| 12233 | |
| 12234 | nla_put_failure: |
| 12235 | nlmsg_free(msg); |
| 12236 | } |
| 12237 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12238 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12239 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12240 | struct net_device *netdev, const u8 *bssid, |
| 12241 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12242 | { |
| 12243 | struct sk_buff *msg; |
| 12244 | struct nlattr *rekey_attr; |
| 12245 | void *hdr; |
| 12246 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12247 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12248 | if (!msg) |
| 12249 | return; |
| 12250 | |
| 12251 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12252 | if (!hdr) { |
| 12253 | nlmsg_free(msg); |
| 12254 | return; |
| 12255 | } |
| 12256 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12257 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12258 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12259 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12260 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12261 | |
| 12262 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12263 | if (!rekey_attr) |
| 12264 | goto nla_put_failure; |
| 12265 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12266 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12267 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12268 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12269 | |
| 12270 | nla_nest_end(msg, rekey_attr); |
| 12271 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12272 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12273 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12274 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12275 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12276 | return; |
| 12277 | |
| 12278 | nla_put_failure: |
| 12279 | genlmsg_cancel(msg, hdr); |
| 12280 | nlmsg_free(msg); |
| 12281 | } |
| 12282 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12283 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12284 | const u8 *replay_ctr, gfp_t gfp) |
| 12285 | { |
| 12286 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12287 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12288 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12289 | |
| 12290 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12291 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12292 | } |
| 12293 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12294 | |
| 12295 | static void |
| 12296 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12297 | struct net_device *netdev, int index, |
| 12298 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12299 | { |
| 12300 | struct sk_buff *msg; |
| 12301 | struct nlattr *attr; |
| 12302 | void *hdr; |
| 12303 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12305 | if (!msg) |
| 12306 | return; |
| 12307 | |
| 12308 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12309 | if (!hdr) { |
| 12310 | nlmsg_free(msg); |
| 12311 | return; |
| 12312 | } |
| 12313 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12314 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12315 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12316 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12317 | |
| 12318 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12319 | if (!attr) |
| 12320 | goto nla_put_failure; |
| 12321 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12322 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12323 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12324 | (preauth && |
| 12325 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12326 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12327 | |
| 12328 | nla_nest_end(msg, attr); |
| 12329 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12330 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12331 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12332 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12333 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12334 | return; |
| 12335 | |
| 12336 | nla_put_failure: |
| 12337 | genlmsg_cancel(msg, hdr); |
| 12338 | nlmsg_free(msg); |
| 12339 | } |
| 12340 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12341 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12342 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12343 | { |
| 12344 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12345 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12346 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12347 | |
| 12348 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12349 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12350 | } |
| 12351 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12352 | |
| 12353 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12354 | struct net_device *netdev, |
| 12355 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12356 | gfp_t gfp, |
| 12357 | enum nl80211_commands notif, |
| 12358 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12359 | { |
| 12360 | struct sk_buff *msg; |
| 12361 | void *hdr; |
| 12362 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12363 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12364 | if (!msg) |
| 12365 | return; |
| 12366 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12367 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12368 | if (!hdr) { |
| 12369 | nlmsg_free(msg); |
| 12370 | return; |
| 12371 | } |
| 12372 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12373 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12374 | goto nla_put_failure; |
| 12375 | |
| 12376 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12377 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12378 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12379 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12380 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12381 | goto nla_put_failure; |
| 12382 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12383 | genlmsg_end(msg, hdr); |
| 12384 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12385 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12386 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12387 | return; |
| 12388 | |
| 12389 | nla_put_failure: |
| 12390 | genlmsg_cancel(msg, hdr); |
| 12391 | nlmsg_free(msg); |
| 12392 | } |
| 12393 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12394 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12395 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12396 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12397 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12398 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12399 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12400 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12401 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12402 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12403 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12404 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12405 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12406 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12407 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12408 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12409 | } |
| 12410 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12411 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12412 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12413 | struct cfg80211_chan_def *chandef, |
| 12414 | u8 count) |
| 12415 | { |
| 12416 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12417 | struct wiphy *wiphy = wdev->wiphy; |
| 12418 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12419 | |
| 12420 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12421 | |
| 12422 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12423 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12424 | } |
| 12425 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12426 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12427 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12428 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12429 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12430 | enum nl80211_radar_event event, |
| 12431 | struct net_device *netdev, gfp_t gfp) |
| 12432 | { |
| 12433 | struct sk_buff *msg; |
| 12434 | void *hdr; |
| 12435 | |
| 12436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12437 | if (!msg) |
| 12438 | return; |
| 12439 | |
| 12440 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12441 | if (!hdr) { |
| 12442 | nlmsg_free(msg); |
| 12443 | return; |
| 12444 | } |
| 12445 | |
| 12446 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12447 | goto nla_put_failure; |
| 12448 | |
| 12449 | /* NOP and radar events don't need a netdev parameter */ |
| 12450 | if (netdev) { |
| 12451 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12452 | |
| 12453 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12454 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12455 | goto nla_put_failure; |
| 12456 | } |
| 12457 | |
| 12458 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12459 | goto nla_put_failure; |
| 12460 | |
| 12461 | if (nl80211_send_chandef(msg, chandef)) |
| 12462 | goto nla_put_failure; |
| 12463 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12464 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12465 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12466 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12467 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12468 | return; |
| 12469 | |
| 12470 | nla_put_failure: |
| 12471 | genlmsg_cancel(msg, hdr); |
| 12472 | nlmsg_free(msg); |
| 12473 | } |
| 12474 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12475 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12476 | u64 cookie, bool acked, gfp_t gfp) |
| 12477 | { |
| 12478 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12479 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12480 | struct sk_buff *msg; |
| 12481 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12482 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12483 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12484 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12485 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12486 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12487 | if (!msg) |
| 12488 | return; |
| 12489 | |
| 12490 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12491 | if (!hdr) { |
| 12492 | nlmsg_free(msg); |
| 12493 | return; |
| 12494 | } |
| 12495 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12496 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12497 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12498 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12499 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12500 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12501 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12502 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12503 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12504 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12505 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12506 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12507 | return; |
| 12508 | |
| 12509 | nla_put_failure: |
| 12510 | genlmsg_cancel(msg, hdr); |
| 12511 | nlmsg_free(msg); |
| 12512 | } |
| 12513 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12514 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12515 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12516 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12517 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12518 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12519 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12520 | struct sk_buff *msg; |
| 12521 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12522 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12523 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12524 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12525 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12526 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12527 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12528 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12529 | if (!msg) { |
| 12530 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12531 | return; |
| 12532 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12533 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12534 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12535 | if (!hdr) |
| 12536 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12537 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12539 | (freq && |
| 12540 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12541 | (sig_dbm && |
| 12542 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12543 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12544 | goto nla_put_failure; |
| 12545 | |
| 12546 | genlmsg_end(msg, hdr); |
| 12547 | |
| 12548 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12549 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12550 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12551 | return; |
| 12552 | |
| 12553 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12554 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12555 | if (hdr) |
| 12556 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12557 | nlmsg_free(msg); |
| 12558 | } |
| 12559 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12560 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12561 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12562 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12563 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12564 | { |
| 12565 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12566 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12567 | int i, j; |
| 12568 | |
| 12569 | nl_results = nla_nest_start( |
| 12570 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12571 | if (!nl_results) |
| 12572 | return -EMSGSIZE; |
| 12573 | |
| 12574 | for (i = 0; i < nd->n_matches; i++) { |
| 12575 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12576 | |
| 12577 | nl_match = nla_nest_start(msg, i); |
| 12578 | if (!nl_match) |
| 12579 | break; |
| 12580 | |
| 12581 | /* The SSID attribute is optional in nl80211, but for |
| 12582 | * simplicity reasons it's always present in the |
| 12583 | * cfg80211 structure. If a driver can't pass the |
| 12584 | * SSID, that needs to be changed. A zero length SSID |
| 12585 | * is still a valid SSID (wildcard), so it cannot be |
| 12586 | * used for this purpose. |
| 12587 | */ |
| 12588 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12589 | match->ssid.ssid)) { |
| 12590 | nla_nest_cancel(msg, nl_match); |
| 12591 | goto out; |
| 12592 | } |
| 12593 | |
| 12594 | if (match->n_channels) { |
| 12595 | nl_freqs = nla_nest_start( |
| 12596 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12597 | if (!nl_freqs) { |
| 12598 | nla_nest_cancel(msg, nl_match); |
| 12599 | goto out; |
| 12600 | } |
| 12601 | |
| 12602 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 12603 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12604 | nla_nest_cancel(msg, nl_freqs); |
| 12605 | nla_nest_cancel(msg, nl_match); |
| 12606 | goto out; |
| 12607 | } |
| 12608 | } |
| 12609 | |
| 12610 | nla_nest_end(msg, nl_freqs); |
| 12611 | } |
| 12612 | |
| 12613 | nla_nest_end(msg, nl_match); |
| 12614 | } |
| 12615 | |
| 12616 | out: |
| 12617 | nla_nest_end(msg, nl_results); |
| 12618 | return 0; |
| 12619 | } |
| 12620 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12621 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 12622 | struct cfg80211_wowlan_wakeup *wakeup, |
| 12623 | gfp_t gfp) |
| 12624 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12625 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12626 | struct sk_buff *msg; |
| 12627 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12628 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12629 | |
| 12630 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 12631 | |
| 12632 | if (wakeup) |
| 12633 | size += wakeup->packet_present_len; |
| 12634 | |
| 12635 | msg = nlmsg_new(size, gfp); |
| 12636 | if (!msg) |
| 12637 | return; |
| 12638 | |
| 12639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 12640 | if (!hdr) |
| 12641 | goto free_msg; |
| 12642 | |
| 12643 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12644 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12645 | goto free_msg; |
| 12646 | |
| 12647 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12648 | wdev->netdev->ifindex)) |
| 12649 | goto free_msg; |
| 12650 | |
| 12651 | if (wakeup) { |
| 12652 | struct nlattr *reasons; |
| 12653 | |
| 12654 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12655 | if (!reasons) |
| 12656 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12657 | |
| 12658 | if (wakeup->disconnect && |
| 12659 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 12660 | goto free_msg; |
| 12661 | if (wakeup->magic_pkt && |
| 12662 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 12663 | goto free_msg; |
| 12664 | if (wakeup->gtk_rekey_failure && |
| 12665 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 12666 | goto free_msg; |
| 12667 | if (wakeup->eap_identity_req && |
| 12668 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 12669 | goto free_msg; |
| 12670 | if (wakeup->four_way_handshake && |
| 12671 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 12672 | goto free_msg; |
| 12673 | if (wakeup->rfkill_release && |
| 12674 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12675 | goto free_msg; |
| 12676 | |
| 12677 | if (wakeup->pattern_idx >= 0 && |
| 12678 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12679 | wakeup->pattern_idx)) |
| 12680 | goto free_msg; |
| 12681 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12682 | if (wakeup->tcp_match && |
| 12683 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12684 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12685 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12686 | if (wakeup->tcp_connlost && |
| 12687 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 12688 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12689 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12690 | if (wakeup->tcp_nomoretokens && |
| 12691 | nla_put_flag(msg, |
| 12692 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12693 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12694 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12695 | if (wakeup->packet) { |
| 12696 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12697 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12698 | |
| 12699 | if (!wakeup->packet_80211) { |
| 12700 | pkt_attr = |
| 12701 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12702 | len_attr = |
| 12703 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12704 | } |
| 12705 | |
| 12706 | if (wakeup->packet_len && |
| 12707 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12708 | goto free_msg; |
| 12709 | |
| 12710 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12711 | wakeup->packet)) |
| 12712 | goto free_msg; |
| 12713 | } |
| 12714 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12715 | if (wakeup->net_detect && |
| 12716 | cfg80211_net_detect_results(msg, wakeup)) |
| 12717 | goto free_msg; |
| 12718 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12719 | nla_nest_end(msg, reasons); |
| 12720 | } |
| 12721 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12722 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12723 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12724 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12725 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12726 | return; |
| 12727 | |
| 12728 | free_msg: |
| 12729 | nlmsg_free(msg); |
| 12730 | } |
| 12731 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12732 | #endif |
| 12733 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12734 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12735 | enum nl80211_tdls_operation oper, |
| 12736 | u16 reason_code, gfp_t gfp) |
| 12737 | { |
| 12738 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12739 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12740 | struct sk_buff *msg; |
| 12741 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12742 | |
| 12743 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12744 | reason_code); |
| 12745 | |
| 12746 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12747 | if (!msg) |
| 12748 | return; |
| 12749 | |
| 12750 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12751 | if (!hdr) { |
| 12752 | nlmsg_free(msg); |
| 12753 | return; |
| 12754 | } |
| 12755 | |
| 12756 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12757 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12758 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12759 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12760 | (reason_code > 0 && |
| 12761 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12762 | goto nla_put_failure; |
| 12763 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12764 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12765 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12766 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12767 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12768 | return; |
| 12769 | |
| 12770 | nla_put_failure: |
| 12771 | genlmsg_cancel(msg, hdr); |
| 12772 | nlmsg_free(msg); |
| 12773 | } |
| 12774 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12775 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12776 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12777 | unsigned long state, |
| 12778 | void *_notify) |
| 12779 | { |
| 12780 | struct netlink_notify *notify = _notify; |
| 12781 | struct cfg80211_registered_device *rdev; |
| 12782 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12783 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12784 | |
| 12785 | if (state != NETLINK_URELEASE) |
| 12786 | return NOTIFY_DONE; |
| 12787 | |
| 12788 | rcu_read_lock(); |
| 12789 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12790 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12791 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12792 | bool schedule_scan_stop = false; |
| 12793 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 12794 | rcu_dereference(rdev->sched_scan_req); |
| 12795 | |
| 12796 | if (sched_scan_req && notify->portid && |
| 12797 | sched_scan_req->owner_nlportid == notify->portid) |
| 12798 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12799 | |
| 12800 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12801 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12802 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12803 | if (wdev->owner_nlportid == notify->portid) |
| 12804 | schedule_destroy_work = true; |
| 12805 | } |
| 12806 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12807 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12808 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12809 | list) { |
| 12810 | if (reg->nlportid == notify->portid) { |
| 12811 | list_del(®->list); |
| 12812 | kfree(reg); |
| 12813 | break; |
| 12814 | } |
| 12815 | } |
| 12816 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12817 | |
| 12818 | if (schedule_destroy_work) { |
| 12819 | struct cfg80211_iface_destroy *destroy; |
| 12820 | |
| 12821 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12822 | if (destroy) { |
| 12823 | destroy->nlportid = notify->portid; |
| 12824 | spin_lock(&rdev->destroy_list_lock); |
| 12825 | list_add(&destroy->list, &rdev->destroy_list); |
| 12826 | spin_unlock(&rdev->destroy_list_lock); |
| 12827 | schedule_work(&rdev->destroy_work); |
| 12828 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12829 | } else if (schedule_scan_stop) { |
| 12830 | sched_scan_req->owner_nlportid = 0; |
| 12831 | |
| 12832 | if (rdev->ops->sched_scan_stop && |
| 12833 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 12834 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12835 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12836 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12837 | |
| 12838 | rcu_read_unlock(); |
| 12839 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 12840 | /* |
| 12841 | * It is possible that the user space process that is controlling the |
| 12842 | * indoor setting disappeared, so notify the regulatory core. |
| 12843 | */ |
| 12844 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12845 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12846 | } |
| 12847 | |
| 12848 | static struct notifier_block nl80211_netlink_notifier = { |
| 12849 | .notifier_call = nl80211_netlink_notify, |
| 12850 | }; |
| 12851 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12852 | void cfg80211_ft_event(struct net_device *netdev, |
| 12853 | struct cfg80211_ft_event_params *ft_event) |
| 12854 | { |
| 12855 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12856 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12857 | struct sk_buff *msg; |
| 12858 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12859 | |
| 12860 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12861 | |
| 12862 | if (!ft_event->target_ap) |
| 12863 | return; |
| 12864 | |
| 12865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12866 | if (!msg) |
| 12867 | return; |
| 12868 | |
| 12869 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12870 | if (!hdr) |
| 12871 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12872 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12873 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12874 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12875 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12876 | goto out; |
| 12877 | |
| 12878 | if (ft_event->ies && |
| 12879 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12880 | goto out; |
| 12881 | if (ft_event->ric_ies && |
| 12882 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12883 | ft_event->ric_ies)) |
| 12884 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12885 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12886 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12887 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12889 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12890 | return; |
| 12891 | out: |
| 12892 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12893 | } |
| 12894 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12895 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12896 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12897 | { |
| 12898 | struct cfg80211_registered_device *rdev; |
| 12899 | struct sk_buff *msg; |
| 12900 | void *hdr; |
| 12901 | u32 nlportid; |
| 12902 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12903 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12904 | if (!rdev->crit_proto_nlportid) |
| 12905 | return; |
| 12906 | |
| 12907 | nlportid = rdev->crit_proto_nlportid; |
| 12908 | rdev->crit_proto_nlportid = 0; |
| 12909 | |
| 12910 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12911 | if (!msg) |
| 12912 | return; |
| 12913 | |
| 12914 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12915 | if (!hdr) |
| 12916 | goto nla_put_failure; |
| 12917 | |
| 12918 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12919 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12920 | goto nla_put_failure; |
| 12921 | |
| 12922 | genlmsg_end(msg, hdr); |
| 12923 | |
| 12924 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12925 | return; |
| 12926 | |
| 12927 | nla_put_failure: |
| 12928 | if (hdr) |
| 12929 | genlmsg_cancel(msg, hdr); |
| 12930 | nlmsg_free(msg); |
| 12931 | |
| 12932 | } |
| 12933 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12934 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12935 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12936 | { |
| 12937 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12938 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12939 | struct sk_buff *msg; |
| 12940 | void *hdr; |
| 12941 | |
| 12942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12943 | if (!msg) |
| 12944 | return; |
| 12945 | |
| 12946 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12947 | if (!hdr) |
| 12948 | goto out; |
| 12949 | |
| 12950 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12951 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12952 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12953 | goto out; |
| 12954 | |
| 12955 | genlmsg_end(msg, hdr); |
| 12956 | |
| 12957 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12958 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12959 | return; |
| 12960 | out: |
| 12961 | nlmsg_free(msg); |
| 12962 | } |
| 12963 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12964 | /* initialisation/exit functions */ |
| 12965 | |
| 12966 | int nl80211_init(void) |
| 12967 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12968 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12969 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12970 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12971 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12972 | if (err) |
| 12973 | return err; |
| 12974 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12975 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12976 | if (err) |
| 12977 | goto err_out; |
| 12978 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12979 | return 0; |
| 12980 | err_out: |
| 12981 | genl_unregister_family(&nl80211_fam); |
| 12982 | return err; |
| 12983 | } |
| 12984 | |
| 12985 | void nl80211_exit(void) |
| 12986 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12987 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12988 | genl_unregister_family(&nl80211_fam); |
| 12989 | } |