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: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 2006 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2007 | result = -EINVAL; |
| 2008 | break; |
| 2009 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2010 | if (wdev->beacon_interval) { |
| 2011 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2012 | !(rdev->wiphy.features & |
| 2013 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2014 | result = -EBUSY; |
| 2015 | break; |
| 2016 | } |
| 2017 | |
| 2018 | /* Only allow dynamic channel width changes */ |
| 2019 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2020 | result = -EBUSY; |
| 2021 | break; |
| 2022 | } |
| 2023 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2024 | if (result) |
| 2025 | break; |
| 2026 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2027 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2028 | result = 0; |
| 2029 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2030 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2031 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2032 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2033 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2034 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2035 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2036 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2037 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2038 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2039 | |
| 2040 | return result; |
| 2041 | } |
| 2042 | |
| 2043 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2044 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2046 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2047 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2048 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2049 | } |
| 2050 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2051 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2052 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2054 | struct net_device *dev = info->user_ptr[1]; |
| 2055 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2056 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2057 | |
| 2058 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2059 | return -EINVAL; |
| 2060 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2061 | if (netif_running(dev)) |
| 2062 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2063 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2064 | if (!rdev->ops->set_wds_peer) |
| 2065 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2066 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2067 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2068 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2069 | |
| 2070 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2071 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2075 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2076 | { |
| 2077 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2078 | struct net_device *netdev = NULL; |
| 2079 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2080 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2081 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2082 | u32 changed; |
| 2083 | u8 retry_short = 0, retry_long = 0; |
| 2084 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2085 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2086 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2087 | ASSERT_RTNL(); |
| 2088 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2089 | /* |
| 2090 | * Try to find the wiphy and netdev. Normally this |
| 2091 | * function shouldn't need the netdev, but this is |
| 2092 | * done for backward compatibility -- previously |
| 2093 | * setting the channel was done per wiphy, but now |
| 2094 | * it is per netdev. Previous userland like hostapd |
| 2095 | * also passed a netdev to set_wiphy, so that it is |
| 2096 | * possible to let that go to the right netdev! |
| 2097 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2098 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2099 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2100 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2101 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2102 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2103 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2104 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2105 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2106 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2107 | } |
| 2108 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2109 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2110 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2111 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2112 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2113 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2114 | wdev = NULL; |
| 2115 | netdev = NULL; |
| 2116 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2117 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2118 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | |
| 2120 | /* |
| 2121 | * end workaround code, by now the rdev is available |
| 2122 | * and locked, and wdev may or may not be NULL. |
| 2123 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2124 | |
| 2125 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2126 | result = cfg80211_dev_rename( |
| 2127 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2128 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2129 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2130 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2131 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2132 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2133 | struct ieee80211_txq_params txq_params; |
| 2134 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2135 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2136 | if (!rdev->ops->set_txq_params) |
| 2137 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2138 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2139 | if (!netdev) |
| 2140 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2141 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2142 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2143 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2144 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2145 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2146 | if (!netif_running(netdev)) |
| 2147 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2148 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2149 | nla_for_each_nested(nl_txq_params, |
| 2150 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2151 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2152 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2153 | nla_data(nl_txq_params), |
| 2154 | nla_len(nl_txq_params), |
| 2155 | txq_params_policy); |
| 2156 | if (result) |
| 2157 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2158 | result = parse_txq_params(tb, &txq_params); |
| 2159 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2160 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2161 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2162 | result = rdev_set_txq_params(rdev, netdev, |
| 2163 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2164 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2165 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2169 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2170 | result = __nl80211_set_channel( |
| 2171 | rdev, |
| 2172 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2173 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2174 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2175 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2176 | } |
| 2177 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2178 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2179 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2180 | enum nl80211_tx_power_setting type; |
| 2181 | int idx, mbm = 0; |
| 2182 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2183 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2184 | txp_wdev = NULL; |
| 2185 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2186 | if (!rdev->ops->set_tx_power) |
| 2187 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2188 | |
| 2189 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2190 | type = nla_get_u32(info->attrs[idx]); |
| 2191 | |
| 2192 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2193 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2194 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2195 | |
| 2196 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2197 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2198 | mbm = nla_get_u32(info->attrs[idx]); |
| 2199 | } |
| 2200 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2201 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2202 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2203 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2204 | } |
| 2205 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2206 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2207 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2208 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2209 | if ((!rdev->wiphy.available_antennas_tx && |
| 2210 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2211 | !rdev->ops->set_antenna) |
| 2212 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2213 | |
| 2214 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2215 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2216 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2217 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2218 | * available antenna masks, except for the "all" mask */ |
| 2219 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2220 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2221 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2222 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2223 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2224 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2225 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2226 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2227 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2228 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2229 | } |
| 2230 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2231 | changed = 0; |
| 2232 | |
| 2233 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2234 | retry_short = nla_get_u8( |
| 2235 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2236 | if (retry_short == 0) |
| 2237 | return -EINVAL; |
| 2238 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2239 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2240 | } |
| 2241 | |
| 2242 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2243 | retry_long = nla_get_u8( |
| 2244 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2245 | if (retry_long == 0) |
| 2246 | return -EINVAL; |
| 2247 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2248 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2249 | } |
| 2250 | |
| 2251 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2252 | frag_threshold = nla_get_u32( |
| 2253 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2254 | if (frag_threshold < 256) |
| 2255 | return -EINVAL; |
| 2256 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2257 | if (frag_threshold != (u32) -1) { |
| 2258 | /* |
| 2259 | * Fragments (apart from the last one) are required to |
| 2260 | * have even length. Make the fragmentation code |
| 2261 | * simpler by stripping LSB should someone try to use |
| 2262 | * odd threshold value. |
| 2263 | */ |
| 2264 | frag_threshold &= ~0x1; |
| 2265 | } |
| 2266 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2267 | } |
| 2268 | |
| 2269 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2270 | rts_threshold = nla_get_u32( |
| 2271 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2272 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2273 | } |
| 2274 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2275 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2276 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2277 | return -EINVAL; |
| 2278 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2279 | coverage_class = nla_get_u8( |
| 2280 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2281 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2282 | } |
| 2283 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2284 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2285 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2286 | return -EOPNOTSUPP; |
| 2287 | |
| 2288 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2289 | } |
| 2290 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2291 | if (changed) { |
| 2292 | u8 old_retry_short, old_retry_long; |
| 2293 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2294 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2295 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2296 | if (!rdev->ops->set_wiphy_params) |
| 2297 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2298 | |
| 2299 | old_retry_short = rdev->wiphy.retry_short; |
| 2300 | old_retry_long = rdev->wiphy.retry_long; |
| 2301 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2302 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2303 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2304 | |
| 2305 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2306 | rdev->wiphy.retry_short = retry_short; |
| 2307 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2308 | rdev->wiphy.retry_long = retry_long; |
| 2309 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2310 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2311 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2312 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2313 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2314 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2315 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2316 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2317 | if (result) { |
| 2318 | rdev->wiphy.retry_short = old_retry_short; |
| 2319 | rdev->wiphy.retry_long = old_retry_long; |
| 2320 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2321 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2322 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2323 | } |
| 2324 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2325 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2328 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2329 | { |
| 2330 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2331 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2332 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2333 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2334 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2335 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2336 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2337 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2338 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2339 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2341 | chandef->chan->center_freq)) |
| 2342 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2343 | switch (chandef->width) { |
| 2344 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2345 | case NL80211_CHAN_WIDTH_20: |
| 2346 | case NL80211_CHAN_WIDTH_40: |
| 2347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2348 | cfg80211_get_chandef_type(chandef))) |
| 2349 | return -ENOBUFS; |
| 2350 | break; |
| 2351 | default: |
| 2352 | break; |
| 2353 | } |
| 2354 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2355 | return -ENOBUFS; |
| 2356 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2357 | return -ENOBUFS; |
| 2358 | if (chandef->center_freq2 && |
| 2359 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2360 | return -ENOBUFS; |
| 2361 | return 0; |
| 2362 | } |
| 2363 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2364 | 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] | 2365 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2366 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2367 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2368 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2369 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2370 | void *hdr; |
| 2371 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2372 | if (removal) |
| 2373 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2374 | |
| 2375 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2376 | if (!hdr) |
| 2377 | return -1; |
| 2378 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2379 | if (dev && |
| 2380 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2381 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2382 | goto nla_put_failure; |
| 2383 | |
| 2384 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2385 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2386 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2387 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2388 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2389 | rdev->devlist_generation ^ |
| 2390 | (cfg80211_rdev_list_generation << 2))) |
| 2391 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2392 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2393 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2394 | int ret; |
| 2395 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2396 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2397 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2398 | if (ret == 0) { |
| 2399 | if (nl80211_send_chandef(msg, &chandef)) |
| 2400 | goto nla_put_failure; |
| 2401 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2402 | } |
| 2403 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2404 | if (wdev->ssid_len) { |
| 2405 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2406 | goto nla_put_failure; |
| 2407 | } |
| 2408 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2409 | genlmsg_end(msg, hdr); |
| 2410 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2411 | |
| 2412 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2413 | genlmsg_cancel(msg, hdr); |
| 2414 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2418 | { |
| 2419 | int wp_idx = 0; |
| 2420 | int if_idx = 0; |
| 2421 | int wp_start = cb->args[0]; |
| 2422 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2423 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | struct wireless_dev *wdev; |
| 2425 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2426 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2427 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2428 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2429 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2430 | if (wp_idx < wp_start) { |
| 2431 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2432 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2433 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | if_idx = 0; |
| 2435 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2436 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2437 | if (if_idx < if_start) { |
| 2438 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2439 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2440 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2441 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2442 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2443 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2444 | goto out; |
| 2445 | } |
| 2446 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2447 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2448 | |
| 2449 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2451 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2452 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2453 | |
| 2454 | cb->args[0] = wp_idx; |
| 2455 | cb->args[1] = if_idx; |
| 2456 | |
| 2457 | return skb->len; |
| 2458 | } |
| 2459 | |
| 2460 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2461 | { |
| 2462 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2464 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2465 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2468 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2469 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2470 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2471 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2472 | nlmsg_free(msg); |
| 2473 | return -ENOBUFS; |
| 2474 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2475 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2476 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2477 | } |
| 2478 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2479 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2480 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2481 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2482 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2483 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2484 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2485 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2486 | }; |
| 2487 | |
| 2488 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2489 | { |
| 2490 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2491 | int flag; |
| 2492 | |
| 2493 | *mntrflags = 0; |
| 2494 | |
| 2495 | if (!nla) |
| 2496 | return -EINVAL; |
| 2497 | |
| 2498 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2499 | nla, mntr_flags_policy)) |
| 2500 | return -EINVAL; |
| 2501 | |
| 2502 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2503 | if (flags[flag]) |
| 2504 | *mntrflags |= (1<<flag); |
| 2505 | |
| 2506 | return 0; |
| 2507 | } |
| 2508 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2509 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2510 | struct net_device *netdev, u8 use_4addr, |
| 2511 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2512 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2513 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2514 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2515 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2516 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2517 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2518 | |
| 2519 | switch (iftype) { |
| 2520 | case NL80211_IFTYPE_AP_VLAN: |
| 2521 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2522 | return 0; |
| 2523 | break; |
| 2524 | case NL80211_IFTYPE_STATION: |
| 2525 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2526 | return 0; |
| 2527 | break; |
| 2528 | default: |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | return -EOPNOTSUPP; |
| 2533 | } |
| 2534 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2535 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2536 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2538 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2539 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2540 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2541 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2542 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2543 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2544 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2545 | memset(¶ms, 0, sizeof(params)); |
| 2546 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2547 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2548 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2549 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2550 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2551 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2552 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | if (ntype > NL80211_IFTYPE_MAX) |
| 2554 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2555 | } |
| 2556 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2557 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2558 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2560 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2561 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2562 | if (netif_running(dev)) |
| 2563 | return -EBUSY; |
| 2564 | |
| 2565 | wdev_lock(wdev); |
| 2566 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2567 | IEEE80211_MAX_MESH_ID_LEN); |
| 2568 | wdev->mesh_id_up_len = |
| 2569 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2570 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2571 | wdev->mesh_id_up_len); |
| 2572 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2575 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2576 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2577 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2578 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2579 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2580 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2581 | } else { |
| 2582 | params.use_4addr = -1; |
| 2583 | } |
| 2584 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2585 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2586 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2587 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2588 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2589 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2590 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2591 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2592 | |
| 2593 | flags = &_flags; |
| 2594 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2595 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2596 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2597 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2598 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2599 | return -EOPNOTSUPP; |
| 2600 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2601 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2602 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2603 | else |
| 2604 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2605 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2606 | if (!err && params.use_4addr != -1) |
| 2607 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2608 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2609 | return err; |
| 2610 | } |
| 2611 | |
| 2612 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2613 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2615 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2616 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2617 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2618 | int err; |
| 2619 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2620 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2621 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2622 | /* to avoid failing a new interface creation due to pending removal */ |
| 2623 | cfg80211_destroy_ifaces(rdev); |
| 2624 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2625 | memset(¶ms, 0, sizeof(params)); |
| 2626 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2627 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2628 | return -EINVAL; |
| 2629 | |
| 2630 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2631 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2632 | if (type > NL80211_IFTYPE_MAX) |
| 2633 | return -EINVAL; |
| 2634 | } |
| 2635 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2636 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2637 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2638 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2639 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2640 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2641 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2642 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2643 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2644 | ETH_ALEN); |
| 2645 | if (!is_valid_ether_addr(params.macaddr)) |
| 2646 | return -EADDRNOTAVAIL; |
| 2647 | } |
| 2648 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2649 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2650 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2651 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2652 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2653 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2654 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2655 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2656 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2657 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2658 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2659 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2660 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2661 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2662 | return -EOPNOTSUPP; |
| 2663 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2665 | if (!msg) |
| 2666 | return -ENOMEM; |
| 2667 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2668 | wdev = rdev_add_virtual_intf(rdev, |
| 2669 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2670 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2671 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2672 | if (WARN_ON(!wdev)) { |
| 2673 | nlmsg_free(msg); |
| 2674 | return -EPROTO; |
| 2675 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2676 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2677 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2678 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2679 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2680 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2681 | wdev->owner_nlportid = info->snd_portid; |
| 2682 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2683 | switch (type) { |
| 2684 | case NL80211_IFTYPE_MESH_POINT: |
| 2685 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2686 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2687 | wdev_lock(wdev); |
| 2688 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2689 | IEEE80211_MAX_MESH_ID_LEN); |
| 2690 | wdev->mesh_id_up_len = |
| 2691 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2692 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2693 | wdev->mesh_id_up_len); |
| 2694 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2695 | break; |
| 2696 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2697 | /* |
| 2698 | * P2P Device doesn't have a netdev, so doesn't go |
| 2699 | * through the netdev notifier and must be added here |
| 2700 | */ |
| 2701 | mutex_init(&wdev->mtx); |
| 2702 | INIT_LIST_HEAD(&wdev->event_list); |
| 2703 | spin_lock_init(&wdev->event_lock); |
| 2704 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2705 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2706 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2707 | wdev->identifier = ++rdev->wdev_id; |
| 2708 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2709 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2710 | break; |
| 2711 | default: |
| 2712 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2713 | } |
| 2714 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2715 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2716 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2717 | nlmsg_free(msg); |
| 2718 | return -ENOBUFS; |
| 2719 | } |
| 2720 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2721 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2722 | if (event) { |
| 2723 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2724 | rdev, wdev, false) < 0) { |
| 2725 | nlmsg_free(event); |
| 2726 | goto out; |
| 2727 | } |
| 2728 | |
| 2729 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2730 | event, 0, NL80211_MCGRP_CONFIG, |
| 2731 | GFP_KERNEL); |
| 2732 | } |
| 2733 | |
| 2734 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2735 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2739 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2741 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2742 | struct sk_buff *msg; |
| 2743 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2744 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2745 | if (!rdev->ops->del_virtual_intf) |
| 2746 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2747 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2748 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2749 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2750 | nlmsg_free(msg); |
| 2751 | msg = NULL; |
| 2752 | } |
| 2753 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2754 | /* |
| 2755 | * If we remove a wireless device without a netdev then clear |
| 2756 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2757 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2758 | * since the wdev has been freed, unlike with a netdev where |
| 2759 | * we need the dev_put() for the netdev to really be freed. |
| 2760 | */ |
| 2761 | if (!wdev->netdev) |
| 2762 | info->user_ptr[1] = NULL; |
| 2763 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2764 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2765 | if (status >= 0 && msg) |
| 2766 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2767 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2768 | GFP_KERNEL); |
| 2769 | else |
| 2770 | nlmsg_free(msg); |
| 2771 | |
| 2772 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2773 | } |
| 2774 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2775 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2776 | { |
| 2777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2778 | struct net_device *dev = info->user_ptr[1]; |
| 2779 | u16 noack_map; |
| 2780 | |
| 2781 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2782 | return -EINVAL; |
| 2783 | |
| 2784 | if (!rdev->ops->set_noack_map) |
| 2785 | return -EOPNOTSUPP; |
| 2786 | |
| 2787 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2788 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2789 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2790 | } |
| 2791 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2792 | struct get_key_cookie { |
| 2793 | struct sk_buff *msg; |
| 2794 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2795 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2796 | }; |
| 2797 | |
| 2798 | static void get_key_callback(void *c, struct key_params *params) |
| 2799 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2800 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2801 | struct get_key_cookie *cookie = c; |
| 2802 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2803 | if ((params->key && |
| 2804 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2805 | params->key_len, params->key)) || |
| 2806 | (params->seq && |
| 2807 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2808 | params->seq_len, params->seq)) || |
| 2809 | (params->cipher && |
| 2810 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2811 | params->cipher))) |
| 2812 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2813 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2814 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2815 | if (!key) |
| 2816 | goto nla_put_failure; |
| 2817 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2818 | if ((params->key && |
| 2819 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2820 | params->key_len, params->key)) || |
| 2821 | (params->seq && |
| 2822 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2823 | params->seq_len, params->seq)) || |
| 2824 | (params->cipher && |
| 2825 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2826 | params->cipher))) |
| 2827 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2828 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2829 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2830 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2831 | |
| 2832 | nla_nest_end(cookie->msg, key); |
| 2833 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2834 | return; |
| 2835 | nla_put_failure: |
| 2836 | cookie->error = 1; |
| 2837 | } |
| 2838 | |
| 2839 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2840 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2842 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2843 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2844 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2845 | const u8 *mac_addr = NULL; |
| 2846 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2847 | struct get_key_cookie cookie = { |
| 2848 | .error = 0, |
| 2849 | }; |
| 2850 | void *hdr; |
| 2851 | struct sk_buff *msg; |
| 2852 | |
| 2853 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2854 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2855 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2856 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2857 | return -EINVAL; |
| 2858 | |
| 2859 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2860 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2861 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2862 | pairwise = !!mac_addr; |
| 2863 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2864 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2865 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2866 | return -EINVAL; |
| 2867 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2868 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2869 | return -EINVAL; |
| 2870 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2871 | } |
| 2872 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2873 | if (!rdev->ops->get_key) |
| 2874 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2875 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 2876 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2877 | return -ENOENT; |
| 2878 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2879 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2880 | if (!msg) |
| 2881 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2882 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2883 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2884 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2885 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2886 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2887 | |
| 2888 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2889 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2890 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2891 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2892 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2893 | goto nla_put_failure; |
| 2894 | if (mac_addr && |
| 2895 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2896 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2897 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2898 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2899 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2900 | |
| 2901 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2902 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2903 | |
| 2904 | if (cookie.error) |
| 2905 | goto nla_put_failure; |
| 2906 | |
| 2907 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2908 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2909 | |
| 2910 | nla_put_failure: |
| 2911 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2912 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2913 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2914 | return err; |
| 2915 | } |
| 2916 | |
| 2917 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2920 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2921 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2922 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2923 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2924 | err = nl80211_parse_key(info, &key); |
| 2925 | if (err) |
| 2926 | return err; |
| 2927 | |
| 2928 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | return -EINVAL; |
| 2930 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2931 | /* only support setting default key */ |
| 2932 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2933 | return -EINVAL; |
| 2934 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2935 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2936 | |
| 2937 | if (key.def) { |
| 2938 | if (!rdev->ops->set_default_key) { |
| 2939 | err = -EOPNOTSUPP; |
| 2940 | goto out; |
| 2941 | } |
| 2942 | |
| 2943 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2944 | if (err) |
| 2945 | goto out; |
| 2946 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2947 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2948 | key.def_uni, key.def_multi); |
| 2949 | |
| 2950 | if (err) |
| 2951 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2952 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2953 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2954 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2955 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2956 | } else { |
| 2957 | if (key.def_uni || !key.def_multi) { |
| 2958 | err = -EINVAL; |
| 2959 | goto out; |
| 2960 | } |
| 2961 | |
| 2962 | if (!rdev->ops->set_default_mgmt_key) { |
| 2963 | err = -EOPNOTSUPP; |
| 2964 | goto out; |
| 2965 | } |
| 2966 | |
| 2967 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2968 | if (err) |
| 2969 | goto out; |
| 2970 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2971 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2972 | if (err) |
| 2973 | goto out; |
| 2974 | |
| 2975 | #ifdef CONFIG_CFG80211_WEXT |
| 2976 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2977 | #endif |
| 2978 | } |
| 2979 | |
| 2980 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2981 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2982 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2983 | return err; |
| 2984 | } |
| 2985 | |
| 2986 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2987 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2989 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2990 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2991 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2992 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2993 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2994 | err = nl80211_parse_key(info, &key); |
| 2995 | if (err) |
| 2996 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2997 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2998 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2999 | return -EINVAL; |
| 3000 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3001 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3002 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3003 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3004 | if (key.type == -1) { |
| 3005 | if (mac_addr) |
| 3006 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3007 | else |
| 3008 | key.type = NL80211_KEYTYPE_GROUP; |
| 3009 | } |
| 3010 | |
| 3011 | /* for now */ |
| 3012 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3013 | key.type != NL80211_KEYTYPE_GROUP) |
| 3014 | return -EINVAL; |
| 3015 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | if (!rdev->ops->add_key) |
| 3017 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3018 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3019 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3020 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3021 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3022 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3023 | |
| 3024 | wdev_lock(dev->ieee80211_ptr); |
| 3025 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3026 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3027 | err = rdev_add_key(rdev, dev, key.idx, |
| 3028 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3029 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3030 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3031 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3032 | return err; |
| 3033 | } |
| 3034 | |
| 3035 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3036 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3039 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3040 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3041 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3042 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3043 | err = nl80211_parse_key(info, &key); |
| 3044 | if (err) |
| 3045 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3046 | |
| 3047 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3048 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3049 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3050 | if (key.type == -1) { |
| 3051 | if (mac_addr) |
| 3052 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3053 | else |
| 3054 | key.type = NL80211_KEYTYPE_GROUP; |
| 3055 | } |
| 3056 | |
| 3057 | /* for now */ |
| 3058 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3059 | key.type != NL80211_KEYTYPE_GROUP) |
| 3060 | return -EINVAL; |
| 3061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3062 | if (!rdev->ops->del_key) |
| 3063 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3064 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3065 | wdev_lock(dev->ieee80211_ptr); |
| 3066 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3067 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3068 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3069 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3070 | err = -ENOENT; |
| 3071 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3072 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3073 | err = rdev_del_key(rdev, dev, key.idx, |
| 3074 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3075 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3076 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3077 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3078 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3079 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3080 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3081 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3082 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3083 | } |
| 3084 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3085 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3086 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3087 | return err; |
| 3088 | } |
| 3089 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3090 | /* This function returns an error or the number of nested attributes */ |
| 3091 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3092 | { |
| 3093 | struct nlattr *attr; |
| 3094 | int n_entries = 0, tmp; |
| 3095 | |
| 3096 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3097 | if (nla_len(attr) != ETH_ALEN) |
| 3098 | return -EINVAL; |
| 3099 | |
| 3100 | n_entries++; |
| 3101 | } |
| 3102 | |
| 3103 | return n_entries; |
| 3104 | } |
| 3105 | |
| 3106 | /* |
| 3107 | * This function parses ACL information and allocates memory for ACL data. |
| 3108 | * On successful return, the calling function is responsible to free the |
| 3109 | * ACL buffer returned by this function. |
| 3110 | */ |
| 3111 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3112 | struct genl_info *info) |
| 3113 | { |
| 3114 | enum nl80211_acl_policy acl_policy; |
| 3115 | struct nlattr *attr; |
| 3116 | struct cfg80211_acl_data *acl; |
| 3117 | int i = 0, n_entries, tmp; |
| 3118 | |
| 3119 | if (!wiphy->max_acl_mac_addrs) |
| 3120 | return ERR_PTR(-EOPNOTSUPP); |
| 3121 | |
| 3122 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3123 | return ERR_PTR(-EINVAL); |
| 3124 | |
| 3125 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3126 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3127 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3128 | return ERR_PTR(-EINVAL); |
| 3129 | |
| 3130 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3131 | return ERR_PTR(-EINVAL); |
| 3132 | |
| 3133 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3134 | if (n_entries < 0) |
| 3135 | return ERR_PTR(n_entries); |
| 3136 | |
| 3137 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3138 | return ERR_PTR(-ENOTSUPP); |
| 3139 | |
| 3140 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3141 | GFP_KERNEL); |
| 3142 | if (!acl) |
| 3143 | return ERR_PTR(-ENOMEM); |
| 3144 | |
| 3145 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3146 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3147 | i++; |
| 3148 | } |
| 3149 | |
| 3150 | acl->n_acl_entries = n_entries; |
| 3151 | acl->acl_policy = acl_policy; |
| 3152 | |
| 3153 | return acl; |
| 3154 | } |
| 3155 | |
| 3156 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3157 | { |
| 3158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3159 | struct net_device *dev = info->user_ptr[1]; |
| 3160 | struct cfg80211_acl_data *acl; |
| 3161 | int err; |
| 3162 | |
| 3163 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3164 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3165 | return -EOPNOTSUPP; |
| 3166 | |
| 3167 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3168 | return -EINVAL; |
| 3169 | |
| 3170 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3171 | if (IS_ERR(acl)) |
| 3172 | return PTR_ERR(acl); |
| 3173 | |
| 3174 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3175 | |
| 3176 | kfree(acl); |
| 3177 | |
| 3178 | return err; |
| 3179 | } |
| 3180 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3181 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3182 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3183 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3184 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3185 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3186 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3187 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3188 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3189 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3190 | return -EINVAL; |
| 3191 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3192 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3193 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3194 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3195 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3196 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3197 | if (!bcn->head_len) |
| 3198 | return -EINVAL; |
| 3199 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3200 | } |
| 3201 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3202 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3203 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3204 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3205 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3206 | } |
| 3207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3208 | if (!haveinfo) |
| 3209 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3210 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3211 | if (attrs[NL80211_ATTR_IE]) { |
| 3212 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3213 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3214 | } |
| 3215 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3216 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3217 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3218 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3219 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3220 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3221 | } |
| 3222 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3223 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3224 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3225 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3226 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3227 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3228 | } |
| 3229 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3230 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3231 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3232 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3233 | } |
| 3234 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3235 | return 0; |
| 3236 | } |
| 3237 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3238 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3239 | struct cfg80211_ap_settings *params) |
| 3240 | { |
| 3241 | struct wireless_dev *wdev; |
| 3242 | bool ret = false; |
| 3243 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3244 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3245 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3246 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3247 | continue; |
| 3248 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3249 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3250 | continue; |
| 3251 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3252 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3253 | ret = true; |
| 3254 | break; |
| 3255 | } |
| 3256 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3257 | return ret; |
| 3258 | } |
| 3259 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3260 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3261 | enum nl80211_auth_type auth_type, |
| 3262 | enum nl80211_commands cmd) |
| 3263 | { |
| 3264 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3265 | return false; |
| 3266 | |
| 3267 | switch (cmd) { |
| 3268 | case NL80211_CMD_AUTHENTICATE: |
| 3269 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3270 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3271 | return false; |
| 3272 | return true; |
| 3273 | case NL80211_CMD_CONNECT: |
| 3274 | case NL80211_CMD_START_AP: |
| 3275 | /* SAE not supported yet */ |
| 3276 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3277 | return false; |
| 3278 | return true; |
| 3279 | default: |
| 3280 | return false; |
| 3281 | } |
| 3282 | } |
| 3283 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3284 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3285 | { |
| 3286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3287 | struct net_device *dev = info->user_ptr[1]; |
| 3288 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3289 | struct cfg80211_ap_settings params; |
| 3290 | int err; |
| 3291 | |
| 3292 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3293 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3294 | return -EOPNOTSUPP; |
| 3295 | |
| 3296 | if (!rdev->ops->start_ap) |
| 3297 | return -EOPNOTSUPP; |
| 3298 | |
| 3299 | if (wdev->beacon_interval) |
| 3300 | return -EALREADY; |
| 3301 | |
| 3302 | memset(¶ms, 0, sizeof(params)); |
| 3303 | |
| 3304 | /* these are required for START_AP */ |
| 3305 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3306 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3307 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3308 | return -EINVAL; |
| 3309 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3310 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3311 | if (err) |
| 3312 | return err; |
| 3313 | |
| 3314 | params.beacon_interval = |
| 3315 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3316 | params.dtim_period = |
| 3317 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3318 | |
| 3319 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3320 | if (err) |
| 3321 | return err; |
| 3322 | |
| 3323 | /* |
| 3324 | * In theory, some of these attributes should be required here |
| 3325 | * but since they were not used when the command was originally |
| 3326 | * added, keep them optional for old user space programs to let |
| 3327 | * them continue to work with drivers that do not need the |
| 3328 | * additional information -- drivers must check! |
| 3329 | */ |
| 3330 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3331 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3332 | params.ssid_len = |
| 3333 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3334 | if (params.ssid_len == 0 || |
| 3335 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3336 | return -EINVAL; |
| 3337 | } |
| 3338 | |
| 3339 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3340 | params.hidden_ssid = nla_get_u32( |
| 3341 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3342 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3343 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3344 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3345 | return -EINVAL; |
| 3346 | } |
| 3347 | |
| 3348 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3349 | |
| 3350 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3351 | params.auth_type = nla_get_u32( |
| 3352 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3353 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3354 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3355 | return -EINVAL; |
| 3356 | } else |
| 3357 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3358 | |
| 3359 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3360 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3361 | if (err) |
| 3362 | return err; |
| 3363 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3364 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3365 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3366 | return -EOPNOTSUPP; |
| 3367 | params.inactivity_timeout = nla_get_u16( |
| 3368 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3369 | } |
| 3370 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3371 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3373 | return -EINVAL; |
| 3374 | params.p2p_ctwindow = |
| 3375 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3376 | if (params.p2p_ctwindow > 127) |
| 3377 | return -EINVAL; |
| 3378 | if (params.p2p_ctwindow != 0 && |
| 3379 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3380 | return -EINVAL; |
| 3381 | } |
| 3382 | |
| 3383 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3384 | u8 tmp; |
| 3385 | |
| 3386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3387 | return -EINVAL; |
| 3388 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3389 | if (tmp > 1) |
| 3390 | return -EINVAL; |
| 3391 | params.p2p_opp_ps = tmp; |
| 3392 | if (params.p2p_opp_ps != 0 && |
| 3393 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3394 | return -EINVAL; |
| 3395 | } |
| 3396 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3397 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3398 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3399 | if (err) |
| 3400 | return err; |
| 3401 | } else if (wdev->preset_chandef.chan) { |
| 3402 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3403 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3404 | return -EINVAL; |
| 3405 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3406 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3407 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3408 | return -EINVAL; |
| 3409 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3410 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3411 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3412 | if (IS_ERR(params.acl)) |
| 3413 | return PTR_ERR(params.acl); |
| 3414 | } |
| 3415 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3416 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3417 | params.smps_mode = |
| 3418 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3419 | switch (params.smps_mode) { |
| 3420 | case NL80211_SMPS_OFF: |
| 3421 | break; |
| 3422 | case NL80211_SMPS_STATIC: |
| 3423 | if (!(rdev->wiphy.features & |
| 3424 | NL80211_FEATURE_STATIC_SMPS)) |
| 3425 | return -EINVAL; |
| 3426 | break; |
| 3427 | case NL80211_SMPS_DYNAMIC: |
| 3428 | if (!(rdev->wiphy.features & |
| 3429 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3430 | return -EINVAL; |
| 3431 | break; |
| 3432 | default: |
| 3433 | return -EINVAL; |
| 3434 | } |
| 3435 | } else { |
| 3436 | params.smps_mode = NL80211_SMPS_OFF; |
| 3437 | } |
| 3438 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3439 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3440 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3441 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3442 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3443 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3444 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3445 | wdev->ssid_len = params.ssid_len; |
| 3446 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3447 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3448 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3449 | |
| 3450 | kfree(params.acl); |
| 3451 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3452 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3453 | } |
| 3454 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3455 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3456 | { |
| 3457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3458 | struct net_device *dev = info->user_ptr[1]; |
| 3459 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3460 | struct cfg80211_beacon_data params; |
| 3461 | int err; |
| 3462 | |
| 3463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3464 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3465 | return -EOPNOTSUPP; |
| 3466 | |
| 3467 | if (!rdev->ops->change_beacon) |
| 3468 | return -EOPNOTSUPP; |
| 3469 | |
| 3470 | if (!wdev->beacon_interval) |
| 3471 | return -EINVAL; |
| 3472 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3473 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3474 | if (err) |
| 3475 | return err; |
| 3476 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3477 | wdev_lock(wdev); |
| 3478 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3479 | wdev_unlock(wdev); |
| 3480 | |
| 3481 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | 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] | 3485 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3487 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3488 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3489 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3490 | } |
| 3491 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3492 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3493 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3494 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3495 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3496 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3497 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3498 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3499 | }; |
| 3500 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3501 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3502 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3503 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3504 | { |
| 3505 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3506 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3507 | int flag; |
| 3508 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3509 | /* |
| 3510 | * Try parsing the new attribute first so userspace |
| 3511 | * can specify both for older kernels. |
| 3512 | */ |
| 3513 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3514 | if (nla) { |
| 3515 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3516 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3517 | sta_flags = nla_data(nla); |
| 3518 | params->sta_flags_mask = sta_flags->mask; |
| 3519 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3520 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3521 | if ((params->sta_flags_mask | |
| 3522 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3523 | return -EINVAL; |
| 3524 | return 0; |
| 3525 | } |
| 3526 | |
| 3527 | /* if present, parse the old attribute */ |
| 3528 | |
| 3529 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3530 | if (!nla) |
| 3531 | return 0; |
| 3532 | |
| 3533 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3534 | nla, sta_flags_policy)) |
| 3535 | return -EINVAL; |
| 3536 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3537 | /* |
| 3538 | * Only allow certain flags for interface types so that |
| 3539 | * other attributes are silently ignored. Remember that |
| 3540 | * this is backward compatibility code with old userspace |
| 3541 | * and shouldn't be hit in other cases anyway. |
| 3542 | */ |
| 3543 | switch (iftype) { |
| 3544 | case NL80211_IFTYPE_AP: |
| 3545 | case NL80211_IFTYPE_AP_VLAN: |
| 3546 | case NL80211_IFTYPE_P2P_GO: |
| 3547 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3548 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3549 | BIT(NL80211_STA_FLAG_WME) | |
| 3550 | BIT(NL80211_STA_FLAG_MFP); |
| 3551 | break; |
| 3552 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3553 | case NL80211_IFTYPE_STATION: |
| 3554 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3555 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3556 | break; |
| 3557 | case NL80211_IFTYPE_MESH_POINT: |
| 3558 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3559 | BIT(NL80211_STA_FLAG_MFP) | |
| 3560 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3561 | default: |
| 3562 | return -EINVAL; |
| 3563 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3564 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3565 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3566 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3567 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3568 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3569 | /* no longer support new API additions in old API */ |
| 3570 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3571 | return -EINVAL; |
| 3572 | } |
| 3573 | } |
| 3574 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3575 | return 0; |
| 3576 | } |
| 3577 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3578 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3579 | int attr) |
| 3580 | { |
| 3581 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3582 | u32 bitrate; |
| 3583 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3584 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3585 | |
| 3586 | rate = nla_nest_start(msg, attr); |
| 3587 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3588 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3589 | |
| 3590 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3591 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3592 | /* report 16-bit bitrate only if we can */ |
| 3593 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3594 | if (bitrate > 0 && |
| 3595 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3596 | return false; |
| 3597 | if (bitrate_compat > 0 && |
| 3598 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3599 | return false; |
| 3600 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3601 | switch (info->bw) { |
| 3602 | case RATE_INFO_BW_5: |
| 3603 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3604 | break; |
| 3605 | case RATE_INFO_BW_10: |
| 3606 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3607 | break; |
| 3608 | default: |
| 3609 | WARN_ON(1); |
| 3610 | /* fall through */ |
| 3611 | case RATE_INFO_BW_20: |
| 3612 | rate_flg = 0; |
| 3613 | break; |
| 3614 | case RATE_INFO_BW_40: |
| 3615 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3616 | break; |
| 3617 | case RATE_INFO_BW_80: |
| 3618 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3619 | break; |
| 3620 | case RATE_INFO_BW_160: |
| 3621 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3622 | break; |
| 3623 | } |
| 3624 | |
| 3625 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3626 | return false; |
| 3627 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3628 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3629 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3630 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3631 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3632 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3633 | return false; |
| 3634 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3635 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3636 | return false; |
| 3637 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3638 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3639 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3640 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3641 | return false; |
| 3642 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3643 | |
| 3644 | nla_nest_end(msg, rate); |
| 3645 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3648 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3649 | int id) |
| 3650 | { |
| 3651 | void *attr; |
| 3652 | int i = 0; |
| 3653 | |
| 3654 | if (!mask) |
| 3655 | return true; |
| 3656 | |
| 3657 | attr = nla_nest_start(msg, id); |
| 3658 | if (!attr) |
| 3659 | return false; |
| 3660 | |
| 3661 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3662 | if (!(mask & BIT(i))) |
| 3663 | continue; |
| 3664 | |
| 3665 | if (nla_put_u8(msg, i, signal[i])) |
| 3666 | return false; |
| 3667 | } |
| 3668 | |
| 3669 | nla_nest_end(msg, attr); |
| 3670 | |
| 3671 | return true; |
| 3672 | } |
| 3673 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3674 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3675 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3676 | struct cfg80211_registered_device *rdev, |
| 3677 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3678 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3679 | { |
| 3680 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3681 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3682 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3683 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3684 | if (!hdr) |
| 3685 | return -1; |
| 3686 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3687 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3688 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3689 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3690 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3691 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3692 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3693 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3694 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3695 | |
| 3696 | #define PUT_SINFO(attr, memb, type) do { \ |
| 3697 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ |
| 3698 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3699 | sinfo->memb)) \ |
| 3700 | goto nla_put_failure; \ |
| 3701 | } while (0) |
| 3702 | |
| 3703 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3704 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3705 | |
| 3706 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3707 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3708 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3709 | (u32)sinfo->rx_bytes)) |
| 3710 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3711 | |
| 3712 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3713 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3714 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3715 | (u32)sinfo->tx_bytes)) |
| 3716 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3717 | |
| 3718 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); |
| 3719 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); |
| 3720 | PUT_SINFO(LLID, llid, u16); |
| 3721 | PUT_SINFO(PLID, plid, u16); |
| 3722 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
| 3723 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3724 | switch (rdev->wiphy.signal_type) { |
| 3725 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3726 | PUT_SINFO(SIGNAL, signal, u8); |
| 3727 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3728 | break; |
| 3729 | default: |
| 3730 | break; |
| 3731 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3732 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3733 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3734 | sinfo->chain_signal, |
| 3735 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3736 | goto nla_put_failure; |
| 3737 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3738 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3739 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3740 | sinfo->chain_signal_avg, |
| 3741 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3742 | goto nla_put_failure; |
| 3743 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3744 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3745 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3746 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3747 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3748 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3749 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3750 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3751 | NL80211_STA_INFO_RX_BITRATE)) |
| 3752 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3753 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3754 | |
| 3755 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3756 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3757 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3758 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3759 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3760 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3761 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3762 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3763 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3764 | |
| 3765 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3766 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3767 | if (!bss_param) |
| 3768 | goto nla_put_failure; |
| 3769 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3770 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3771 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3772 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3773 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3774 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3775 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3776 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3777 | sinfo->bss_param.dtim_period) || |
| 3778 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3779 | sinfo->bss_param.beacon_interval)) |
| 3780 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3781 | |
| 3782 | nla_nest_end(msg, bss_param); |
| 3783 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3784 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3785 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3786 | sizeof(struct nl80211_sta_flag_update), |
| 3787 | &sinfo->sta_flags)) |
| 3788 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3789 | |
| 3790 | PUT_SINFO(T_OFFSET, t_offset, u64); |
| 3791 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3792 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
| 3793 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3794 | |
| 3795 | #undef PUT_SINFO |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3796 | |
| 3797 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3798 | struct nlattr *tidsattr; |
| 3799 | int tid; |
| 3800 | |
| 3801 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3802 | if (!tidsattr) |
| 3803 | goto nla_put_failure; |
| 3804 | |
| 3805 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3806 | struct cfg80211_tid_stats *tidstats; |
| 3807 | struct nlattr *tidattr; |
| 3808 | |
| 3809 | tidstats = &sinfo->pertid[tid]; |
| 3810 | |
| 3811 | if (!tidstats->filled) |
| 3812 | continue; |
| 3813 | |
| 3814 | tidattr = nla_nest_start(msg, tid + 1); |
| 3815 | if (!tidattr) |
| 3816 | goto nla_put_failure; |
| 3817 | |
| 3818 | #define PUT_TIDVAL(attr, memb, type) do { \ |
| 3819 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
| 3820 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ |
| 3821 | tidstats->memb)) \ |
| 3822 | goto nla_put_failure; \ |
| 3823 | } while (0) |
| 3824 | |
| 3825 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); |
| 3826 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); |
| 3827 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); |
| 3828 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); |
| 3829 | |
| 3830 | #undef PUT_TIDVAL |
| 3831 | nla_nest_end(msg, tidattr); |
| 3832 | } |
| 3833 | |
| 3834 | nla_nest_end(msg, tidsattr); |
| 3835 | } |
| 3836 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3837 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3838 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3839 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3840 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3841 | sinfo->assoc_req_ies)) |
| 3842 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3843 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3844 | genlmsg_end(msg, hdr); |
| 3845 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3846 | |
| 3847 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3848 | genlmsg_cancel(msg, hdr); |
| 3849 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3850 | } |
| 3851 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3852 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3853 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3854 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3855 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3856 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3857 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3858 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3859 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3860 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3861 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3862 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3863 | if (err) |
| 3864 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3865 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3866 | if (!wdev->netdev) { |
| 3867 | err = -EINVAL; |
| 3868 | goto out_err; |
| 3869 | } |
| 3870 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3871 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3872 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3873 | goto out_err; |
| 3874 | } |
| 3875 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3876 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3877 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3878 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3879 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3880 | if (err == -ENOENT) |
| 3881 | break; |
| 3882 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3883 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3884 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3885 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3886 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3887 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3888 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3889 | &sinfo) < 0) |
| 3890 | goto out; |
| 3891 | |
| 3892 | sta_idx++; |
| 3893 | } |
| 3894 | |
| 3895 | |
| 3896 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3897 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3898 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3899 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3900 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3901 | |
| 3902 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3903 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3904 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3905 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3908 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3909 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3910 | struct sk_buff *msg; |
| 3911 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3912 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3913 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3914 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3915 | |
| 3916 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3917 | return -EINVAL; |
| 3918 | |
| 3919 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3921 | if (!rdev->ops->get_station) |
| 3922 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3923 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3924 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3925 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3926 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3927 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3928 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3929 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3930 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3931 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3932 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 3933 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3934 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3935 | nlmsg_free(msg); |
| 3936 | return -ENOBUFS; |
| 3937 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3938 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3939 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3940 | } |
| 3941 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3942 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3943 | struct station_parameters *params, |
| 3944 | enum cfg80211_station_type statype) |
| 3945 | { |
| 3946 | if (params->listen_interval != -1) |
| 3947 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3948 | if (params->aid && |
| 3949 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3950 | return -EINVAL; |
| 3951 | |
| 3952 | /* When you run into this, adjust the code below for the new flag */ |
| 3953 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3954 | |
| 3955 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3956 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3957 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3958 | /* |
| 3959 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3960 | * code doesn't have the bug of including TDLS in the |
| 3961 | * mask everywhere. |
| 3962 | */ |
| 3963 | if (params->sta_flags_mask & |
| 3964 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3965 | BIT(NL80211_STA_FLAG_MFP) | |
| 3966 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3967 | return -EINVAL; |
| 3968 | break; |
| 3969 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3970 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3971 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3972 | return -EINVAL; |
| 3973 | /* ignore since it can't change */ |
| 3974 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3975 | break; |
| 3976 | default: |
| 3977 | /* disallow mesh-specific things */ |
| 3978 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3979 | return -EINVAL; |
| 3980 | if (params->local_pm) |
| 3981 | return -EINVAL; |
| 3982 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3983 | return -EINVAL; |
| 3984 | } |
| 3985 | |
| 3986 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3987 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3988 | /* TDLS can't be set, ... */ |
| 3989 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3990 | return -EINVAL; |
| 3991 | /* |
| 3992 | * ... but don't bother the driver with it. This works around |
| 3993 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3994 | * TLDS_PEER flag in the mask even for AP mode. |
| 3995 | */ |
| 3996 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3997 | } |
| 3998 | |
| 3999 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 4000 | /* reject other things that can't change */ |
| 4001 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4002 | return -EINVAL; |
| 4003 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4004 | return -EINVAL; |
| 4005 | if (params->supported_rates) |
| 4006 | return -EINVAL; |
| 4007 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4008 | return -EINVAL; |
| 4009 | } |
| 4010 | |
| 4011 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 4012 | if (params->vlan) |
| 4013 | return -EINVAL; |
| 4014 | } |
| 4015 | |
| 4016 | switch (statype) { |
| 4017 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4018 | /* Use this only for authorizing/unauthorizing a station */ |
| 4019 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4020 | return -EOPNOTSUPP; |
| 4021 | break; |
| 4022 | case CFG80211_STA_AP_CLIENT: |
| 4023 | /* accept only the listed bits */ |
| 4024 | if (params->sta_flags_mask & |
| 4025 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4026 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4027 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4028 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4029 | BIT(NL80211_STA_FLAG_WME) | |
| 4030 | BIT(NL80211_STA_FLAG_MFP))) |
| 4031 | return -EINVAL; |
| 4032 | |
| 4033 | /* but authenticated/associated only if driver handles it */ |
| 4034 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4035 | params->sta_flags_mask & |
| 4036 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4037 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4038 | return -EINVAL; |
| 4039 | break; |
| 4040 | case CFG80211_STA_IBSS: |
| 4041 | case CFG80211_STA_AP_STA: |
| 4042 | /* reject any changes other than AUTHORIZED */ |
| 4043 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4044 | return -EINVAL; |
| 4045 | break; |
| 4046 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4047 | /* reject any changes other than AUTHORIZED or WME */ |
| 4048 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4049 | BIT(NL80211_STA_FLAG_WME))) |
| 4050 | return -EINVAL; |
| 4051 | /* force (at least) rates when authorizing */ |
| 4052 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4053 | !params->supported_rates) |
| 4054 | return -EINVAL; |
| 4055 | break; |
| 4056 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4057 | /* reject any changes */ |
| 4058 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4059 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4060 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4061 | return -EINVAL; |
| 4062 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4063 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4064 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4065 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4066 | return -EINVAL; |
| 4067 | break; |
| 4068 | } |
| 4069 | |
| 4070 | return 0; |
| 4071 | } |
| 4072 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4073 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4074 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4075 | * 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] | 4076 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4077 | static struct net_device *get_vlan(struct genl_info *info, |
| 4078 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4079 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4080 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4081 | struct net_device *v; |
| 4082 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4083 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4084 | if (!vlanattr) |
| 4085 | return NULL; |
| 4086 | |
| 4087 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4088 | if (!v) |
| 4089 | return ERR_PTR(-ENODEV); |
| 4090 | |
| 4091 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4092 | ret = -EINVAL; |
| 4093 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4094 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4095 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4096 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4097 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4098 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4099 | ret = -EINVAL; |
| 4100 | goto error; |
| 4101 | } |
| 4102 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4103 | if (!netif_running(v)) { |
| 4104 | ret = -ENETDOWN; |
| 4105 | goto error; |
| 4106 | } |
| 4107 | |
| 4108 | return v; |
| 4109 | error: |
| 4110 | dev_put(v); |
| 4111 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4114 | static const struct nla_policy |
| 4115 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4116 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4117 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4118 | }; |
| 4119 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4120 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4121 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4122 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4123 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4124 | struct nlattr *nla; |
| 4125 | int err; |
| 4126 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4127 | /* parse WME attributes if present */ |
| 4128 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4129 | return 0; |
| 4130 | |
| 4131 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4132 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4133 | nl80211_sta_wme_policy); |
| 4134 | if (err) |
| 4135 | return err; |
| 4136 | |
| 4137 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4138 | params->uapsd_queues = nla_get_u8( |
| 4139 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4140 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4141 | return -EINVAL; |
| 4142 | |
| 4143 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4144 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4145 | |
| 4146 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4147 | return -EINVAL; |
| 4148 | |
| 4149 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4150 | |
| 4151 | return 0; |
| 4152 | } |
| 4153 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4154 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4155 | struct station_parameters *params) |
| 4156 | { |
| 4157 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4158 | params->supported_channels = |
| 4159 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4160 | params->supported_channels_len = |
| 4161 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4162 | /* |
| 4163 | * Need to include at least one (first channel, number of |
| 4164 | * channels) tuple for each subband, and must have proper |
| 4165 | * tuples for the rest of the data as well. |
| 4166 | */ |
| 4167 | if (params->supported_channels_len < 2) |
| 4168 | return -EINVAL; |
| 4169 | if (params->supported_channels_len % 2) |
| 4170 | return -EINVAL; |
| 4171 | } |
| 4172 | |
| 4173 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4174 | params->supported_oper_classes = |
| 4175 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4176 | params->supported_oper_classes_len = |
| 4177 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4178 | /* |
| 4179 | * The value of the Length field of the Supported Operating |
| 4180 | * Classes element is between 2 and 253. |
| 4181 | */ |
| 4182 | if (params->supported_oper_classes_len < 2 || |
| 4183 | params->supported_oper_classes_len > 253) |
| 4184 | return -EINVAL; |
| 4185 | } |
| 4186 | return 0; |
| 4187 | } |
| 4188 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4189 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4190 | struct station_parameters *params) |
| 4191 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4192 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4193 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4194 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4195 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4196 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4197 | params->ht_capa = |
| 4198 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4199 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4200 | params->vht_capa = |
| 4201 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4202 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4203 | err = nl80211_parse_sta_channel_info(info, params); |
| 4204 | if (err) |
| 4205 | return err; |
| 4206 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4207 | return nl80211_parse_sta_wme(info, params); |
| 4208 | } |
| 4209 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4210 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4211 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4213 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4214 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4215 | u8 *mac_addr; |
| 4216 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4217 | |
| 4218 | memset(¶ms, 0, sizeof(params)); |
| 4219 | |
| 4220 | params.listen_interval = -1; |
| 4221 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4222 | if (!rdev->ops->change_station) |
| 4223 | return -EOPNOTSUPP; |
| 4224 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4225 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4226 | return -EINVAL; |
| 4227 | |
| 4228 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4229 | return -EINVAL; |
| 4230 | |
| 4231 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4232 | |
| 4233 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4234 | params.supported_rates = |
| 4235 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4236 | params.supported_rates_len = |
| 4237 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4238 | } |
| 4239 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4240 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4241 | params.capability = |
| 4242 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4243 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4244 | } |
| 4245 | |
| 4246 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4247 | params.ext_capab = |
| 4248 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4249 | params.ext_capab_len = |
| 4250 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4251 | } |
| 4252 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4253 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4254 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4255 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4256 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4257 | return -EINVAL; |
| 4258 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4259 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4260 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4261 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4262 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4263 | return -EINVAL; |
| 4264 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4265 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4266 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4267 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4268 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4269 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4270 | return -EINVAL; |
| 4271 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4272 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4273 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4274 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4275 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4276 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4277 | |
| 4278 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4279 | pm > NL80211_MESH_POWER_MAX) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | params.local_pm = pm; |
| 4283 | } |
| 4284 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4285 | /* Include parameters for TDLS peer (will check later) */ |
| 4286 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4287 | if (err) |
| 4288 | return err; |
| 4289 | |
| 4290 | params.vlan = get_vlan(info, rdev); |
| 4291 | if (IS_ERR(params.vlan)) |
| 4292 | return PTR_ERR(params.vlan); |
| 4293 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4294 | switch (dev->ieee80211_ptr->iftype) { |
| 4295 | case NL80211_IFTYPE_AP: |
| 4296 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4297 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4298 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4299 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4300 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4301 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4302 | break; |
| 4303 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4304 | err = -EOPNOTSUPP; |
| 4305 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4306 | } |
| 4307 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4308 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4309 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4310 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4311 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4312 | if (params.vlan) |
| 4313 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4314 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4315 | return err; |
| 4316 | } |
| 4317 | |
| 4318 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4321 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4322 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4323 | struct station_parameters params; |
| 4324 | u8 *mac_addr = NULL; |
| 4325 | |
| 4326 | memset(¶ms, 0, sizeof(params)); |
| 4327 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4328 | if (!rdev->ops->add_station) |
| 4329 | return -EOPNOTSUPP; |
| 4330 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4331 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4332 | return -EINVAL; |
| 4333 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4334 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4335 | return -EINVAL; |
| 4336 | |
| 4337 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4338 | return -EINVAL; |
| 4339 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4340 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4341 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4342 | return -EINVAL; |
| 4343 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4344 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4345 | params.supported_rates = |
| 4346 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4347 | params.supported_rates_len = |
| 4348 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4349 | params.listen_interval = |
| 4350 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4351 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4352 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4353 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4354 | else |
| 4355 | 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] | 4356 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4357 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4358 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4359 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4360 | params.capability = |
| 4361 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4362 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4363 | } |
| 4364 | |
| 4365 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4366 | params.ext_capab = |
| 4367 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4368 | params.ext_capab_len = |
| 4369 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4370 | } |
| 4371 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4372 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4373 | params.ht_capa = |
| 4374 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4375 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4376 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4377 | params.vht_capa = |
| 4378 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4379 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4380 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4381 | params.opmode_notif_used = true; |
| 4382 | params.opmode_notif = |
| 4383 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4384 | } |
| 4385 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4386 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4387 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4388 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4389 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4390 | return -EINVAL; |
| 4391 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4392 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4393 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4394 | if (err) |
| 4395 | return err; |
| 4396 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4397 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4398 | if (err) |
| 4399 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4400 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4401 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4402 | return -EINVAL; |
| 4403 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4404 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4405 | * as userspace might just pass through the capabilities from the IEs |
| 4406 | * directly, rather than enforcing this restriction and returning an |
| 4407 | * error in this case. |
| 4408 | */ |
| 4409 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4410 | params.ht_capa = NULL; |
| 4411 | params.vht_capa = NULL; |
| 4412 | } |
| 4413 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4414 | /* When you run into this, adjust the code below for the new flag */ |
| 4415 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4416 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4417 | switch (dev->ieee80211_ptr->iftype) { |
| 4418 | case NL80211_IFTYPE_AP: |
| 4419 | case NL80211_IFTYPE_AP_VLAN: |
| 4420 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4421 | /* ignore WME attributes if iface/sta is not capable */ |
| 4422 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4423 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4424 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4425 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4426 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4427 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4428 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4429 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4430 | /* but don't bother the driver with it */ |
| 4431 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4432 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4433 | /* allow authenticated/associated only if driver handles it */ |
| 4434 | if (!(rdev->wiphy.features & |
| 4435 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4436 | params.sta_flags_mask & |
| 4437 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4438 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4439 | return -EINVAL; |
| 4440 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4441 | /* must be last in here for error handling */ |
| 4442 | params.vlan = get_vlan(info, rdev); |
| 4443 | if (IS_ERR(params.vlan)) |
| 4444 | return PTR_ERR(params.vlan); |
| 4445 | break; |
| 4446 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4447 | /* ignore uAPSD data */ |
| 4448 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4449 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4450 | /* associated is disallowed */ |
| 4451 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4452 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4453 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4454 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4455 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4456 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4457 | break; |
| 4458 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4459 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4460 | /* ignore uAPSD data */ |
| 4461 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4462 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4463 | /* these are disallowed */ |
| 4464 | if (params.sta_flags_mask & |
| 4465 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4466 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4467 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4468 | /* Only TDLS peers can be added */ |
| 4469 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4470 | return -EINVAL; |
| 4471 | /* Can only add if TDLS ... */ |
| 4472 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4473 | return -EOPNOTSUPP; |
| 4474 | /* ... with external setup is supported */ |
| 4475 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4476 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4477 | /* |
| 4478 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4479 | * as authorized, but it shouldn't yet be. |
| 4480 | */ |
| 4481 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4482 | break; |
| 4483 | default: |
| 4484 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4485 | } |
| 4486 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4487 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4488 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4489 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4490 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4491 | if (params.vlan) |
| 4492 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4493 | return err; |
| 4494 | } |
| 4495 | |
| 4496 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4497 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4499 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4500 | struct station_del_parameters params; |
| 4501 | |
| 4502 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4503 | |
| 4504 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4505 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4506 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4507 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4508 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4509 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4511 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4512 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4513 | if (!rdev->ops->del_station) |
| 4514 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4515 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4516 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4517 | params.subtype = |
| 4518 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4519 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4520 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4521 | return -EINVAL; |
| 4522 | } else { |
| 4523 | /* Default to Deauthentication frame */ |
| 4524 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4525 | } |
| 4526 | |
| 4527 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4528 | params.reason_code = |
| 4529 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4530 | if (params.reason_code == 0) |
| 4531 | return -EINVAL; /* 0 is reserved */ |
| 4532 | } else { |
| 4533 | /* Default to reason code 2 */ |
| 4534 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4535 | } |
| 4536 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4537 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4538 | } |
| 4539 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4540 | 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] | 4541 | int flags, struct net_device *dev, |
| 4542 | u8 *dst, u8 *next_hop, |
| 4543 | struct mpath_info *pinfo) |
| 4544 | { |
| 4545 | void *hdr; |
| 4546 | struct nlattr *pinfoattr; |
| 4547 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4548 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4549 | if (!hdr) |
| 4550 | return -1; |
| 4551 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4552 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4553 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4554 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4555 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4556 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4557 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4558 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4559 | if (!pinfoattr) |
| 4560 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4561 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4562 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4563 | pinfo->frame_qlen)) |
| 4564 | goto nla_put_failure; |
| 4565 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4566 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4567 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4568 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4569 | pinfo->metric)) || |
| 4570 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4571 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4572 | pinfo->exptime)) || |
| 4573 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4574 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4575 | pinfo->flags)) || |
| 4576 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4577 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4578 | pinfo->discovery_timeout)) || |
| 4579 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4580 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4581 | pinfo->discovery_retries))) |
| 4582 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4583 | |
| 4584 | nla_nest_end(msg, pinfoattr); |
| 4585 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4586 | genlmsg_end(msg, hdr); |
| 4587 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4588 | |
| 4589 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4590 | genlmsg_cancel(msg, hdr); |
| 4591 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4595 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4596 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4597 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4598 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4599 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4600 | u8 dst[ETH_ALEN]; |
| 4601 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4602 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4603 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4604 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4605 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4606 | if (err) |
| 4607 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4608 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4609 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4610 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4611 | goto out_err; |
| 4612 | } |
| 4613 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4614 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4615 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4616 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4617 | } |
| 4618 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4619 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4620 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4621 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4622 | if (err == -ENOENT) |
| 4623 | break; |
| 4624 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4625 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4626 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4627 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4628 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4629 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4630 | &pinfo) < 0) |
| 4631 | goto out; |
| 4632 | |
| 4633 | path_idx++; |
| 4634 | } |
| 4635 | |
| 4636 | |
| 4637 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4638 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4639 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4640 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4641 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4642 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4646 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4648 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4649 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4650 | struct mpath_info pinfo; |
| 4651 | struct sk_buff *msg; |
| 4652 | u8 *dst = NULL; |
| 4653 | u8 next_hop[ETH_ALEN]; |
| 4654 | |
| 4655 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4656 | |
| 4657 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4658 | return -EINVAL; |
| 4659 | |
| 4660 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4662 | if (!rdev->ops->get_mpath) |
| 4663 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4665 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4666 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4667 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4668 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4669 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4670 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4671 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4673 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4674 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4675 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4676 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4677 | dev, dst, next_hop, &pinfo) < 0) { |
| 4678 | nlmsg_free(msg); |
| 4679 | return -ENOBUFS; |
| 4680 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4682 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4686 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4688 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4689 | u8 *dst = NULL; |
| 4690 | u8 *next_hop = NULL; |
| 4691 | |
| 4692 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4693 | return -EINVAL; |
| 4694 | |
| 4695 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4696 | return -EINVAL; |
| 4697 | |
| 4698 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4699 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4700 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4701 | if (!rdev->ops->change_mpath) |
| 4702 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4703 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4704 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4705 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4706 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4707 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4708 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4709 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4710 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4711 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4713 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4714 | u8 *dst = NULL; |
| 4715 | u8 *next_hop = NULL; |
| 4716 | |
| 4717 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4718 | return -EINVAL; |
| 4719 | |
| 4720 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4721 | return -EINVAL; |
| 4722 | |
| 4723 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4724 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | if (!rdev->ops->add_mpath) |
| 4727 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4728 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4729 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4730 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4731 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4732 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4738 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4739 | u8 *dst = NULL; |
| 4740 | |
| 4741 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4742 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4743 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4744 | if (!rdev->ops->del_mpath) |
| 4745 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4746 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4747 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4748 | } |
| 4749 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4750 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4751 | { |
| 4752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4753 | int err; |
| 4754 | struct net_device *dev = info->user_ptr[1]; |
| 4755 | struct mpath_info pinfo; |
| 4756 | struct sk_buff *msg; |
| 4757 | u8 *dst = NULL; |
| 4758 | u8 mpp[ETH_ALEN]; |
| 4759 | |
| 4760 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4761 | |
| 4762 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4763 | return -EINVAL; |
| 4764 | |
| 4765 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4766 | |
| 4767 | if (!rdev->ops->get_mpp) |
| 4768 | return -EOPNOTSUPP; |
| 4769 | |
| 4770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4771 | return -EOPNOTSUPP; |
| 4772 | |
| 4773 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4774 | if (err) |
| 4775 | return err; |
| 4776 | |
| 4777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4778 | if (!msg) |
| 4779 | return -ENOMEM; |
| 4780 | |
| 4781 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4782 | dev, dst, mpp, &pinfo) < 0) { |
| 4783 | nlmsg_free(msg); |
| 4784 | return -ENOBUFS; |
| 4785 | } |
| 4786 | |
| 4787 | return genlmsg_reply(msg, info); |
| 4788 | } |
| 4789 | |
| 4790 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4791 | struct netlink_callback *cb) |
| 4792 | { |
| 4793 | struct mpath_info pinfo; |
| 4794 | struct cfg80211_registered_device *rdev; |
| 4795 | struct wireless_dev *wdev; |
| 4796 | u8 dst[ETH_ALEN]; |
| 4797 | u8 mpp[ETH_ALEN]; |
| 4798 | int path_idx = cb->args[2]; |
| 4799 | int err; |
| 4800 | |
| 4801 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4802 | if (err) |
| 4803 | return err; |
| 4804 | |
| 4805 | if (!rdev->ops->dump_mpp) { |
| 4806 | err = -EOPNOTSUPP; |
| 4807 | goto out_err; |
| 4808 | } |
| 4809 | |
| 4810 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4811 | err = -EOPNOTSUPP; |
| 4812 | goto out_err; |
| 4813 | } |
| 4814 | |
| 4815 | while (1) { |
| 4816 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4817 | mpp, &pinfo); |
| 4818 | if (err == -ENOENT) |
| 4819 | break; |
| 4820 | if (err) |
| 4821 | goto out_err; |
| 4822 | |
| 4823 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4824 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4825 | wdev->netdev, dst, mpp, |
| 4826 | &pinfo) < 0) |
| 4827 | goto out; |
| 4828 | |
| 4829 | path_idx++; |
| 4830 | } |
| 4831 | |
| 4832 | out: |
| 4833 | cb->args[2] = path_idx; |
| 4834 | err = skb->len; |
| 4835 | out_err: |
| 4836 | nl80211_finish_wdev_dump(rdev); |
| 4837 | return err; |
| 4838 | } |
| 4839 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4840 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4843 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4844 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4845 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4846 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4847 | |
| 4848 | memset(¶ms, 0, sizeof(params)); |
| 4849 | /* default to not changing parameters */ |
| 4850 | params.use_cts_prot = -1; |
| 4851 | params.use_short_preamble = -1; |
| 4852 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4853 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4854 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4855 | params.p2p_ctwindow = -1; |
| 4856 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4857 | |
| 4858 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4859 | params.use_cts_prot = |
| 4860 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4861 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4862 | params.use_short_preamble = |
| 4863 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4864 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4865 | params.use_short_slot_time = |
| 4866 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4867 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4868 | params.basic_rates = |
| 4869 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4870 | params.basic_rates_len = |
| 4871 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4872 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4873 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4874 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4875 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4876 | params.ht_opmode = |
| 4877 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4878 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4879 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4881 | return -EINVAL; |
| 4882 | params.p2p_ctwindow = |
| 4883 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4884 | if (params.p2p_ctwindow < 0) |
| 4885 | return -EINVAL; |
| 4886 | if (params.p2p_ctwindow != 0 && |
| 4887 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4888 | return -EINVAL; |
| 4889 | } |
| 4890 | |
| 4891 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4892 | u8 tmp; |
| 4893 | |
| 4894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4895 | return -EINVAL; |
| 4896 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4897 | if (tmp > 1) |
| 4898 | return -EINVAL; |
| 4899 | params.p2p_opp_ps = tmp; |
| 4900 | if (params.p2p_opp_ps && |
| 4901 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4902 | return -EINVAL; |
| 4903 | } |
| 4904 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4905 | if (!rdev->ops->change_bss) |
| 4906 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4907 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4908 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4909 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4910 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4911 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4912 | wdev_lock(wdev); |
| 4913 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4914 | wdev_unlock(wdev); |
| 4915 | |
| 4916 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4917 | } |
| 4918 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4919 | 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] | 4920 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4921 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4922 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4923 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4924 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4925 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4926 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4927 | }; |
| 4928 | |
| 4929 | static int parse_reg_rule(struct nlattr *tb[], |
| 4930 | struct ieee80211_reg_rule *reg_rule) |
| 4931 | { |
| 4932 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4933 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4934 | |
| 4935 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4936 | return -EINVAL; |
| 4937 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4938 | return -EINVAL; |
| 4939 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4940 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4941 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4942 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4943 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4944 | return -EINVAL; |
| 4945 | |
| 4946 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4947 | |
| 4948 | freq_range->start_freq_khz = |
| 4949 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4950 | freq_range->end_freq_khz = |
| 4951 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4952 | freq_range->max_bandwidth_khz = |
| 4953 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4954 | |
| 4955 | power_rule->max_eirp = |
| 4956 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4957 | |
| 4958 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4959 | power_rule->max_antenna_gain = |
| 4960 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4961 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4962 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4963 | reg_rule->dfs_cac_ms = |
| 4964 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4965 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4966 | return 0; |
| 4967 | } |
| 4968 | |
| 4969 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4970 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4971 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4972 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4973 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 4974 | u32 owner_nlportid; |
| 4975 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4976 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4977 | /* |
| 4978 | * You should only get this when cfg80211 hasn't yet initialized |
| 4979 | * completely when built-in to the kernel right between the time |
| 4980 | * window between nl80211_init() and regulatory_init(), if that is |
| 4981 | * even possible. |
| 4982 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4983 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4984 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4985 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4986 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4987 | user_reg_hint_type = |
| 4988 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4989 | else |
| 4990 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4991 | |
| 4992 | switch (user_reg_hint_type) { |
| 4993 | case NL80211_USER_REG_HINT_USER: |
| 4994 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4995 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4996 | return -EINVAL; |
| 4997 | |
| 4998 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4999 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5000 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5001 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5002 | owner_nlportid = info->snd_portid; |
| 5003 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5004 | } else { |
| 5005 | owner_nlportid = 0; |
| 5006 | is_indoor = true; |
| 5007 | } |
| 5008 | |
| 5009 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5010 | default: |
| 5011 | return -EINVAL; |
| 5012 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5015 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5016 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5017 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5019 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5021 | struct mesh_config cur_params; |
| 5022 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5023 | void *hdr; |
| 5024 | struct nlattr *pinfoattr; |
| 5025 | struct sk_buff *msg; |
| 5026 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5027 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5028 | return -EOPNOTSUPP; |
| 5029 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5030 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5031 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5032 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5033 | wdev_lock(wdev); |
| 5034 | /* If not connected, get default parameters */ |
| 5035 | if (!wdev->mesh_id_len) |
| 5036 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5037 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5038 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5039 | wdev_unlock(wdev); |
| 5040 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5041 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5042 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5043 | |
| 5044 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5046 | if (!msg) |
| 5047 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5048 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5049 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5050 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5051 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5052 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5053 | if (!pinfoattr) |
| 5054 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5055 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5056 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5057 | cur_params.dot11MeshRetryTimeout) || |
| 5058 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5059 | cur_params.dot11MeshConfirmTimeout) || |
| 5060 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5061 | cur_params.dot11MeshHoldingTimeout) || |
| 5062 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5063 | cur_params.dot11MeshMaxPeerLinks) || |
| 5064 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5065 | cur_params.dot11MeshMaxRetries) || |
| 5066 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5067 | cur_params.dot11MeshTTL) || |
| 5068 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5069 | cur_params.element_ttl) || |
| 5070 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5071 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5072 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5073 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5074 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5075 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5076 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5077 | cur_params.path_refresh_time) || |
| 5078 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5079 | cur_params.min_discovery_timeout) || |
| 5080 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5081 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5082 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5083 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5084 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5085 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5086 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5087 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5088 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5089 | cur_params.dot11MeshHWMPRootMode) || |
| 5090 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5091 | cur_params.dot11MeshHWMPRannInterval) || |
| 5092 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5093 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5094 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5095 | cur_params.dot11MeshForwarding) || |
| 5096 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5097 | cur_params.rssi_threshold) || |
| 5098 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5099 | cur_params.ht_opmode) || |
| 5100 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5101 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5102 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5103 | cur_params.dot11MeshHWMProotInterval) || |
| 5104 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5105 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5106 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5107 | cur_params.power_mode) || |
| 5108 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5109 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5110 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5111 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5112 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5113 | nla_nest_end(msg, pinfoattr); |
| 5114 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5115 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5116 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5117 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5118 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5119 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5120 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5124 | 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] | 5125 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5126 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5127 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5128 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5129 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5130 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5131 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5132 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5133 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5134 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5135 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5136 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5137 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5138 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5139 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5140 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5141 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5142 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5143 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5144 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5145 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5146 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5147 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5148 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5149 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5150 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5151 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5152 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5153 | }; |
| 5154 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5155 | static const struct nla_policy |
| 5156 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5157 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5158 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5159 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5160 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5161 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5162 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5163 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5164 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5165 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5166 | }; |
| 5167 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5168 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5169 | struct mesh_config *cfg, |
| 5170 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5171 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5172 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5173 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5174 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5175 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5176 | do { \ |
| 5177 | if (tb[attr]) { \ |
| 5178 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5179 | return -EINVAL; \ |
| 5180 | cfg->param = fn(tb[attr]); \ |
| 5181 | mask |= (1 << (attr - 1)); \ |
| 5182 | } \ |
| 5183 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5184 | |
| 5185 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5186 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5187 | return -EINVAL; |
| 5188 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5189 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5190 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5191 | return -EINVAL; |
| 5192 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5193 | /* This makes sure that there aren't more than 32 mesh config |
| 5194 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5195 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5196 | |
| 5197 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5199 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5200 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5201 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5202 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5203 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5204 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5205 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5206 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5207 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5208 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5209 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5211 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5212 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5213 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5214 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5215 | 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] | 5216 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5217 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5218 | 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] | 5219 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5220 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5222 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5223 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5224 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5226 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5227 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5229 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5230 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5231 | 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] | 5232 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5233 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5235 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5236 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5237 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5239 | 1, 65535, mask, |
| 5240 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5241 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5243 | 1, 65535, mask, |
| 5244 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5245 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5247 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5248 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5249 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5250 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5251 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5252 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5253 | nla_get_u8); |
| 5254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5255 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5256 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5257 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5258 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5259 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5260 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5261 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5262 | mask, NL80211_MESHCONF_FORWARDING, |
| 5263 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5264 | 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] | 5265 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5266 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5267 | 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] | 5268 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5269 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5270 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5271 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5272 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5273 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5275 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5276 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5278 | dot11MeshHWMPconfirmationInterval, |
| 5279 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5280 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5281 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5282 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5283 | NL80211_MESH_POWER_ACTIVE, |
| 5284 | NL80211_MESH_POWER_MAX, |
| 5285 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5286 | nla_get_u32); |
| 5287 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5288 | 0, 65535, mask, |
| 5289 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5290 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5291 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5292 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5293 | if (mask_out) |
| 5294 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5295 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5296 | return 0; |
| 5297 | |
| 5298 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5299 | } |
| 5300 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5301 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5302 | struct mesh_setup *setup) |
| 5303 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5305 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5306 | |
| 5307 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5308 | return -EINVAL; |
| 5309 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5310 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5311 | nl80211_mesh_setup_params_policy)) |
| 5312 | return -EINVAL; |
| 5313 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5314 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5315 | setup->sync_method = |
| 5316 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5317 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5318 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5319 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5320 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5321 | setup->path_sel_proto = |
| 5322 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5323 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5324 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5325 | |
| 5326 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5327 | setup->path_metric = |
| 5328 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5329 | IEEE80211_PATH_METRIC_VENDOR : |
| 5330 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5331 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5332 | |
| 5333 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5334 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5335 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5336 | if (!is_valid_ie_attr(ieattr)) |
| 5337 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5338 | setup->ie = nla_data(ieattr); |
| 5339 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5340 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5341 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5342 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5343 | return -EINVAL; |
| 5344 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5345 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5346 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5347 | if (setup->is_secure) |
| 5348 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5349 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5350 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5351 | if (!setup->user_mpm) |
| 5352 | return -EINVAL; |
| 5353 | setup->auth_id = |
| 5354 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5355 | } |
| 5356 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5357 | return 0; |
| 5358 | } |
| 5359 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5360 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5361 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5362 | { |
| 5363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5364 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5365 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5366 | struct mesh_config cfg; |
| 5367 | u32 mask; |
| 5368 | int err; |
| 5369 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5370 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5371 | return -EOPNOTSUPP; |
| 5372 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5373 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5374 | return -EOPNOTSUPP; |
| 5375 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5376 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5377 | if (err) |
| 5378 | return err; |
| 5379 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5380 | wdev_lock(wdev); |
| 5381 | if (!wdev->mesh_id_len) |
| 5382 | err = -ENOLINK; |
| 5383 | |
| 5384 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5385 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5386 | |
| 5387 | wdev_unlock(wdev); |
| 5388 | |
| 5389 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5390 | } |
| 5391 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5392 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5393 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5394 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5395 | struct nlattr *nl_reg_rules; |
| 5396 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5397 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5398 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5399 | (regdom->dfs_region && |
| 5400 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5401 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5402 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5403 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5404 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5405 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5406 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5407 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5408 | struct nlattr *nl_reg_rule; |
| 5409 | const struct ieee80211_reg_rule *reg_rule; |
| 5410 | const struct ieee80211_freq_range *freq_range; |
| 5411 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5412 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5413 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5414 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5415 | freq_range = ®_rule->freq_range; |
| 5416 | power_rule = ®_rule->power_rule; |
| 5417 | |
| 5418 | nl_reg_rule = nla_nest_start(msg, i); |
| 5419 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5420 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5421 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5422 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5423 | if (!max_bandwidth_khz) |
| 5424 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5425 | reg_rule); |
| 5426 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5427 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5428 | reg_rule->flags) || |
| 5429 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5430 | freq_range->start_freq_khz) || |
| 5431 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5432 | freq_range->end_freq_khz) || |
| 5433 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5434 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5435 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5436 | power_rule->max_antenna_gain) || |
| 5437 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5438 | power_rule->max_eirp) || |
| 5439 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5440 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5441 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5442 | |
| 5443 | nla_nest_end(msg, nl_reg_rule); |
| 5444 | } |
| 5445 | |
| 5446 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5447 | return 0; |
| 5448 | |
| 5449 | nla_put_failure: |
| 5450 | return -EMSGSIZE; |
| 5451 | } |
| 5452 | |
| 5453 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5454 | { |
| 5455 | const struct ieee80211_regdomain *regdom = NULL; |
| 5456 | struct cfg80211_registered_device *rdev; |
| 5457 | struct wiphy *wiphy = NULL; |
| 5458 | struct sk_buff *msg; |
| 5459 | void *hdr; |
| 5460 | |
| 5461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5462 | if (!msg) |
| 5463 | return -ENOBUFS; |
| 5464 | |
| 5465 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5466 | NL80211_CMD_GET_REG); |
| 5467 | if (!hdr) |
| 5468 | goto put_failure; |
| 5469 | |
| 5470 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5471 | bool self_managed; |
| 5472 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5473 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5474 | if (IS_ERR(rdev)) { |
| 5475 | nlmsg_free(msg); |
| 5476 | return PTR_ERR(rdev); |
| 5477 | } |
| 5478 | |
| 5479 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5480 | self_managed = wiphy->regulatory_flags & |
| 5481 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5482 | regdom = get_wiphy_regdom(wiphy); |
| 5483 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5484 | /* a self-managed-reg device must have a private regdom */ |
| 5485 | if (WARN_ON(!regdom && self_managed)) { |
| 5486 | nlmsg_free(msg); |
| 5487 | return -EINVAL; |
| 5488 | } |
| 5489 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5490 | if (regdom && |
| 5491 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5492 | goto nla_put_failure; |
| 5493 | } |
| 5494 | |
| 5495 | if (!wiphy && reg_last_request_cell_base() && |
| 5496 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5497 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5498 | goto nla_put_failure; |
| 5499 | |
| 5500 | rcu_read_lock(); |
| 5501 | |
| 5502 | if (!regdom) |
| 5503 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5504 | |
| 5505 | if (nl80211_put_regdom(regdom, msg)) |
| 5506 | goto nla_put_failure_rcu; |
| 5507 | |
| 5508 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5509 | |
| 5510 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5511 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5512 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5513 | nla_put_failure_rcu: |
| 5514 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5515 | nla_put_failure: |
| 5516 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5517 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5518 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5519 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5520 | } |
| 5521 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5522 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5523 | u32 seq, int flags, struct wiphy *wiphy, |
| 5524 | const struct ieee80211_regdomain *regdom) |
| 5525 | { |
| 5526 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5527 | NL80211_CMD_GET_REG); |
| 5528 | |
| 5529 | if (!hdr) |
| 5530 | return -1; |
| 5531 | |
| 5532 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5533 | |
| 5534 | if (nl80211_put_regdom(regdom, msg)) |
| 5535 | goto nla_put_failure; |
| 5536 | |
| 5537 | if (!wiphy && reg_last_request_cell_base() && |
| 5538 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5539 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5540 | goto nla_put_failure; |
| 5541 | |
| 5542 | if (wiphy && |
| 5543 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5544 | goto nla_put_failure; |
| 5545 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5546 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5547 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5548 | goto nla_put_failure; |
| 5549 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5550 | genlmsg_end(msg, hdr); |
| 5551 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5552 | |
| 5553 | nla_put_failure: |
| 5554 | genlmsg_cancel(msg, hdr); |
| 5555 | return -EMSGSIZE; |
| 5556 | } |
| 5557 | |
| 5558 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5559 | struct netlink_callback *cb) |
| 5560 | { |
| 5561 | const struct ieee80211_regdomain *regdom = NULL; |
| 5562 | struct cfg80211_registered_device *rdev; |
| 5563 | int err, reg_idx, start = cb->args[2]; |
| 5564 | |
| 5565 | rtnl_lock(); |
| 5566 | |
| 5567 | if (cfg80211_regdomain && start == 0) { |
| 5568 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5569 | NLM_F_MULTI, NULL, |
| 5570 | rtnl_dereference(cfg80211_regdomain)); |
| 5571 | if (err < 0) |
| 5572 | goto out_err; |
| 5573 | } |
| 5574 | |
| 5575 | /* the global regdom is idx 0 */ |
| 5576 | reg_idx = 1; |
| 5577 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5578 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5579 | if (!regdom) |
| 5580 | continue; |
| 5581 | |
| 5582 | if (++reg_idx <= start) |
| 5583 | continue; |
| 5584 | |
| 5585 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5586 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5587 | if (err < 0) { |
| 5588 | reg_idx--; |
| 5589 | break; |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | cb->args[2] = reg_idx; |
| 5594 | err = skb->len; |
| 5595 | out_err: |
| 5596 | rtnl_unlock(); |
| 5597 | return err; |
| 5598 | } |
| 5599 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5600 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5601 | { |
| 5602 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5603 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5604 | char *alpha2; |
| 5605 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5606 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5607 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5608 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5609 | |
| 5610 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5611 | return -EINVAL; |
| 5612 | |
| 5613 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5614 | return -EINVAL; |
| 5615 | |
| 5616 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5617 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5618 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5619 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5620 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5621 | 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] | 5622 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5623 | num_rules++; |
| 5624 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5625 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5626 | } |
| 5627 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5628 | if (!reg_is_valid_request(alpha2)) |
| 5629 | return -EINVAL; |
| 5630 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5631 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5632 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5633 | |
| 5634 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5635 | if (!rd) |
| 5636 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5637 | |
| 5638 | rd->n_reg_rules = num_rules; |
| 5639 | rd->alpha2[0] = alpha2[0]; |
| 5640 | rd->alpha2[1] = alpha2[1]; |
| 5641 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5642 | /* |
| 5643 | * Disable DFS master mode if the DFS region was |
| 5644 | * not supported or known on this kernel. |
| 5645 | */ |
| 5646 | if (reg_supported_dfs_region(dfs_region)) |
| 5647 | rd->dfs_region = dfs_region; |
| 5648 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5649 | 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] | 5650 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5651 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5652 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5653 | reg_rule_policy); |
| 5654 | if (r) |
| 5655 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5656 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5657 | if (r) |
| 5658 | goto bad_reg; |
| 5659 | |
| 5660 | rule_idx++; |
| 5661 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5662 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5663 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5664 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5665 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5666 | } |
| 5667 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 5668 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5669 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5670 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5671 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5672 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5673 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5674 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5677 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5678 | { |
| 5679 | struct nlattr *attr1, *attr2; |
| 5680 | int n_channels = 0, tmp1, tmp2; |
| 5681 | |
| 5682 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5683 | n_channels++; |
| 5684 | /* |
| 5685 | * Some hardware has a limited channel list for |
| 5686 | * scanning, and it is pretty much nonsensical |
| 5687 | * to scan for a channel twice, so disallow that |
| 5688 | * and don't require drivers to check that the |
| 5689 | * channel list they get isn't longer than what |
| 5690 | * they can scan, as long as they can scan all |
| 5691 | * the channels they registered at once. |
| 5692 | */ |
| 5693 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5694 | if (attr1 != attr2 && |
| 5695 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5696 | return 0; |
| 5697 | } |
| 5698 | |
| 5699 | return n_channels; |
| 5700 | } |
| 5701 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5702 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5703 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5704 | { |
| 5705 | int i; |
| 5706 | |
| 5707 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 5708 | eth_zero_addr(mac_addr); |
| 5709 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5710 | mac_addr[0] = 0x2; |
| 5711 | mac_addr_mask[0] = 0x3; |
| 5712 | |
| 5713 | return 0; |
| 5714 | } |
| 5715 | |
| 5716 | /* need both or none */ |
| 5717 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5718 | return -EINVAL; |
| 5719 | |
| 5720 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5721 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5722 | |
| 5723 | /* don't allow or configure an mcast address */ |
| 5724 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5725 | is_multicast_ether_addr(mac_addr)) |
| 5726 | return -EINVAL; |
| 5727 | |
| 5728 | /* |
| 5729 | * allow users to pass a MAC address that has bits set outside |
| 5730 | * of the mask, but don't bother drivers with having to deal |
| 5731 | * with such bits |
| 5732 | */ |
| 5733 | for (i = 0; i < ETH_ALEN; i++) |
| 5734 | mac_addr[i] &= mac_addr_mask[i]; |
| 5735 | |
| 5736 | return 0; |
| 5737 | } |
| 5738 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5739 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5740 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5742 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5743 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5744 | struct nlattr *attr; |
| 5745 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5746 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5747 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5748 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5749 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5750 | return -EINVAL; |
| 5751 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5752 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5753 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5754 | if (!rdev->ops->scan) |
| 5755 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5756 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5757 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5758 | err = -EBUSY; |
| 5759 | goto unlock; |
| 5760 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5761 | |
| 5762 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5763 | n_channels = validate_scan_freqs( |
| 5764 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5765 | if (!n_channels) { |
| 5766 | err = -EINVAL; |
| 5767 | goto unlock; |
| 5768 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5769 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5770 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5774 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5775 | n_ssids++; |
| 5776 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5777 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5778 | err = -EINVAL; |
| 5779 | goto unlock; |
| 5780 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5781 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5782 | if (info->attrs[NL80211_ATTR_IE]) |
| 5783 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5784 | else |
| 5785 | ie_len = 0; |
| 5786 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5787 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5788 | err = -EINVAL; |
| 5789 | goto unlock; |
| 5790 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5791 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5792 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5793 | + sizeof(*request->ssids) * n_ssids |
| 5794 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5795 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5796 | if (!request) { |
| 5797 | err = -ENOMEM; |
| 5798 | goto unlock; |
| 5799 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5800 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5801 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5802 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5803 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5804 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5805 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5806 | request->ie = (void *)(request->ssids + n_ssids); |
| 5807 | else |
| 5808 | request->ie = (void *)(request->channels + n_channels); |
| 5809 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5810 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5811 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5812 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5813 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5814 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5815 | struct ieee80211_channel *chan; |
| 5816 | |
| 5817 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5818 | |
| 5819 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5820 | err = -EINVAL; |
| 5821 | goto out_free; |
| 5822 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5823 | |
| 5824 | /* ignore disabled channels */ |
| 5825 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5826 | continue; |
| 5827 | |
| 5828 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5829 | i++; |
| 5830 | } |
| 5831 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5832 | enum ieee80211_band band; |
| 5833 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5834 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5835 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5836 | int j; |
| 5837 | if (!wiphy->bands[band]) |
| 5838 | continue; |
| 5839 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5840 | struct ieee80211_channel *chan; |
| 5841 | |
| 5842 | chan = &wiphy->bands[band]->channels[j]; |
| 5843 | |
| 5844 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5845 | continue; |
| 5846 | |
| 5847 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5848 | i++; |
| 5849 | } |
| 5850 | } |
| 5851 | } |
| 5852 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5853 | if (!i) { |
| 5854 | err = -EINVAL; |
| 5855 | goto out_free; |
| 5856 | } |
| 5857 | |
| 5858 | request->n_channels = i; |
| 5859 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5860 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 5861 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5863 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5864 | err = -EINVAL; |
| 5865 | goto out_free; |
| 5866 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5867 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5868 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5869 | i++; |
| 5870 | } |
| 5871 | } |
| 5872 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5873 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5874 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5875 | memcpy((void *)request->ie, |
| 5876 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5877 | request->ie_len); |
| 5878 | } |
| 5879 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5880 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5881 | if (wiphy->bands[i]) |
| 5882 | request->rates[i] = |
| 5883 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5884 | |
| 5885 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5886 | nla_for_each_nested(attr, |
| 5887 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5888 | tmp) { |
| 5889 | enum ieee80211_band band = nla_type(attr); |
| 5890 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5891 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5892 | err = -EINVAL; |
| 5893 | goto out_free; |
| 5894 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5895 | |
| 5896 | if (!wiphy->bands[band]) |
| 5897 | continue; |
| 5898 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5899 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5900 | nla_data(attr), |
| 5901 | nla_len(attr), |
| 5902 | &request->rates[band]); |
| 5903 | if (err) |
| 5904 | goto out_free; |
| 5905 | } |
| 5906 | } |
| 5907 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5908 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5909 | request->flags = nla_get_u32( |
| 5910 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5911 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5912 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5913 | err = -EOPNOTSUPP; |
| 5914 | goto out_free; |
| 5915 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5916 | |
| 5917 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5918 | if (!(wiphy->features & |
| 5919 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5920 | err = -EOPNOTSUPP; |
| 5921 | goto out_free; |
| 5922 | } |
| 5923 | |
| 5924 | if (wdev->current_bss) { |
| 5925 | err = -EOPNOTSUPP; |
| 5926 | goto out_free; |
| 5927 | } |
| 5928 | |
| 5929 | err = nl80211_parse_random_mac(info->attrs, |
| 5930 | request->mac_addr, |
| 5931 | request->mac_addr_mask); |
| 5932 | if (err) |
| 5933 | goto out_free; |
| 5934 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5935 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5936 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5937 | request->no_cck = |
| 5938 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5939 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5940 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5941 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5942 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5943 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5944 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5945 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5946 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5947 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5948 | nl80211_send_scan_start(rdev, wdev); |
| 5949 | if (wdev->netdev) |
| 5950 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5951 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5952 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5953 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5954 | kfree(request); |
| 5955 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5956 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5957 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5958 | return err; |
| 5959 | } |
| 5960 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5961 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5962 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5963 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5964 | { |
| 5965 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5966 | struct nlattr *attr; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5967 | 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] | 5968 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5969 | enum ieee80211_band band; |
| 5970 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5971 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5972 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5973 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5974 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 5975 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5976 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5977 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5978 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5979 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5980 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5981 | if (interval == 0) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5982 | return ERR_PTR(-EINVAL); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5983 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5984 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5985 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5986 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5987 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5988 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5989 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5990 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5991 | } |
| 5992 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5993 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5994 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5995 | tmp) |
| 5996 | n_ssids++; |
| 5997 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5998 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5999 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6000 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6001 | /* |
| 6002 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6003 | * the old implementation, matchsets containing only the RSSI attribute |
| 6004 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6005 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6006 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6007 | * older userspace that treated a matchset with only the RSSI as the |
| 6008 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6009 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6010 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6011 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6012 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6013 | tmp) { |
| 6014 | struct nlattr *rssi; |
| 6015 | |
| 6016 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6017 | nla_data(attr), nla_len(attr), |
| 6018 | nl80211_match_policy); |
| 6019 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6020 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6021 | /* add other standalone attributes here */ |
| 6022 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6023 | n_match_sets++; |
| 6024 | continue; |
| 6025 | } |
| 6026 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6027 | if (rssi) |
| 6028 | default_match_rssi = nla_get_s32(rssi); |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /* However, if there's no other matchset, add the RSSI one */ |
| 6033 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6034 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6035 | |
| 6036 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6037 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6038 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6039 | if (attrs[NL80211_ATTR_IE]) |
| 6040 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6041 | else |
| 6042 | ie_len = 0; |
| 6043 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6044 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6045 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6046 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6047 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6048 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6049 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6050 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6051 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6052 | if (!request) |
| 6053 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6054 | |
| 6055 | if (n_ssids) |
| 6056 | request->ssids = (void *)&request->channels[n_channels]; |
| 6057 | request->n_ssids = n_ssids; |
| 6058 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6059 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6060 | request->ie = (void *)(request->ssids + n_ssids); |
| 6061 | else |
| 6062 | request->ie = (void *)(request->channels + n_channels); |
| 6063 | } |
| 6064 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6065 | if (n_match_sets) { |
| 6066 | if (request->ie) |
| 6067 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6068 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6069 | request->match_sets = |
| 6070 | (void *)(request->ssids + n_ssids); |
| 6071 | else |
| 6072 | request->match_sets = |
| 6073 | (void *)(request->channels + n_channels); |
| 6074 | } |
| 6075 | request->n_match_sets = n_match_sets; |
| 6076 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6077 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6078 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6079 | /* user specified, bail out if channel not found */ |
| 6080 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6081 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6082 | tmp) { |
| 6083 | struct ieee80211_channel *chan; |
| 6084 | |
| 6085 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6086 | |
| 6087 | if (!chan) { |
| 6088 | err = -EINVAL; |
| 6089 | goto out_free; |
| 6090 | } |
| 6091 | |
| 6092 | /* ignore disabled channels */ |
| 6093 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6094 | continue; |
| 6095 | |
| 6096 | request->channels[i] = chan; |
| 6097 | i++; |
| 6098 | } |
| 6099 | } else { |
| 6100 | /* all channels */ |
| 6101 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6102 | int j; |
| 6103 | if (!wiphy->bands[band]) |
| 6104 | continue; |
| 6105 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6106 | struct ieee80211_channel *chan; |
| 6107 | |
| 6108 | chan = &wiphy->bands[band]->channels[j]; |
| 6109 | |
| 6110 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6111 | continue; |
| 6112 | |
| 6113 | request->channels[i] = chan; |
| 6114 | i++; |
| 6115 | } |
| 6116 | } |
| 6117 | } |
| 6118 | |
| 6119 | if (!i) { |
| 6120 | err = -EINVAL; |
| 6121 | goto out_free; |
| 6122 | } |
| 6123 | |
| 6124 | request->n_channels = i; |
| 6125 | |
| 6126 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6127 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6128 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6129 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6130 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6131 | err = -EINVAL; |
| 6132 | goto out_free; |
| 6133 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6134 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6135 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6136 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6137 | i++; |
| 6138 | } |
| 6139 | } |
| 6140 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6141 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6142 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6143 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6144 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6145 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6146 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6147 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6148 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6149 | nla_data(attr), nla_len(attr), |
| 6150 | nl80211_match_policy); |
| 6151 | if (err) |
| 6152 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6153 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6154 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6155 | if (WARN_ON(i >= n_match_sets)) { |
| 6156 | /* this indicates a programming error, |
| 6157 | * the loop above should have verified |
| 6158 | * things properly |
| 6159 | */ |
| 6160 | err = -EINVAL; |
| 6161 | goto out_free; |
| 6162 | } |
| 6163 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6164 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6165 | err = -EINVAL; |
| 6166 | goto out_free; |
| 6167 | } |
| 6168 | memcpy(request->match_sets[i].ssid.ssid, |
| 6169 | nla_data(ssid), nla_len(ssid)); |
| 6170 | request->match_sets[i].ssid.ssid_len = |
| 6171 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6172 | /* special attribute - old implemenation w/a */ |
| 6173 | request->match_sets[i].rssi_thold = |
| 6174 | default_match_rssi; |
| 6175 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6176 | if (rssi) |
| 6177 | request->match_sets[i].rssi_thold = |
| 6178 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6179 | } |
| 6180 | i++; |
| 6181 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6182 | |
| 6183 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6184 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6185 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6186 | |
| 6187 | request->min_rssi_thold = INT_MAX; |
| 6188 | for (i = 0; i < n_match_sets; i++) |
| 6189 | request->min_rssi_thold = |
| 6190 | min(request->match_sets[i].rssi_thold, |
| 6191 | request->min_rssi_thold); |
| 6192 | } else { |
| 6193 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6194 | } |
| 6195 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6196 | if (ie_len) { |
| 6197 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6198 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6199 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6200 | request->ie_len); |
| 6201 | } |
| 6202 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6203 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6204 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6205 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6206 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6207 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6208 | err = -EOPNOTSUPP; |
| 6209 | goto out_free; |
| 6210 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6211 | |
| 6212 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6213 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6214 | |
| 6215 | if (!wdev) /* must be net-detect */ |
| 6216 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6217 | |
| 6218 | if (!(wiphy->features & flg)) { |
| 6219 | err = -EOPNOTSUPP; |
| 6220 | goto out_free; |
| 6221 | } |
| 6222 | |
| 6223 | if (wdev && wdev->current_bss) { |
| 6224 | err = -EOPNOTSUPP; |
| 6225 | goto out_free; |
| 6226 | } |
| 6227 | |
| 6228 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6229 | request->mac_addr_mask); |
| 6230 | if (err) |
| 6231 | goto out_free; |
| 6232 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6233 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6234 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6235 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6236 | request->delay = |
| 6237 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6238 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 6239 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6240 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6241 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6242 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6243 | |
| 6244 | out_free: |
| 6245 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6246 | return ERR_PTR(err); |
| 6247 | } |
| 6248 | |
| 6249 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6250 | struct genl_info *info) |
| 6251 | { |
| 6252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6253 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6254 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6255 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6256 | int err; |
| 6257 | |
| 6258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6259 | !rdev->ops->sched_scan_start) |
| 6260 | return -EOPNOTSUPP; |
| 6261 | |
| 6262 | if (rdev->sched_scan_req) |
| 6263 | return -EINPROGRESS; |
| 6264 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6265 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6266 | info->attrs); |
| 6267 | |
| 6268 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6269 | if (err) |
| 6270 | goto out_err; |
| 6271 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6272 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6273 | if (err) |
| 6274 | goto out_free; |
| 6275 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6276 | sched_scan_req->dev = dev; |
| 6277 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6278 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6279 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6280 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6281 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6282 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6283 | |
| 6284 | nl80211_send_sched_scan(rdev, dev, |
| 6285 | NL80211_CMD_START_SCHED_SCAN); |
| 6286 | return 0; |
| 6287 | |
| 6288 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6289 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6290 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6291 | return err; |
| 6292 | } |
| 6293 | |
| 6294 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6295 | struct genl_info *info) |
| 6296 | { |
| 6297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6298 | |
| 6299 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6300 | !rdev->ops->sched_scan_stop) |
| 6301 | return -EOPNOTSUPP; |
| 6302 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6303 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6304 | } |
| 6305 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6306 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6307 | struct genl_info *info) |
| 6308 | { |
| 6309 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6310 | struct net_device *dev = info->user_ptr[1]; |
| 6311 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6312 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6313 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6314 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6315 | int err; |
| 6316 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6317 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6318 | if (dfs_region == NL80211_DFS_UNSET) |
| 6319 | return -EINVAL; |
| 6320 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6321 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6322 | if (err) |
| 6323 | return err; |
| 6324 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6325 | if (netif_carrier_ok(dev)) |
| 6326 | return -EBUSY; |
| 6327 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6328 | if (wdev->cac_started) |
| 6329 | return -EBUSY; |
| 6330 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6331 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6332 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6333 | if (err < 0) |
| 6334 | return err; |
| 6335 | |
| 6336 | if (err == 0) |
| 6337 | return -EINVAL; |
| 6338 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6339 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6340 | return -EINVAL; |
| 6341 | |
| 6342 | if (!rdev->ops->start_radar_detection) |
| 6343 | return -EOPNOTSUPP; |
| 6344 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6345 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6346 | if (WARN_ON(!cac_time_ms)) |
| 6347 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6348 | |
| 6349 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6350 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6351 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6352 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6353 | wdev->cac_started = true; |
| 6354 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6355 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6356 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6357 | return err; |
| 6358 | } |
| 6359 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6360 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6361 | { |
| 6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6363 | struct net_device *dev = info->user_ptr[1]; |
| 6364 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6365 | struct cfg80211_csa_settings params; |
| 6366 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6367 | * function is called under RTNL lock, so this should not be a problem. |
| 6368 | */ |
| 6369 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6370 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6371 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6372 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6373 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6374 | |
| 6375 | if (!rdev->ops->channel_switch || |
| 6376 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6377 | return -EOPNOTSUPP; |
| 6378 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6379 | switch (dev->ieee80211_ptr->iftype) { |
| 6380 | case NL80211_IFTYPE_AP: |
| 6381 | case NL80211_IFTYPE_P2P_GO: |
| 6382 | need_new_beacon = true; |
| 6383 | |
| 6384 | /* useless if AP is not running */ |
| 6385 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6386 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6387 | break; |
| 6388 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6389 | if (!wdev->ssid_len) |
| 6390 | return -ENOTCONN; |
| 6391 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6392 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6393 | if (!wdev->mesh_id_len) |
| 6394 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6395 | break; |
| 6396 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6397 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6398 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6399 | |
| 6400 | memset(¶ms, 0, sizeof(params)); |
| 6401 | |
| 6402 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6403 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6404 | return -EINVAL; |
| 6405 | |
| 6406 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6407 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6408 | return -EINVAL; |
| 6409 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6410 | /* Even though the attribute is u32, the specification says |
| 6411 | * u8, so let's make sure we don't overflow. |
| 6412 | */ |
| 6413 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6414 | if (cs_count > 255) |
| 6415 | return -EINVAL; |
| 6416 | |
| 6417 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6418 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6419 | if (!need_new_beacon) |
| 6420 | goto skip_beacons; |
| 6421 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6422 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6423 | if (err) |
| 6424 | return err; |
| 6425 | |
| 6426 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6427 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6428 | nl80211_policy); |
| 6429 | if (err) |
| 6430 | return err; |
| 6431 | |
| 6432 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6433 | if (err) |
| 6434 | return err; |
| 6435 | |
| 6436 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6437 | return -EINVAL; |
| 6438 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6439 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6440 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6441 | return -EINVAL; |
| 6442 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6443 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6444 | if (rdev->wiphy.max_num_csa_counters && |
| 6445 | (params.n_counter_offsets_beacon > |
| 6446 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6447 | return -EINVAL; |
| 6448 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6449 | params.counter_offsets_beacon = |
| 6450 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6451 | |
| 6452 | /* sanity checks - counters should fit and be the same */ |
| 6453 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6454 | u16 offset = params.counter_offsets_beacon[i]; |
| 6455 | |
| 6456 | if (offset >= params.beacon_csa.tail_len) |
| 6457 | return -EINVAL; |
| 6458 | |
| 6459 | if (params.beacon_csa.tail[offset] != params.count) |
| 6460 | return -EINVAL; |
| 6461 | } |
| 6462 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6463 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6464 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6465 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6466 | return -EINVAL; |
| 6467 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6468 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6469 | if (rdev->wiphy.max_num_csa_counters && |
| 6470 | (params.n_counter_offsets_beacon > |
| 6471 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6472 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6473 | |
| 6474 | params.counter_offsets_presp = |
| 6475 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6476 | |
| 6477 | /* sanity checks - counters should fit and be the same */ |
| 6478 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6479 | u16 offset = params.counter_offsets_presp[i]; |
| 6480 | |
| 6481 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6482 | return -EINVAL; |
| 6483 | |
| 6484 | if (params.beacon_csa.probe_resp[offset] != |
| 6485 | params.count) |
| 6486 | return -EINVAL; |
| 6487 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6488 | } |
| 6489 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6490 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6491 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6492 | if (err) |
| 6493 | return err; |
| 6494 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6495 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6496 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6497 | return -EINVAL; |
| 6498 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6499 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6500 | ¶ms.chandef, |
| 6501 | wdev->iftype); |
| 6502 | if (err < 0) |
| 6503 | return err; |
| 6504 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6505 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6506 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6507 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6508 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6509 | params.block_tx = true; |
| 6510 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6511 | wdev_lock(wdev); |
| 6512 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6513 | wdev_unlock(wdev); |
| 6514 | |
| 6515 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6516 | } |
| 6517 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6518 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6519 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6520 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6521 | struct wireless_dev *wdev, |
| 6522 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6523 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6524 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6525 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6526 | void *hdr; |
| 6527 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6528 | |
| 6529 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6530 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6531 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6533 | if (!hdr) |
| 6534 | return -1; |
| 6535 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6536 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6537 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6538 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6539 | goto nla_put_failure; |
| 6540 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6541 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6542 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6543 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6544 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6545 | |
| 6546 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6547 | if (!bss) |
| 6548 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6549 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6550 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6551 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6552 | |
| 6553 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6554 | /* indicate whether we have probe response data or not */ |
| 6555 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6556 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6557 | goto fail_unlock_rcu; |
| 6558 | |
| 6559 | /* this pointer prefers to be pointed to probe response data |
| 6560 | * but is always valid |
| 6561 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6562 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6563 | if (ies) { |
| 6564 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6565 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6566 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6567 | ies->len, ies->data)) |
| 6568 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6569 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6570 | |
| 6571 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6572 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6573 | if (ies && ies->from_beacon) { |
| 6574 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6575 | goto fail_unlock_rcu; |
| 6576 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6577 | ies->len, ies->data)) |
| 6578 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6579 | } |
| 6580 | rcu_read_unlock(); |
| 6581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6582 | if (res->beacon_interval && |
| 6583 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6584 | goto nla_put_failure; |
| 6585 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6586 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6587 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6588 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6589 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6590 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6591 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6592 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6593 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6594 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6595 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6596 | break; |
| 6597 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6598 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6599 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6600 | break; |
| 6601 | default: |
| 6602 | break; |
| 6603 | } |
| 6604 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6605 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6606 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6607 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6608 | if (intbss == wdev->current_bss && |
| 6609 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6610 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6611 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6612 | break; |
| 6613 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6614 | if (intbss == wdev->current_bss && |
| 6615 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6616 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6617 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6618 | break; |
| 6619 | default: |
| 6620 | break; |
| 6621 | } |
| 6622 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6623 | nla_nest_end(msg, bss); |
| 6624 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6625 | genlmsg_end(msg, hdr); |
| 6626 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6627 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6628 | fail_unlock_rcu: |
| 6629 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6630 | nla_put_failure: |
| 6631 | genlmsg_cancel(msg, hdr); |
| 6632 | return -EMSGSIZE; |
| 6633 | } |
| 6634 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6635 | 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] | 6636 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6637 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6638 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6639 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6640 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6641 | int err; |
| 6642 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6643 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6644 | if (err) |
| 6645 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6646 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6647 | wdev_lock(wdev); |
| 6648 | spin_lock_bh(&rdev->bss_lock); |
| 6649 | cfg80211_bss_expire(rdev); |
| 6650 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6651 | cb->seq = rdev->bss_generation; |
| 6652 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6653 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6654 | if (++idx <= start) |
| 6655 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6656 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6657 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6658 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6659 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6660 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6661 | } |
| 6662 | } |
| 6663 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6664 | spin_unlock_bh(&rdev->bss_lock); |
| 6665 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6666 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6667 | cb->args[2] = idx; |
| 6668 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6669 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6670 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6671 | } |
| 6672 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6673 | 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] | 6674 | int flags, struct net_device *dev, |
| 6675 | bool allow_radio_stats, |
| 6676 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6677 | { |
| 6678 | void *hdr; |
| 6679 | struct nlattr *infoattr; |
| 6680 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6681 | /* skip radio stats if userspace didn't request them */ |
| 6682 | if (!survey->channel && !allow_radio_stats) |
| 6683 | return 0; |
| 6684 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6685 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6686 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6687 | if (!hdr) |
| 6688 | return -ENOMEM; |
| 6689 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6690 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6691 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6692 | |
| 6693 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6694 | if (!infoattr) |
| 6695 | goto nla_put_failure; |
| 6696 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6697 | if (survey->channel && |
| 6698 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6699 | survey->channel->center_freq)) |
| 6700 | goto nla_put_failure; |
| 6701 | |
| 6702 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6703 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6704 | goto nla_put_failure; |
| 6705 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6706 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6707 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6708 | if ((survey->filled & SURVEY_INFO_TIME) && |
| 6709 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, |
| 6710 | survey->time)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6711 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6712 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
| 6713 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 6714 | survey->time_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6715 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6716 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
| 6717 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 6718 | survey->time_ext_busy)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6719 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6720 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
| 6721 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 6722 | survey->time_rx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6723 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6724 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
| 6725 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 6726 | survey->time_tx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6727 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 6728 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
| 6729 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 6730 | survey->time_scan)) |
| 6731 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6732 | |
| 6733 | nla_nest_end(msg, infoattr); |
| 6734 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6735 | genlmsg_end(msg, hdr); |
| 6736 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6737 | |
| 6738 | nla_put_failure: |
| 6739 | genlmsg_cancel(msg, hdr); |
| 6740 | return -EMSGSIZE; |
| 6741 | } |
| 6742 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6743 | 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] | 6744 | { |
| 6745 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6746 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6747 | struct wireless_dev *wdev; |
| 6748 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6749 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6750 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6751 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6752 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6753 | if (res) |
| 6754 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6755 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6756 | /* prepare_wdev_dump parsed the attributes */ |
| 6757 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 6758 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6759 | if (!wdev->netdev) { |
| 6760 | res = -EINVAL; |
| 6761 | goto out_err; |
| 6762 | } |
| 6763 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6764 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6765 | res = -EOPNOTSUPP; |
| 6766 | goto out_err; |
| 6767 | } |
| 6768 | |
| 6769 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6770 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6771 | if (res == -ENOENT) |
| 6772 | break; |
| 6773 | if (res) |
| 6774 | goto out_err; |
| 6775 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6776 | /* don't send disabled channels, but do send non-channel data */ |
| 6777 | if (survey.channel && |
| 6778 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6779 | survey_idx++; |
| 6780 | continue; |
| 6781 | } |
| 6782 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6783 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6784 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6785 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 6786 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6787 | goto out; |
| 6788 | survey_idx++; |
| 6789 | } |
| 6790 | |
| 6791 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6792 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6793 | res = skb->len; |
| 6794 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6795 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6796 | return res; |
| 6797 | } |
| 6798 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6799 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6800 | { |
| 6801 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6802 | NL80211_WPA_VERSION_2)); |
| 6803 | } |
| 6804 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6805 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6806 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6808 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6809 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6810 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6811 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6812 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6813 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6814 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6815 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6816 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6817 | return -EINVAL; |
| 6818 | |
| 6819 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6820 | return -EINVAL; |
| 6821 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6822 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6823 | return -EINVAL; |
| 6824 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6825 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6826 | return -EINVAL; |
| 6827 | |
| 6828 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6829 | return -EINVAL; |
| 6830 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6831 | err = nl80211_parse_key(info, &key); |
| 6832 | if (err) |
| 6833 | return err; |
| 6834 | |
| 6835 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6836 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6837 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6838 | if (!key.p.key || !key.p.key_len) |
| 6839 | return -EINVAL; |
| 6840 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6841 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6842 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6843 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6844 | return -EINVAL; |
| 6845 | if (key.idx > 4) |
| 6846 | return -EINVAL; |
| 6847 | } else { |
| 6848 | key.p.key_len = 0; |
| 6849 | key.p.key = NULL; |
| 6850 | } |
| 6851 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6852 | if (key.idx >= 0) { |
| 6853 | int i; |
| 6854 | bool ok = false; |
| 6855 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6856 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6857 | ok = true; |
| 6858 | break; |
| 6859 | } |
| 6860 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6861 | if (!ok) |
| 6862 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6863 | } |
| 6864 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6865 | if (!rdev->ops->auth) |
| 6866 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6867 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6868 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6869 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6870 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6871 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6872 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6873 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6874 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6875 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6876 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6877 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6878 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6879 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6880 | |
| 6881 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6882 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6883 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6884 | } |
| 6885 | |
| 6886 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6887 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6888 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6889 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6890 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6891 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6892 | return -EINVAL; |
| 6893 | |
| 6894 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6895 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6896 | return -EINVAL; |
| 6897 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6898 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6899 | /* need to include at least Auth Transaction and Status Code */ |
| 6900 | if (sae_data_len < 4) |
| 6901 | return -EINVAL; |
| 6902 | } |
| 6903 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6904 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6905 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6906 | /* |
| 6907 | * Since we no longer track auth state, ignore |
| 6908 | * requests to only change local state. |
| 6909 | */ |
| 6910 | if (local_state_change) |
| 6911 | return 0; |
| 6912 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6913 | wdev_lock(dev->ieee80211_ptr); |
| 6914 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6915 | ssid, ssid_len, ie, ie_len, |
| 6916 | key.p.key, key.p.key_len, key.idx, |
| 6917 | sae_data, sae_data_len); |
| 6918 | wdev_unlock(dev->ieee80211_ptr); |
| 6919 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6920 | } |
| 6921 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6922 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6923 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6924 | struct cfg80211_crypto_settings *settings, |
| 6925 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6926 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6927 | memset(settings, 0, sizeof(*settings)); |
| 6928 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6929 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6930 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6931 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6932 | u16 proto; |
| 6933 | proto = nla_get_u16( |
| 6934 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6935 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6936 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6937 | proto != ETH_P_PAE) |
| 6938 | return -EINVAL; |
| 6939 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6940 | settings->control_port_no_encrypt = true; |
| 6941 | } else |
| 6942 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6943 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6944 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6945 | void *data; |
| 6946 | int len, i; |
| 6947 | |
| 6948 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6949 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6950 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6951 | |
| 6952 | if (len % sizeof(u32)) |
| 6953 | return -EINVAL; |
| 6954 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6955 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6956 | return -EINVAL; |
| 6957 | |
| 6958 | memcpy(settings->ciphers_pairwise, data, len); |
| 6959 | |
| 6960 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6961 | if (!cfg80211_supported_cipher_suite( |
| 6962 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6963 | settings->ciphers_pairwise[i])) |
| 6964 | return -EINVAL; |
| 6965 | } |
| 6966 | |
| 6967 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6968 | settings->cipher_group = |
| 6969 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6970 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6971 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6972 | return -EINVAL; |
| 6973 | } |
| 6974 | |
| 6975 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6976 | settings->wpa_versions = |
| 6977 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6978 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6979 | return -EINVAL; |
| 6980 | } |
| 6981 | |
| 6982 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6983 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6984 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6985 | |
| 6986 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6987 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6988 | settings->n_akm_suites = len / sizeof(u32); |
| 6989 | |
| 6990 | if (len % sizeof(u32)) |
| 6991 | return -EINVAL; |
| 6992 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6993 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6994 | return -EINVAL; |
| 6995 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6996 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6997 | } |
| 6998 | |
| 6999 | return 0; |
| 7000 | } |
| 7001 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7002 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7005 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7006 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7007 | struct cfg80211_assoc_request req = {}; |
| 7008 | const u8 *bssid, *ssid; |
| 7009 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7010 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7011 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7012 | return -EINVAL; |
| 7013 | |
| 7014 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7015 | !info->attrs[NL80211_ATTR_SSID] || |
| 7016 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7017 | return -EINVAL; |
| 7018 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7019 | if (!rdev->ops->assoc) |
| 7020 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7021 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7022 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7023 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7024 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7025 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7026 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7027 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7028 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7029 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7030 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7031 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7032 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7033 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7034 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7035 | |
| 7036 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7037 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7038 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7039 | } |
| 7040 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7041 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7042 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7043 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7044 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7045 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7046 | else if (mfp != NL80211_MFP_NO) |
| 7047 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7048 | } |
| 7049 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7050 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7051 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7052 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7053 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7054 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7055 | |
| 7056 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7057 | memcpy(&req.ht_capa_mask, |
| 7058 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7059 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7060 | |
| 7061 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7062 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7063 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7064 | memcpy(&req.ht_capa, |
| 7065 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7066 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7067 | } |
| 7068 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7069 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7070 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7071 | |
| 7072 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7073 | memcpy(&req.vht_capa_mask, |
| 7074 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7075 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7076 | |
| 7077 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7078 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7079 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7080 | memcpy(&req.vht_capa, |
| 7081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7082 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7083 | } |
| 7084 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7085 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7086 | if (!(rdev->wiphy.features & |
| 7087 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7088 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7089 | return -EINVAL; |
| 7090 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7091 | } |
| 7092 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7093 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7094 | if (!err) { |
| 7095 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7096 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7097 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7098 | wdev_unlock(dev->ieee80211_ptr); |
| 7099 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7100 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7101 | return err; |
| 7102 | } |
| 7103 | |
| 7104 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7105 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7107 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7108 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7109 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7110 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7111 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7112 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7113 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7114 | return -EINVAL; |
| 7115 | |
| 7116 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7117 | return -EINVAL; |
| 7118 | |
| 7119 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7120 | return -EINVAL; |
| 7121 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7122 | if (!rdev->ops->deauth) |
| 7123 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7124 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7125 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7126 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7127 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7128 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7129 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7130 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7131 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7132 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7133 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7134 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7135 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7136 | |
| 7137 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7138 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7139 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7140 | } |
| 7141 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7142 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7143 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7144 | wdev_lock(dev->ieee80211_ptr); |
| 7145 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7146 | local_state_change); |
| 7147 | wdev_unlock(dev->ieee80211_ptr); |
| 7148 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7149 | } |
| 7150 | |
| 7151 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7152 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7154 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7155 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7156 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7157 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7158 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7159 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7160 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7161 | return -EINVAL; |
| 7162 | |
| 7163 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7164 | return -EINVAL; |
| 7165 | |
| 7166 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7167 | return -EINVAL; |
| 7168 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7169 | if (!rdev->ops->disassoc) |
| 7170 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7171 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7174 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7175 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7176 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7177 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7178 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7179 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7180 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7181 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7182 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7183 | |
| 7184 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7185 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7186 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7187 | } |
| 7188 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7189 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7190 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7191 | wdev_lock(dev->ieee80211_ptr); |
| 7192 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7193 | local_state_change); |
| 7194 | wdev_unlock(dev->ieee80211_ptr); |
| 7195 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7196 | } |
| 7197 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7198 | static bool |
| 7199 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7200 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7201 | int rateval) |
| 7202 | { |
| 7203 | struct wiphy *wiphy = &rdev->wiphy; |
| 7204 | bool found = false; |
| 7205 | int band, i; |
| 7206 | |
| 7207 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7208 | struct ieee80211_supported_band *sband; |
| 7209 | |
| 7210 | sband = wiphy->bands[band]; |
| 7211 | if (!sband) |
| 7212 | continue; |
| 7213 | |
| 7214 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7215 | if (sband->bitrates[i].bitrate == rateval) { |
| 7216 | mcast_rate[band] = i + 1; |
| 7217 | found = true; |
| 7218 | break; |
| 7219 | } |
| 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | return found; |
| 7224 | } |
| 7225 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7226 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7227 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7229 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7230 | struct cfg80211_ibss_params ibss; |
| 7231 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7232 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7233 | int err; |
| 7234 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7235 | memset(&ibss, 0, sizeof(ibss)); |
| 7236 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7237 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7238 | return -EINVAL; |
| 7239 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7240 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7241 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7242 | return -EINVAL; |
| 7243 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7244 | ibss.beacon_interval = 100; |
| 7245 | |
| 7246 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7247 | ibss.beacon_interval = |
| 7248 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7249 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7250 | return -EINVAL; |
| 7251 | } |
| 7252 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7253 | if (!rdev->ops->join_ibss) |
| 7254 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7255 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7256 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7257 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7258 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7259 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7260 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7261 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7262 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7263 | |
| 7264 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7265 | return -EINVAL; |
| 7266 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7267 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7268 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7269 | |
| 7270 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7271 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7272 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7273 | } |
| 7274 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7275 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7276 | if (err) |
| 7277 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7278 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7279 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7280 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7281 | return -EINVAL; |
| 7282 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7283 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7284 | case NL80211_CHAN_WIDTH_5: |
| 7285 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7286 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7287 | break; |
| 7288 | case NL80211_CHAN_WIDTH_20: |
| 7289 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7290 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7291 | return -EINVAL; |
| 7292 | break; |
| 7293 | case NL80211_CHAN_WIDTH_80: |
| 7294 | case NL80211_CHAN_WIDTH_80P80: |
| 7295 | case NL80211_CHAN_WIDTH_160: |
| 7296 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7297 | return -EINVAL; |
| 7298 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7299 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7300 | return -EINVAL; |
| 7301 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7302 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7303 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7304 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7305 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7306 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7307 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7308 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7309 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7310 | u8 *rates = |
| 7311 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7312 | int n_rates = |
| 7313 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7314 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7315 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7316 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7317 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7318 | &ibss.basic_rates); |
| 7319 | if (err) |
| 7320 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7321 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7322 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7323 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7324 | memcpy(&ibss.ht_capa_mask, |
| 7325 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7326 | sizeof(ibss.ht_capa_mask)); |
| 7327 | |
| 7328 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7329 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7330 | return -EINVAL; |
| 7331 | memcpy(&ibss.ht_capa, |
| 7332 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7333 | sizeof(ibss.ht_capa)); |
| 7334 | } |
| 7335 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7336 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7337 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7338 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7339 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7341 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7342 | bool no_ht = false; |
| 7343 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7344 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7345 | info->attrs[NL80211_ATTR_KEYS], |
| 7346 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7347 | if (IS_ERR(connkeys)) |
| 7348 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7349 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7350 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7351 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7352 | kfree(connkeys); |
| 7353 | return -EINVAL; |
| 7354 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7355 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7356 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7357 | ibss.control_port = |
| 7358 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7359 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7360 | ibss.userspace_handles_dfs = |
| 7361 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7364 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7365 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7366 | return err; |
| 7367 | } |
| 7368 | |
| 7369 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7370 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7372 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7373 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7374 | if (!rdev->ops->leave_ibss) |
| 7375 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7376 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7377 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7378 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7379 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7380 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7381 | } |
| 7382 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7383 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7384 | { |
| 7385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7386 | struct net_device *dev = info->user_ptr[1]; |
| 7387 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7388 | u32 nla_rate; |
| 7389 | int err; |
| 7390 | |
| 7391 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7392 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7393 | return -EOPNOTSUPP; |
| 7394 | |
| 7395 | if (!rdev->ops->set_mcast_rate) |
| 7396 | return -EOPNOTSUPP; |
| 7397 | |
| 7398 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7399 | |
| 7400 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7401 | return -EINVAL; |
| 7402 | |
| 7403 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7404 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7405 | return -EINVAL; |
| 7406 | |
| 7407 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7408 | |
| 7409 | return err; |
| 7410 | } |
| 7411 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7412 | static struct sk_buff * |
| 7413 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7414 | struct wireless_dev *wdev, int approxlen, |
| 7415 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7416 | enum nl80211_attrs attr, |
| 7417 | const struct nl80211_vendor_cmd_info *info, |
| 7418 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7419 | { |
| 7420 | struct sk_buff *skb; |
| 7421 | void *hdr; |
| 7422 | struct nlattr *data; |
| 7423 | |
| 7424 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7425 | if (!skb) |
| 7426 | return NULL; |
| 7427 | |
| 7428 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7429 | if (!hdr) { |
| 7430 | kfree_skb(skb); |
| 7431 | return NULL; |
| 7432 | } |
| 7433 | |
| 7434 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7435 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7436 | |
| 7437 | if (info) { |
| 7438 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7439 | info->vendor_id)) |
| 7440 | goto nla_put_failure; |
| 7441 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7442 | info->subcmd)) |
| 7443 | goto nla_put_failure; |
| 7444 | } |
| 7445 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7446 | if (wdev) { |
| 7447 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, |
| 7448 | wdev_id(wdev))) |
| 7449 | goto nla_put_failure; |
| 7450 | if (wdev->netdev && |
| 7451 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7452 | wdev->netdev->ifindex)) |
| 7453 | goto nla_put_failure; |
| 7454 | } |
| 7455 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7456 | data = nla_nest_start(skb, attr); |
| 7457 | |
| 7458 | ((void **)skb->cb)[0] = rdev; |
| 7459 | ((void **)skb->cb)[1] = hdr; |
| 7460 | ((void **)skb->cb)[2] = data; |
| 7461 | |
| 7462 | return skb; |
| 7463 | |
| 7464 | nla_put_failure: |
| 7465 | kfree_skb(skb); |
| 7466 | return NULL; |
| 7467 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7468 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7469 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7470 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7471 | enum nl80211_commands cmd, |
| 7472 | enum nl80211_attrs attr, |
| 7473 | int vendor_event_idx, |
| 7474 | int approxlen, gfp_t gfp) |
| 7475 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7476 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7477 | const struct nl80211_vendor_cmd_info *info; |
| 7478 | |
| 7479 | switch (cmd) { |
| 7480 | case NL80211_CMD_TESTMODE: |
| 7481 | if (WARN_ON(vendor_event_idx != -1)) |
| 7482 | return NULL; |
| 7483 | info = NULL; |
| 7484 | break; |
| 7485 | case NL80211_CMD_VENDOR: |
| 7486 | if (WARN_ON(vendor_event_idx < 0 || |
| 7487 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7488 | return NULL; |
| 7489 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7490 | break; |
| 7491 | default: |
| 7492 | WARN_ON(1); |
| 7493 | return NULL; |
| 7494 | } |
| 7495 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7496 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7497 | cmd, attr, info, gfp); |
| 7498 | } |
| 7499 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7500 | |
| 7501 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7502 | { |
| 7503 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7504 | void *hdr = ((void **)skb->cb)[1]; |
| 7505 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7506 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7507 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7508 | /* clear CB data for netlink core to own from now on */ |
| 7509 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7510 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7511 | nla_nest_end(skb, data); |
| 7512 | genlmsg_end(skb, hdr); |
| 7513 | |
| 7514 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7515 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7516 | |
| 7517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7518 | mcgrp, gfp); |
| 7519 | } |
| 7520 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7521 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7522 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7523 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7524 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7526 | struct wireless_dev *wdev = |
| 7527 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7528 | int err; |
| 7529 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7530 | if (!rdev->ops->testmode_cmd) |
| 7531 | return -EOPNOTSUPP; |
| 7532 | |
| 7533 | if (IS_ERR(wdev)) { |
| 7534 | err = PTR_ERR(wdev); |
| 7535 | if (err != -EINVAL) |
| 7536 | return err; |
| 7537 | wdev = NULL; |
| 7538 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7539 | return -EINVAL; |
| 7540 | } |
| 7541 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7542 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7543 | return -EINVAL; |
| 7544 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7545 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7546 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7547 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7548 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7549 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7550 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7551 | return err; |
| 7552 | } |
| 7553 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7554 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7555 | struct netlink_callback *cb) |
| 7556 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7557 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7558 | int err; |
| 7559 | long phy_idx; |
| 7560 | void *data = NULL; |
| 7561 | int data_len = 0; |
| 7562 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7563 | rtnl_lock(); |
| 7564 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7565 | if (cb->args[0]) { |
| 7566 | /* |
| 7567 | * 0 is a valid index, but not valid for args[0], |
| 7568 | * so we need to offset by 1. |
| 7569 | */ |
| 7570 | phy_idx = cb->args[0] - 1; |
| 7571 | } else { |
| 7572 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7573 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7574 | nl80211_policy); |
| 7575 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7576 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7577 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7578 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7579 | nl80211_fam.attrbuf); |
| 7580 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7581 | err = PTR_ERR(rdev); |
| 7582 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7583 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7584 | phy_idx = rdev->wiphy_idx; |
| 7585 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7586 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7587 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7588 | cb->args[1] = |
| 7589 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7590 | } |
| 7591 | |
| 7592 | if (cb->args[1]) { |
| 7593 | data = nla_data((void *)cb->args[1]); |
| 7594 | data_len = nla_len((void *)cb->args[1]); |
| 7595 | } |
| 7596 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7597 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7598 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7599 | err = -ENOENT; |
| 7600 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7601 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7602 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7603 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7604 | err = -EOPNOTSUPP; |
| 7605 | goto out_err; |
| 7606 | } |
| 7607 | |
| 7608 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7609 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7610 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7611 | NL80211_CMD_TESTMODE); |
| 7612 | struct nlattr *tmdata; |
| 7613 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7614 | if (!hdr) |
| 7615 | break; |
| 7616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7617 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7618 | genlmsg_cancel(skb, hdr); |
| 7619 | break; |
| 7620 | } |
| 7621 | |
| 7622 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7623 | if (!tmdata) { |
| 7624 | genlmsg_cancel(skb, hdr); |
| 7625 | break; |
| 7626 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7627 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7628 | nla_nest_end(skb, tmdata); |
| 7629 | |
| 7630 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7631 | genlmsg_cancel(skb, hdr); |
| 7632 | break; |
| 7633 | } else if (err) { |
| 7634 | genlmsg_cancel(skb, hdr); |
| 7635 | goto out_err; |
| 7636 | } |
| 7637 | |
| 7638 | genlmsg_end(skb, hdr); |
| 7639 | } |
| 7640 | |
| 7641 | err = skb->len; |
| 7642 | /* see above */ |
| 7643 | cb->args[0] = phy_idx + 1; |
| 7644 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7645 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7646 | return err; |
| 7647 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7648 | #endif |
| 7649 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7650 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7651 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7653 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7654 | struct cfg80211_connect_params connect; |
| 7655 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7656 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7657 | int err; |
| 7658 | |
| 7659 | memset(&connect, 0, sizeof(connect)); |
| 7660 | |
| 7661 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7662 | return -EINVAL; |
| 7663 | |
| 7664 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7665 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7666 | return -EINVAL; |
| 7667 | |
| 7668 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7669 | connect.auth_type = |
| 7670 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7671 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7672 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7673 | return -EINVAL; |
| 7674 | } else |
| 7675 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7676 | |
| 7677 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7678 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7679 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7680 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7681 | if (err) |
| 7682 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7683 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7684 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7685 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7686 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7687 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7688 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7689 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7690 | connect.bg_scan_period = -1; |
| 7691 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7692 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7693 | connect.bg_scan_period = |
| 7694 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7695 | } |
| 7696 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7697 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7698 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7699 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7700 | connect.bssid_hint = |
| 7701 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7702 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7703 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7704 | |
| 7705 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7706 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7707 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7708 | } |
| 7709 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7710 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7711 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7712 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7713 | connect.mfp != NL80211_MFP_NO) |
| 7714 | return -EINVAL; |
| 7715 | } else { |
| 7716 | connect.mfp = NL80211_MFP_NO; |
| 7717 | } |
| 7718 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7719 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7720 | connect.channel = nl80211_get_valid_chan( |
| 7721 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7722 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7723 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7724 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7725 | connect.channel_hint = nl80211_get_valid_chan( |
| 7726 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7727 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7728 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7729 | } |
| 7730 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7731 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7732 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7733 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7734 | if (IS_ERR(connkeys)) |
| 7735 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7736 | } |
| 7737 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7738 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7739 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7740 | |
| 7741 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7742 | memcpy(&connect.ht_capa_mask, |
| 7743 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7744 | sizeof(connect.ht_capa_mask)); |
| 7745 | |
| 7746 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7747 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7748 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7749 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7750 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7751 | memcpy(&connect.ht_capa, |
| 7752 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7753 | sizeof(connect.ht_capa)); |
| 7754 | } |
| 7755 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7756 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7757 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7758 | |
| 7759 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7760 | memcpy(&connect.vht_capa_mask, |
| 7761 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7762 | sizeof(connect.vht_capa_mask)); |
| 7763 | |
| 7764 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7765 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7766 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7767 | return -EINVAL; |
| 7768 | } |
| 7769 | memcpy(&connect.vht_capa, |
| 7770 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7771 | sizeof(connect.vht_capa)); |
| 7772 | } |
| 7773 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7774 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7775 | if (!(rdev->wiphy.features & |
| 7776 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7777 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7778 | return -EINVAL; |
| 7779 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7780 | } |
| 7781 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7782 | wdev_lock(dev->ieee80211_ptr); |
| 7783 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7784 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7785 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7786 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7787 | return err; |
| 7788 | } |
| 7789 | |
| 7790 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7791 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7793 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7794 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7795 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7796 | |
| 7797 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7798 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7799 | else |
| 7800 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7801 | |
| 7802 | if (reason == 0) |
| 7803 | return -EINVAL; |
| 7804 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7806 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7807 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7808 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7809 | wdev_lock(dev->ieee80211_ptr); |
| 7810 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7811 | wdev_unlock(dev->ieee80211_ptr); |
| 7812 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7813 | } |
| 7814 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7815 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7816 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7818 | struct net *net; |
| 7819 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7820 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 7821 | if (info->attrs[NL80211_ATTR_PID]) { |
| 7822 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7823 | |
| 7824 | net = get_net_ns_by_pid(pid); |
| 7825 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 7826 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 7827 | |
| 7828 | net = get_net_ns_by_fd(fd); |
| 7829 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7830 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 7831 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7832 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7833 | if (IS_ERR(net)) |
| 7834 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7835 | |
| 7836 | err = 0; |
| 7837 | |
| 7838 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7839 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7840 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7841 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7842 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7843 | return err; |
| 7844 | } |
| 7845 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7846 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7847 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7849 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7850 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7851 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7852 | struct cfg80211_pmksa pmksa; |
| 7853 | |
| 7854 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7855 | |
| 7856 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7857 | return -EINVAL; |
| 7858 | |
| 7859 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7860 | return -EINVAL; |
| 7861 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7862 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7863 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7864 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7866 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7867 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7868 | |
| 7869 | switch (info->genlhdr->cmd) { |
| 7870 | case NL80211_CMD_SET_PMKSA: |
| 7871 | rdev_ops = rdev->ops->set_pmksa; |
| 7872 | break; |
| 7873 | case NL80211_CMD_DEL_PMKSA: |
| 7874 | rdev_ops = rdev->ops->del_pmksa; |
| 7875 | break; |
| 7876 | default: |
| 7877 | WARN_ON(1); |
| 7878 | break; |
| 7879 | } |
| 7880 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7881 | if (!rdev_ops) |
| 7882 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7884 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7885 | } |
| 7886 | |
| 7887 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7890 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7891 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7893 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7894 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7895 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7896 | if (!rdev->ops->flush_pmksa) |
| 7897 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7898 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7899 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7900 | } |
| 7901 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7902 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7903 | { |
| 7904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7905 | struct net_device *dev = info->user_ptr[1]; |
| 7906 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7907 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7908 | u16 status_code; |
| 7909 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7910 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7911 | |
| 7912 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7913 | !rdev->ops->tdls_mgmt) |
| 7914 | return -EOPNOTSUPP; |
| 7915 | |
| 7916 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7917 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7918 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7919 | !info->attrs[NL80211_ATTR_IE] || |
| 7920 | !info->attrs[NL80211_ATTR_MAC]) |
| 7921 | return -EINVAL; |
| 7922 | |
| 7923 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7924 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7925 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7926 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7927 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7928 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7929 | peer_capability = |
| 7930 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7931 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7932 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7933 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7934 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7935 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7936 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7937 | } |
| 7938 | |
| 7939 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7940 | { |
| 7941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7942 | struct net_device *dev = info->user_ptr[1]; |
| 7943 | enum nl80211_tdls_operation operation; |
| 7944 | u8 *peer; |
| 7945 | |
| 7946 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7947 | !rdev->ops->tdls_oper) |
| 7948 | return -EOPNOTSUPP; |
| 7949 | |
| 7950 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7951 | !info->attrs[NL80211_ATTR_MAC]) |
| 7952 | return -EINVAL; |
| 7953 | |
| 7954 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7955 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7956 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7957 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7958 | } |
| 7959 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7960 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7961 | struct genl_info *info) |
| 7962 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7964 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7965 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7966 | struct sk_buff *msg; |
| 7967 | void *hdr; |
| 7968 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7969 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7970 | int err; |
| 7971 | |
| 7972 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7973 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7974 | return -EINVAL; |
| 7975 | |
| 7976 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7977 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7978 | if (!rdev->ops->remain_on_channel || |
| 7979 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7980 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7981 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7982 | /* |
| 7983 | * We should be on that channel for at least a minimum amount of |
| 7984 | * time (10ms) but no longer than the driver supports. |
| 7985 | */ |
| 7986 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7987 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7988 | return -EINVAL; |
| 7989 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7990 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7991 | if (err) |
| 7992 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7993 | |
| 7994 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7995 | if (!msg) |
| 7996 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7997 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7998 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7999 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8000 | if (!hdr) { |
| 8001 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8002 | goto free_msg; |
| 8003 | } |
| 8004 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8005 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8006 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8007 | |
| 8008 | if (err) |
| 8009 | goto free_msg; |
| 8010 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8011 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8012 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8013 | |
| 8014 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8015 | |
| 8016 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8017 | |
| 8018 | nla_put_failure: |
| 8019 | err = -ENOBUFS; |
| 8020 | free_msg: |
| 8021 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8022 | return err; |
| 8023 | } |
| 8024 | |
| 8025 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8026 | struct genl_info *info) |
| 8027 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8029 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8030 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8031 | |
| 8032 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8033 | return -EINVAL; |
| 8034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8035 | if (!rdev->ops->cancel_remain_on_channel) |
| 8036 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8037 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8038 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8039 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8040 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8041 | } |
| 8042 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8043 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8044 | u8 *rates, u8 rates_len) |
| 8045 | { |
| 8046 | u8 i; |
| 8047 | u32 mask = 0; |
| 8048 | |
| 8049 | for (i = 0; i < rates_len; i++) { |
| 8050 | int rate = (rates[i] & 0x7f) * 5; |
| 8051 | int ridx; |
| 8052 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8053 | struct ieee80211_rate *srate = |
| 8054 | &sband->bitrates[ridx]; |
| 8055 | if (rate == srate->bitrate) { |
| 8056 | mask |= 1 << ridx; |
| 8057 | break; |
| 8058 | } |
| 8059 | } |
| 8060 | if (ridx == sband->n_bitrates) |
| 8061 | return 0; /* rate not found */ |
| 8062 | } |
| 8063 | |
| 8064 | return mask; |
| 8065 | } |
| 8066 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8067 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8068 | u8 *rates, u8 rates_len, |
| 8069 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8070 | { |
| 8071 | u8 i; |
| 8072 | |
| 8073 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8074 | |
| 8075 | for (i = 0; i < rates_len; i++) { |
| 8076 | int ridx, rbit; |
| 8077 | |
| 8078 | ridx = rates[i] / 8; |
| 8079 | rbit = BIT(rates[i] % 8); |
| 8080 | |
| 8081 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8082 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8083 | return false; |
| 8084 | |
| 8085 | /* check availability */ |
| 8086 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8087 | mcs[ridx] |= rbit; |
| 8088 | else |
| 8089 | return false; |
| 8090 | } |
| 8091 | |
| 8092 | return true; |
| 8093 | } |
| 8094 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8095 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8096 | { |
| 8097 | u16 mcs_mask = 0; |
| 8098 | |
| 8099 | switch (vht_mcs_map) { |
| 8100 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8101 | break; |
| 8102 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8103 | mcs_mask = 0x00FF; |
| 8104 | break; |
| 8105 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8106 | mcs_mask = 0x01FF; |
| 8107 | break; |
| 8108 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8109 | mcs_mask = 0x03FF; |
| 8110 | break; |
| 8111 | default: |
| 8112 | break; |
| 8113 | } |
| 8114 | |
| 8115 | return mcs_mask; |
| 8116 | } |
| 8117 | |
| 8118 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8119 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8120 | { |
| 8121 | u8 nss; |
| 8122 | |
| 8123 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8124 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8125 | vht_mcs_map >>= 2; |
| 8126 | } |
| 8127 | } |
| 8128 | |
| 8129 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8130 | struct nl80211_txrate_vht *txrate, |
| 8131 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8132 | { |
| 8133 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8134 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8135 | u8 i; |
| 8136 | |
| 8137 | if (!sband->vht_cap.vht_supported) |
| 8138 | return false; |
| 8139 | |
| 8140 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8141 | |
| 8142 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8143 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8144 | |
| 8145 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8146 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8147 | mcs[i] = txrate->mcs[i]; |
| 8148 | else |
| 8149 | return false; |
| 8150 | } |
| 8151 | |
| 8152 | return true; |
| 8153 | } |
| 8154 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8155 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8156 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8157 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8158 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8159 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8160 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8161 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8162 | }; |
| 8163 | |
| 8164 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8165 | struct genl_info *info) |
| 8166 | { |
| 8167 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8169 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8170 | int rem, i; |
| 8171 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8172 | struct nlattr *tx_rates; |
| 8173 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8174 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8176 | if (!rdev->ops->set_bitrate_mask) |
| 8177 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8178 | |
| 8179 | memset(&mask, 0, sizeof(mask)); |
| 8180 | /* Default to all rates enabled */ |
| 8181 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8182 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8183 | |
| 8184 | if (!sband) |
| 8185 | continue; |
| 8186 | |
| 8187 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8188 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8189 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8190 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8191 | |
| 8192 | if (!sband->vht_cap.vht_supported) |
| 8193 | continue; |
| 8194 | |
| 8195 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8196 | 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] | 8197 | } |
| 8198 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8199 | /* if no rates are given set it back to the defaults */ |
| 8200 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8201 | goto out; |
| 8202 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8203 | /* |
| 8204 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8205 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8206 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8207 | 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] | 8208 | 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] | 8209 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8210 | int err; |
| 8211 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8212 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8213 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8214 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | if (sband == NULL) |
| 8216 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8217 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8218 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8219 | if (err) |
| 8220 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8221 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8222 | mask.control[band].legacy = rateset_to_mask( |
| 8223 | sband, |
| 8224 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8225 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8226 | if ((mask.control[band].legacy == 0) && |
| 8227 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8228 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8229 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8230 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8231 | if (!ht_rateset_to_mask( |
| 8232 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8233 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8234 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8235 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8236 | return -EINVAL; |
| 8237 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8238 | if (tb[NL80211_TXRATE_VHT]) { |
| 8239 | if (!vht_set_mcs_mask( |
| 8240 | sband, |
| 8241 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8242 | mask.control[band].vht_mcs)) |
| 8243 | return -EINVAL; |
| 8244 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8245 | if (tb[NL80211_TXRATE_GI]) { |
| 8246 | mask.control[band].gi = |
| 8247 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8248 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8249 | return -EINVAL; |
| 8250 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8251 | |
| 8252 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8253 | /* don't allow empty legacy rates if HT or VHT |
| 8254 | * are not even supported. |
| 8255 | */ |
| 8256 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8257 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8258 | return -EINVAL; |
| 8259 | |
| 8260 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8261 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8262 | goto out; |
| 8263 | |
| 8264 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8265 | if (mask.control[band].vht_mcs[i]) |
| 8266 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8267 | |
| 8268 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8269 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8270 | } |
| 8271 | } |
| 8272 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8273 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8274 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8275 | } |
| 8276 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8277 | 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] | 8278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8280 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8281 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8282 | |
| 8283 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8284 | return -EINVAL; |
| 8285 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8286 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8287 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8288 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8289 | switch (wdev->iftype) { |
| 8290 | case NL80211_IFTYPE_STATION: |
| 8291 | case NL80211_IFTYPE_ADHOC: |
| 8292 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8293 | case NL80211_IFTYPE_AP: |
| 8294 | case NL80211_IFTYPE_AP_VLAN: |
| 8295 | case NL80211_IFTYPE_MESH_POINT: |
| 8296 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8297 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8298 | break; |
| 8299 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8300 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8301 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8302 | |
| 8303 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8304 | if (!rdev->ops->mgmt_tx) |
| 8305 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8306 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8307 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8308 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8309 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8310 | } |
| 8311 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8312 | 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] | 8313 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8315 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8316 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8317 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8318 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8319 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8320 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8321 | struct cfg80211_mgmt_tx_params params = { |
| 8322 | .dont_wait_for_ack = |
| 8323 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8324 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8325 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8326 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8327 | return -EINVAL; |
| 8328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8329 | if (!rdev->ops->mgmt_tx) |
| 8330 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8331 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8332 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8333 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8334 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8335 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8336 | case NL80211_IFTYPE_STATION: |
| 8337 | case NL80211_IFTYPE_ADHOC: |
| 8338 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8339 | case NL80211_IFTYPE_AP: |
| 8340 | case NL80211_IFTYPE_AP_VLAN: |
| 8341 | case NL80211_IFTYPE_MESH_POINT: |
| 8342 | case NL80211_IFTYPE_P2P_GO: |
| 8343 | break; |
| 8344 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8345 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8346 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8347 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8348 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8349 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8350 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8351 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8352 | |
| 8353 | /* |
| 8354 | * We should wait on the channel for at least a minimum amount |
| 8355 | * of time (10ms) but no longer than the driver supports. |
| 8356 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8357 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8358 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8359 | return -EINVAL; |
| 8360 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8361 | } |
| 8362 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8363 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8364 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8365 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8366 | return -EINVAL; |
| 8367 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8368 | 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] | 8369 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8370 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8371 | * the driver. The latter will use the current one |
| 8372 | */ |
| 8373 | chandef.chan = NULL; |
| 8374 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8375 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8376 | if (err) |
| 8377 | return err; |
| 8378 | } |
| 8379 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8380 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8381 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8382 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8383 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8384 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8385 | |
| 8386 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8387 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8388 | int i; |
| 8389 | |
| 8390 | if (len % sizeof(u16)) |
| 8391 | return -EINVAL; |
| 8392 | |
| 8393 | params.n_csa_offsets = len / sizeof(u16); |
| 8394 | params.csa_offsets = |
| 8395 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8396 | |
| 8397 | /* check that all the offsets fit the frame */ |
| 8398 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8399 | if (params.csa_offsets[i] >= params.len) |
| 8400 | return -EINVAL; |
| 8401 | } |
| 8402 | } |
| 8403 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8404 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8405 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8406 | if (!msg) |
| 8407 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8408 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8409 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8410 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8411 | if (!hdr) { |
| 8412 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8413 | goto free_msg; |
| 8414 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8415 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8416 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8417 | params.chan = chandef.chan; |
| 8418 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8419 | if (err) |
| 8420 | goto free_msg; |
| 8421 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8422 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8423 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8424 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8425 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8426 | genlmsg_end(msg, hdr); |
| 8427 | return genlmsg_reply(msg, info); |
| 8428 | } |
| 8429 | |
| 8430 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8431 | |
| 8432 | nla_put_failure: |
| 8433 | err = -ENOBUFS; |
| 8434 | free_msg: |
| 8435 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8436 | return err; |
| 8437 | } |
| 8438 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8439 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8440 | { |
| 8441 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8442 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8443 | u64 cookie; |
| 8444 | |
| 8445 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8446 | return -EINVAL; |
| 8447 | |
| 8448 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8449 | return -EOPNOTSUPP; |
| 8450 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8451 | switch (wdev->iftype) { |
| 8452 | case NL80211_IFTYPE_STATION: |
| 8453 | case NL80211_IFTYPE_ADHOC: |
| 8454 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8455 | case NL80211_IFTYPE_AP: |
| 8456 | case NL80211_IFTYPE_AP_VLAN: |
| 8457 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8458 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8459 | break; |
| 8460 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8461 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8462 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8463 | |
| 8464 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8465 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8466 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8467 | } |
| 8468 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8469 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8470 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8472 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8473 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8474 | u8 ps_state; |
| 8475 | bool state; |
| 8476 | int err; |
| 8477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8478 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8479 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8480 | |
| 8481 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8483 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8484 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8485 | |
| 8486 | wdev = dev->ieee80211_ptr; |
| 8487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8488 | if (!rdev->ops->set_power_mgmt) |
| 8489 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8490 | |
| 8491 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8492 | |
| 8493 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8494 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8495 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8496 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8497 | if (!err) |
| 8498 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8499 | return err; |
| 8500 | } |
| 8501 | |
| 8502 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8505 | enum nl80211_ps_state ps_state; |
| 8506 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8507 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8508 | struct sk_buff *msg; |
| 8509 | void *hdr; |
| 8510 | int err; |
| 8511 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8512 | wdev = dev->ieee80211_ptr; |
| 8513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8514 | if (!rdev->ops->set_power_mgmt) |
| 8515 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8516 | |
| 8517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8518 | if (!msg) |
| 8519 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8520 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8521 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8522 | NL80211_CMD_GET_POWER_SAVE); |
| 8523 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8524 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8525 | goto free_msg; |
| 8526 | } |
| 8527 | |
| 8528 | if (wdev->ps) |
| 8529 | ps_state = NL80211_PS_ENABLED; |
| 8530 | else |
| 8531 | ps_state = NL80211_PS_DISABLED; |
| 8532 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8533 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8534 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8535 | |
| 8536 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8537 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8538 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8539 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8540 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8541 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8542 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8543 | return err; |
| 8544 | } |
| 8545 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8546 | static const struct nla_policy |
| 8547 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8548 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8549 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8550 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8551 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8552 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8553 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8554 | }; |
| 8555 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8556 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8557 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8558 | { |
| 8559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8560 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8561 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8562 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8563 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8564 | return -EINVAL; |
| 8565 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8566 | if (!rdev->ops->set_cqm_txe_config) |
| 8567 | return -EOPNOTSUPP; |
| 8568 | |
| 8569 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8570 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8571 | return -EOPNOTSUPP; |
| 8572 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8573 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8574 | } |
| 8575 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8576 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8577 | s32 threshold, u32 hysteresis) |
| 8578 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8579 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8580 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8581 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8582 | |
| 8583 | if (threshold > 0) |
| 8584 | return -EINVAL; |
| 8585 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8586 | /* disabling - hysteresis should also be zero then */ |
| 8587 | if (threshold == 0) |
| 8588 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8589 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8590 | if (!rdev->ops->set_cqm_rssi_config) |
| 8591 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8592 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8593 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8594 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8595 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8596 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8597 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8598 | } |
| 8599 | |
| 8600 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8601 | { |
| 8602 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8603 | struct nlattr *cqm; |
| 8604 | int err; |
| 8605 | |
| 8606 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8607 | if (!cqm) |
| 8608 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8609 | |
| 8610 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8611 | nl80211_attr_cqm_policy); |
| 8612 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8613 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8614 | |
| 8615 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8616 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8617 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8618 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8619 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8620 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8621 | } |
| 8622 | |
| 8623 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8624 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8625 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8626 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8627 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8628 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8629 | |
| 8630 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8631 | } |
| 8632 | |
| 8633 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8634 | } |
| 8635 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8636 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8637 | { |
| 8638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8639 | struct net_device *dev = info->user_ptr[1]; |
| 8640 | struct ocb_setup setup = {}; |
| 8641 | int err; |
| 8642 | |
| 8643 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8644 | if (err) |
| 8645 | return err; |
| 8646 | |
| 8647 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8648 | } |
| 8649 | |
| 8650 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8651 | { |
| 8652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8653 | struct net_device *dev = info->user_ptr[1]; |
| 8654 | |
| 8655 | return cfg80211_leave_ocb(rdev, dev); |
| 8656 | } |
| 8657 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8658 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8659 | { |
| 8660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8661 | struct net_device *dev = info->user_ptr[1]; |
| 8662 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8663 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8664 | int err; |
| 8665 | |
| 8666 | /* start with default */ |
| 8667 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8668 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8669 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8670 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8671 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8672 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8673 | if (err) |
| 8674 | return err; |
| 8675 | } |
| 8676 | |
| 8677 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8678 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8679 | return -EINVAL; |
| 8680 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8681 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8682 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8683 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8684 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8685 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8686 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8687 | return -EINVAL; |
| 8688 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8689 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8690 | setup.beacon_interval = |
| 8691 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8692 | if (setup.beacon_interval < 10 || |
| 8693 | setup.beacon_interval > 10000) |
| 8694 | return -EINVAL; |
| 8695 | } |
| 8696 | |
| 8697 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8698 | setup.dtim_period = |
| 8699 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8700 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8701 | return -EINVAL; |
| 8702 | } |
| 8703 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8704 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8705 | /* parse additional setup parameters if given */ |
| 8706 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8707 | if (err) |
| 8708 | return err; |
| 8709 | } |
| 8710 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8711 | if (setup.user_mpm) |
| 8712 | cfg.auto_open_plinks = false; |
| 8713 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8714 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8715 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8716 | if (err) |
| 8717 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8718 | } else { |
| 8719 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8720 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8721 | } |
| 8722 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8723 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8724 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8725 | int n_rates = |
| 8726 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8727 | struct ieee80211_supported_band *sband; |
| 8728 | |
| 8729 | if (!setup.chandef.chan) |
| 8730 | return -EINVAL; |
| 8731 | |
| 8732 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8733 | |
| 8734 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8735 | &setup.basic_rates); |
| 8736 | if (err) |
| 8737 | return err; |
| 8738 | } |
| 8739 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8740 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8744 | { |
| 8745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8746 | struct net_device *dev = info->user_ptr[1]; |
| 8747 | |
| 8748 | return cfg80211_leave_mesh(rdev, dev); |
| 8749 | } |
| 8750 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8751 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8752 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8753 | struct cfg80211_registered_device *rdev) |
| 8754 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8755 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8756 | struct nlattr *nl_pats, *nl_pat; |
| 8757 | int i, pat_len; |
| 8758 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8759 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8760 | return 0; |
| 8761 | |
| 8762 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8763 | if (!nl_pats) |
| 8764 | return -ENOBUFS; |
| 8765 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8766 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8767 | nl_pat = nla_nest_start(msg, i + 1); |
| 8768 | if (!nl_pat) |
| 8769 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8770 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8771 | 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] | 8772 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8773 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8774 | wowlan->patterns[i].pattern) || |
| 8775 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8776 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8777 | return -ENOBUFS; |
| 8778 | nla_nest_end(msg, nl_pat); |
| 8779 | } |
| 8780 | nla_nest_end(msg, nl_pats); |
| 8781 | |
| 8782 | return 0; |
| 8783 | } |
| 8784 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8785 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8786 | struct cfg80211_wowlan_tcp *tcp) |
| 8787 | { |
| 8788 | struct nlattr *nl_tcp; |
| 8789 | |
| 8790 | if (!tcp) |
| 8791 | return 0; |
| 8792 | |
| 8793 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8794 | if (!nl_tcp) |
| 8795 | return -ENOBUFS; |
| 8796 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 8797 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8798 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8799 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8800 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8801 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8802 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8803 | tcp->payload_len, tcp->payload) || |
| 8804 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8805 | tcp->data_interval) || |
| 8806 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8807 | tcp->wake_len, tcp->wake_data) || |
| 8808 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8809 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8810 | return -ENOBUFS; |
| 8811 | |
| 8812 | if (tcp->payload_seq.len && |
| 8813 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8814 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8815 | return -ENOBUFS; |
| 8816 | |
| 8817 | if (tcp->payload_tok.len && |
| 8818 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8819 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8820 | &tcp->payload_tok)) |
| 8821 | return -ENOBUFS; |
| 8822 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8823 | nla_nest_end(msg, nl_tcp); |
| 8824 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8825 | return 0; |
| 8826 | } |
| 8827 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8828 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 8829 | struct cfg80211_sched_scan_request *req) |
| 8830 | { |
| 8831 | struct nlattr *nd, *freqs, *matches, *match; |
| 8832 | int i; |
| 8833 | |
| 8834 | if (!req) |
| 8835 | return 0; |
| 8836 | |
| 8837 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 8838 | if (!nd) |
| 8839 | return -ENOBUFS; |
| 8840 | |
| 8841 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) |
| 8842 | return -ENOBUFS; |
| 8843 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 8844 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 8845 | return -ENOBUFS; |
| 8846 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8847 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 8848 | if (!freqs) |
| 8849 | return -ENOBUFS; |
| 8850 | |
| 8851 | for (i = 0; i < req->n_channels; i++) |
| 8852 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 8853 | |
| 8854 | nla_nest_end(msg, freqs); |
| 8855 | |
| 8856 | if (req->n_match_sets) { |
| 8857 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 8858 | for (i = 0; i < req->n_match_sets; i++) { |
| 8859 | match = nla_nest_start(msg, i); |
| 8860 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 8861 | req->match_sets[i].ssid.ssid_len, |
| 8862 | req->match_sets[i].ssid.ssid); |
| 8863 | nla_nest_end(msg, match); |
| 8864 | } |
| 8865 | nla_nest_end(msg, matches); |
| 8866 | } |
| 8867 | |
| 8868 | nla_nest_end(msg, nd); |
| 8869 | |
| 8870 | return 0; |
| 8871 | } |
| 8872 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8873 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8874 | { |
| 8875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8876 | struct sk_buff *msg; |
| 8877 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8878 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8879 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8880 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8881 | return -EOPNOTSUPP; |
| 8882 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8883 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8884 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8885 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8886 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8887 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8888 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8889 | } |
| 8890 | |
| 8891 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8892 | if (!msg) |
| 8893 | return -ENOMEM; |
| 8894 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8895 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8896 | NL80211_CMD_GET_WOWLAN); |
| 8897 | if (!hdr) |
| 8898 | goto nla_put_failure; |
| 8899 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8900 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8901 | struct nlattr *nl_wowlan; |
| 8902 | |
| 8903 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8904 | if (!nl_wowlan) |
| 8905 | goto nla_put_failure; |
| 8906 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8907 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8908 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8909 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8910 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8911 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8912 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8913 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8914 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8915 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8916 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8917 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8918 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8919 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8920 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8921 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8922 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8923 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8924 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8925 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8926 | if (nl80211_send_wowlan_tcp(msg, |
| 8927 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8928 | goto nla_put_failure; |
| 8929 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 8930 | if (nl80211_send_wowlan_nd( |
| 8931 | msg, |
| 8932 | rdev->wiphy.wowlan_config->nd_config)) |
| 8933 | goto nla_put_failure; |
| 8934 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8935 | nla_nest_end(msg, nl_wowlan); |
| 8936 | } |
| 8937 | |
| 8938 | genlmsg_end(msg, hdr); |
| 8939 | return genlmsg_reply(msg, info); |
| 8940 | |
| 8941 | nla_put_failure: |
| 8942 | nlmsg_free(msg); |
| 8943 | return -ENOBUFS; |
| 8944 | } |
| 8945 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8946 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8947 | struct nlattr *attr, |
| 8948 | struct cfg80211_wowlan *trig) |
| 8949 | { |
| 8950 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8951 | struct cfg80211_wowlan_tcp *cfg; |
| 8952 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8953 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8954 | u32 size; |
| 8955 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8956 | int err, port; |
| 8957 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8958 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8959 | return -EINVAL; |
| 8960 | |
| 8961 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8962 | nla_data(attr), nla_len(attr), |
| 8963 | nl80211_wowlan_tcp_policy); |
| 8964 | if (err) |
| 8965 | return err; |
| 8966 | |
| 8967 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8968 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8969 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8970 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8971 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8972 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8973 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8974 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8975 | return -EINVAL; |
| 8976 | |
| 8977 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8978 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8979 | return -EINVAL; |
| 8980 | |
| 8981 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8982 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8983 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8984 | return -EINVAL; |
| 8985 | |
| 8986 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8987 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8988 | return -EINVAL; |
| 8989 | |
| 8990 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8991 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8992 | return -EINVAL; |
| 8993 | |
| 8994 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8995 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8996 | |
| 8997 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8998 | tokens_size = tokln - sizeof(*tok); |
| 8999 | |
| 9000 | if (!tok->len || tokens_size % tok->len) |
| 9001 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9002 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9003 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9004 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9005 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9006 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9007 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9008 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9009 | return -EINVAL; |
| 9010 | if (tok->offset + tok->len > data_size) |
| 9011 | return -EINVAL; |
| 9012 | } |
| 9013 | |
| 9014 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9015 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9016 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9017 | return -EINVAL; |
| 9018 | if (seq->len == 0 || seq->len > 4) |
| 9019 | return -EINVAL; |
| 9020 | if (seq->len + seq->offset > data_size) |
| 9021 | return -EINVAL; |
| 9022 | } |
| 9023 | |
| 9024 | size = sizeof(*cfg); |
| 9025 | size += data_size; |
| 9026 | size += wake_size + wake_mask_size; |
| 9027 | size += tokens_size; |
| 9028 | |
| 9029 | cfg = kzalloc(size, GFP_KERNEL); |
| 9030 | if (!cfg) |
| 9031 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9032 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9033 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9034 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9035 | ETH_ALEN); |
| 9036 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9037 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9038 | else |
| 9039 | port = 0; |
| 9040 | #ifdef CONFIG_INET |
| 9041 | /* allocate a socket and port for it and use it */ |
| 9042 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9043 | IPPROTO_TCP, &cfg->sock, 1); |
| 9044 | if (err) { |
| 9045 | kfree(cfg); |
| 9046 | return err; |
| 9047 | } |
| 9048 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9049 | sock_release(cfg->sock); |
| 9050 | kfree(cfg); |
| 9051 | return -EADDRINUSE; |
| 9052 | } |
| 9053 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9054 | #else |
| 9055 | if (!port) { |
| 9056 | kfree(cfg); |
| 9057 | return -EINVAL; |
| 9058 | } |
| 9059 | cfg->src_port = port; |
| 9060 | #endif |
| 9061 | |
| 9062 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9063 | cfg->payload_len = data_size; |
| 9064 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9065 | memcpy((void *)cfg->payload, |
| 9066 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9067 | data_size); |
| 9068 | if (seq) |
| 9069 | cfg->payload_seq = *seq; |
| 9070 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9071 | cfg->wake_len = wake_size; |
| 9072 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9073 | memcpy((void *)cfg->wake_data, |
| 9074 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9075 | wake_size); |
| 9076 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9077 | data_size + wake_size; |
| 9078 | memcpy((void *)cfg->wake_mask, |
| 9079 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9080 | wake_mask_size); |
| 9081 | if (tok) { |
| 9082 | cfg->tokens_size = tokens_size; |
| 9083 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9084 | } |
| 9085 | |
| 9086 | trig->tcp = cfg; |
| 9087 | |
| 9088 | return 0; |
| 9089 | } |
| 9090 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9091 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9092 | const struct wiphy_wowlan_support *wowlan, |
| 9093 | struct nlattr *attr, |
| 9094 | struct cfg80211_wowlan *trig) |
| 9095 | { |
| 9096 | struct nlattr **tb; |
| 9097 | int err; |
| 9098 | |
| 9099 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9100 | if (!tb) |
| 9101 | return -ENOMEM; |
| 9102 | |
| 9103 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9104 | err = -EOPNOTSUPP; |
| 9105 | goto out; |
| 9106 | } |
| 9107 | |
| 9108 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9109 | nla_data(attr), nla_len(attr), |
| 9110 | nl80211_policy); |
| 9111 | if (err) |
| 9112 | goto out; |
| 9113 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9114 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9115 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9116 | if (err) |
| 9117 | trig->nd_config = NULL; |
| 9118 | |
| 9119 | out: |
| 9120 | kfree(tb); |
| 9121 | return err; |
| 9122 | } |
| 9123 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9124 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9125 | { |
| 9126 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9127 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9128 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9129 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9130 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9131 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9132 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9133 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9134 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9135 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9136 | return -EOPNOTSUPP; |
| 9137 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9138 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9139 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9140 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9141 | goto set_wakeup; |
| 9142 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9143 | |
| 9144 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9145 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9146 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9147 | nl80211_wowlan_policy); |
| 9148 | if (err) |
| 9149 | return err; |
| 9150 | |
| 9151 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9152 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9153 | return -EINVAL; |
| 9154 | new_triggers.any = true; |
| 9155 | } |
| 9156 | |
| 9157 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9158 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9159 | return -EINVAL; |
| 9160 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9161 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9162 | } |
| 9163 | |
| 9164 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9165 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9166 | return -EINVAL; |
| 9167 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9168 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9169 | } |
| 9170 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9171 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9172 | return -EINVAL; |
| 9173 | |
| 9174 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9175 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9176 | return -EINVAL; |
| 9177 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9178 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9179 | } |
| 9180 | |
| 9181 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9182 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9183 | return -EINVAL; |
| 9184 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9185 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9186 | } |
| 9187 | |
| 9188 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9189 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9190 | return -EINVAL; |
| 9191 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9192 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9193 | } |
| 9194 | |
| 9195 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9196 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9197 | return -EINVAL; |
| 9198 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9199 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9200 | } |
| 9201 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9202 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9203 | struct nlattr *pat; |
| 9204 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9205 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9206 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9207 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9208 | regular = true; |
| 9209 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9210 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9211 | rem) |
| 9212 | n_patterns++; |
| 9213 | if (n_patterns > wowlan->n_patterns) |
| 9214 | return -EINVAL; |
| 9215 | |
| 9216 | new_triggers.patterns = kcalloc(n_patterns, |
| 9217 | sizeof(new_triggers.patterns[0]), |
| 9218 | GFP_KERNEL); |
| 9219 | if (!new_triggers.patterns) |
| 9220 | return -ENOMEM; |
| 9221 | |
| 9222 | new_triggers.n_patterns = n_patterns; |
| 9223 | i = 0; |
| 9224 | |
| 9225 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9226 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9227 | u8 *mask_pat; |
| 9228 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9229 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9230 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9231 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9232 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9233 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9234 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9235 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9236 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9237 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9238 | goto error; |
| 9239 | if (pat_len > wowlan->pattern_max_len || |
| 9240 | pat_len < wowlan->pattern_min_len) |
| 9241 | goto error; |
| 9242 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9243 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9244 | pkt_offset = 0; |
| 9245 | else |
| 9246 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9247 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9248 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9249 | goto error; |
| 9250 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9251 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9252 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9253 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9254 | err = -ENOMEM; |
| 9255 | goto error; |
| 9256 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9257 | new_triggers.patterns[i].mask = mask_pat; |
| 9258 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9259 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9260 | mask_pat += mask_len; |
| 9261 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9262 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9263 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9264 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9265 | pat_len); |
| 9266 | i++; |
| 9267 | } |
| 9268 | } |
| 9269 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9270 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9271 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9272 | err = nl80211_parse_wowlan_tcp( |
| 9273 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9274 | &new_triggers); |
| 9275 | if (err) |
| 9276 | goto error; |
| 9277 | } |
| 9278 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9279 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9280 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9281 | err = nl80211_parse_wowlan_nd( |
| 9282 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9283 | &new_triggers); |
| 9284 | if (err) |
| 9285 | goto error; |
| 9286 | } |
| 9287 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9288 | /* The 'any' trigger means the device continues operating more or less |
| 9289 | * as in its normal operation mode and wakes up the host on most of the |
| 9290 | * normal interrupts (like packet RX, ...) |
| 9291 | * It therefore makes little sense to combine with the more constrained |
| 9292 | * wakeup trigger modes. |
| 9293 | */ |
| 9294 | if (new_triggers.any && regular) { |
| 9295 | err = -EINVAL; |
| 9296 | goto error; |
| 9297 | } |
| 9298 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9299 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9300 | if (!ntrig) { |
| 9301 | err = -ENOMEM; |
| 9302 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9303 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9304 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9305 | rdev->wiphy.wowlan_config = ntrig; |
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 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9308 | if (rdev->ops->set_wakeup && |
| 9309 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9310 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9311 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9312 | return 0; |
| 9313 | error: |
| 9314 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9315 | kfree(new_triggers.patterns[i].mask); |
| 9316 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9317 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9318 | sock_release(new_triggers.tcp->sock); |
| 9319 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9320 | return err; |
| 9321 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9322 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9323 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9324 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9325 | struct cfg80211_registered_device *rdev) |
| 9326 | { |
| 9327 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9328 | int i, j, pat_len; |
| 9329 | struct cfg80211_coalesce_rules *rule; |
| 9330 | |
| 9331 | if (!rdev->coalesce->n_rules) |
| 9332 | return 0; |
| 9333 | |
| 9334 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9335 | if (!nl_rules) |
| 9336 | return -ENOBUFS; |
| 9337 | |
| 9338 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9339 | nl_rule = nla_nest_start(msg, i + 1); |
| 9340 | if (!nl_rule) |
| 9341 | return -ENOBUFS; |
| 9342 | |
| 9343 | rule = &rdev->coalesce->rules[i]; |
| 9344 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9345 | rule->delay)) |
| 9346 | return -ENOBUFS; |
| 9347 | |
| 9348 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9349 | rule->condition)) |
| 9350 | return -ENOBUFS; |
| 9351 | |
| 9352 | nl_pats = nla_nest_start(msg, |
| 9353 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9354 | if (!nl_pats) |
| 9355 | return -ENOBUFS; |
| 9356 | |
| 9357 | for (j = 0; j < rule->n_patterns; j++) { |
| 9358 | nl_pat = nla_nest_start(msg, j + 1); |
| 9359 | if (!nl_pat) |
| 9360 | return -ENOBUFS; |
| 9361 | pat_len = rule->patterns[j].pattern_len; |
| 9362 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9363 | DIV_ROUND_UP(pat_len, 8), |
| 9364 | rule->patterns[j].mask) || |
| 9365 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9366 | rule->patterns[j].pattern) || |
| 9367 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9368 | rule->patterns[j].pkt_offset)) |
| 9369 | return -ENOBUFS; |
| 9370 | nla_nest_end(msg, nl_pat); |
| 9371 | } |
| 9372 | nla_nest_end(msg, nl_pats); |
| 9373 | nla_nest_end(msg, nl_rule); |
| 9374 | } |
| 9375 | nla_nest_end(msg, nl_rules); |
| 9376 | |
| 9377 | return 0; |
| 9378 | } |
| 9379 | |
| 9380 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9381 | { |
| 9382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9383 | struct sk_buff *msg; |
| 9384 | void *hdr; |
| 9385 | |
| 9386 | if (!rdev->wiphy.coalesce) |
| 9387 | return -EOPNOTSUPP; |
| 9388 | |
| 9389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9390 | if (!msg) |
| 9391 | return -ENOMEM; |
| 9392 | |
| 9393 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9394 | NL80211_CMD_GET_COALESCE); |
| 9395 | if (!hdr) |
| 9396 | goto nla_put_failure; |
| 9397 | |
| 9398 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9399 | goto nla_put_failure; |
| 9400 | |
| 9401 | genlmsg_end(msg, hdr); |
| 9402 | return genlmsg_reply(msg, info); |
| 9403 | |
| 9404 | nla_put_failure: |
| 9405 | nlmsg_free(msg); |
| 9406 | return -ENOBUFS; |
| 9407 | } |
| 9408 | |
| 9409 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9410 | { |
| 9411 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9412 | int i, j; |
| 9413 | struct cfg80211_coalesce_rules *rule; |
| 9414 | |
| 9415 | if (!coalesce) |
| 9416 | return; |
| 9417 | |
| 9418 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9419 | rule = &coalesce->rules[i]; |
| 9420 | for (j = 0; j < rule->n_patterns; j++) |
| 9421 | kfree(rule->patterns[j].mask); |
| 9422 | kfree(rule->patterns); |
| 9423 | } |
| 9424 | kfree(coalesce->rules); |
| 9425 | kfree(coalesce); |
| 9426 | rdev->coalesce = NULL; |
| 9427 | } |
| 9428 | |
| 9429 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9430 | struct nlattr *rule, |
| 9431 | struct cfg80211_coalesce_rules *new_rule) |
| 9432 | { |
| 9433 | int err, i; |
| 9434 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9435 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9436 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9437 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9438 | |
| 9439 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9440 | nla_len(rule), nl80211_coalesce_policy); |
| 9441 | if (err) |
| 9442 | return err; |
| 9443 | |
| 9444 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9445 | new_rule->delay = |
| 9446 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9447 | if (new_rule->delay > coalesce->max_delay) |
| 9448 | return -EINVAL; |
| 9449 | |
| 9450 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9451 | new_rule->condition = |
| 9452 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9453 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9454 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9455 | return -EINVAL; |
| 9456 | |
| 9457 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9458 | return -EINVAL; |
| 9459 | |
| 9460 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9461 | rem) |
| 9462 | n_patterns++; |
| 9463 | if (n_patterns > coalesce->n_patterns) |
| 9464 | return -EINVAL; |
| 9465 | |
| 9466 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9467 | GFP_KERNEL); |
| 9468 | if (!new_rule->patterns) |
| 9469 | return -ENOMEM; |
| 9470 | |
| 9471 | new_rule->n_patterns = n_patterns; |
| 9472 | i = 0; |
| 9473 | |
| 9474 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9475 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9476 | u8 *mask_pat; |
| 9477 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9478 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9479 | nla_len(pat), NULL); |
| 9480 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9481 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9482 | return -EINVAL; |
| 9483 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9484 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9485 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9486 | return -EINVAL; |
| 9487 | if (pat_len > coalesce->pattern_max_len || |
| 9488 | pat_len < coalesce->pattern_min_len) |
| 9489 | return -EINVAL; |
| 9490 | |
| 9491 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9492 | pkt_offset = 0; |
| 9493 | else |
| 9494 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9495 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9496 | return -EINVAL; |
| 9497 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9498 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9499 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9500 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9501 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9502 | |
| 9503 | new_rule->patterns[i].mask = mask_pat; |
| 9504 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9505 | mask_len); |
| 9506 | |
| 9507 | mask_pat += mask_len; |
| 9508 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9509 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9510 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9511 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9512 | i++; |
| 9513 | } |
| 9514 | |
| 9515 | return 0; |
| 9516 | } |
| 9517 | |
| 9518 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9519 | { |
| 9520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9521 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9522 | struct cfg80211_coalesce new_coalesce = {}; |
| 9523 | struct cfg80211_coalesce *n_coalesce; |
| 9524 | int err, rem_rule, n_rules = 0, i, j; |
| 9525 | struct nlattr *rule; |
| 9526 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9527 | |
| 9528 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9529 | return -EOPNOTSUPP; |
| 9530 | |
| 9531 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9532 | cfg80211_rdev_free_coalesce(rdev); |
| 9533 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9534 | return 0; |
| 9535 | } |
| 9536 | |
| 9537 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9538 | rem_rule) |
| 9539 | n_rules++; |
| 9540 | if (n_rules > coalesce->n_rules) |
| 9541 | return -EINVAL; |
| 9542 | |
| 9543 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9544 | GFP_KERNEL); |
| 9545 | if (!new_coalesce.rules) |
| 9546 | return -ENOMEM; |
| 9547 | |
| 9548 | new_coalesce.n_rules = n_rules; |
| 9549 | i = 0; |
| 9550 | |
| 9551 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9552 | rem_rule) { |
| 9553 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9554 | &new_coalesce.rules[i]); |
| 9555 | if (err) |
| 9556 | goto error; |
| 9557 | |
| 9558 | i++; |
| 9559 | } |
| 9560 | |
| 9561 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9562 | if (err) |
| 9563 | goto error; |
| 9564 | |
| 9565 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9566 | if (!n_coalesce) { |
| 9567 | err = -ENOMEM; |
| 9568 | goto error; |
| 9569 | } |
| 9570 | cfg80211_rdev_free_coalesce(rdev); |
| 9571 | rdev->coalesce = n_coalesce; |
| 9572 | |
| 9573 | return 0; |
| 9574 | error: |
| 9575 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9576 | tmp_rule = &new_coalesce.rules[i]; |
| 9577 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9578 | kfree(tmp_rule->patterns[j].mask); |
| 9579 | kfree(tmp_rule->patterns); |
| 9580 | } |
| 9581 | kfree(new_coalesce.rules); |
| 9582 | |
| 9583 | return err; |
| 9584 | } |
| 9585 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9586 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9587 | { |
| 9588 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9589 | struct net_device *dev = info->user_ptr[1]; |
| 9590 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9591 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9592 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9593 | int err; |
| 9594 | |
| 9595 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9596 | return -EINVAL; |
| 9597 | |
| 9598 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9599 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9600 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9601 | nl80211_rekey_policy); |
| 9602 | if (err) |
| 9603 | return err; |
| 9604 | |
| 9605 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9606 | return -ERANGE; |
| 9607 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9608 | return -ERANGE; |
| 9609 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9610 | return -ERANGE; |
| 9611 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9612 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9613 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9614 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9615 | |
| 9616 | wdev_lock(wdev); |
| 9617 | if (!wdev->current_bss) { |
| 9618 | err = -ENOTCONN; |
| 9619 | goto out; |
| 9620 | } |
| 9621 | |
| 9622 | if (!rdev->ops->set_rekey_data) { |
| 9623 | err = -EOPNOTSUPP; |
| 9624 | goto out; |
| 9625 | } |
| 9626 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9627 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9628 | out: |
| 9629 | wdev_unlock(wdev); |
| 9630 | return err; |
| 9631 | } |
| 9632 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9633 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9634 | struct genl_info *info) |
| 9635 | { |
| 9636 | struct net_device *dev = info->user_ptr[1]; |
| 9637 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9638 | |
| 9639 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9640 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9641 | return -EINVAL; |
| 9642 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9643 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9644 | return -EBUSY; |
| 9645 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9646 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9647 | return 0; |
| 9648 | } |
| 9649 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9650 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9651 | struct genl_info *info) |
| 9652 | { |
| 9653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9654 | struct net_device *dev = info->user_ptr[1]; |
| 9655 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9656 | struct sk_buff *msg; |
| 9657 | void *hdr; |
| 9658 | const u8 *addr; |
| 9659 | u64 cookie; |
| 9660 | int err; |
| 9661 | |
| 9662 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9663 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9664 | return -EOPNOTSUPP; |
| 9665 | |
| 9666 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9667 | return -EINVAL; |
| 9668 | |
| 9669 | if (!rdev->ops->probe_client) |
| 9670 | return -EOPNOTSUPP; |
| 9671 | |
| 9672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9673 | if (!msg) |
| 9674 | return -ENOMEM; |
| 9675 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9676 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9677 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9678 | if (!hdr) { |
| 9679 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9680 | goto free_msg; |
| 9681 | } |
| 9682 | |
| 9683 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9684 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9685 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9686 | if (err) |
| 9687 | goto free_msg; |
| 9688 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9689 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9690 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9691 | |
| 9692 | genlmsg_end(msg, hdr); |
| 9693 | |
| 9694 | return genlmsg_reply(msg, info); |
| 9695 | |
| 9696 | nla_put_failure: |
| 9697 | err = -ENOBUFS; |
| 9698 | free_msg: |
| 9699 | nlmsg_free(msg); |
| 9700 | return err; |
| 9701 | } |
| 9702 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9703 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9704 | { |
| 9705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9706 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9707 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9708 | |
| 9709 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9710 | return -EOPNOTSUPP; |
| 9711 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9712 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9713 | if (!nreg) |
| 9714 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9715 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9716 | /* First, check if already registered. */ |
| 9717 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9718 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9719 | if (reg->nlportid == info->snd_portid) { |
| 9720 | rv = -EALREADY; |
| 9721 | goto out_err; |
| 9722 | } |
| 9723 | } |
| 9724 | /* Add it to the list */ |
| 9725 | nreg->nlportid = info->snd_portid; |
| 9726 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9727 | |
| 9728 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9729 | |
| 9730 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9731 | out_err: |
| 9732 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9733 | kfree(nreg); |
| 9734 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9735 | } |
| 9736 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9737 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9738 | { |
| 9739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9740 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9741 | int err; |
| 9742 | |
| 9743 | if (!rdev->ops->start_p2p_device) |
| 9744 | return -EOPNOTSUPP; |
| 9745 | |
| 9746 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9747 | return -EOPNOTSUPP; |
| 9748 | |
| 9749 | if (wdev->p2p_started) |
| 9750 | return 0; |
| 9751 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9752 | if (rfkill_blocked(rdev->rfkill)) |
| 9753 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9754 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9755 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9756 | if (err) |
| 9757 | return err; |
| 9758 | |
| 9759 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9760 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9761 | |
| 9762 | return 0; |
| 9763 | } |
| 9764 | |
| 9765 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9766 | { |
| 9767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9768 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9769 | |
| 9770 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9771 | return -EOPNOTSUPP; |
| 9772 | |
| 9773 | if (!rdev->ops->stop_p2p_device) |
| 9774 | return -EOPNOTSUPP; |
| 9775 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9776 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9777 | |
| 9778 | return 0; |
| 9779 | } |
| 9780 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9781 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9782 | struct genl_info *info) |
| 9783 | { |
| 9784 | void *hdr; |
| 9785 | struct sk_buff *msg; |
| 9786 | |
| 9787 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9788 | if (!msg) |
| 9789 | return -ENOMEM; |
| 9790 | |
| 9791 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9792 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9793 | if (!hdr) |
| 9794 | goto nla_put_failure; |
| 9795 | |
| 9796 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9797 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9798 | goto nla_put_failure; |
| 9799 | |
| 9800 | genlmsg_end(msg, hdr); |
| 9801 | return genlmsg_reply(msg, info); |
| 9802 | |
| 9803 | nla_put_failure: |
| 9804 | kfree_skb(msg); |
| 9805 | return -ENOBUFS; |
| 9806 | } |
| 9807 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9808 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9809 | { |
| 9810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9811 | struct cfg80211_update_ft_ies_params ft_params; |
| 9812 | struct net_device *dev = info->user_ptr[1]; |
| 9813 | |
| 9814 | if (!rdev->ops->update_ft_ies) |
| 9815 | return -EOPNOTSUPP; |
| 9816 | |
| 9817 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9818 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9819 | return -EINVAL; |
| 9820 | |
| 9821 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9822 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9823 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9824 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9825 | |
| 9826 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9827 | } |
| 9828 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9829 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9830 | struct genl_info *info) |
| 9831 | { |
| 9832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9833 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9834 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9835 | u16 duration; |
| 9836 | int ret; |
| 9837 | |
| 9838 | if (!rdev->ops->crit_proto_start) |
| 9839 | return -EOPNOTSUPP; |
| 9840 | |
| 9841 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9842 | return -EINVAL; |
| 9843 | |
| 9844 | if (rdev->crit_proto_nlportid) |
| 9845 | return -EBUSY; |
| 9846 | |
| 9847 | /* determine protocol if provided */ |
| 9848 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9849 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9850 | |
| 9851 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9852 | return -EINVAL; |
| 9853 | |
| 9854 | /* timeout must be provided */ |
| 9855 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9856 | return -EINVAL; |
| 9857 | |
| 9858 | duration = |
| 9859 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9860 | |
| 9861 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9862 | return -ERANGE; |
| 9863 | |
| 9864 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9865 | if (!ret) |
| 9866 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9867 | |
| 9868 | return ret; |
| 9869 | } |
| 9870 | |
| 9871 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9872 | struct genl_info *info) |
| 9873 | { |
| 9874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9875 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9876 | |
| 9877 | if (!rdev->ops->crit_proto_stop) |
| 9878 | return -EOPNOTSUPP; |
| 9879 | |
| 9880 | if (rdev->crit_proto_nlportid) { |
| 9881 | rdev->crit_proto_nlportid = 0; |
| 9882 | rdev_crit_proto_stop(rdev, wdev); |
| 9883 | } |
| 9884 | return 0; |
| 9885 | } |
| 9886 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9887 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9888 | { |
| 9889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9890 | struct wireless_dev *wdev = |
| 9891 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9892 | int i, err; |
| 9893 | u32 vid, subcmd; |
| 9894 | |
| 9895 | if (!rdev->wiphy.vendor_commands) |
| 9896 | return -EOPNOTSUPP; |
| 9897 | |
| 9898 | if (IS_ERR(wdev)) { |
| 9899 | err = PTR_ERR(wdev); |
| 9900 | if (err != -EINVAL) |
| 9901 | return err; |
| 9902 | wdev = NULL; |
| 9903 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9904 | return -EINVAL; |
| 9905 | } |
| 9906 | |
| 9907 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9908 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9909 | return -EINVAL; |
| 9910 | |
| 9911 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9912 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9913 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9914 | const struct wiphy_vendor_command *vcmd; |
| 9915 | void *data = NULL; |
| 9916 | int len = 0; |
| 9917 | |
| 9918 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9919 | |
| 9920 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9921 | continue; |
| 9922 | |
| 9923 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9924 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9925 | if (!wdev) |
| 9926 | return -EINVAL; |
| 9927 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9928 | !wdev->netdev) |
| 9929 | return -EINVAL; |
| 9930 | |
| 9931 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9932 | if (wdev->netdev && |
| 9933 | !netif_running(wdev->netdev)) |
| 9934 | return -ENETDOWN; |
| 9935 | if (!wdev->netdev && !wdev->p2p_started) |
| 9936 | return -ENETDOWN; |
| 9937 | } |
| 9938 | } else { |
| 9939 | wdev = NULL; |
| 9940 | } |
| 9941 | |
| 9942 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9943 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9944 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9945 | } |
| 9946 | |
| 9947 | rdev->cur_cmd_info = info; |
| 9948 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9949 | data, len); |
| 9950 | rdev->cur_cmd_info = NULL; |
| 9951 | return err; |
| 9952 | } |
| 9953 | |
| 9954 | return -EOPNOTSUPP; |
| 9955 | } |
| 9956 | |
| 9957 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9958 | enum nl80211_commands cmd, |
| 9959 | enum nl80211_attrs attr, |
| 9960 | int approxlen) |
| 9961 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9962 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9963 | |
| 9964 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9965 | return NULL; |
| 9966 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9967 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9968 | rdev->cur_cmd_info->snd_portid, |
| 9969 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9970 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9971 | } |
| 9972 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9973 | |
| 9974 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9975 | { |
| 9976 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9977 | void *hdr = ((void **)skb->cb)[1]; |
| 9978 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9979 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9980 | /* clear CB data for netlink core to own from now on */ |
| 9981 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9982 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9983 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9984 | kfree_skb(skb); |
| 9985 | return -EINVAL; |
| 9986 | } |
| 9987 | |
| 9988 | nla_nest_end(skb, data); |
| 9989 | genlmsg_end(skb, hdr); |
| 9990 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9991 | } |
| 9992 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9993 | |
| 9994 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9995 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9996 | struct genl_info *info) |
| 9997 | { |
| 9998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9999 | struct cfg80211_qos_map *qos_map = NULL; |
| 10000 | struct net_device *dev = info->user_ptr[1]; |
| 10001 | u8 *pos, len, num_des, des_len, des; |
| 10002 | int ret; |
| 10003 | |
| 10004 | if (!rdev->ops->set_qos_map) |
| 10005 | return -EOPNOTSUPP; |
| 10006 | |
| 10007 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10008 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10009 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10010 | |
| 10011 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10012 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10013 | return -EINVAL; |
| 10014 | |
| 10015 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10016 | if (!qos_map) |
| 10017 | return -ENOMEM; |
| 10018 | |
| 10019 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10020 | if (num_des) { |
| 10021 | des_len = num_des * |
| 10022 | sizeof(struct cfg80211_dscp_exception); |
| 10023 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10024 | qos_map->num_des = num_des; |
| 10025 | for (des = 0; des < num_des; des++) { |
| 10026 | if (qos_map->dscp_exception[des].up > 7) { |
| 10027 | kfree(qos_map); |
| 10028 | return -EINVAL; |
| 10029 | } |
| 10030 | } |
| 10031 | pos += des_len; |
| 10032 | } |
| 10033 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10034 | } |
| 10035 | |
| 10036 | wdev_lock(dev->ieee80211_ptr); |
| 10037 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10038 | if (!ret) |
| 10039 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10040 | wdev_unlock(dev->ieee80211_ptr); |
| 10041 | |
| 10042 | kfree(qos_map); |
| 10043 | return ret; |
| 10044 | } |
| 10045 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10046 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10047 | { |
| 10048 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10049 | struct net_device *dev = info->user_ptr[1]; |
| 10050 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10051 | const u8 *peer; |
| 10052 | u8 tsid, up; |
| 10053 | u16 admitted_time = 0; |
| 10054 | int err; |
| 10055 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10056 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10057 | return -EOPNOTSUPP; |
| 10058 | |
| 10059 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10060 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10061 | return -EINVAL; |
| 10062 | |
| 10063 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10064 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10065 | return -EINVAL; |
| 10066 | |
| 10067 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10068 | if (up >= IEEE80211_NUM_UPS) |
| 10069 | return -EINVAL; |
| 10070 | |
| 10071 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10072 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10073 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10074 | * need more attributes for that (e.g. BA session requirement); |
| 10075 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10076 | */ |
| 10077 | return -EINVAL; |
| 10078 | } |
| 10079 | |
| 10080 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10081 | |
| 10082 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10083 | admitted_time = |
| 10084 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10085 | if (!admitted_time) |
| 10086 | return -EINVAL; |
| 10087 | } |
| 10088 | |
| 10089 | wdev_lock(wdev); |
| 10090 | switch (wdev->iftype) { |
| 10091 | case NL80211_IFTYPE_STATION: |
| 10092 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10093 | if (wdev->current_bss) |
| 10094 | break; |
| 10095 | err = -ENOTCONN; |
| 10096 | goto out; |
| 10097 | default: |
| 10098 | err = -EOPNOTSUPP; |
| 10099 | goto out; |
| 10100 | } |
| 10101 | |
| 10102 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10103 | |
| 10104 | out: |
| 10105 | wdev_unlock(wdev); |
| 10106 | return err; |
| 10107 | } |
| 10108 | |
| 10109 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10110 | { |
| 10111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10112 | struct net_device *dev = info->user_ptr[1]; |
| 10113 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10114 | const u8 *peer; |
| 10115 | u8 tsid; |
| 10116 | int err; |
| 10117 | |
| 10118 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10119 | return -EINVAL; |
| 10120 | |
| 10121 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10122 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10123 | |
| 10124 | wdev_lock(wdev); |
| 10125 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10126 | wdev_unlock(wdev); |
| 10127 | |
| 10128 | return err; |
| 10129 | } |
| 10130 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10131 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10132 | struct genl_info *info) |
| 10133 | { |
| 10134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10135 | struct net_device *dev = info->user_ptr[1]; |
| 10136 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10137 | struct cfg80211_chan_def chandef = {}; |
| 10138 | const u8 *addr; |
| 10139 | u8 oper_class; |
| 10140 | int err; |
| 10141 | |
| 10142 | if (!rdev->ops->tdls_channel_switch || |
| 10143 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10144 | return -EOPNOTSUPP; |
| 10145 | |
| 10146 | switch (dev->ieee80211_ptr->iftype) { |
| 10147 | case NL80211_IFTYPE_STATION: |
| 10148 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10149 | break; |
| 10150 | default: |
| 10151 | return -EOPNOTSUPP; |
| 10152 | } |
| 10153 | |
| 10154 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10155 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10156 | return -EINVAL; |
| 10157 | |
| 10158 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10159 | if (err) |
| 10160 | return err; |
| 10161 | |
| 10162 | /* |
| 10163 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10164 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10165 | * specification is not defined for them. |
| 10166 | */ |
| 10167 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 10168 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10169 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10170 | return -EINVAL; |
| 10171 | |
| 10172 | /* we will be active on the TDLS link */ |
| 10173 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) |
| 10174 | return -EINVAL; |
| 10175 | |
| 10176 | /* don't allow switching to DFS channels */ |
| 10177 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10178 | return -EINVAL; |
| 10179 | |
| 10180 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10181 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10182 | |
| 10183 | wdev_lock(wdev); |
| 10184 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10185 | wdev_unlock(wdev); |
| 10186 | |
| 10187 | return err; |
| 10188 | } |
| 10189 | |
| 10190 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10191 | struct genl_info *info) |
| 10192 | { |
| 10193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10194 | struct net_device *dev = info->user_ptr[1]; |
| 10195 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10196 | const u8 *addr; |
| 10197 | |
| 10198 | if (!rdev->ops->tdls_channel_switch || |
| 10199 | !rdev->ops->tdls_cancel_channel_switch || |
| 10200 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10201 | return -EOPNOTSUPP; |
| 10202 | |
| 10203 | switch (dev->ieee80211_ptr->iftype) { |
| 10204 | case NL80211_IFTYPE_STATION: |
| 10205 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10206 | break; |
| 10207 | default: |
| 10208 | return -EOPNOTSUPP; |
| 10209 | } |
| 10210 | |
| 10211 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10212 | return -EINVAL; |
| 10213 | |
| 10214 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10215 | |
| 10216 | wdev_lock(wdev); |
| 10217 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10218 | wdev_unlock(wdev); |
| 10219 | |
| 10220 | return 0; |
| 10221 | } |
| 10222 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10223 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10224 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10225 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10226 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10227 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10228 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10229 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10230 | /* 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] | 10231 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10232 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10233 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10234 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10235 | 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] | 10236 | struct genl_info *info) |
| 10237 | { |
| 10238 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10239 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10240 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10241 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10242 | |
| 10243 | if (rtnl) |
| 10244 | rtnl_lock(); |
| 10245 | |
| 10246 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10247 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10248 | if (IS_ERR(rdev)) { |
| 10249 | if (rtnl) |
| 10250 | rtnl_unlock(); |
| 10251 | return PTR_ERR(rdev); |
| 10252 | } |
| 10253 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10254 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10255 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10256 | ASSERT_RTNL(); |
| 10257 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10258 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10259 | info->attrs); |
| 10260 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10261 | if (rtnl) |
| 10262 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10263 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10264 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10265 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10266 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10267 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10268 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10269 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10270 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10271 | if (rtnl) |
| 10272 | rtnl_unlock(); |
| 10273 | return -EINVAL; |
| 10274 | } |
| 10275 | |
| 10276 | info->user_ptr[1] = dev; |
| 10277 | } else { |
| 10278 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10279 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10280 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10281 | if (dev) { |
| 10282 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10283 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10284 | if (rtnl) |
| 10285 | rtnl_unlock(); |
| 10286 | return -ENETDOWN; |
| 10287 | } |
| 10288 | |
| 10289 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10290 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10291 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10292 | if (rtnl) |
| 10293 | rtnl_unlock(); |
| 10294 | return -ENETDOWN; |
| 10295 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10296 | } |
| 10297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10298 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10299 | } |
| 10300 | |
| 10301 | return 0; |
| 10302 | } |
| 10303 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10304 | 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] | 10305 | struct genl_info *info) |
| 10306 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10307 | if (info->user_ptr[1]) { |
| 10308 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10309 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10310 | |
| 10311 | if (wdev->netdev) |
| 10312 | dev_put(wdev->netdev); |
| 10313 | } else { |
| 10314 | dev_put(info->user_ptr[1]); |
| 10315 | } |
| 10316 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10318 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10319 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10320 | |
| 10321 | /* If needed, clear the netlink message payload from the SKB |
| 10322 | * as it might contain key data that shouldn't stick around on |
| 10323 | * the heap after the SKB is freed. The netlink message header |
| 10324 | * is still needed for further processing, so leave it intact. |
| 10325 | */ |
| 10326 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10327 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10328 | |
| 10329 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10330 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10331 | } |
| 10332 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10333 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10334 | { |
| 10335 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10336 | .doit = nl80211_get_wiphy, |
| 10337 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10338 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10339 | .policy = nl80211_policy, |
| 10340 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10341 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10342 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10343 | }, |
| 10344 | { |
| 10345 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10346 | .doit = nl80211_set_wiphy, |
| 10347 | .policy = nl80211_policy, |
| 10348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10349 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10350 | }, |
| 10351 | { |
| 10352 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10353 | .doit = nl80211_get_interface, |
| 10354 | .dumpit = nl80211_dump_interface, |
| 10355 | .policy = nl80211_policy, |
| 10356 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10357 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10358 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10359 | }, |
| 10360 | { |
| 10361 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10362 | .doit = nl80211_set_interface, |
| 10363 | .policy = nl80211_policy, |
| 10364 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10366 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10367 | }, |
| 10368 | { |
| 10369 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10370 | .doit = nl80211_new_interface, |
| 10371 | .policy = nl80211_policy, |
| 10372 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10374 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10375 | }, |
| 10376 | { |
| 10377 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10378 | .doit = nl80211_del_interface, |
| 10379 | .policy = nl80211_policy, |
| 10380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10381 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10382 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10383 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10384 | { |
| 10385 | .cmd = NL80211_CMD_GET_KEY, |
| 10386 | .doit = nl80211_get_key, |
| 10387 | .policy = nl80211_policy, |
| 10388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10390 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10391 | }, |
| 10392 | { |
| 10393 | .cmd = NL80211_CMD_SET_KEY, |
| 10394 | .doit = nl80211_set_key, |
| 10395 | .policy = nl80211_policy, |
| 10396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10398 | NL80211_FLAG_NEED_RTNL | |
| 10399 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10400 | }, |
| 10401 | { |
| 10402 | .cmd = NL80211_CMD_NEW_KEY, |
| 10403 | .doit = nl80211_new_key, |
| 10404 | .policy = nl80211_policy, |
| 10405 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10407 | NL80211_FLAG_NEED_RTNL | |
| 10408 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10409 | }, |
| 10410 | { |
| 10411 | .cmd = NL80211_CMD_DEL_KEY, |
| 10412 | .doit = nl80211_del_key, |
| 10413 | .policy = nl80211_policy, |
| 10414 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10416 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10417 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10418 | { |
| 10419 | .cmd = NL80211_CMD_SET_BEACON, |
| 10420 | .policy = nl80211_policy, |
| 10421 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10422 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10424 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10425 | }, |
| 10426 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10427 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10428 | .policy = nl80211_policy, |
| 10429 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10430 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10432 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10433 | }, |
| 10434 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10435 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10436 | .policy = nl80211_policy, |
| 10437 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10438 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10440 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10441 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10442 | { |
| 10443 | .cmd = NL80211_CMD_GET_STATION, |
| 10444 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10445 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10446 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10447 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10448 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10449 | }, |
| 10450 | { |
| 10451 | .cmd = NL80211_CMD_SET_STATION, |
| 10452 | .doit = nl80211_set_station, |
| 10453 | .policy = nl80211_policy, |
| 10454 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10456 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10457 | }, |
| 10458 | { |
| 10459 | .cmd = NL80211_CMD_NEW_STATION, |
| 10460 | .doit = nl80211_new_station, |
| 10461 | .policy = nl80211_policy, |
| 10462 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10463 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10464 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10465 | }, |
| 10466 | { |
| 10467 | .cmd = NL80211_CMD_DEL_STATION, |
| 10468 | .doit = nl80211_del_station, |
| 10469 | .policy = nl80211_policy, |
| 10470 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10471 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10472 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10473 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10474 | { |
| 10475 | .cmd = NL80211_CMD_GET_MPATH, |
| 10476 | .doit = nl80211_get_mpath, |
| 10477 | .dumpit = nl80211_dump_mpath, |
| 10478 | .policy = nl80211_policy, |
| 10479 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10481 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10482 | }, |
| 10483 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10484 | .cmd = NL80211_CMD_GET_MPP, |
| 10485 | .doit = nl80211_get_mpp, |
| 10486 | .dumpit = nl80211_dump_mpp, |
| 10487 | .policy = nl80211_policy, |
| 10488 | .flags = GENL_ADMIN_PERM, |
| 10489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10490 | NL80211_FLAG_NEED_RTNL, |
| 10491 | }, |
| 10492 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10493 | .cmd = NL80211_CMD_SET_MPATH, |
| 10494 | .doit = nl80211_set_mpath, |
| 10495 | .policy = nl80211_policy, |
| 10496 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10498 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10499 | }, |
| 10500 | { |
| 10501 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10502 | .doit = nl80211_new_mpath, |
| 10503 | .policy = nl80211_policy, |
| 10504 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10506 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10507 | }, |
| 10508 | { |
| 10509 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10510 | .doit = nl80211_del_mpath, |
| 10511 | .policy = nl80211_policy, |
| 10512 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10514 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10515 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10516 | { |
| 10517 | .cmd = NL80211_CMD_SET_BSS, |
| 10518 | .doit = nl80211_set_bss, |
| 10519 | .policy = nl80211_policy, |
| 10520 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10522 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10523 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10524 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10525 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10526 | .doit = nl80211_get_reg_do, |
| 10527 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10528 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10529 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10530 | /* can be retrieved by unprivileged users */ |
| 10531 | }, |
| 10532 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10533 | .cmd = NL80211_CMD_SET_REG, |
| 10534 | .doit = nl80211_set_reg, |
| 10535 | .policy = nl80211_policy, |
| 10536 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10537 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10538 | }, |
| 10539 | { |
| 10540 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10541 | .doit = nl80211_req_set_reg, |
| 10542 | .policy = nl80211_policy, |
| 10543 | .flags = GENL_ADMIN_PERM, |
| 10544 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10545 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10546 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10547 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10548 | .policy = nl80211_policy, |
| 10549 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10551 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10552 | }, |
| 10553 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10554 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10555 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10556 | .policy = nl80211_policy, |
| 10557 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10559 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10560 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10561 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10562 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10563 | .doit = nl80211_trigger_scan, |
| 10564 | .policy = nl80211_policy, |
| 10565 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10566 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10567 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10568 | }, |
| 10569 | { |
| 10570 | .cmd = NL80211_CMD_GET_SCAN, |
| 10571 | .policy = nl80211_policy, |
| 10572 | .dumpit = nl80211_dump_scan, |
| 10573 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10574 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10575 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10576 | .doit = nl80211_start_sched_scan, |
| 10577 | .policy = nl80211_policy, |
| 10578 | .flags = GENL_ADMIN_PERM, |
| 10579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10580 | NL80211_FLAG_NEED_RTNL, |
| 10581 | }, |
| 10582 | { |
| 10583 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10584 | .doit = nl80211_stop_sched_scan, |
| 10585 | .policy = nl80211_policy, |
| 10586 | .flags = GENL_ADMIN_PERM, |
| 10587 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10588 | NL80211_FLAG_NEED_RTNL, |
| 10589 | }, |
| 10590 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10591 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10592 | .doit = nl80211_authenticate, |
| 10593 | .policy = nl80211_policy, |
| 10594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10596 | NL80211_FLAG_NEED_RTNL | |
| 10597 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10598 | }, |
| 10599 | { |
| 10600 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10601 | .doit = nl80211_associate, |
| 10602 | .policy = nl80211_policy, |
| 10603 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10604 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10605 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10606 | }, |
| 10607 | { |
| 10608 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10609 | .doit = nl80211_deauthenticate, |
| 10610 | .policy = nl80211_policy, |
| 10611 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10613 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10614 | }, |
| 10615 | { |
| 10616 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10617 | .doit = nl80211_disassociate, |
| 10618 | .policy = nl80211_policy, |
| 10619 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10621 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10622 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10623 | { |
| 10624 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10625 | .doit = nl80211_join_ibss, |
| 10626 | .policy = nl80211_policy, |
| 10627 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10629 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10630 | }, |
| 10631 | { |
| 10632 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10633 | .doit = nl80211_leave_ibss, |
| 10634 | .policy = nl80211_policy, |
| 10635 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10636 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10637 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10638 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10639 | #ifdef CONFIG_NL80211_TESTMODE |
| 10640 | { |
| 10641 | .cmd = NL80211_CMD_TESTMODE, |
| 10642 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10643 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10644 | .policy = nl80211_policy, |
| 10645 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10646 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10647 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10648 | }, |
| 10649 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10650 | { |
| 10651 | .cmd = NL80211_CMD_CONNECT, |
| 10652 | .doit = nl80211_connect, |
| 10653 | .policy = nl80211_policy, |
| 10654 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10656 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10657 | }, |
| 10658 | { |
| 10659 | .cmd = NL80211_CMD_DISCONNECT, |
| 10660 | .doit = nl80211_disconnect, |
| 10661 | .policy = nl80211_policy, |
| 10662 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10664 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10665 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10666 | { |
| 10667 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10668 | .doit = nl80211_wiphy_netns, |
| 10669 | .policy = nl80211_policy, |
| 10670 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10671 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10672 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10673 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10674 | { |
| 10675 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10676 | .policy = nl80211_policy, |
| 10677 | .dumpit = nl80211_dump_survey, |
| 10678 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10679 | { |
| 10680 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10681 | .doit = nl80211_setdel_pmksa, |
| 10682 | .policy = nl80211_policy, |
| 10683 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10684 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10685 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10686 | }, |
| 10687 | { |
| 10688 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10689 | .doit = nl80211_setdel_pmksa, |
| 10690 | .policy = nl80211_policy, |
| 10691 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10692 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10693 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10694 | }, |
| 10695 | { |
| 10696 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10697 | .doit = nl80211_flush_pmksa, |
| 10698 | .policy = nl80211_policy, |
| 10699 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10701 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10702 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10703 | { |
| 10704 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10705 | .doit = nl80211_remain_on_channel, |
| 10706 | .policy = nl80211_policy, |
| 10707 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10708 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10709 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10710 | }, |
| 10711 | { |
| 10712 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10713 | .doit = nl80211_cancel_remain_on_channel, |
| 10714 | .policy = nl80211_policy, |
| 10715 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10716 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10717 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10718 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10719 | { |
| 10720 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10721 | .doit = nl80211_set_tx_bitrate_mask, |
| 10722 | .policy = nl80211_policy, |
| 10723 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10724 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10725 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10726 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10727 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10728 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10729 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10730 | .policy = nl80211_policy, |
| 10731 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10732 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10733 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10734 | }, |
| 10735 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10736 | .cmd = NL80211_CMD_FRAME, |
| 10737 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10738 | .policy = nl80211_policy, |
| 10739 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10740 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10741 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10742 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10743 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10744 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10745 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10746 | .policy = nl80211_policy, |
| 10747 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10748 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10749 | NL80211_FLAG_NEED_RTNL, |
| 10750 | }, |
| 10751 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10752 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10753 | .doit = nl80211_set_power_save, |
| 10754 | .policy = nl80211_policy, |
| 10755 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10756 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10757 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10758 | }, |
| 10759 | { |
| 10760 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10761 | .doit = nl80211_get_power_save, |
| 10762 | .policy = nl80211_policy, |
| 10763 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10764 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10765 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10766 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10767 | { |
| 10768 | .cmd = NL80211_CMD_SET_CQM, |
| 10769 | .doit = nl80211_set_cqm, |
| 10770 | .policy = nl80211_policy, |
| 10771 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10772 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10773 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10774 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10775 | { |
| 10776 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10777 | .doit = nl80211_set_channel, |
| 10778 | .policy = nl80211_policy, |
| 10779 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10780 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10781 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10782 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10783 | { |
| 10784 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10785 | .doit = nl80211_set_wds_peer, |
| 10786 | .policy = nl80211_policy, |
| 10787 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10788 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10789 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10790 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10791 | { |
| 10792 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10793 | .doit = nl80211_join_mesh, |
| 10794 | .policy = nl80211_policy, |
| 10795 | .flags = GENL_ADMIN_PERM, |
| 10796 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10797 | NL80211_FLAG_NEED_RTNL, |
| 10798 | }, |
| 10799 | { |
| 10800 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10801 | .doit = nl80211_leave_mesh, |
| 10802 | .policy = nl80211_policy, |
| 10803 | .flags = GENL_ADMIN_PERM, |
| 10804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10805 | NL80211_FLAG_NEED_RTNL, |
| 10806 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10807 | { |
| 10808 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10809 | .doit = nl80211_join_ocb, |
| 10810 | .policy = nl80211_policy, |
| 10811 | .flags = GENL_ADMIN_PERM, |
| 10812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10813 | NL80211_FLAG_NEED_RTNL, |
| 10814 | }, |
| 10815 | { |
| 10816 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10817 | .doit = nl80211_leave_ocb, |
| 10818 | .policy = nl80211_policy, |
| 10819 | .flags = GENL_ADMIN_PERM, |
| 10820 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10821 | NL80211_FLAG_NEED_RTNL, |
| 10822 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10823 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10824 | { |
| 10825 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10826 | .doit = nl80211_get_wowlan, |
| 10827 | .policy = nl80211_policy, |
| 10828 | /* can be retrieved by unprivileged users */ |
| 10829 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10830 | NL80211_FLAG_NEED_RTNL, |
| 10831 | }, |
| 10832 | { |
| 10833 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10834 | .doit = nl80211_set_wowlan, |
| 10835 | .policy = nl80211_policy, |
| 10836 | .flags = GENL_ADMIN_PERM, |
| 10837 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10838 | NL80211_FLAG_NEED_RTNL, |
| 10839 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10840 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10841 | { |
| 10842 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10843 | .doit = nl80211_set_rekey_data, |
| 10844 | .policy = nl80211_policy, |
| 10845 | .flags = GENL_ADMIN_PERM, |
| 10846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10847 | NL80211_FLAG_NEED_RTNL | |
| 10848 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10849 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10850 | { |
| 10851 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10852 | .doit = nl80211_tdls_mgmt, |
| 10853 | .policy = nl80211_policy, |
| 10854 | .flags = GENL_ADMIN_PERM, |
| 10855 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10856 | NL80211_FLAG_NEED_RTNL, |
| 10857 | }, |
| 10858 | { |
| 10859 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10860 | .doit = nl80211_tdls_oper, |
| 10861 | .policy = nl80211_policy, |
| 10862 | .flags = GENL_ADMIN_PERM, |
| 10863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10864 | NL80211_FLAG_NEED_RTNL, |
| 10865 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10866 | { |
| 10867 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10868 | .doit = nl80211_register_unexpected_frame, |
| 10869 | .policy = nl80211_policy, |
| 10870 | .flags = GENL_ADMIN_PERM, |
| 10871 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10872 | NL80211_FLAG_NEED_RTNL, |
| 10873 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10874 | { |
| 10875 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10876 | .doit = nl80211_probe_client, |
| 10877 | .policy = nl80211_policy, |
| 10878 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10879 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10880 | NL80211_FLAG_NEED_RTNL, |
| 10881 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10882 | { |
| 10883 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10884 | .doit = nl80211_register_beacons, |
| 10885 | .policy = nl80211_policy, |
| 10886 | .flags = GENL_ADMIN_PERM, |
| 10887 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10888 | NL80211_FLAG_NEED_RTNL, |
| 10889 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10890 | { |
| 10891 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10892 | .doit = nl80211_set_noack_map, |
| 10893 | .policy = nl80211_policy, |
| 10894 | .flags = GENL_ADMIN_PERM, |
| 10895 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10896 | NL80211_FLAG_NEED_RTNL, |
| 10897 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10898 | { |
| 10899 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10900 | .doit = nl80211_start_p2p_device, |
| 10901 | .policy = nl80211_policy, |
| 10902 | .flags = GENL_ADMIN_PERM, |
| 10903 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10904 | NL80211_FLAG_NEED_RTNL, |
| 10905 | }, |
| 10906 | { |
| 10907 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10908 | .doit = nl80211_stop_p2p_device, |
| 10909 | .policy = nl80211_policy, |
| 10910 | .flags = GENL_ADMIN_PERM, |
| 10911 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10912 | NL80211_FLAG_NEED_RTNL, |
| 10913 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10914 | { |
| 10915 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10916 | .doit = nl80211_set_mcast_rate, |
| 10917 | .policy = nl80211_policy, |
| 10918 | .flags = GENL_ADMIN_PERM, |
| 10919 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10920 | NL80211_FLAG_NEED_RTNL, |
| 10921 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10922 | { |
| 10923 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10924 | .doit = nl80211_set_mac_acl, |
| 10925 | .policy = nl80211_policy, |
| 10926 | .flags = GENL_ADMIN_PERM, |
| 10927 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10928 | NL80211_FLAG_NEED_RTNL, |
| 10929 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10930 | { |
| 10931 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10932 | .doit = nl80211_start_radar_detection, |
| 10933 | .policy = nl80211_policy, |
| 10934 | .flags = GENL_ADMIN_PERM, |
| 10935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10936 | NL80211_FLAG_NEED_RTNL, |
| 10937 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10938 | { |
| 10939 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10940 | .doit = nl80211_get_protocol_features, |
| 10941 | .policy = nl80211_policy, |
| 10942 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10943 | { |
| 10944 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10945 | .doit = nl80211_update_ft_ies, |
| 10946 | .policy = nl80211_policy, |
| 10947 | .flags = GENL_ADMIN_PERM, |
| 10948 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10949 | NL80211_FLAG_NEED_RTNL, |
| 10950 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10951 | { |
| 10952 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10953 | .doit = nl80211_crit_protocol_start, |
| 10954 | .policy = nl80211_policy, |
| 10955 | .flags = GENL_ADMIN_PERM, |
| 10956 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10957 | NL80211_FLAG_NEED_RTNL, |
| 10958 | }, |
| 10959 | { |
| 10960 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10961 | .doit = nl80211_crit_protocol_stop, |
| 10962 | .policy = nl80211_policy, |
| 10963 | .flags = GENL_ADMIN_PERM, |
| 10964 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10965 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10966 | }, |
| 10967 | { |
| 10968 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10969 | .doit = nl80211_get_coalesce, |
| 10970 | .policy = nl80211_policy, |
| 10971 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10972 | NL80211_FLAG_NEED_RTNL, |
| 10973 | }, |
| 10974 | { |
| 10975 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10976 | .doit = nl80211_set_coalesce, |
| 10977 | .policy = nl80211_policy, |
| 10978 | .flags = GENL_ADMIN_PERM, |
| 10979 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10980 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10981 | }, |
| 10982 | { |
| 10983 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10984 | .doit = nl80211_channel_switch, |
| 10985 | .policy = nl80211_policy, |
| 10986 | .flags = GENL_ADMIN_PERM, |
| 10987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10988 | NL80211_FLAG_NEED_RTNL, |
| 10989 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10990 | { |
| 10991 | .cmd = NL80211_CMD_VENDOR, |
| 10992 | .doit = nl80211_vendor_cmd, |
| 10993 | .policy = nl80211_policy, |
| 10994 | .flags = GENL_ADMIN_PERM, |
| 10995 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10996 | NL80211_FLAG_NEED_RTNL, |
| 10997 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10998 | { |
| 10999 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11000 | .doit = nl80211_set_qos_map, |
| 11001 | .policy = nl80211_policy, |
| 11002 | .flags = GENL_ADMIN_PERM, |
| 11003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11004 | NL80211_FLAG_NEED_RTNL, |
| 11005 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11006 | { |
| 11007 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11008 | .doit = nl80211_add_tx_ts, |
| 11009 | .policy = nl80211_policy, |
| 11010 | .flags = GENL_ADMIN_PERM, |
| 11011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11012 | NL80211_FLAG_NEED_RTNL, |
| 11013 | }, |
| 11014 | { |
| 11015 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11016 | .doit = nl80211_del_tx_ts, |
| 11017 | .policy = nl80211_policy, |
| 11018 | .flags = GENL_ADMIN_PERM, |
| 11019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11020 | NL80211_FLAG_NEED_RTNL, |
| 11021 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11022 | { |
| 11023 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11024 | .doit = nl80211_tdls_channel_switch, |
| 11025 | .policy = nl80211_policy, |
| 11026 | .flags = GENL_ADMIN_PERM, |
| 11027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11028 | NL80211_FLAG_NEED_RTNL, |
| 11029 | }, |
| 11030 | { |
| 11031 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11032 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11033 | .policy = nl80211_policy, |
| 11034 | .flags = GENL_ADMIN_PERM, |
| 11035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11036 | NL80211_FLAG_NEED_RTNL, |
| 11037 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11038 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11039 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11040 | /* notification functions */ |
| 11041 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11042 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11043 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11044 | { |
| 11045 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11046 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11047 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11048 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11049 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11050 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11052 | if (!msg) |
| 11053 | return; |
| 11054 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11055 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11056 | nlmsg_free(msg); |
| 11057 | return; |
| 11058 | } |
| 11059 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11060 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11061 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11062 | } |
| 11063 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11064 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11065 | struct cfg80211_registered_device *rdev) |
| 11066 | { |
| 11067 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11068 | struct nlattr *nest; |
| 11069 | int i; |
| 11070 | |
| 11071 | if (WARN_ON(!req)) |
| 11072 | return 0; |
| 11073 | |
| 11074 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11075 | if (!nest) |
| 11076 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11077 | for (i = 0; i < req->n_ssids; i++) { |
| 11078 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11079 | goto nla_put_failure; |
| 11080 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11081 | nla_nest_end(msg, nest); |
| 11082 | |
| 11083 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11084 | if (!nest) |
| 11085 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11086 | for (i = 0; i < req->n_channels; i++) { |
| 11087 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11088 | goto nla_put_failure; |
| 11089 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11090 | nla_nest_end(msg, nest); |
| 11091 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11092 | if (req->ie && |
| 11093 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11094 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11095 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11096 | if (req->flags && |
| 11097 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11098 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11099 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11100 | return 0; |
| 11101 | nla_put_failure: |
| 11102 | return -ENOBUFS; |
| 11103 | } |
| 11104 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11105 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11106 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11107 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11108 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11109 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11110 | { |
| 11111 | void *hdr; |
| 11112 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11113 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11114 | if (!hdr) |
| 11115 | return -1; |
| 11116 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11117 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11118 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11119 | wdev->netdev->ifindex)) || |
| 11120 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11121 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11122 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11123 | /* ignore errors and send incomplete event anyway */ |
| 11124 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11125 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11126 | genlmsg_end(msg, hdr); |
| 11127 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11128 | |
| 11129 | nla_put_failure: |
| 11130 | genlmsg_cancel(msg, hdr); |
| 11131 | return -EMSGSIZE; |
| 11132 | } |
| 11133 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11134 | static int |
| 11135 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11136 | struct cfg80211_registered_device *rdev, |
| 11137 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11138 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11139 | { |
| 11140 | void *hdr; |
| 11141 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11142 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11143 | if (!hdr) |
| 11144 | return -1; |
| 11145 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11146 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11147 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11148 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11149 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11150 | genlmsg_end(msg, hdr); |
| 11151 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11152 | |
| 11153 | nla_put_failure: |
| 11154 | genlmsg_cancel(msg, hdr); |
| 11155 | return -EMSGSIZE; |
| 11156 | } |
| 11157 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11158 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11159 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11160 | { |
| 11161 | struct sk_buff *msg; |
| 11162 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11163 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11164 | if (!msg) |
| 11165 | return; |
| 11166 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11167 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11168 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11169 | nlmsg_free(msg); |
| 11170 | return; |
| 11171 | } |
| 11172 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11173 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11174 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11175 | } |
| 11176 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11177 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11178 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11179 | { |
| 11180 | struct sk_buff *msg; |
| 11181 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11183 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11184 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11185 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11186 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11187 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11188 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11189 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11190 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11191 | } |
| 11192 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11193 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11194 | } |
| 11195 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11196 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11197 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11198 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11199 | if (!msg) |
| 11200 | return; |
| 11201 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11203 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11204 | } |
| 11205 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11206 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11207 | struct net_device *netdev) |
| 11208 | { |
| 11209 | struct sk_buff *msg; |
| 11210 | |
| 11211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11212 | if (!msg) |
| 11213 | return; |
| 11214 | |
| 11215 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11216 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11217 | nlmsg_free(msg); |
| 11218 | return; |
| 11219 | } |
| 11220 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11221 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11222 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11223 | } |
| 11224 | |
| 11225 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11226 | struct net_device *netdev, u32 cmd) |
| 11227 | { |
| 11228 | struct sk_buff *msg; |
| 11229 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11231 | if (!msg) |
| 11232 | return; |
| 11233 | |
| 11234 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11235 | nlmsg_free(msg); |
| 11236 | return; |
| 11237 | } |
| 11238 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11239 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11240 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11241 | } |
| 11242 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11243 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11244 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11245 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11246 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11247 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11248 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11249 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11250 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11251 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11252 | NL80211_REGDOM_TYPE_WORLD)) |
| 11253 | goto nla_put_failure; |
| 11254 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11255 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11256 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11257 | goto nla_put_failure; |
| 11258 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11259 | request->intersect) { |
| 11260 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11261 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11262 | goto nla_put_failure; |
| 11263 | } else { |
| 11264 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11265 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11266 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11267 | request->alpha2)) |
| 11268 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11269 | } |
| 11270 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11271 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11272 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11273 | |
| 11274 | if (wiphy && |
| 11275 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11276 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 11277 | |
| 11278 | if (wiphy && |
| 11279 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 11280 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 11281 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11282 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11283 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11284 | return true; |
| 11285 | |
| 11286 | nla_put_failure: |
| 11287 | return false; |
| 11288 | } |
| 11289 | |
| 11290 | /* |
| 11291 | * This can happen on global regulatory changes or device specific settings |
| 11292 | * based on custom regulatory domains. |
| 11293 | */ |
| 11294 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11295 | struct regulatory_request *request) |
| 11296 | { |
| 11297 | struct sk_buff *msg; |
| 11298 | void *hdr; |
| 11299 | |
| 11300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11301 | if (!msg) |
| 11302 | return; |
| 11303 | |
| 11304 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11305 | if (!hdr) { |
| 11306 | nlmsg_free(msg); |
| 11307 | return; |
| 11308 | } |
| 11309 | |
| 11310 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11311 | goto nla_put_failure; |
| 11312 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11313 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11314 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11315 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11316 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11317 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11318 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11319 | |
| 11320 | return; |
| 11321 | |
| 11322 | nla_put_failure: |
| 11323 | genlmsg_cancel(msg, hdr); |
| 11324 | nlmsg_free(msg); |
| 11325 | } |
| 11326 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11327 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11328 | struct net_device *netdev, |
| 11329 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11330 | enum nl80211_commands cmd, gfp_t gfp, |
| 11331 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11332 | { |
| 11333 | struct sk_buff *msg; |
| 11334 | void *hdr; |
| 11335 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11336 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11337 | if (!msg) |
| 11338 | return; |
| 11339 | |
| 11340 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11341 | if (!hdr) { |
| 11342 | nlmsg_free(msg); |
| 11343 | return; |
| 11344 | } |
| 11345 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11348 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11349 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11350 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11351 | if (uapsd_queues >= 0) { |
| 11352 | struct nlattr *nla_wmm = |
| 11353 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11354 | if (!nla_wmm) |
| 11355 | goto nla_put_failure; |
| 11356 | |
| 11357 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11358 | uapsd_queues)) |
| 11359 | goto nla_put_failure; |
| 11360 | |
| 11361 | nla_nest_end(msg, nla_wmm); |
| 11362 | } |
| 11363 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11364 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11365 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11366 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11367 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11368 | return; |
| 11369 | |
| 11370 | nla_put_failure: |
| 11371 | genlmsg_cancel(msg, hdr); |
| 11372 | nlmsg_free(msg); |
| 11373 | } |
| 11374 | |
| 11375 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11376 | struct net_device *netdev, const u8 *buf, |
| 11377 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11378 | { |
| 11379 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11380 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11381 | } |
| 11382 | |
| 11383 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11384 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11385 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11386 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11387 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11388 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11389 | } |
| 11390 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11391 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11392 | struct net_device *netdev, const u8 *buf, |
| 11393 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11394 | { |
| 11395 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11396 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11397 | } |
| 11398 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11399 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11400 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11401 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11402 | { |
| 11403 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11404 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11405 | } |
| 11406 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11407 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11408 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11409 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11410 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11411 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11412 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11413 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11414 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11415 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11416 | if (WARN_ON(len < 2)) |
| 11417 | return; |
| 11418 | |
| 11419 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11420 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11421 | else |
| 11422 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11423 | |
| 11424 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11425 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11426 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11427 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11428 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11429 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11430 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11431 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11432 | { |
| 11433 | struct sk_buff *msg; |
| 11434 | void *hdr; |
| 11435 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11437 | if (!msg) |
| 11438 | return; |
| 11439 | |
| 11440 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11441 | if (!hdr) { |
| 11442 | nlmsg_free(msg); |
| 11443 | return; |
| 11444 | } |
| 11445 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11446 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11447 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11448 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11450 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11451 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11452 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11453 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11454 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11455 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11456 | return; |
| 11457 | |
| 11458 | nla_put_failure: |
| 11459 | genlmsg_cancel(msg, hdr); |
| 11460 | nlmsg_free(msg); |
| 11461 | } |
| 11462 | |
| 11463 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11464 | struct net_device *netdev, const u8 *addr, |
| 11465 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11466 | { |
| 11467 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11468 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11469 | } |
| 11470 | |
| 11471 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11472 | struct net_device *netdev, const u8 *addr, |
| 11473 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11474 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11475 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11476 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11477 | } |
| 11478 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11479 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11480 | struct net_device *netdev, const u8 *bssid, |
| 11481 | const u8 *req_ie, size_t req_ie_len, |
| 11482 | const u8 *resp_ie, size_t resp_ie_len, |
| 11483 | u16 status, gfp_t gfp) |
| 11484 | { |
| 11485 | struct sk_buff *msg; |
| 11486 | void *hdr; |
| 11487 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11489 | if (!msg) |
| 11490 | return; |
| 11491 | |
| 11492 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11493 | if (!hdr) { |
| 11494 | nlmsg_free(msg); |
| 11495 | return; |
| 11496 | } |
| 11497 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11499 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11500 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11501 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11502 | (req_ie && |
| 11503 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11504 | (resp_ie && |
| 11505 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11506 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11507 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11508 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11509 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11510 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11511 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11512 | return; |
| 11513 | |
| 11514 | nla_put_failure: |
| 11515 | genlmsg_cancel(msg, hdr); |
| 11516 | nlmsg_free(msg); |
| 11517 | |
| 11518 | } |
| 11519 | |
| 11520 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11521 | struct net_device *netdev, const u8 *bssid, |
| 11522 | const u8 *req_ie, size_t req_ie_len, |
| 11523 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11524 | { |
| 11525 | struct sk_buff *msg; |
| 11526 | void *hdr; |
| 11527 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11529 | if (!msg) |
| 11530 | return; |
| 11531 | |
| 11532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11533 | if (!hdr) { |
| 11534 | nlmsg_free(msg); |
| 11535 | return; |
| 11536 | } |
| 11537 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11539 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11540 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11541 | (req_ie && |
| 11542 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11543 | (resp_ie && |
| 11544 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11545 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11546 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11547 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11548 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11549 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11550 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11551 | return; |
| 11552 | |
| 11553 | nla_put_failure: |
| 11554 | genlmsg_cancel(msg, hdr); |
| 11555 | nlmsg_free(msg); |
| 11556 | |
| 11557 | } |
| 11558 | |
| 11559 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11560 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11561 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11562 | { |
| 11563 | struct sk_buff *msg; |
| 11564 | void *hdr; |
| 11565 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11566 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11567 | if (!msg) |
| 11568 | return; |
| 11569 | |
| 11570 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11571 | if (!hdr) { |
| 11572 | nlmsg_free(msg); |
| 11573 | return; |
| 11574 | } |
| 11575 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11576 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11577 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11578 | (from_ap && reason && |
| 11579 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11580 | (from_ap && |
| 11581 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11582 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11583 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11584 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11585 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11586 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11587 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11588 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11589 | return; |
| 11590 | |
| 11591 | nla_put_failure: |
| 11592 | genlmsg_cancel(msg, hdr); |
| 11593 | nlmsg_free(msg); |
| 11594 | |
| 11595 | } |
| 11596 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11597 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 11598 | struct net_device *netdev, const u8 *bssid, |
| 11599 | gfp_t gfp) |
| 11600 | { |
| 11601 | struct sk_buff *msg; |
| 11602 | void *hdr; |
| 11603 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11605 | if (!msg) |
| 11606 | return; |
| 11607 | |
| 11608 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11609 | if (!hdr) { |
| 11610 | nlmsg_free(msg); |
| 11611 | return; |
| 11612 | } |
| 11613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11616 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11617 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11618 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11619 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11620 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11621 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11622 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11623 | return; |
| 11624 | |
| 11625 | nla_put_failure: |
| 11626 | genlmsg_cancel(msg, hdr); |
| 11627 | nlmsg_free(msg); |
| 11628 | } |
| 11629 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11630 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11631 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11632 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11633 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11634 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11635 | struct sk_buff *msg; |
| 11636 | void *hdr; |
| 11637 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11638 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11639 | return; |
| 11640 | |
| 11641 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11642 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11644 | if (!msg) |
| 11645 | return; |
| 11646 | |
| 11647 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11648 | if (!hdr) { |
| 11649 | nlmsg_free(msg); |
| 11650 | return; |
| 11651 | } |
| 11652 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11653 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11654 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11655 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11656 | (ie_len && ie && |
| 11657 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11658 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11659 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11660 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11661 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11662 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11663 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11664 | return; |
| 11665 | |
| 11666 | nla_put_failure: |
| 11667 | genlmsg_cancel(msg, hdr); |
| 11668 | nlmsg_free(msg); |
| 11669 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11670 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11671 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11672 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11673 | struct net_device *netdev, const u8 *addr, |
| 11674 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11675 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11676 | { |
| 11677 | struct sk_buff *msg; |
| 11678 | void *hdr; |
| 11679 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11681 | if (!msg) |
| 11682 | return; |
| 11683 | |
| 11684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11685 | if (!hdr) { |
| 11686 | nlmsg_free(msg); |
| 11687 | return; |
| 11688 | } |
| 11689 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11690 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11691 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11692 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11693 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11694 | (key_id != -1 && |
| 11695 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11696 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11697 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11698 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11699 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11700 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11701 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11702 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11703 | return; |
| 11704 | |
| 11705 | nla_put_failure: |
| 11706 | genlmsg_cancel(msg, hdr); |
| 11707 | nlmsg_free(msg); |
| 11708 | } |
| 11709 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11710 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11711 | struct ieee80211_channel *channel_before, |
| 11712 | struct ieee80211_channel *channel_after) |
| 11713 | { |
| 11714 | struct sk_buff *msg; |
| 11715 | void *hdr; |
| 11716 | struct nlattr *nl_freq; |
| 11717 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11718 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11719 | if (!msg) |
| 11720 | return; |
| 11721 | |
| 11722 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11723 | if (!hdr) { |
| 11724 | nlmsg_free(msg); |
| 11725 | return; |
| 11726 | } |
| 11727 | |
| 11728 | /* |
| 11729 | * Since we are applying the beacon hint to a wiphy we know its |
| 11730 | * wiphy_idx is valid |
| 11731 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11733 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11734 | |
| 11735 | /* Before */ |
| 11736 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11737 | if (!nl_freq) |
| 11738 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11739 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11740 | goto nla_put_failure; |
| 11741 | nla_nest_end(msg, nl_freq); |
| 11742 | |
| 11743 | /* After */ |
| 11744 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11745 | if (!nl_freq) |
| 11746 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11747 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11748 | goto nla_put_failure; |
| 11749 | nla_nest_end(msg, nl_freq); |
| 11750 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11751 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11752 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11753 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11754 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11755 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11756 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11757 | |
| 11758 | return; |
| 11759 | |
| 11760 | nla_put_failure: |
| 11761 | genlmsg_cancel(msg, hdr); |
| 11762 | nlmsg_free(msg); |
| 11763 | } |
| 11764 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11765 | static void nl80211_send_remain_on_chan_event( |
| 11766 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11767 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11768 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11769 | unsigned int duration, gfp_t gfp) |
| 11770 | { |
| 11771 | struct sk_buff *msg; |
| 11772 | void *hdr; |
| 11773 | |
| 11774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11775 | if (!msg) |
| 11776 | return; |
| 11777 | |
| 11778 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11779 | if (!hdr) { |
| 11780 | nlmsg_free(msg); |
| 11781 | return; |
| 11782 | } |
| 11783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11784 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11785 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11786 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11787 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11788 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11789 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11790 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11791 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11792 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11793 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11794 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11795 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11796 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11797 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11798 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11799 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11801 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11802 | return; |
| 11803 | |
| 11804 | nla_put_failure: |
| 11805 | genlmsg_cancel(msg, hdr); |
| 11806 | nlmsg_free(msg); |
| 11807 | } |
| 11808 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11809 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11810 | struct ieee80211_channel *chan, |
| 11811 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11812 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11813 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11814 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11815 | |
| 11816 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11817 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11818 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11819 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11820 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11821 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11822 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11823 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11824 | struct ieee80211_channel *chan, |
| 11825 | gfp_t gfp) |
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 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11828 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11829 | |
| 11830 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11831 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11832 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11833 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11834 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11835 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11836 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11837 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11838 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11839 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11840 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11841 | struct sk_buff *msg; |
| 11842 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11843 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11844 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11845 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11846 | if (!msg) |
| 11847 | return; |
| 11848 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11849 | 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] | 11850 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11851 | nlmsg_free(msg); |
| 11852 | return; |
| 11853 | } |
| 11854 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11855 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11856 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11857 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11858 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11859 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11860 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 11861 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11862 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11863 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11865 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11866 | struct station_info empty_sinfo = {}; |
| 11867 | |
| 11868 | if (!sinfo) |
| 11869 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11870 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11871 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11872 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11874 | if (!msg) |
| 11875 | return; |
| 11876 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11877 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 11878 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11879 | nlmsg_free(msg); |
| 11880 | return; |
| 11881 | } |
| 11882 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11883 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11884 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11885 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 11886 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11887 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11888 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11889 | enum nl80211_connect_failed_reason reason, |
| 11890 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11891 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11892 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11893 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11894 | struct sk_buff *msg; |
| 11895 | void *hdr; |
| 11896 | |
| 11897 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11898 | if (!msg) |
| 11899 | return; |
| 11900 | |
| 11901 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11902 | if (!hdr) { |
| 11903 | nlmsg_free(msg); |
| 11904 | return; |
| 11905 | } |
| 11906 | |
| 11907 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11908 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11909 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11910 | goto nla_put_failure; |
| 11911 | |
| 11912 | genlmsg_end(msg, hdr); |
| 11913 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11914 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11915 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11916 | return; |
| 11917 | |
| 11918 | nla_put_failure: |
| 11919 | genlmsg_cancel(msg, hdr); |
| 11920 | nlmsg_free(msg); |
| 11921 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11922 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11923 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11924 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11925 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11926 | { |
| 11927 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11928 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11929 | struct sk_buff *msg; |
| 11930 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11931 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11932 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11933 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11934 | return false; |
| 11935 | |
| 11936 | msg = nlmsg_new(100, gfp); |
| 11937 | if (!msg) |
| 11938 | return true; |
| 11939 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11940 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11941 | if (!hdr) { |
| 11942 | nlmsg_free(msg); |
| 11943 | return true; |
| 11944 | } |
| 11945 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11947 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11948 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11949 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11950 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11951 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11952 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11953 | return true; |
| 11954 | |
| 11955 | nla_put_failure: |
| 11956 | genlmsg_cancel(msg, hdr); |
| 11957 | nlmsg_free(msg); |
| 11958 | return true; |
| 11959 | } |
| 11960 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11961 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11962 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11963 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11964 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11965 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11966 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11967 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11968 | |
| 11969 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11970 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11971 | trace_cfg80211_return_bool(false); |
| 11972 | return false; |
| 11973 | } |
| 11974 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11975 | addr, gfp); |
| 11976 | trace_cfg80211_return_bool(ret); |
| 11977 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11978 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11979 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11980 | |
| 11981 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11982 | const u8 *addr, gfp_t gfp) |
| 11983 | { |
| 11984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11985 | bool ret; |
| 11986 | |
| 11987 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11988 | |
| 11989 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11990 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11991 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11992 | trace_cfg80211_return_bool(false); |
| 11993 | return false; |
| 11994 | } |
| 11995 | ret = __nl80211_unexpected_frame(dev, |
| 11996 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11997 | addr, gfp); |
| 11998 | trace_cfg80211_return_bool(ret); |
| 11999 | return ret; |
| 12000 | } |
| 12001 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12002 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12003 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12004 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12005 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12006 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12007 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12008 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12009 | struct sk_buff *msg; |
| 12010 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12011 | |
| 12012 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12013 | if (!msg) |
| 12014 | return -ENOMEM; |
| 12015 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12016 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12017 | if (!hdr) { |
| 12018 | nlmsg_free(msg); |
| 12019 | return -ENOMEM; |
| 12020 | } |
| 12021 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12022 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12023 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12024 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12025 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12026 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12027 | (sig_dbm && |
| 12028 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12029 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12030 | (flags && |
| 12031 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12032 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12033 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12034 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12035 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12036 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12037 | |
| 12038 | nla_put_failure: |
| 12039 | genlmsg_cancel(msg, hdr); |
| 12040 | nlmsg_free(msg); |
| 12041 | return -ENOBUFS; |
| 12042 | } |
| 12043 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12044 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12045 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12046 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12047 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12048 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12049 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12050 | struct sk_buff *msg; |
| 12051 | void *hdr; |
| 12052 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12053 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12054 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12055 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12056 | if (!msg) |
| 12057 | return; |
| 12058 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12059 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12060 | if (!hdr) { |
| 12061 | nlmsg_free(msg); |
| 12062 | return; |
| 12063 | } |
| 12064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12065 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12066 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12067 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 12068 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12069 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12070 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12071 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12072 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12073 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12074 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12075 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12076 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12077 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12078 | return; |
| 12079 | |
| 12080 | nla_put_failure: |
| 12081 | genlmsg_cancel(msg, hdr); |
| 12082 | nlmsg_free(msg); |
| 12083 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12084 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12085 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12086 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12087 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12088 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12089 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12090 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12091 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12092 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12093 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12094 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12095 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12096 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12097 | cb = (void **)msg->cb; |
| 12098 | |
| 12099 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12100 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12101 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12102 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12103 | } |
| 12104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12106 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12107 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12108 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12109 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12110 | goto nla_put_failure; |
| 12111 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12112 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12113 | if (!cb[1]) |
| 12114 | goto nla_put_failure; |
| 12115 | |
| 12116 | cb[2] = rdev; |
| 12117 | |
| 12118 | return msg; |
| 12119 | nla_put_failure: |
| 12120 | nlmsg_free(msg); |
| 12121 | return NULL; |
| 12122 | } |
| 12123 | |
| 12124 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12125 | { |
| 12126 | void **cb = (void **)msg->cb; |
| 12127 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12128 | |
| 12129 | nla_nest_end(msg, cb[1]); |
| 12130 | genlmsg_end(msg, cb[0]); |
| 12131 | |
| 12132 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12133 | |
| 12134 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12135 | NL80211_MCGRP_MLME, gfp); |
| 12136 | } |
| 12137 | |
| 12138 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12139 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12140 | gfp_t gfp) |
| 12141 | { |
| 12142 | struct sk_buff *msg; |
| 12143 | |
| 12144 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12145 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12146 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12147 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12148 | return; |
| 12149 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12150 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12151 | if (!msg) |
| 12152 | return; |
| 12153 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12154 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12155 | rssi_event)) |
| 12156 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12157 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12158 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12159 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12160 | return; |
| 12161 | |
| 12162 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12163 | nlmsg_free(msg); |
| 12164 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12165 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12166 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12167 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12168 | const u8 *peer, u32 num_packets, |
| 12169 | u32 rate, u32 intvl, gfp_t gfp) |
| 12170 | { |
| 12171 | struct sk_buff *msg; |
| 12172 | |
| 12173 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12174 | if (!msg) |
| 12175 | return; |
| 12176 | |
| 12177 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12178 | goto nla_put_failure; |
| 12179 | |
| 12180 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12181 | goto nla_put_failure; |
| 12182 | |
| 12183 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12184 | goto nla_put_failure; |
| 12185 | |
| 12186 | cfg80211_send_cqm(msg, gfp); |
| 12187 | return; |
| 12188 | |
| 12189 | nla_put_failure: |
| 12190 | nlmsg_free(msg); |
| 12191 | } |
| 12192 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12193 | |
| 12194 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12195 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12196 | { |
| 12197 | struct sk_buff *msg; |
| 12198 | |
| 12199 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12200 | |
| 12201 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12202 | if (!msg) |
| 12203 | return; |
| 12204 | |
| 12205 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12206 | goto nla_put_failure; |
| 12207 | |
| 12208 | cfg80211_send_cqm(msg, gfp); |
| 12209 | return; |
| 12210 | |
| 12211 | nla_put_failure: |
| 12212 | nlmsg_free(msg); |
| 12213 | } |
| 12214 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12215 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12216 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12217 | { |
| 12218 | struct sk_buff *msg; |
| 12219 | |
| 12220 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12221 | if (!msg) |
| 12222 | return; |
| 12223 | |
| 12224 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12225 | goto nla_put_failure; |
| 12226 | |
| 12227 | cfg80211_send_cqm(msg, gfp); |
| 12228 | return; |
| 12229 | |
| 12230 | nla_put_failure: |
| 12231 | nlmsg_free(msg); |
| 12232 | } |
| 12233 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12234 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12235 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12236 | struct net_device *netdev, const u8 *bssid, |
| 12237 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12238 | { |
| 12239 | struct sk_buff *msg; |
| 12240 | struct nlattr *rekey_attr; |
| 12241 | void *hdr; |
| 12242 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12244 | if (!msg) |
| 12245 | return; |
| 12246 | |
| 12247 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12248 | if (!hdr) { |
| 12249 | nlmsg_free(msg); |
| 12250 | return; |
| 12251 | } |
| 12252 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12253 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12254 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12255 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12256 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12257 | |
| 12258 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12259 | if (!rekey_attr) |
| 12260 | goto nla_put_failure; |
| 12261 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12262 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12263 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12264 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12265 | |
| 12266 | nla_nest_end(msg, rekey_attr); |
| 12267 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12268 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12269 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12270 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12271 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12272 | return; |
| 12273 | |
| 12274 | nla_put_failure: |
| 12275 | genlmsg_cancel(msg, hdr); |
| 12276 | nlmsg_free(msg); |
| 12277 | } |
| 12278 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12279 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12280 | const u8 *replay_ctr, gfp_t gfp) |
| 12281 | { |
| 12282 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12283 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12284 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12285 | |
| 12286 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12287 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12288 | } |
| 12289 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12290 | |
| 12291 | static void |
| 12292 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12293 | struct net_device *netdev, int index, |
| 12294 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12295 | { |
| 12296 | struct sk_buff *msg; |
| 12297 | struct nlattr *attr; |
| 12298 | void *hdr; |
| 12299 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12301 | if (!msg) |
| 12302 | return; |
| 12303 | |
| 12304 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12305 | if (!hdr) { |
| 12306 | nlmsg_free(msg); |
| 12307 | return; |
| 12308 | } |
| 12309 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12310 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12311 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12312 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12313 | |
| 12314 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12315 | if (!attr) |
| 12316 | goto nla_put_failure; |
| 12317 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12318 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12319 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12320 | (preauth && |
| 12321 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12322 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12323 | |
| 12324 | nla_nest_end(msg, attr); |
| 12325 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12326 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12327 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12328 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12329 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12330 | return; |
| 12331 | |
| 12332 | nla_put_failure: |
| 12333 | genlmsg_cancel(msg, hdr); |
| 12334 | nlmsg_free(msg); |
| 12335 | } |
| 12336 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12337 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12338 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12339 | { |
| 12340 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12341 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12342 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12343 | |
| 12344 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12345 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12346 | } |
| 12347 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12348 | |
| 12349 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12350 | struct net_device *netdev, |
| 12351 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12352 | gfp_t gfp, |
| 12353 | enum nl80211_commands notif, |
| 12354 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12355 | { |
| 12356 | struct sk_buff *msg; |
| 12357 | void *hdr; |
| 12358 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12360 | if (!msg) |
| 12361 | return; |
| 12362 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12363 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12364 | if (!hdr) { |
| 12365 | nlmsg_free(msg); |
| 12366 | return; |
| 12367 | } |
| 12368 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12369 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12370 | goto nla_put_failure; |
| 12371 | |
| 12372 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12373 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12374 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12375 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12376 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12377 | goto nla_put_failure; |
| 12378 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12379 | genlmsg_end(msg, hdr); |
| 12380 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12381 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12382 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12383 | return; |
| 12384 | |
| 12385 | nla_put_failure: |
| 12386 | genlmsg_cancel(msg, hdr); |
| 12387 | nlmsg_free(msg); |
| 12388 | } |
| 12389 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12390 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12391 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12392 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12393 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12394 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12395 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12396 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12397 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12398 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12399 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12400 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12401 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12402 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12403 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12404 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12405 | } |
| 12406 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12407 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12408 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12409 | struct cfg80211_chan_def *chandef, |
| 12410 | u8 count) |
| 12411 | { |
| 12412 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12413 | struct wiphy *wiphy = wdev->wiphy; |
| 12414 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12415 | |
| 12416 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12417 | |
| 12418 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12419 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12420 | } |
| 12421 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12422 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12423 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12424 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12425 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12426 | enum nl80211_radar_event event, |
| 12427 | struct net_device *netdev, gfp_t gfp) |
| 12428 | { |
| 12429 | struct sk_buff *msg; |
| 12430 | void *hdr; |
| 12431 | |
| 12432 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12433 | if (!msg) |
| 12434 | return; |
| 12435 | |
| 12436 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12437 | if (!hdr) { |
| 12438 | nlmsg_free(msg); |
| 12439 | return; |
| 12440 | } |
| 12441 | |
| 12442 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12443 | goto nla_put_failure; |
| 12444 | |
| 12445 | /* NOP and radar events don't need a netdev parameter */ |
| 12446 | if (netdev) { |
| 12447 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12448 | |
| 12449 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12450 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12451 | goto nla_put_failure; |
| 12452 | } |
| 12453 | |
| 12454 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12455 | goto nla_put_failure; |
| 12456 | |
| 12457 | if (nl80211_send_chandef(msg, chandef)) |
| 12458 | goto nla_put_failure; |
| 12459 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12460 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12461 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12462 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12463 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12464 | return; |
| 12465 | |
| 12466 | nla_put_failure: |
| 12467 | genlmsg_cancel(msg, hdr); |
| 12468 | nlmsg_free(msg); |
| 12469 | } |
| 12470 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12471 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12472 | u64 cookie, bool acked, gfp_t gfp) |
| 12473 | { |
| 12474 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12475 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12476 | struct sk_buff *msg; |
| 12477 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12478 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12479 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12480 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12482 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12483 | if (!msg) |
| 12484 | return; |
| 12485 | |
| 12486 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12487 | if (!hdr) { |
| 12488 | nlmsg_free(msg); |
| 12489 | return; |
| 12490 | } |
| 12491 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12492 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12493 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12494 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12495 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12496 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12497 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12498 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12499 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12500 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12501 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12502 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12503 | return; |
| 12504 | |
| 12505 | nla_put_failure: |
| 12506 | genlmsg_cancel(msg, hdr); |
| 12507 | nlmsg_free(msg); |
| 12508 | } |
| 12509 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12510 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12511 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12512 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12513 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12514 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12515 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12516 | struct sk_buff *msg; |
| 12517 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12518 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12519 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12520 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12521 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12522 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12523 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12524 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12525 | if (!msg) { |
| 12526 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12527 | return; |
| 12528 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12529 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12530 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12531 | if (!hdr) |
| 12532 | goto nla_put_failure; |
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 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12535 | (freq && |
| 12536 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12537 | (sig_dbm && |
| 12538 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12539 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12540 | goto nla_put_failure; |
| 12541 | |
| 12542 | genlmsg_end(msg, hdr); |
| 12543 | |
| 12544 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12545 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12546 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12547 | return; |
| 12548 | |
| 12549 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12550 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12551 | if (hdr) |
| 12552 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12553 | nlmsg_free(msg); |
| 12554 | } |
| 12555 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12556 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12557 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12558 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12559 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12560 | { |
| 12561 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12562 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12563 | int i, j; |
| 12564 | |
| 12565 | nl_results = nla_nest_start( |
| 12566 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12567 | if (!nl_results) |
| 12568 | return -EMSGSIZE; |
| 12569 | |
| 12570 | for (i = 0; i < nd->n_matches; i++) { |
| 12571 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12572 | |
| 12573 | nl_match = nla_nest_start(msg, i); |
| 12574 | if (!nl_match) |
| 12575 | break; |
| 12576 | |
| 12577 | /* The SSID attribute is optional in nl80211, but for |
| 12578 | * simplicity reasons it's always present in the |
| 12579 | * cfg80211 structure. If a driver can't pass the |
| 12580 | * SSID, that needs to be changed. A zero length SSID |
| 12581 | * is still a valid SSID (wildcard), so it cannot be |
| 12582 | * used for this purpose. |
| 12583 | */ |
| 12584 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12585 | match->ssid.ssid)) { |
| 12586 | nla_nest_cancel(msg, nl_match); |
| 12587 | goto out; |
| 12588 | } |
| 12589 | |
| 12590 | if (match->n_channels) { |
| 12591 | nl_freqs = nla_nest_start( |
| 12592 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12593 | if (!nl_freqs) { |
| 12594 | nla_nest_cancel(msg, nl_match); |
| 12595 | goto out; |
| 12596 | } |
| 12597 | |
| 12598 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 12599 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12600 | nla_nest_cancel(msg, nl_freqs); |
| 12601 | nla_nest_cancel(msg, nl_match); |
| 12602 | goto out; |
| 12603 | } |
| 12604 | } |
| 12605 | |
| 12606 | nla_nest_end(msg, nl_freqs); |
| 12607 | } |
| 12608 | |
| 12609 | nla_nest_end(msg, nl_match); |
| 12610 | } |
| 12611 | |
| 12612 | out: |
| 12613 | nla_nest_end(msg, nl_results); |
| 12614 | return 0; |
| 12615 | } |
| 12616 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12617 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 12618 | struct cfg80211_wowlan_wakeup *wakeup, |
| 12619 | gfp_t gfp) |
| 12620 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12622 | struct sk_buff *msg; |
| 12623 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12624 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12625 | |
| 12626 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 12627 | |
| 12628 | if (wakeup) |
| 12629 | size += wakeup->packet_present_len; |
| 12630 | |
| 12631 | msg = nlmsg_new(size, gfp); |
| 12632 | if (!msg) |
| 12633 | return; |
| 12634 | |
| 12635 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 12636 | if (!hdr) |
| 12637 | goto free_msg; |
| 12638 | |
| 12639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12640 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12641 | goto free_msg; |
| 12642 | |
| 12643 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12644 | wdev->netdev->ifindex)) |
| 12645 | goto free_msg; |
| 12646 | |
| 12647 | if (wakeup) { |
| 12648 | struct nlattr *reasons; |
| 12649 | |
| 12650 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12651 | if (!reasons) |
| 12652 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12653 | |
| 12654 | if (wakeup->disconnect && |
| 12655 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 12656 | goto free_msg; |
| 12657 | if (wakeup->magic_pkt && |
| 12658 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 12659 | goto free_msg; |
| 12660 | if (wakeup->gtk_rekey_failure && |
| 12661 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 12662 | goto free_msg; |
| 12663 | if (wakeup->eap_identity_req && |
| 12664 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 12665 | goto free_msg; |
| 12666 | if (wakeup->four_way_handshake && |
| 12667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 12668 | goto free_msg; |
| 12669 | if (wakeup->rfkill_release && |
| 12670 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12671 | goto free_msg; |
| 12672 | |
| 12673 | if (wakeup->pattern_idx >= 0 && |
| 12674 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12675 | wakeup->pattern_idx)) |
| 12676 | goto free_msg; |
| 12677 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12678 | if (wakeup->tcp_match && |
| 12679 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12680 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12681 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12682 | if (wakeup->tcp_connlost && |
| 12683 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 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_nomoretokens && |
| 12687 | nla_put_flag(msg, |
| 12688 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12689 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12690 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12691 | if (wakeup->packet) { |
| 12692 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12693 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12694 | |
| 12695 | if (!wakeup->packet_80211) { |
| 12696 | pkt_attr = |
| 12697 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12698 | len_attr = |
| 12699 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12700 | } |
| 12701 | |
| 12702 | if (wakeup->packet_len && |
| 12703 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12704 | goto free_msg; |
| 12705 | |
| 12706 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12707 | wakeup->packet)) |
| 12708 | goto free_msg; |
| 12709 | } |
| 12710 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12711 | if (wakeup->net_detect && |
| 12712 | cfg80211_net_detect_results(msg, wakeup)) |
| 12713 | goto free_msg; |
| 12714 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12715 | nla_nest_end(msg, reasons); |
| 12716 | } |
| 12717 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12718 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12719 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12720 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12721 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12722 | return; |
| 12723 | |
| 12724 | free_msg: |
| 12725 | nlmsg_free(msg); |
| 12726 | } |
| 12727 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12728 | #endif |
| 12729 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12730 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12731 | enum nl80211_tdls_operation oper, |
| 12732 | u16 reason_code, gfp_t gfp) |
| 12733 | { |
| 12734 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12735 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12736 | struct sk_buff *msg; |
| 12737 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12738 | |
| 12739 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12740 | reason_code); |
| 12741 | |
| 12742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12743 | if (!msg) |
| 12744 | return; |
| 12745 | |
| 12746 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12747 | if (!hdr) { |
| 12748 | nlmsg_free(msg); |
| 12749 | return; |
| 12750 | } |
| 12751 | |
| 12752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12754 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12755 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12756 | (reason_code > 0 && |
| 12757 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12758 | goto nla_put_failure; |
| 12759 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12760 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12761 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12763 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12764 | return; |
| 12765 | |
| 12766 | nla_put_failure: |
| 12767 | genlmsg_cancel(msg, hdr); |
| 12768 | nlmsg_free(msg); |
| 12769 | } |
| 12770 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12771 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12772 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12773 | unsigned long state, |
| 12774 | void *_notify) |
| 12775 | { |
| 12776 | struct netlink_notify *notify = _notify; |
| 12777 | struct cfg80211_registered_device *rdev; |
| 12778 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12779 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12780 | |
| 12781 | if (state != NETLINK_URELEASE) |
| 12782 | return NOTIFY_DONE; |
| 12783 | |
| 12784 | rcu_read_lock(); |
| 12785 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12786 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12787 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12788 | bool schedule_scan_stop = false; |
| 12789 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 12790 | rcu_dereference(rdev->sched_scan_req); |
| 12791 | |
| 12792 | if (sched_scan_req && notify->portid && |
| 12793 | sched_scan_req->owner_nlportid == notify->portid) |
| 12794 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12795 | |
| 12796 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12797 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12798 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12799 | if (wdev->owner_nlportid == notify->portid) |
| 12800 | schedule_destroy_work = true; |
| 12801 | } |
| 12802 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12803 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12804 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12805 | list) { |
| 12806 | if (reg->nlportid == notify->portid) { |
| 12807 | list_del(®->list); |
| 12808 | kfree(reg); |
| 12809 | break; |
| 12810 | } |
| 12811 | } |
| 12812 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12813 | |
| 12814 | if (schedule_destroy_work) { |
| 12815 | struct cfg80211_iface_destroy *destroy; |
| 12816 | |
| 12817 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12818 | if (destroy) { |
| 12819 | destroy->nlportid = notify->portid; |
| 12820 | spin_lock(&rdev->destroy_list_lock); |
| 12821 | list_add(&destroy->list, &rdev->destroy_list); |
| 12822 | spin_unlock(&rdev->destroy_list_lock); |
| 12823 | schedule_work(&rdev->destroy_work); |
| 12824 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12825 | } else if (schedule_scan_stop) { |
| 12826 | sched_scan_req->owner_nlportid = 0; |
| 12827 | |
| 12828 | if (rdev->ops->sched_scan_stop && |
| 12829 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 12830 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12831 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12832 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12833 | |
| 12834 | rcu_read_unlock(); |
| 12835 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 12836 | /* |
| 12837 | * It is possible that the user space process that is controlling the |
| 12838 | * indoor setting disappeared, so notify the regulatory core. |
| 12839 | */ |
| 12840 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12841 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12842 | } |
| 12843 | |
| 12844 | static struct notifier_block nl80211_netlink_notifier = { |
| 12845 | .notifier_call = nl80211_netlink_notify, |
| 12846 | }; |
| 12847 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12848 | void cfg80211_ft_event(struct net_device *netdev, |
| 12849 | struct cfg80211_ft_event_params *ft_event) |
| 12850 | { |
| 12851 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12853 | struct sk_buff *msg; |
| 12854 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12855 | |
| 12856 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12857 | |
| 12858 | if (!ft_event->target_ap) |
| 12859 | return; |
| 12860 | |
| 12861 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12862 | if (!msg) |
| 12863 | return; |
| 12864 | |
| 12865 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12866 | if (!hdr) |
| 12867 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12868 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12870 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12871 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12872 | goto out; |
| 12873 | |
| 12874 | if (ft_event->ies && |
| 12875 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12876 | goto out; |
| 12877 | if (ft_event->ric_ies && |
| 12878 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12879 | ft_event->ric_ies)) |
| 12880 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12881 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12882 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12883 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12884 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12885 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12886 | return; |
| 12887 | out: |
| 12888 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12889 | } |
| 12890 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12891 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12892 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12893 | { |
| 12894 | struct cfg80211_registered_device *rdev; |
| 12895 | struct sk_buff *msg; |
| 12896 | void *hdr; |
| 12897 | u32 nlportid; |
| 12898 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12899 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12900 | if (!rdev->crit_proto_nlportid) |
| 12901 | return; |
| 12902 | |
| 12903 | nlportid = rdev->crit_proto_nlportid; |
| 12904 | rdev->crit_proto_nlportid = 0; |
| 12905 | |
| 12906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12907 | if (!msg) |
| 12908 | return; |
| 12909 | |
| 12910 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12911 | if (!hdr) |
| 12912 | goto nla_put_failure; |
| 12913 | |
| 12914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12915 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12916 | goto nla_put_failure; |
| 12917 | |
| 12918 | genlmsg_end(msg, hdr); |
| 12919 | |
| 12920 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12921 | return; |
| 12922 | |
| 12923 | nla_put_failure: |
| 12924 | if (hdr) |
| 12925 | genlmsg_cancel(msg, hdr); |
| 12926 | nlmsg_free(msg); |
| 12927 | |
| 12928 | } |
| 12929 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12930 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12931 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12932 | { |
| 12933 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12934 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12935 | struct sk_buff *msg; |
| 12936 | void *hdr; |
| 12937 | |
| 12938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12939 | if (!msg) |
| 12940 | return; |
| 12941 | |
| 12942 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12943 | if (!hdr) |
| 12944 | goto out; |
| 12945 | |
| 12946 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12947 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12948 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12949 | goto out; |
| 12950 | |
| 12951 | genlmsg_end(msg, hdr); |
| 12952 | |
| 12953 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12954 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12955 | return; |
| 12956 | out: |
| 12957 | nlmsg_free(msg); |
| 12958 | } |
| 12959 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12960 | /* initialisation/exit functions */ |
| 12961 | |
| 12962 | int nl80211_init(void) |
| 12963 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12964 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12965 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12966 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12967 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12968 | if (err) |
| 12969 | return err; |
| 12970 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12971 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12972 | if (err) |
| 12973 | goto err_out; |
| 12974 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12975 | return 0; |
| 12976 | err_out: |
| 12977 | genl_unregister_family(&nl80211_fam); |
| 12978 | return err; |
| 12979 | } |
| 12980 | |
| 12981 | void nl80211_exit(void) |
| 12982 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12983 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12984 | genl_unregister_family(&nl80211_fam); |
| 12985 | } |