| 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 | 36aedc9 | 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 | dc6382ce | 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 }, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 400 | }; | 
 | 401 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 402 | /* policy for the key attributes */ | 
| Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 403 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 404 | 	[NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 405 | 	[NL80211_KEY_IDX] = { .type = NLA_U8 }, | 
 | 406 | 	[NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | 
| Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 407 | 	[NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | 	[NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | 
 | 409 | 	[NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 410 | 	[NL80211_KEY_TYPE] = { .type = NLA_U32 }, | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 411 | 	[NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, | 
 | 412 | }; | 
 | 413 |  | 
 | 414 | /* policy for the key default flags */ | 
 | 415 | static const struct nla_policy | 
 | 416 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | 
 | 417 | 	[NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | 
 | 418 | 	[NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 419 | }; | 
 | 420 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 421 | /* policy for WoWLAN attributes */ | 
 | 422 | static const struct nla_policy | 
 | 423 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | 
 | 424 | 	[NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | 
 | 425 | 	[NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | 
 | 426 | 	[NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | 
 | 427 | 	[NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | 
| Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 428 | 	[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, | 
 | 429 | 	[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | 
 | 430 | 	[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | 
 | 431 | 	[NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 432 | 	[NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 433 | 	[NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 434 | }; | 
 | 435 |  | 
 | 436 | static const struct nla_policy | 
 | 437 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | 
 | 438 | 	[NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | 
 | 439 | 	[NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | 
 | 440 | 	[NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | 
 | 441 | 	[NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | 
 | 442 | 	[NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | 
 | 443 | 	[NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | 
 | 444 | 	[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | 
 | 445 | 		.len = sizeof(struct nl80211_wowlan_tcp_data_seq) | 
 | 446 | 	}, | 
 | 447 | 	[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | 
 | 448 | 		.len = sizeof(struct nl80211_wowlan_tcp_data_token) | 
 | 449 | 	}, | 
 | 450 | 	[NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | 
 | 451 | 	[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | 
 | 452 | 	[NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 453 | }; | 
 | 454 |  | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 455 | /* policy for coalesce rule attributes */ | 
 | 456 | static const struct nla_policy | 
 | 457 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | 
 | 458 | 	[NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | 
 | 459 | 	[NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | 
 | 460 | 	[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | 
 | 461 | }; | 
 | 462 |  | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 463 | /* policy for GTK rekey offload attributes */ | 
 | 464 | static const struct nla_policy | 
 | 465 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | 
 | 466 | 	[NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | 
 | 467 | 	[NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | 
 | 468 | 	[NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | 
 | 469 | }; | 
 | 470 |  | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 471 | static const struct nla_policy | 
 | 472 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | 
| Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 473 | 	[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 474 | 						 .len = IEEE80211_MAX_SSID_LEN }, | 
| Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 475 | 	[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 476 | }; | 
 | 477 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 478 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, | 
 | 479 | 				     struct netlink_callback *cb, | 
 | 480 | 				     struct cfg80211_registered_device **rdev, | 
 | 481 | 				     struct wireless_dev **wdev) | 
| Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 482 | { | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 483 | 	int err; | 
 | 484 |  | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 485 | 	rtnl_lock(); | 
 | 486 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 487 | 	if (!cb->args[0]) { | 
 | 488 | 		err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | 
 | 489 | 				  nl80211_fam.attrbuf, nl80211_fam.maxattr, | 
 | 490 | 				  nl80211_policy); | 
 | 491 | 		if (err) | 
 | 492 | 			goto out_unlock; | 
 | 493 |  | 
 | 494 | 		*wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), | 
 | 495 | 						   nl80211_fam.attrbuf); | 
 | 496 | 		if (IS_ERR(*wdev)) { | 
 | 497 | 			err = PTR_ERR(*wdev); | 
 | 498 | 			goto out_unlock; | 
 | 499 | 		} | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 500 | 		*rdev = wiphy_to_rdev((*wdev)->wiphy); | 
| Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 501 | 		/* 0 is the first index - add 1 to parse only once */ | 
 | 502 | 		cb->args[0] = (*rdev)->wiphy_idx + 1; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 503 | 		cb->args[1] = (*wdev)->identifier; | 
 | 504 | 	} else { | 
| Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 505 | 		/* subtract the 1 again here */ | 
 | 506 | 		struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 507 | 		struct wireless_dev *tmp; | 
 | 508 |  | 
 | 509 | 		if (!wiphy) { | 
 | 510 | 			err = -ENODEV; | 
 | 511 | 			goto out_unlock; | 
 | 512 | 		} | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 513 | 		*rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | 		*wdev = NULL; | 
 | 515 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 516 | 		list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { | 
 | 517 | 			if (tmp->identifier == cb->args[1]) { | 
 | 518 | 				*wdev = tmp; | 
 | 519 | 				break; | 
 | 520 | 			} | 
 | 521 | 		} | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 522 |  | 
 | 523 | 		if (!*wdev) { | 
 | 524 | 			err = -ENODEV; | 
 | 525 | 			goto out_unlock; | 
 | 526 | 		} | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 527 | 	} | 
 | 528 |  | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 529 | 	return 0; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 530 |  out_unlock: | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 531 | 	rtnl_unlock(); | 
 | 532 | 	return err; | 
 | 533 | } | 
 | 534 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 535 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 536 | { | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 537 | 	rtnl_unlock(); | 
 | 538 | } | 
 | 539 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 540 | /* IE validation */ | 
 | 541 | static bool is_valid_ie_attr(const struct nlattr *attr) | 
 | 542 | { | 
 | 543 | 	const u8 *pos; | 
 | 544 | 	int len; | 
 | 545 |  | 
 | 546 | 	if (!attr) | 
 | 547 | 		return true; | 
 | 548 |  | 
 | 549 | 	pos = nla_data(attr); | 
 | 550 | 	len = nla_len(attr); | 
 | 551 |  | 
 | 552 | 	while (len) { | 
 | 553 | 		u8 elemlen; | 
 | 554 |  | 
 | 555 | 		if (len < 2) | 
 | 556 | 			return false; | 
 | 557 | 		len -= 2; | 
 | 558 |  | 
 | 559 | 		elemlen = pos[1]; | 
 | 560 | 		if (elemlen > len) | 
 | 561 | 			return false; | 
 | 562 |  | 
 | 563 | 		len -= elemlen; | 
 | 564 | 		pos += 2 + elemlen; | 
 | 565 | 	} | 
 | 566 |  | 
 | 567 | 	return true; | 
 | 568 | } | 
 | 569 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 570 | /* message building helper */ | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 571 | 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] | 572 | 				   int flags, u8 cmd) | 
 | 573 | { | 
 | 574 | 	/* since there is no private header just add the generic one */ | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 575 | 	return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 576 | } | 
 | 577 |  | 
| Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 578 | static int nl80211_msg_put_channel(struct sk_buff *msg, | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 579 | 				   struct ieee80211_channel *chan, | 
 | 580 | 				   bool large) | 
| Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 581 | { | 
| Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 582 | 	/* Some channels must be completely excluded from the | 
 | 583 | 	 * list to protect old user-space tools from breaking | 
 | 584 | 	 */ | 
 | 585 | 	if (!large && chan->flags & | 
 | 586 | 	    (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | 
 | 587 | 		return 0; | 
 | 588 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 589 | 	if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, | 
 | 590 | 			chan->center_freq)) | 
 | 591 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 592 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 593 | 	if ((chan->flags & IEEE80211_CHAN_DISABLED) && | 
 | 594 | 	    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | 
 | 595 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 596 | 	if (chan->flags & IEEE80211_CHAN_NO_IR) { | 
 | 597 | 		if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | 
 | 598 | 			goto nla_put_failure; | 
 | 599 | 		if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | 
 | 600 | 			goto nla_put_failure; | 
 | 601 | 	} | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 602 | 	if (chan->flags & IEEE80211_CHAN_RADAR) { | 
 | 603 | 		if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | 
 | 604 | 			goto nla_put_failure; | 
 | 605 | 		if (large) { | 
 | 606 | 			u32 time; | 
 | 607 |  | 
 | 608 | 			time = elapsed_jiffies_msecs(chan->dfs_state_entered); | 
 | 609 |  | 
 | 610 | 			if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | 
 | 611 | 					chan->dfs_state)) | 
 | 612 | 				goto nla_put_failure; | 
 | 613 | 			if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | 
 | 614 | 					time)) | 
 | 615 | 				goto nla_put_failure; | 
| Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 616 | 			if (nla_put_u32(msg, | 
 | 617 | 					NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | 
 | 618 | 					chan->dfs_cac_ms)) | 
 | 619 | 				goto nla_put_failure; | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 620 | 		} | 
 | 621 | 	} | 
| Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 622 |  | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 623 | 	if (large) { | 
 | 624 | 		if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | 
 | 625 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | 
 | 626 | 			goto nla_put_failure; | 
 | 627 | 		if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | 
 | 628 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | 
 | 629 | 			goto nla_put_failure; | 
 | 630 | 		if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | 
 | 631 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | 
 | 632 | 			goto nla_put_failure; | 
 | 633 | 		if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | 
 | 634 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | 
 | 635 | 			goto nla_put_failure; | 
| David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 636 | 		if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && | 
 | 637 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | 
 | 638 | 			goto nla_put_failure; | 
 | 639 | 		if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | 
 | 640 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | 
 | 641 | 			goto nla_put_failure; | 
| Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 642 | 		if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && | 
 | 643 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | 
 | 644 | 			goto nla_put_failure; | 
 | 645 | 		if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | 
 | 646 | 		    nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | 
 | 647 | 			goto nla_put_failure; | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 648 | 	} | 
 | 649 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 650 | 	if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | 
 | 651 | 			DBM_TO_MBM(chan->max_power))) | 
 | 652 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 653 |  | 
 | 654 | 	return 0; | 
 | 655 |  | 
 | 656 |  nla_put_failure: | 
 | 657 | 	return -ENOBUFS; | 
 | 658 | } | 
 | 659 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 660 | /* netlink command implementations */ | 
 | 661 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 662 | struct key_parse { | 
 | 663 | 	struct key_params p; | 
 | 664 | 	int idx; | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 665 | 	int type; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 666 | 	bool def, defmgmt; | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 667 | 	bool def_uni, def_multi; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 668 | }; | 
 | 669 |  | 
 | 670 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | 
 | 671 | { | 
 | 672 | 	struct nlattr *tb[NL80211_KEY_MAX + 1]; | 
 | 673 | 	int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | 
 | 674 | 				   nl80211_key_policy); | 
 | 675 | 	if (err) | 
 | 676 | 		return err; | 
 | 677 |  | 
 | 678 | 	k->def = !!tb[NL80211_KEY_DEFAULT]; | 
 | 679 | 	k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | 
 | 680 |  | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 681 | 	if (k->def) { | 
 | 682 | 		k->def_uni = true; | 
 | 683 | 		k->def_multi = true; | 
 | 684 | 	} | 
 | 685 | 	if (k->defmgmt) | 
 | 686 | 		k->def_multi = true; | 
 | 687 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 688 | 	if (tb[NL80211_KEY_IDX]) | 
 | 689 | 		k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | 
 | 690 |  | 
 | 691 | 	if (tb[NL80211_KEY_DATA]) { | 
 | 692 | 		k->p.key = nla_data(tb[NL80211_KEY_DATA]); | 
 | 693 | 		k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | 
 | 694 | 	} | 
 | 695 |  | 
 | 696 | 	if (tb[NL80211_KEY_SEQ]) { | 
 | 697 | 		k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | 
 | 698 | 		k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | 
 | 699 | 	} | 
 | 700 |  | 
 | 701 | 	if (tb[NL80211_KEY_CIPHER]) | 
 | 702 | 		k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | 
 | 703 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 704 | 	if (tb[NL80211_KEY_TYPE]) { | 
 | 705 | 		k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | 
 | 706 | 		if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | 
 | 707 | 			return -EINVAL; | 
 | 708 | 	} | 
 | 709 |  | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 710 | 	if (tb[NL80211_KEY_DEFAULT_TYPES]) { | 
 | 711 | 		struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | 
| Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 712 | 		err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | 
 | 713 | 				       tb[NL80211_KEY_DEFAULT_TYPES], | 
 | 714 | 				       nl80211_key_default_policy); | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 715 | 		if (err) | 
 | 716 | 			return err; | 
 | 717 |  | 
 | 718 | 		k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | 
 | 719 | 		k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | 
 | 720 | 	} | 
 | 721 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 722 | 	return 0; | 
 | 723 | } | 
 | 724 |  | 
 | 725 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | 
 | 726 | { | 
 | 727 | 	if (info->attrs[NL80211_ATTR_KEY_DATA]) { | 
 | 728 | 		k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | 
 | 729 | 		k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | 
 | 730 | 	} | 
 | 731 |  | 
 | 732 | 	if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | 
 | 733 | 		k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | 
 | 734 | 		k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | 
 | 735 | 	} | 
 | 736 |  | 
 | 737 | 	if (info->attrs[NL80211_ATTR_KEY_IDX]) | 
 | 738 | 		k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | 
 | 739 |  | 
 | 740 | 	if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | 
 | 741 | 		k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | 
 | 742 |  | 
 | 743 | 	k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | 
 | 744 | 	k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | 
 | 745 |  | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 746 | 	if (k->def) { | 
 | 747 | 		k->def_uni = true; | 
 | 748 | 		k->def_multi = true; | 
 | 749 | 	} | 
 | 750 | 	if (k->defmgmt) | 
 | 751 | 		k->def_multi = true; | 
 | 752 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 753 | 	if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | 
 | 754 | 		k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | 
 | 755 | 		if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | 
 | 756 | 			return -EINVAL; | 
 | 757 | 	} | 
 | 758 |  | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 759 | 	if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { | 
 | 760 | 		struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | 
 | 761 | 		int err = nla_parse_nested( | 
 | 762 | 				kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | 
 | 763 | 				info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | 
 | 764 | 				nl80211_key_default_policy); | 
 | 765 | 		if (err) | 
 | 766 | 			return err; | 
 | 767 |  | 
 | 768 | 		k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | 
 | 769 | 		k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | 
 | 770 | 	} | 
 | 771 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 772 | 	return 0; | 
 | 773 | } | 
 | 774 |  | 
 | 775 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | 
 | 776 | { | 
 | 777 | 	int err; | 
 | 778 |  | 
 | 779 | 	memset(k, 0, sizeof(*k)); | 
 | 780 | 	k->idx = -1; | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | 	k->type = -1; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 782 |  | 
 | 783 | 	if (info->attrs[NL80211_ATTR_KEY]) | 
 | 784 | 		err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | 
 | 785 | 	else | 
 | 786 | 		err = nl80211_parse_key_old(info, k); | 
 | 787 |  | 
 | 788 | 	if (err) | 
 | 789 | 		return err; | 
 | 790 |  | 
 | 791 | 	if (k->def && k->defmgmt) | 
 | 792 | 		return -EINVAL; | 
 | 793 |  | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 794 | 	if (k->defmgmt) { | 
 | 795 | 		if (k->def_uni || !k->def_multi) | 
 | 796 | 			return -EINVAL; | 
 | 797 | 	} | 
 | 798 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 799 | 	if (k->idx != -1) { | 
 | 800 | 		if (k->defmgmt) { | 
 | 801 | 			if (k->idx < 4 || k->idx > 5) | 
 | 802 | 				return -EINVAL; | 
 | 803 | 		} else if (k->def) { | 
 | 804 | 			if (k->idx < 0 || k->idx > 3) | 
 | 805 | 				return -EINVAL; | 
 | 806 | 		} else { | 
 | 807 | 			if (k->idx < 0 || k->idx > 5) | 
 | 808 | 				return -EINVAL; | 
 | 809 | 		} | 
 | 810 | 	} | 
 | 811 |  | 
 | 812 | 	return 0; | 
 | 813 | } | 
 | 814 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | static struct cfg80211_cached_keys * | 
 | 816 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 817 | 		       struct nlattr *keys, bool *no_ht) | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | { | 
 | 819 | 	struct key_parse parse; | 
 | 820 | 	struct nlattr *key; | 
 | 821 | 	struct cfg80211_cached_keys *result; | 
 | 822 | 	int rem, err, def = 0; | 
 | 823 |  | 
 | 824 | 	result = kzalloc(sizeof(*result), GFP_KERNEL); | 
 | 825 | 	if (!result) | 
 | 826 | 		return ERR_PTR(-ENOMEM); | 
 | 827 |  | 
 | 828 | 	result->def = -1; | 
 | 829 | 	result->defmgmt = -1; | 
 | 830 |  | 
 | 831 | 	nla_for_each_nested(key, keys, rem) { | 
 | 832 | 		memset(&parse, 0, sizeof(parse)); | 
 | 833 | 		parse.idx = -1; | 
 | 834 |  | 
 | 835 | 		err = nl80211_parse_key_new(key, &parse); | 
 | 836 | 		if (err) | 
 | 837 | 			goto error; | 
 | 838 | 		err = -EINVAL; | 
 | 839 | 		if (!parse.p.key) | 
 | 840 | 			goto error; | 
 | 841 | 		if (parse.idx < 0 || parse.idx > 4) | 
 | 842 | 			goto error; | 
 | 843 | 		if (parse.def) { | 
 | 844 | 			if (def) | 
 | 845 | 				goto error; | 
 | 846 | 			def = 1; | 
 | 847 | 			result->def = parse.idx; | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 848 | 			if (!parse.def_uni || !parse.def_multi) | 
 | 849 | 				goto error; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 850 | 		} else if (parse.defmgmt) | 
 | 851 | 			goto error; | 
 | 852 | 		err = cfg80211_validate_key_settings(rdev, &parse.p, | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 853 | 						     parse.idx, false, NULL); | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 854 | 		if (err) | 
 | 855 | 			goto error; | 
 | 856 | 		result->params[parse.idx].cipher = parse.p.cipher; | 
 | 857 | 		result->params[parse.idx].key_len = parse.p.key_len; | 
 | 858 | 		result->params[parse.idx].key = result->data[parse.idx]; | 
 | 859 | 		memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 860 |  | 
 | 861 | 		if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | 
 | 862 | 		    parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | 
 | 863 | 			if (no_ht) | 
 | 864 | 				*no_ht = true; | 
 | 865 | 		} | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 866 | 	} | 
 | 867 |  | 
 | 868 | 	return result; | 
 | 869 |  error: | 
 | 870 | 	kfree(result); | 
 | 871 | 	return ERR_PTR(err); | 
 | 872 | } | 
 | 873 |  | 
 | 874 | static int nl80211_key_allowed(struct wireless_dev *wdev) | 
 | 875 | { | 
 | 876 | 	ASSERT_WDEV_LOCK(wdev); | 
 | 877 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | 	switch (wdev->iftype) { | 
 | 879 | 	case NL80211_IFTYPE_AP: | 
 | 880 | 	case NL80211_IFTYPE_AP_VLAN: | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 881 | 	case NL80211_IFTYPE_P2P_GO: | 
| Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 882 | 	case NL80211_IFTYPE_MESH_POINT: | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 883 | 		break; | 
 | 884 | 	case NL80211_IFTYPE_ADHOC: | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 885 | 	case NL80211_IFTYPE_STATION: | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 886 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
| Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 887 | 		if (!wdev->current_bss) | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 888 | 			return -ENOLINK; | 
 | 889 | 		break; | 
| Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 890 | 	case NL80211_IFTYPE_UNSPECIFIED: | 
| Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 891 | 	case NL80211_IFTYPE_OCB: | 
| Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 892 | 	case NL80211_IFTYPE_MONITOR: | 
 | 893 | 	case NL80211_IFTYPE_P2P_DEVICE: | 
 | 894 | 	case NL80211_IFTYPE_WDS: | 
 | 895 | 	case NUM_NL80211_IFTYPES: | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 896 | 		return -EINVAL; | 
 | 897 | 	} | 
 | 898 |  | 
 | 899 | 	return 0; | 
 | 900 | } | 
 | 901 |  | 
| Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 902 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, | 
 | 903 | 							struct nlattr *tb) | 
 | 904 | { | 
 | 905 | 	struct ieee80211_channel *chan; | 
 | 906 |  | 
 | 907 | 	if (tb == NULL) | 
 | 908 | 		return NULL; | 
 | 909 | 	chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | 
 | 910 | 	if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 911 | 		return NULL; | 
 | 912 | 	return chan; | 
 | 913 | } | 
 | 914 |  | 
| Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 915 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) | 
 | 916 | { | 
 | 917 | 	struct nlattr *nl_modes = nla_nest_start(msg, attr); | 
 | 918 | 	int i; | 
 | 919 |  | 
 | 920 | 	if (!nl_modes) | 
 | 921 | 		goto nla_put_failure; | 
 | 922 |  | 
 | 923 | 	i = 0; | 
 | 924 | 	while (ifmodes) { | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 925 | 		if ((ifmodes & 1) && nla_put_flag(msg, i)) | 
 | 926 | 			goto nla_put_failure; | 
| Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 927 | 		ifmodes >>= 1; | 
 | 928 | 		i++; | 
 | 929 | 	} | 
 | 930 |  | 
 | 931 | 	nla_nest_end(msg, nl_modes); | 
 | 932 | 	return 0; | 
 | 933 |  | 
 | 934 | nla_put_failure: | 
 | 935 | 	return -ENOBUFS; | 
 | 936 | } | 
 | 937 |  | 
 | 938 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 939 | 					  struct sk_buff *msg, | 
 | 940 | 					  bool large) | 
| Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 941 | { | 
 | 942 | 	struct nlattr *nl_combis; | 
 | 943 | 	int i, j; | 
 | 944 |  | 
 | 945 | 	nl_combis = nla_nest_start(msg, | 
 | 946 | 				NL80211_ATTR_INTERFACE_COMBINATIONS); | 
 | 947 | 	if (!nl_combis) | 
 | 948 | 		goto nla_put_failure; | 
 | 949 |  | 
 | 950 | 	for (i = 0; i < wiphy->n_iface_combinations; i++) { | 
 | 951 | 		const struct ieee80211_iface_combination *c; | 
 | 952 | 		struct nlattr *nl_combi, *nl_limits; | 
 | 953 |  | 
 | 954 | 		c = &wiphy->iface_combinations[i]; | 
 | 955 |  | 
 | 956 | 		nl_combi = nla_nest_start(msg, i + 1); | 
 | 957 | 		if (!nl_combi) | 
 | 958 | 			goto nla_put_failure; | 
 | 959 |  | 
 | 960 | 		nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | 
 | 961 | 		if (!nl_limits) | 
 | 962 | 			goto nla_put_failure; | 
 | 963 |  | 
 | 964 | 		for (j = 0; j < c->n_limits; j++) { | 
 | 965 | 			struct nlattr *nl_limit; | 
 | 966 |  | 
 | 967 | 			nl_limit = nla_nest_start(msg, j + 1); | 
 | 968 | 			if (!nl_limit) | 
 | 969 | 				goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 970 | 			if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, | 
 | 971 | 					c->limits[j].max)) | 
 | 972 | 				goto nla_put_failure; | 
| Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 973 | 			if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, | 
 | 974 | 						c->limits[j].types)) | 
 | 975 | 				goto nla_put_failure; | 
 | 976 | 			nla_nest_end(msg, nl_limit); | 
 | 977 | 		} | 
 | 978 |  | 
 | 979 | 		nla_nest_end(msg, nl_limits); | 
 | 980 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 981 | 		if (c->beacon_int_infra_match && | 
 | 982 | 		    nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | 
 | 983 | 			goto nla_put_failure; | 
 | 984 | 		if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | 
 | 985 | 				c->num_different_channels) || | 
 | 986 | 		    nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | 
 | 987 | 				c->max_interfaces)) | 
 | 988 | 			goto nla_put_failure; | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 989 | 		if (large && | 
| Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 990 | 		    (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | 
 | 991 | 				c->radar_detect_widths) || | 
 | 992 | 		     nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | 
 | 993 | 				c->radar_detect_regions))) | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 994 | 			goto nla_put_failure; | 
| Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 995 |  | 
 | 996 | 		nla_nest_end(msg, nl_combi); | 
 | 997 | 	} | 
 | 998 |  | 
 | 999 | 	nla_nest_end(msg, nl_combis); | 
 | 1000 |  | 
 | 1001 | 	return 0; | 
 | 1002 | nla_put_failure: | 
 | 1003 | 	return -ENOBUFS; | 
 | 1004 | } | 
 | 1005 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | #ifdef CONFIG_PM | 
| Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1007 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, | 
 | 1008 | 					struct sk_buff *msg) | 
 | 1009 | { | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1010 | 	const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; | 
| Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1011 | 	struct nlattr *nl_tcp; | 
 | 1012 |  | 
 | 1013 | 	if (!tcp) | 
 | 1014 | 		return 0; | 
 | 1015 |  | 
 | 1016 | 	nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | 
 | 1017 | 	if (!nl_tcp) | 
 | 1018 | 		return -ENOBUFS; | 
 | 1019 |  | 
 | 1020 | 	if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
 | 1021 | 			tcp->data_payload_max)) | 
 | 1022 | 		return -ENOBUFS; | 
 | 1023 |  | 
 | 1024 | 	if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
 | 1025 | 			tcp->data_payload_max)) | 
 | 1026 | 		return -ENOBUFS; | 
 | 1027 |  | 
 | 1028 | 	if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | 
 | 1029 | 		return -ENOBUFS; | 
 | 1030 |  | 
 | 1031 | 	if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | 
 | 1032 | 				sizeof(*tcp->tok), tcp->tok)) | 
 | 1033 | 		return -ENOBUFS; | 
 | 1034 |  | 
 | 1035 | 	if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | 
 | 1036 | 			tcp->data_interval_max)) | 
 | 1037 | 		return -ENOBUFS; | 
 | 1038 |  | 
 | 1039 | 	if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | 
 | 1040 | 			tcp->wake_payload_max)) | 
 | 1041 | 		return -ENOBUFS; | 
 | 1042 |  | 
 | 1043 | 	nla_nest_end(msg, nl_tcp); | 
 | 1044 | 	return 0; | 
 | 1045 | } | 
 | 1046 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1047 | static int nl80211_send_wowlan(struct sk_buff *msg, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1048 | 			       struct cfg80211_registered_device *rdev, | 
| Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1049 | 			       bool large) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | { | 
 | 1051 | 	struct nlattr *nl_wowlan; | 
 | 1052 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1053 | 	if (!rdev->wiphy.wowlan) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1054 | 		return 0; | 
 | 1055 |  | 
 | 1056 | 	nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | 
 | 1057 | 	if (!nl_wowlan) | 
 | 1058 | 		return -ENOBUFS; | 
 | 1059 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1060 | 	if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1061 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1062 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1063 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1066 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1067 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1068 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1069 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1070 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1071 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1073 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1074 | 	    ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | 	     nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | 
 | 1076 | 		return -ENOBUFS; | 
 | 1077 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1078 | 	if (rdev->wiphy.wowlan->n_patterns) { | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1079 | 		struct nl80211_pattern_support pat = { | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1080 | 			.max_patterns = rdev->wiphy.wowlan->n_patterns, | 
 | 1081 | 			.min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | 
 | 1082 | 			.max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | 
 | 1083 | 			.max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1084 | 		}; | 
 | 1085 |  | 
 | 1086 | 		if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | 
 | 1087 | 			    sizeof(pat), &pat)) | 
 | 1088 | 			return -ENOBUFS; | 
 | 1089 | 	} | 
 | 1090 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1091 | 	if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) | 
| Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1092 | 		return -ENOBUFS; | 
 | 1093 |  | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 1094 | 	/* TODO: send wowlan net detect */ | 
 | 1095 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1096 | 	nla_nest_end(msg, nl_wowlan); | 
 | 1097 |  | 
 | 1098 | 	return 0; | 
 | 1099 | } | 
 | 1100 | #endif | 
 | 1101 |  | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1102 | static int nl80211_send_coalesce(struct sk_buff *msg, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1103 | 				 struct cfg80211_registered_device *rdev) | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1104 | { | 
 | 1105 | 	struct nl80211_coalesce_rule_support rule; | 
 | 1106 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1107 | 	if (!rdev->wiphy.coalesce) | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1108 | 		return 0; | 
 | 1109 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1110 | 	rule.max_rules = rdev->wiphy.coalesce->n_rules; | 
 | 1111 | 	rule.max_delay = rdev->wiphy.coalesce->max_delay; | 
 | 1112 | 	rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | 
 | 1113 | 	rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | 
 | 1114 | 	rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | 
 | 1115 | 	rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1116 |  | 
 | 1117 | 	if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | 
 | 1118 | 		return -ENOBUFS; | 
 | 1119 |  | 
 | 1120 | 	return 0; | 
 | 1121 | } | 
 | 1122 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1123 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, | 
 | 1124 | 				      struct ieee80211_supported_band *sband) | 
 | 1125 | { | 
 | 1126 | 	struct nlattr *nl_rates, *nl_rate; | 
 | 1127 | 	struct ieee80211_rate *rate; | 
 | 1128 | 	int i; | 
 | 1129 |  | 
 | 1130 | 	/* add HT info */ | 
 | 1131 | 	if (sband->ht_cap.ht_supported && | 
 | 1132 | 	    (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | 
 | 1133 | 		     sizeof(sband->ht_cap.mcs), | 
 | 1134 | 		     &sband->ht_cap.mcs) || | 
 | 1135 | 	     nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | 
 | 1136 | 			 sband->ht_cap.cap) || | 
 | 1137 | 	     nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | 
 | 1138 | 			sband->ht_cap.ampdu_factor) || | 
 | 1139 | 	     nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | 
 | 1140 | 			sband->ht_cap.ampdu_density))) | 
 | 1141 | 		return -ENOBUFS; | 
 | 1142 |  | 
 | 1143 | 	/* add VHT info */ | 
 | 1144 | 	if (sband->vht_cap.vht_supported && | 
 | 1145 | 	    (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | 
 | 1146 | 		     sizeof(sband->vht_cap.vht_mcs), | 
 | 1147 | 		     &sband->vht_cap.vht_mcs) || | 
 | 1148 | 	     nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | 
 | 1149 | 			 sband->vht_cap.cap))) | 
 | 1150 | 		return -ENOBUFS; | 
 | 1151 |  | 
 | 1152 | 	/* add bitrates */ | 
 | 1153 | 	nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | 
 | 1154 | 	if (!nl_rates) | 
 | 1155 | 		return -ENOBUFS; | 
 | 1156 |  | 
 | 1157 | 	for (i = 0; i < sband->n_bitrates; i++) { | 
 | 1158 | 		nl_rate = nla_nest_start(msg, i); | 
 | 1159 | 		if (!nl_rate) | 
 | 1160 | 			return -ENOBUFS; | 
 | 1161 |  | 
 | 1162 | 		rate = &sband->bitrates[i]; | 
 | 1163 | 		if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | 
 | 1164 | 				rate->bitrate)) | 
 | 1165 | 			return -ENOBUFS; | 
 | 1166 | 		if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | 
 | 1167 | 		    nla_put_flag(msg, | 
 | 1168 | 				 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | 
 | 1169 | 			return -ENOBUFS; | 
 | 1170 |  | 
 | 1171 | 		nla_nest_end(msg, nl_rate); | 
 | 1172 | 	} | 
 | 1173 |  | 
 | 1174 | 	nla_nest_end(msg, nl_rates); | 
 | 1175 |  | 
 | 1176 | 	return 0; | 
 | 1177 | } | 
 | 1178 |  | 
 | 1179 | static int | 
 | 1180 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | 
 | 1181 | 			 const struct ieee80211_txrx_stypes *mgmt_stypes) | 
 | 1182 | { | 
 | 1183 | 	u16 stypes; | 
 | 1184 | 	struct nlattr *nl_ftypes, *nl_ifs; | 
 | 1185 | 	enum nl80211_iftype ift; | 
 | 1186 | 	int i; | 
 | 1187 |  | 
 | 1188 | 	if (!mgmt_stypes) | 
 | 1189 | 		return 0; | 
 | 1190 |  | 
 | 1191 | 	nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | 
 | 1192 | 	if (!nl_ifs) | 
 | 1193 | 		return -ENOBUFS; | 
 | 1194 |  | 
 | 1195 | 	for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | 
 | 1196 | 		nl_ftypes = nla_nest_start(msg, ift); | 
 | 1197 | 		if (!nl_ftypes) | 
 | 1198 | 			return -ENOBUFS; | 
 | 1199 | 		i = 0; | 
 | 1200 | 		stypes = mgmt_stypes[ift].tx; | 
 | 1201 | 		while (stypes) { | 
 | 1202 | 			if ((stypes & 1) && | 
 | 1203 | 			    nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | 
 | 1204 | 					(i << 4) | IEEE80211_FTYPE_MGMT)) | 
 | 1205 | 				return -ENOBUFS; | 
 | 1206 | 			stypes >>= 1; | 
 | 1207 | 			i++; | 
 | 1208 | 		} | 
 | 1209 | 		nla_nest_end(msg, nl_ftypes); | 
 | 1210 | 	} | 
 | 1211 |  | 
 | 1212 | 	nla_nest_end(msg, nl_ifs); | 
 | 1213 |  | 
 | 1214 | 	nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); | 
 | 1215 | 	if (!nl_ifs) | 
 | 1216 | 		return -ENOBUFS; | 
 | 1217 |  | 
 | 1218 | 	for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | 
 | 1219 | 		nl_ftypes = nla_nest_start(msg, ift); | 
 | 1220 | 		if (!nl_ftypes) | 
 | 1221 | 			return -ENOBUFS; | 
 | 1222 | 		i = 0; | 
 | 1223 | 		stypes = mgmt_stypes[ift].rx; | 
 | 1224 | 		while (stypes) { | 
 | 1225 | 			if ((stypes & 1) && | 
 | 1226 | 			    nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | 
 | 1227 | 					(i << 4) | IEEE80211_FTYPE_MGMT)) | 
 | 1228 | 				return -ENOBUFS; | 
 | 1229 | 			stypes >>= 1; | 
 | 1230 | 			i++; | 
 | 1231 | 		} | 
 | 1232 | 		nla_nest_end(msg, nl_ftypes); | 
 | 1233 | 	} | 
 | 1234 | 	nla_nest_end(msg, nl_ifs); | 
 | 1235 |  | 
 | 1236 | 	return 0; | 
 | 1237 | } | 
 | 1238 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1239 | struct nl80211_dump_wiphy_state { | 
 | 1240 | 	s64 filter_wiphy; | 
 | 1241 | 	long start; | 
 | 1242 | 	long split_start, band_start, chan_start; | 
 | 1243 | 	bool split; | 
 | 1244 | }; | 
 | 1245 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1246 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1247 | 			      enum nl80211_commands cmd, | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | 			      struct sk_buff *msg, u32 portid, u32 seq, | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1249 | 			      int flags, struct nl80211_dump_wiphy_state *state) | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1250 | { | 
 | 1251 | 	void *hdr; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1252 | 	struct nlattr *nl_bands, *nl_band; | 
 | 1253 | 	struct nlattr *nl_freqs, *nl_freq; | 
| Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1254 | 	struct nlattr *nl_cmds; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1255 | 	enum ieee80211_band band; | 
 | 1256 | 	struct ieee80211_channel *chan; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1257 | 	int i; | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1258 | 	const struct ieee80211_txrx_stypes *mgmt_stypes = | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1259 | 				rdev->wiphy.mgmt_stypes; | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1260 | 	u32 features; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1261 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1262 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1263 | 	if (!hdr) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | 		return -ENOBUFS; | 
 | 1265 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1266 | 	if (WARN_ON(!state)) | 
 | 1267 | 		return -EINVAL; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1268 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | 	    nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | 			   wiphy_name(&rdev->wiphy)) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1272 | 	    nla_put_u32(msg, NL80211_ATTR_GENERATION, | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | 			cfg80211_rdev_list_generation)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1274 | 		goto nla_put_failure; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1275 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1276 | 	if (cmd != NL80211_CMD_NEW_WIPHY) | 
 | 1277 | 		goto finish; | 
 | 1278 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1279 | 	switch (state->split_start) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | 	case 0: | 
 | 1281 | 		if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | 			       rdev->wiphy.retry_short) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | 		    nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | 			       rdev->wiphy.retry_long) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | 		    nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1286 | 				rdev->wiphy.frag_threshold) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | 		    nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | 				rdev->wiphy.rts_threshold) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | 		    nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | 			       rdev->wiphy.coverage_class) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1291 | 		    nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | 			       rdev->wiphy.max_scan_ssids) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | 		    nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1294 | 			       rdev->wiphy.max_sched_scan_ssids) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | 		    nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | 				rdev->wiphy.max_scan_ie_len) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | 		    nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | 				rdev->wiphy.max_sched_scan_ie_len) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | 		    nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | 			       rdev->wiphy.max_match_sets)) | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1301 | 			goto nla_put_failure; | 
 | 1302 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1303 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | 		    nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | 
 | 1305 | 			goto nla_put_failure; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1307 | 		    nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | 
 | 1308 | 			goto nla_put_failure; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | 		    nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | 
 | 1311 | 			goto nla_put_failure; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1312 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | 		    nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | 
 | 1314 | 			goto nla_put_failure; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | 		    nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | 
 | 1317 | 			goto nla_put_failure; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1318 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | 		    nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1320 | 			goto nla_put_failure; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1321 | 		state->split_start++; | 
 | 1322 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | 			break; | 
 | 1324 | 	case 1: | 
 | 1325 | 		if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1326 | 			    sizeof(u32) * rdev->wiphy.n_cipher_suites, | 
 | 1327 | 			    rdev->wiphy.cipher_suites)) | 
| Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1328 | 			goto nla_put_failure; | 
 | 1329 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | 		if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | 			       rdev->wiphy.max_num_pmkids)) | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1332 | 			goto nla_put_failure; | 
 | 1333 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | 		    nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | 
 | 1336 | 			goto nla_put_failure; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1337 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | 				rdev->wiphy.available_antennas_tx) || | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | 		    nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1341 | 				rdev->wiphy.available_antennas_rx)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | 			goto nla_put_failure; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1343 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | 		    nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | 				rdev->wiphy.probe_resp_offload)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | 			goto nla_put_failure; | 
| Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1348 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1349 | 		if ((rdev->wiphy.available_antennas_tx || | 
 | 1350 | 		     rdev->wiphy.available_antennas_rx) && | 
 | 1351 | 		    rdev->ops->get_antenna) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1352 | 			u32 tx_ant = 0, rx_ant = 0; | 
 | 1353 | 			int res; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1354 | 			res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | 			if (!res) { | 
 | 1356 | 				if (nla_put_u32(msg, | 
 | 1357 | 						NL80211_ATTR_WIPHY_ANTENNA_TX, | 
 | 1358 | 						tx_ant) || | 
 | 1359 | 				    nla_put_u32(msg, | 
 | 1360 | 						NL80211_ATTR_WIPHY_ANTENNA_RX, | 
 | 1361 | 						rx_ant)) | 
 | 1362 | 					goto nla_put_failure; | 
 | 1363 | 			} | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1364 | 		} | 
 | 1365 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1366 | 		state->split_start++; | 
 | 1367 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | 			break; | 
 | 1369 | 	case 2: | 
 | 1370 | 		if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | 					rdev->wiphy.interface_modes)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | 				goto nla_put_failure; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1373 | 		state->split_start++; | 
 | 1374 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | 			break; | 
 | 1376 | 	case 3: | 
 | 1377 | 		nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | 
 | 1378 | 		if (!nl_bands) | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1379 | 			goto nla_put_failure; | 
 | 1380 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1381 | 		for (band = state->band_start; | 
 | 1382 | 		     band < IEEE80211_NUM_BANDS; band++) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | 			struct ieee80211_supported_band *sband; | 
 | 1384 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1385 | 			sband = rdev->wiphy.bands[band]; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 |  | 
 | 1387 | 			if (!sband) | 
 | 1388 | 				continue; | 
 | 1389 |  | 
 | 1390 | 			nl_band = nla_nest_start(msg, band); | 
 | 1391 | 			if (!nl_band) | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1392 | 				goto nla_put_failure; | 
 | 1393 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1394 | 			switch (state->chan_start) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | 			case 0: | 
 | 1396 | 				if (nl80211_send_band_rateinfo(msg, sband)) | 
 | 1397 | 					goto nla_put_failure; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1398 | 				state->chan_start++; | 
 | 1399 | 				if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1400 | 					break; | 
 | 1401 | 			default: | 
 | 1402 | 				/* add frequencies */ | 
 | 1403 | 				nl_freqs = nla_nest_start( | 
 | 1404 | 					msg, NL80211_BAND_ATTR_FREQS); | 
 | 1405 | 				if (!nl_freqs) | 
 | 1406 | 					goto nla_put_failure; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1407 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1408 | 				for (i = state->chan_start - 1; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1409 | 				     i < sband->n_channels; | 
 | 1410 | 				     i++) { | 
 | 1411 | 					nl_freq = nla_nest_start(msg, i); | 
 | 1412 | 					if (!nl_freq) | 
 | 1413 | 						goto nla_put_failure; | 
 | 1414 |  | 
 | 1415 | 					chan = &sband->channels[i]; | 
 | 1416 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | 					if (nl80211_msg_put_channel( | 
 | 1418 | 							msg, chan, | 
 | 1419 | 							state->split)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | 						goto nla_put_failure; | 
 | 1421 |  | 
 | 1422 | 					nla_nest_end(msg, nl_freq); | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1423 | 					if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | 						break; | 
 | 1425 | 				} | 
 | 1426 | 				if (i < sband->n_channels) | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | 					state->chan_start = i + 2; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | 				else | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1429 | 					state->chan_start = 0; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1430 | 				nla_nest_end(msg, nl_freqs); | 
 | 1431 | 			} | 
 | 1432 |  | 
 | 1433 | 			nla_nest_end(msg, nl_band); | 
 | 1434 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | 			if (state->split) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | 				/* start again here */ | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1437 | 				if (state->chan_start) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | 					band--; | 
 | 1439 | 				break; | 
 | 1440 | 			} | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1441 | 		} | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | 		nla_nest_end(msg, nl_bands); | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1443 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | 		if (band < IEEE80211_NUM_BANDS) | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | 			state->band_start = band + 1; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | 		else | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1447 | 			state->band_start = 0; | 
| Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1448 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1449 | 		/* if bands & channels are done, continue outside */ | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1450 | 		if (state->band_start == 0 && state->chan_start == 0) | 
 | 1451 | 			state->split_start++; | 
 | 1452 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | 			break; | 
 | 1454 | 	case 4: | 
 | 1455 | 		nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | 
 | 1456 | 		if (!nl_cmds) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1457 | 			goto nla_put_failure; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 |  | 
 | 1459 | 		i = 0; | 
 | 1460 | #define CMD(op, n)							\ | 
 | 1461 | 		 do {							\ | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1462 | 			if (rdev->ops->op) {				\ | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | 				i++;					\ | 
 | 1464 | 				if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | 
 | 1465 | 					goto nla_put_failure;		\ | 
 | 1466 | 			}						\ | 
 | 1467 | 		} while (0) | 
 | 1468 |  | 
 | 1469 | 		CMD(add_virtual_intf, NEW_INTERFACE); | 
 | 1470 | 		CMD(change_virtual_intf, SET_INTERFACE); | 
 | 1471 | 		CMD(add_key, NEW_KEY); | 
 | 1472 | 		CMD(start_ap, START_AP); | 
 | 1473 | 		CMD(add_station, NEW_STATION); | 
 | 1474 | 		CMD(add_mpath, NEW_MPATH); | 
 | 1475 | 		CMD(update_mesh_config, SET_MESH_CONFIG); | 
 | 1476 | 		CMD(change_bss, SET_BSS); | 
 | 1477 | 		CMD(auth, AUTHENTICATE); | 
 | 1478 | 		CMD(assoc, ASSOCIATE); | 
 | 1479 | 		CMD(deauth, DEAUTHENTICATE); | 
 | 1480 | 		CMD(disassoc, DISASSOCIATE); | 
 | 1481 | 		CMD(join_ibss, JOIN_IBSS); | 
 | 1482 | 		CMD(join_mesh, JOIN_MESH); | 
 | 1483 | 		CMD(set_pmksa, SET_PMKSA); | 
 | 1484 | 		CMD(del_pmksa, DEL_PMKSA); | 
 | 1485 | 		CMD(flush_pmksa, FLUSH_PMKSA); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | 		if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | 			CMD(remain_on_channel, REMAIN_ON_CHANNEL); | 
 | 1488 | 		CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | 
 | 1489 | 		CMD(mgmt_tx, FRAME); | 
 | 1490 | 		CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1491 | 		if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | 			i++; | 
 | 1493 | 			if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | 
 | 1494 | 				goto nla_put_failure; | 
 | 1495 | 		} | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | 		if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || | 
 | 1497 | 		    rdev->ops->join_mesh) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | 			i++; | 
 | 1499 | 			if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | 
 | 1500 | 				goto nla_put_failure; | 
 | 1501 | 		} | 
 | 1502 | 		CMD(set_wds_peer, SET_WDS_PEER); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1503 | 		if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1504 | 			CMD(tdls_mgmt, TDLS_MGMT); | 
 | 1505 | 			CMD(tdls_oper, TDLS_OPER); | 
 | 1506 | 		} | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1507 | 		if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1508 | 			CMD(sched_scan_start, START_SCHED_SCAN); | 
 | 1509 | 		CMD(probe_client, PROBE_CLIENT); | 
 | 1510 | 		CMD(set_noack_map, SET_NOACK_MAP); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1511 | 		if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | 			i++; | 
 | 1513 | 			if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | 
 | 1514 | 				goto nla_put_failure; | 
 | 1515 | 		} | 
 | 1516 | 		CMD(start_p2p_device, START_P2P_DEVICE); | 
 | 1517 | 		CMD(set_mcast_rate, SET_MCAST_RATE); | 
| Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1518 | #ifdef CONFIG_NL80211_TESTMODE | 
 | 1519 | 		CMD(testmode_cmd, TESTMODE); | 
 | 1520 | #endif | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1521 | 		if (state->split) { | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1522 | 			CMD(crit_proto_start, CRIT_PROTOCOL_START); | 
 | 1523 | 			CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | 			if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1525 | 				CMD(channel_switch, CHANNEL_SWITCH); | 
| Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1526 | 			CMD(set_qos_map, SET_QOS_MAP); | 
| Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1527 | 			if (rdev->wiphy.features & | 
 | 1528 | 					NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1529 | 				CMD(add_tx_ts, ADD_TX_TS); | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1530 | 		} | 
| Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1531 | 		/* add into the if now */ | 
| Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1532 | #undef CMD | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1533 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | 		if (rdev->ops->connect || rdev->ops->auth) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | 			i++; | 
 | 1536 | 			if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1537 | 				goto nla_put_failure; | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1538 | 		} | 
 | 1539 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1540 | 		if (rdev->ops->disconnect || rdev->ops->deauth) { | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | 			i++; | 
 | 1542 | 			if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | 
 | 1543 | 				goto nla_put_failure; | 
 | 1544 | 		} | 
| Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1545 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | 		nla_nest_end(msg, nl_cmds); | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1547 | 		state->split_start++; | 
 | 1548 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | 			break; | 
 | 1550 | 	case 5: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1551 | 		if (rdev->ops->remain_on_channel && | 
 | 1552 | 		    (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1553 | 		    nla_put_u32(msg, | 
 | 1554 | 				NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1555 | 				rdev->wiphy.max_remain_on_channel_duration)) | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1556 | 			goto nla_put_failure; | 
 | 1557 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1558 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | 		    nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | 
 | 1560 | 			goto nla_put_failure; | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1561 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | 		if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | 
 | 1563 | 			goto nla_put_failure; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1564 | 		state->split_start++; | 
 | 1565 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | 			break; | 
 | 1567 | 	case 6: | 
| Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1568 | #ifdef CONFIG_PM | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1569 | 		if (nl80211_send_wowlan(msg, rdev, state->split)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1570 | 			goto nla_put_failure; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1571 | 		state->split_start++; | 
 | 1572 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | 			break; | 
 | 1574 | #else | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | 		state->split_start++; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1576 | #endif | 
 | 1577 | 	case 7: | 
 | 1578 | 		if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | 					rdev->wiphy.software_iftypes)) | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1580 | 			goto nla_put_failure; | 
 | 1581 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1582 | 		if (nl80211_put_iface_combinations(&rdev->wiphy, msg, | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1583 | 						   state->split)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | 			goto nla_put_failure; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1585 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1586 | 		state->split_start++; | 
 | 1587 | 		if (state->split) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1588 | 			break; | 
 | 1589 | 	case 8: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1590 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | 		    nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1592 | 				rdev->wiphy.ap_sme_capa)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1593 | 			goto nla_put_failure; | 
 | 1594 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1595 | 		features = rdev->wiphy.features; | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1596 | 		/* | 
 | 1597 | 		 * We can only add the per-channel limit information if the | 
 | 1598 | 		 * dump is split, otherwise it makes it too big. Therefore | 
 | 1599 | 		 * only advertise it in that case. | 
 | 1600 | 		 */ | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1601 | 		if (state->split) | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1602 | 			features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; | 
 | 1603 | 		if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | 			goto nla_put_failure; | 
 | 1605 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1606 | 		if (rdev->wiphy.ht_capa_mod_mask && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1607 | 		    nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1608 | 			    sizeof(*rdev->wiphy.ht_capa_mod_mask), | 
 | 1609 | 			    rdev->wiphy.ht_capa_mod_mask)) | 
| 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.flags & WIPHY_FLAG_HAVE_AP_SME && | 
 | 1613 | 		    rdev->wiphy.max_acl_mac_addrs && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | 		    nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1615 | 				rdev->wiphy.max_acl_mac_addrs)) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | 			goto nla_put_failure; | 
 | 1617 |  | 
 | 1618 | 		/* | 
 | 1619 | 		 * Any information below this point is only available to | 
 | 1620 | 		 * applications that can deal with it being split. This | 
 | 1621 | 		 * helps ensure that newly added capabilities don't break | 
 | 1622 | 		 * older tools by overrunning their buffers. | 
 | 1623 | 		 * | 
 | 1624 | 		 * We still increment split_start so that in the split | 
 | 1625 | 		 * case we'll continue with more data in the next round, | 
 | 1626 | 		 * but break unconditionally so unsplit data stops here. | 
 | 1627 | 		 */ | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | 		state->split_start++; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | 		break; | 
 | 1630 | 	case 9: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | 		if (rdev->wiphy.extended_capabilities && | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1632 | 		    (nla_put(msg, NL80211_ATTR_EXT_CAPA, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | 			     rdev->wiphy.extended_capabilities_len, | 
 | 1634 | 			     rdev->wiphy.extended_capabilities) || | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1635 | 		     nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1636 | 			     rdev->wiphy.extended_capabilities_len, | 
 | 1637 | 			     rdev->wiphy.extended_capabilities_mask))) | 
| Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1638 | 			goto nla_put_failure; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1639 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1640 | 		if (rdev->wiphy.vht_capa_mod_mask && | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1641 | 		    nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1642 | 			    sizeof(*rdev->wiphy.vht_capa_mod_mask), | 
 | 1643 | 			    rdev->wiphy.vht_capa_mod_mask)) | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1644 | 			goto nla_put_failure; | 
 | 1645 |  | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1646 | 		state->split_start++; | 
 | 1647 | 		break; | 
 | 1648 | 	case 10: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1649 | 		if (nl80211_send_coalesce(msg, rdev)) | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1650 | 			goto nla_put_failure; | 
 | 1651 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1652 | 		if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && | 
| Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1653 | 		    (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || | 
 | 1654 | 		     nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | 
 | 1655 | 			goto nla_put_failure; | 
| Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1656 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1657 | 		if (rdev->wiphy.max_ap_assoc_sta && | 
| Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1658 | 		    nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1659 | 				rdev->wiphy.max_ap_assoc_sta)) | 
| Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1660 | 			goto nla_put_failure; | 
 | 1661 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1662 | 		state->split_start++; | 
 | 1663 | 		break; | 
 | 1664 | 	case 11: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1665 | 		if (rdev->wiphy.n_vendor_commands) { | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1666 | 			const struct nl80211_vendor_cmd_info *info; | 
 | 1667 | 			struct nlattr *nested; | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1668 |  | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1669 | 			nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
 | 1670 | 			if (!nested) | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1671 | 				goto nla_put_failure; | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1672 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1673 | 			for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | 
 | 1674 | 				info = &rdev->wiphy.vendor_commands[i].info; | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1675 | 				if (nla_put(msg, i + 1, sizeof(*info), info)) | 
 | 1676 | 					goto nla_put_failure; | 
 | 1677 | 			} | 
 | 1678 | 			nla_nest_end(msg, nested); | 
 | 1679 | 		} | 
 | 1680 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1681 | 		if (rdev->wiphy.n_vendor_events) { | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1682 | 			const struct nl80211_vendor_cmd_info *info; | 
 | 1683 | 			struct nlattr *nested; | 
 | 1684 |  | 
 | 1685 | 			nested = nla_nest_start(msg, | 
 | 1686 | 						NL80211_ATTR_VENDOR_EVENTS); | 
 | 1687 | 			if (!nested) | 
 | 1688 | 				goto nla_put_failure; | 
 | 1689 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | 			for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { | 
 | 1691 | 				info = &rdev->wiphy.vendor_events[i]; | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1692 | 				if (nla_put(msg, i + 1, sizeof(*info), info)) | 
 | 1693 | 					goto nla_put_failure; | 
 | 1694 | 			} | 
 | 1695 | 			nla_nest_end(msg, nested); | 
 | 1696 | 		} | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1697 | 		state->split_start++; | 
 | 1698 | 		break; | 
 | 1699 | 	case 12: | 
 | 1700 | 		if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | 
 | 1701 | 		    nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | 
 | 1702 | 			       rdev->wiphy.max_num_csa_counters)) | 
 | 1703 | 			goto nla_put_failure; | 
| Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1704 |  | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1705 | 		if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
 | 1706 | 		    nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
 | 1707 | 			goto nla_put_failure; | 
 | 1708 |  | 
| Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1709 | 		if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, | 
 | 1710 | 			    sizeof(rdev->wiphy.ext_features), | 
 | 1711 | 			    rdev->wiphy.ext_features)) | 
 | 1712 | 			goto nla_put_failure; | 
 | 1713 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1714 | 		/* done */ | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1715 | 		state->split_start = 0; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1716 | 		break; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1717 | 	} | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1718 |  finish: | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1719 | 	return genlmsg_end(msg, hdr); | 
 | 1720 |  | 
 | 1721 |  nla_put_failure: | 
| Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1722 | 	genlmsg_cancel(msg, hdr); | 
 | 1723 | 	return -EMSGSIZE; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1724 | } | 
 | 1725 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1726 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, | 
 | 1727 | 				    struct netlink_callback *cb, | 
 | 1728 | 				    struct nl80211_dump_wiphy_state *state) | 
 | 1729 | { | 
 | 1730 | 	struct nlattr **tb = nl80211_fam.attrbuf; | 
 | 1731 | 	int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | 
 | 1732 | 			      tb, nl80211_fam.maxattr, nl80211_policy); | 
 | 1733 | 	/* ignore parse errors for backward compatibility */ | 
 | 1734 | 	if (ret) | 
 | 1735 | 		return 0; | 
 | 1736 |  | 
 | 1737 | 	state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | 
 | 1738 | 	if (tb[NL80211_ATTR_WIPHY]) | 
 | 1739 | 		state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | 
 | 1740 | 	if (tb[NL80211_ATTR_WDEV]) | 
 | 1741 | 		state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | 
 | 1742 | 	if (tb[NL80211_ATTR_IFINDEX]) { | 
 | 1743 | 		struct net_device *netdev; | 
 | 1744 | 		struct cfg80211_registered_device *rdev; | 
 | 1745 | 		int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | 
 | 1746 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1747 | 		netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1748 | 		if (!netdev) | 
 | 1749 | 			return -ENODEV; | 
 | 1750 | 		if (netdev->ieee80211_ptr) { | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1751 | 			rdev = wiphy_to_rdev( | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | 				netdev->ieee80211_ptr->wiphy); | 
 | 1753 | 			state->filter_wiphy = rdev->wiphy_idx; | 
 | 1754 | 		} | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1755 | 	} | 
 | 1756 |  | 
 | 1757 | 	return 0; | 
 | 1758 | } | 
 | 1759 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1760 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | 
 | 1761 | { | 
| Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1762 | 	int idx = 0, ret; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1763 | 	struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1764 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1765 |  | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1766 | 	rtnl_lock(); | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1767 | 	if (!state) { | 
 | 1768 | 		state = kzalloc(sizeof(*state), GFP_KERNEL); | 
| John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1769 | 		if (!state) { | 
 | 1770 | 			rtnl_unlock(); | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1771 | 			return -ENOMEM; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1772 | 		} | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1773 | 		state->filter_wiphy = -1; | 
 | 1774 | 		ret = nl80211_dump_wiphy_parse(skb, cb, state); | 
 | 1775 | 		if (ret) { | 
 | 1776 | 			kfree(state); | 
 | 1777 | 			rtnl_unlock(); | 
 | 1778 | 			return ret; | 
| 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 | 		cb->args[0] = (long)state; | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1781 | 	} | 
 | 1782 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1783 | 	list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
 | 1784 | 		if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1785 | 			continue; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1786 | 		if (++idx <= state->start) | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1787 | 			continue; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1788 | 		if (state->filter_wiphy != -1 && | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1789 | 		    state->filter_wiphy != rdev->wiphy_idx) | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1790 | 			continue; | 
 | 1791 | 		/* attempt to fit multiple wiphy data chunks into the skb */ | 
 | 1792 | 		do { | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1793 | 			ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, | 
 | 1794 | 						 skb, | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1795 | 						 NETLINK_CB(cb->skb).portid, | 
 | 1796 | 						 cb->nlh->nlmsg_seq, | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1797 | 						 NLM_F_MULTI, state); | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1798 | 			if (ret < 0) { | 
 | 1799 | 				/* | 
 | 1800 | 				 * If sending the wiphy data didn't fit (ENOBUFS | 
 | 1801 | 				 * or EMSGSIZE returned), this SKB is still | 
 | 1802 | 				 * empty (so it's not too big because another | 
 | 1803 | 				 * wiphy dataset is already in the skb) and | 
 | 1804 | 				 * we've not tried to adjust the dump allocation | 
 | 1805 | 				 * yet ... then adjust the alloc size to be | 
 | 1806 | 				 * bigger, and return 1 but with the empty skb. | 
 | 1807 | 				 * This results in an empty message being RX'ed | 
 | 1808 | 				 * in userspace, but that is ignored. | 
 | 1809 | 				 * | 
 | 1810 | 				 * We can then retry with the larger buffer. | 
 | 1811 | 				 */ | 
 | 1812 | 				if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | 
| Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1813 | 				    !skb->len && !state->split && | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | 				    cb->min_dump_alloc < 4096) { | 
 | 1815 | 					cb->min_dump_alloc = 4096; | 
| Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1816 | 					state->split_start = 0; | 
| David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1817 | 					rtnl_unlock(); | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1818 | 					return 1; | 
 | 1819 | 				} | 
 | 1820 | 				idx--; | 
 | 1821 | 				break; | 
| Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1822 | 			} | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1823 | 		} while (state->split_start > 0); | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1824 | 		break; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | 	} | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1826 | 	rtnl_unlock(); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1827 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1828 | 	state->start = idx; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1829 |  | 
 | 1830 | 	return skb->len; | 
 | 1831 | } | 
 | 1832 |  | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1833 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) | 
 | 1834 | { | 
 | 1835 | 	kfree((void *)cb->args[0]); | 
 | 1836 | 	return 0; | 
 | 1837 | } | 
 | 1838 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1839 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | 
 | 1840 | { | 
 | 1841 | 	struct sk_buff *msg; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1842 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1843 | 	struct nl80211_dump_wiphy_state state = {}; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1844 |  | 
| Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1845 | 	msg = nlmsg_new(4096, GFP_KERNEL); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1846 | 	if (!msg) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1847 | 		return -ENOMEM; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1848 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1849 | 	if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, | 
 | 1850 | 			       info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1851 | 			       &state) < 0) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1852 | 		nlmsg_free(msg); | 
 | 1853 | 		return -ENOBUFS; | 
 | 1854 | 	} | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1855 |  | 
| Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1856 | 	return genlmsg_reply(msg, info); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1857 | } | 
 | 1858 |  | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1859 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { | 
 | 1860 | 	[NL80211_TXQ_ATTR_QUEUE]		= { .type = NLA_U8 }, | 
 | 1861 | 	[NL80211_TXQ_ATTR_TXOP]			= { .type = NLA_U16 }, | 
 | 1862 | 	[NL80211_TXQ_ATTR_CWMIN]		= { .type = NLA_U16 }, | 
 | 1863 | 	[NL80211_TXQ_ATTR_CWMAX]		= { .type = NLA_U16 }, | 
 | 1864 | 	[NL80211_TXQ_ATTR_AIFS]			= { .type = NLA_U8 }, | 
 | 1865 | }; | 
 | 1866 |  | 
 | 1867 | static int parse_txq_params(struct nlattr *tb[], | 
 | 1868 | 			    struct ieee80211_txq_params *txq_params) | 
 | 1869 | { | 
| Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1870 | 	if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1871 | 	    !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | 
 | 1872 | 	    !tb[NL80211_TXQ_ATTR_AIFS]) | 
 | 1873 | 		return -EINVAL; | 
 | 1874 |  | 
| Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1875 | 	txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1876 | 	txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | 
 | 1877 | 	txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | 
 | 1878 | 	txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | 
 | 1879 | 	txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | 
 | 1880 |  | 
| Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1881 | 	if (txq_params->ac >= NL80211_NUM_ACS) | 
 | 1882 | 		return -EINVAL; | 
 | 1883 |  | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1884 | 	return 0; | 
 | 1885 | } | 
 | 1886 |  | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1887 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) | 
 | 1888 | { | 
 | 1889 | 	/* | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1890 | 	 * You can only set the channel explicitly for WDS interfaces, | 
 | 1891 | 	 * all others have their channel managed via their respective | 
 | 1892 | 	 * "establish a connection" command (connect, join, ...) | 
 | 1893 | 	 * | 
 | 1894 | 	 * For AP/GO and mesh mode, the channel can be set with the | 
 | 1895 | 	 * channel userspace API, but is only stored and passed to the | 
 | 1896 | 	 * low-level driver when the AP starts or the mesh is joined. | 
 | 1897 | 	 * This is for backward compatibility, userspace can also give | 
 | 1898 | 	 * the channel in the start-ap or join-mesh commands instead. | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1899 | 	 * | 
 | 1900 | 	 * Monitors are special as they are normally slaved to | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1901 | 	 * whatever else is going on, so they have their own special | 
 | 1902 | 	 * operation to set the monitor channel if possible. | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1903 | 	 */ | 
 | 1904 | 	return !wdev || | 
 | 1905 | 		wdev->iftype == NL80211_IFTYPE_AP || | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1906 | 		wdev->iftype == NL80211_IFTYPE_MESH_POINT || | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1907 | 		wdev->iftype == NL80211_IFTYPE_MONITOR || | 
 | 1908 | 		wdev->iftype == NL80211_IFTYPE_P2P_GO; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1909 | } | 
 | 1910 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1911 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, | 
 | 1912 | 				 struct genl_info *info, | 
 | 1913 | 				 struct cfg80211_chan_def *chandef) | 
 | 1914 | { | 
| Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1915 | 	u32 control_freq; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1916 |  | 
 | 1917 | 	if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
 | 1918 | 		return -EINVAL; | 
 | 1919 |  | 
 | 1920 | 	control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
 | 1921 |  | 
 | 1922 | 	chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1923 | 	chandef->width = NL80211_CHAN_WIDTH_20_NOHT; | 
 | 1924 | 	chandef->center_freq1 = control_freq; | 
 | 1925 | 	chandef->center_freq2 = 0; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1926 |  | 
 | 1927 | 	/* Primary channel not allowed */ | 
 | 1928 | 	if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 1929 | 		return -EINVAL; | 
 | 1930 |  | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1931 | 	if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | 
 | 1932 | 		enum nl80211_channel_type chantype; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1933 |  | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1934 | 		chantype = nla_get_u32( | 
 | 1935 | 				info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | 
 | 1936 |  | 
 | 1937 | 		switch (chantype) { | 
 | 1938 | 		case NL80211_CHAN_NO_HT: | 
 | 1939 | 		case NL80211_CHAN_HT20: | 
 | 1940 | 		case NL80211_CHAN_HT40PLUS: | 
 | 1941 | 		case NL80211_CHAN_HT40MINUS: | 
 | 1942 | 			cfg80211_chandef_create(chandef, chandef->chan, | 
 | 1943 | 						chantype); | 
 | 1944 | 			break; | 
 | 1945 | 		default: | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1946 | 			return -EINVAL; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1947 | 		} | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1948 | 	} else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | 
 | 1949 | 		chandef->width = | 
 | 1950 | 			nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | 
 | 1951 | 		if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | 
 | 1952 | 			chandef->center_freq1 = | 
 | 1953 | 				nla_get_u32( | 
 | 1954 | 					info->attrs[NL80211_ATTR_CENTER_FREQ1]); | 
 | 1955 | 		if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | 
 | 1956 | 			chandef->center_freq2 = | 
 | 1957 | 				nla_get_u32( | 
 | 1958 | 					info->attrs[NL80211_ATTR_CENTER_FREQ2]); | 
 | 1959 | 	} | 
 | 1960 |  | 
| Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1961 | 	if (!cfg80211_chandef_valid(chandef)) | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1962 | 		return -EINVAL; | 
 | 1963 |  | 
| Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1964 | 	if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, | 
 | 1965 | 				     IEEE80211_CHAN_DISABLED)) | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1966 | 		return -EINVAL; | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1967 |  | 
| Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1968 | 	if ((chandef->width == NL80211_CHAN_WIDTH_5 || | 
 | 1969 | 	     chandef->width == NL80211_CHAN_WIDTH_10) && | 
 | 1970 | 	    !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | 
 | 1971 | 		return -EINVAL; | 
 | 1972 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1973 | 	return 0; | 
 | 1974 | } | 
 | 1975 |  | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1976 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1977 | 				 struct net_device *dev, | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1978 | 				 struct genl_info *info) | 
 | 1979 | { | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1980 | 	struct cfg80211_chan_def chandef; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1981 | 	int result; | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1982 | 	enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1983 | 	struct wireless_dev *wdev = NULL; | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1984 |  | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1985 | 	if (dev) | 
 | 1986 | 		wdev = dev->ieee80211_ptr; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1987 | 	if (!nl80211_can_set_dev_channel(wdev)) | 
 | 1988 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1989 | 	if (wdev) | 
 | 1990 | 		iftype = wdev->iftype; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1991 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1992 | 	result = nl80211_parse_chandef(rdev, info, &chandef); | 
 | 1993 | 	if (result) | 
 | 1994 | 		return result; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1995 |  | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1996 | 	switch (iftype) { | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1997 | 	case NL80211_IFTYPE_AP: | 
 | 1998 | 	case NL80211_IFTYPE_P2P_GO: | 
| Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1999 | 		if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2000 | 			result = -EINVAL; | 
 | 2001 | 			break; | 
 | 2002 | 		} | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2003 | 		if (wdev->beacon_interval) { | 
 | 2004 | 			if (!dev || !rdev->ops->set_ap_chanwidth || | 
 | 2005 | 			    !(rdev->wiphy.features & | 
 | 2006 | 			      NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | 
 | 2007 | 				result = -EBUSY; | 
 | 2008 | 				break; | 
 | 2009 | 			} | 
 | 2010 |  | 
 | 2011 | 			/* Only allow dynamic channel width changes */ | 
 | 2012 | 			if (chandef.chan != wdev->preset_chandef.chan) { | 
 | 2013 | 				result = -EBUSY; | 
 | 2014 | 				break; | 
 | 2015 | 			} | 
 | 2016 | 			result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | 
 | 2017 | 			if (result) | 
 | 2018 | 				break; | 
 | 2019 | 		} | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2020 | 		wdev->preset_chandef = chandef; | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2021 | 		result = 0; | 
 | 2022 | 		break; | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2023 | 	case NL80211_IFTYPE_MESH_POINT: | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2024 | 		result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2025 | 		break; | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2026 | 	case NL80211_IFTYPE_MONITOR: | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2027 | 		result = cfg80211_set_monitor_channel(rdev, &chandef); | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2028 | 		break; | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2029 | 	default: | 
| Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2030 | 		result = -EINVAL; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2031 | 	} | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2032 |  | 
 | 2033 | 	return result; | 
 | 2034 | } | 
 | 2035 |  | 
 | 2036 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | 
 | 2037 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2038 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 2039 | 	struct net_device *netdev = info->user_ptr[1]; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2040 |  | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2041 | 	return __nl80211_set_channel(rdev, netdev, info); | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2042 | } | 
 | 2043 |  | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2044 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) | 
 | 2045 | { | 
| Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2046 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 2047 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 2048 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2049 | 	const u8 *bssid; | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2050 |  | 
 | 2051 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 2052 | 		return -EINVAL; | 
 | 2053 |  | 
| Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2054 | 	if (netif_running(dev)) | 
 | 2055 | 		return -EBUSY; | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2056 |  | 
| Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2057 | 	if (!rdev->ops->set_wds_peer) | 
 | 2058 | 		return -EOPNOTSUPP; | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2059 |  | 
| Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2060 | 	if (wdev->iftype != NL80211_IFTYPE_WDS) | 
 | 2061 | 		return -EOPNOTSUPP; | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2062 |  | 
 | 2063 | 	bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2064 | 	return rdev_set_wds_peer(rdev, dev, bssid); | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2065 | } | 
 | 2066 |  | 
 | 2067 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2068 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | 
 | 2069 | { | 
 | 2070 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2071 | 	struct net_device *netdev = NULL; | 
 | 2072 | 	struct wireless_dev *wdev; | 
| Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2073 | 	int result = 0, rem_txq_params = 0; | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2074 | 	struct nlattr *nl_txq_params; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2075 | 	u32 changed; | 
 | 2076 | 	u8 retry_short = 0, retry_long = 0; | 
 | 2077 | 	u32 frag_threshold = 0, rts_threshold = 0; | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2078 | 	u8 coverage_class = 0; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2079 |  | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2080 | 	ASSERT_RTNL(); | 
 | 2081 |  | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | 	/* | 
 | 2083 | 	 * Try to find the wiphy and netdev. Normally this | 
 | 2084 | 	 * function shouldn't need the netdev, but this is | 
 | 2085 | 	 * done for backward compatibility -- previously | 
 | 2086 | 	 * setting the channel was done per wiphy, but now | 
 | 2087 | 	 * it is per netdev. Previous userland like hostapd | 
 | 2088 | 	 * also passed a netdev to set_wiphy, so that it is | 
 | 2089 | 	 * possible to let that go to the right netdev! | 
 | 2090 | 	 */ | 
| Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2091 |  | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | 	if (info->attrs[NL80211_ATTR_IFINDEX]) { | 
 | 2093 | 		int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | 
 | 2094 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2095 | 		netdev = __dev_get_by_index(genl_info_net(info), ifindex); | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2096 | 		if (netdev && netdev->ieee80211_ptr) | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2097 | 			rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2098 | 		else | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2099 | 			netdev = NULL; | 
| Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2100 | 	} | 
 | 2101 |  | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2102 | 	if (!netdev) { | 
| Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2103 | 		rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), | 
 | 2104 | 						  info->attrs); | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2105 | 		if (IS_ERR(rdev)) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2106 | 			return PTR_ERR(rdev); | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2107 | 		wdev = NULL; | 
 | 2108 | 		netdev = NULL; | 
 | 2109 | 		result = 0; | 
| Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2110 | 	} else | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2111 | 		wdev = netdev->ieee80211_ptr; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2112 |  | 
 | 2113 | 	/* | 
 | 2114 | 	 * end workaround code, by now the rdev is available | 
 | 2115 | 	 * and locked, and wdev may or may not be NULL. | 
 | 2116 | 	 */ | 
| Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2117 |  | 
 | 2118 | 	if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2119 | 		result = cfg80211_dev_rename( | 
 | 2120 | 			rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | 
| Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2121 |  | 
| Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2122 | 	if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2123 | 		return result; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2124 |  | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2125 | 	if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | 
 | 2126 | 		struct ieee80211_txq_params txq_params; | 
 | 2127 | 		struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | 
 | 2128 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2129 | 		if (!rdev->ops->set_txq_params) | 
 | 2130 | 			return -EOPNOTSUPP; | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2131 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2132 | 		if (!netdev) | 
 | 2133 | 			return -EINVAL; | 
| Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2134 |  | 
| Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2135 | 		if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2136 | 		    netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 2137 | 			return -EINVAL; | 
| Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2138 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2139 | 		if (!netif_running(netdev)) | 
 | 2140 | 			return -ENETDOWN; | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2141 |  | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2142 | 		nla_for_each_nested(nl_txq_params, | 
 | 2143 | 				    info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | 
 | 2144 | 				    rem_txq_params) { | 
| Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2145 | 			result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, | 
 | 2146 | 					   nla_data(nl_txq_params), | 
 | 2147 | 					   nla_len(nl_txq_params), | 
 | 2148 | 					   txq_params_policy); | 
 | 2149 | 			if (result) | 
 | 2150 | 				return result; | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2151 | 			result = parse_txq_params(tb, &txq_params); | 
 | 2152 | 			if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2153 | 				return result; | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2154 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2155 | 			result = rdev_set_txq_params(rdev, netdev, | 
 | 2156 | 						     &txq_params); | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2157 | 			if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2158 | 				return result; | 
| Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2159 | 		} | 
 | 2160 | 	} | 
 | 2161 |  | 
| Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2162 | 	if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
| Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2163 | 		result = __nl80211_set_channel( | 
 | 2164 | 			rdev, | 
 | 2165 | 			nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | 
 | 2166 | 			info); | 
| Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2167 | 		if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2168 | 			return result; | 
| Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2169 | 	} | 
 | 2170 |  | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2171 | 	if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { | 
| Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2172 | 		struct wireless_dev *txp_wdev = wdev; | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2173 | 		enum nl80211_tx_power_setting type; | 
 | 2174 | 		int idx, mbm = 0; | 
 | 2175 |  | 
| Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2176 | 		if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) | 
 | 2177 | 			txp_wdev = NULL; | 
 | 2178 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2179 | 		if (!rdev->ops->set_tx_power) | 
 | 2180 | 			return -EOPNOTSUPP; | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2181 |  | 
 | 2182 | 		idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | 
 | 2183 | 		type = nla_get_u32(info->attrs[idx]); | 
 | 2184 |  | 
 | 2185 | 		if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2186 | 		    (type != NL80211_TX_POWER_AUTOMATIC)) | 
 | 2187 | 			return -EINVAL; | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2188 |  | 
 | 2189 | 		if (type != NL80211_TX_POWER_AUTOMATIC) { | 
 | 2190 | 			idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | 
 | 2191 | 			mbm = nla_get_u32(info->attrs[idx]); | 
 | 2192 | 		} | 
 | 2193 |  | 
| Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2194 | 		result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2195 | 		if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2196 | 			return result; | 
| Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2197 | 	} | 
 | 2198 |  | 
| Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2199 | 	if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && | 
 | 2200 | 	    info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | 
 | 2201 | 		u32 tx_ant, rx_ant; | 
| Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2202 | 		if ((!rdev->wiphy.available_antennas_tx && | 
 | 2203 | 		     !rdev->wiphy.available_antennas_rx) || | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2204 | 		    !rdev->ops->set_antenna) | 
 | 2205 | 			return -EOPNOTSUPP; | 
| Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2206 |  | 
 | 2207 | 		tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | 
 | 2208 | 		rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | 
 | 2209 |  | 
| Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2210 | 		/* reject antenna configurations which don't match the | 
| Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2211 | 		 * available antenna masks, except for the "all" mask */ | 
 | 2212 | 		if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2213 | 		    (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) | 
 | 2214 | 			return -EINVAL; | 
| Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2215 |  | 
| Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2216 | 		tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; | 
 | 2217 | 		rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | 
| Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2218 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2219 | 		result = rdev_set_antenna(rdev, tx_ant, rx_ant); | 
| Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2220 | 		if (result) | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2221 | 			return result; | 
| Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2222 | 	} | 
 | 2223 |  | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2224 | 	changed = 0; | 
 | 2225 |  | 
 | 2226 | 	if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | 
 | 2227 | 		retry_short = nla_get_u8( | 
 | 2228 | 			info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2229 | 		if (retry_short == 0) | 
 | 2230 | 			return -EINVAL; | 
 | 2231 |  | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2232 | 		changed |= WIPHY_PARAM_RETRY_SHORT; | 
 | 2233 | 	} | 
 | 2234 |  | 
 | 2235 | 	if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | 
 | 2236 | 		retry_long = nla_get_u8( | 
 | 2237 | 			info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2238 | 		if (retry_long == 0) | 
 | 2239 | 			return -EINVAL; | 
 | 2240 |  | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2241 | 		changed |= WIPHY_PARAM_RETRY_LONG; | 
 | 2242 | 	} | 
 | 2243 |  | 
 | 2244 | 	if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | 
 | 2245 | 		frag_threshold = nla_get_u32( | 
 | 2246 | 			info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2247 | 		if (frag_threshold < 256) | 
 | 2248 | 			return -EINVAL; | 
 | 2249 |  | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2250 | 		if (frag_threshold != (u32) -1) { | 
 | 2251 | 			/* | 
 | 2252 | 			 * Fragments (apart from the last one) are required to | 
 | 2253 | 			 * have even length. Make the fragmentation code | 
 | 2254 | 			 * simpler by stripping LSB should someone try to use | 
 | 2255 | 			 * odd threshold value. | 
 | 2256 | 			 */ | 
 | 2257 | 			frag_threshold &= ~0x1; | 
 | 2258 | 		} | 
 | 2259 | 		changed |= WIPHY_PARAM_FRAG_THRESHOLD; | 
 | 2260 | 	} | 
 | 2261 |  | 
 | 2262 | 	if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | 
 | 2263 | 		rts_threshold = nla_get_u32( | 
 | 2264 | 			info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | 
 | 2265 | 		changed |= WIPHY_PARAM_RTS_THRESHOLD; | 
 | 2266 | 	} | 
 | 2267 |  | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2268 | 	if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { | 
| Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2269 | 		if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) | 
 | 2270 | 			return -EINVAL; | 
 | 2271 |  | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2272 | 		coverage_class = nla_get_u8( | 
 | 2273 | 			info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | 
 | 2274 | 		changed |= WIPHY_PARAM_COVERAGE_CLASS; | 
 | 2275 | 	} | 
 | 2276 |  | 
| Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2277 | 	if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { | 
 | 2278 | 		if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | 
 | 2279 | 			return -EOPNOTSUPP; | 
 | 2280 |  | 
 | 2281 | 		changed |= WIPHY_PARAM_DYN_ACK; | 
 | 2282 | 	} | 
 | 2283 |  | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2284 | 	if (changed) { | 
 | 2285 | 		u8 old_retry_short, old_retry_long; | 
 | 2286 | 		u32 old_frag_threshold, old_rts_threshold; | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2287 | 		u8 old_coverage_class; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2288 |  | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2289 | 		if (!rdev->ops->set_wiphy_params) | 
 | 2290 | 			return -EOPNOTSUPP; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2291 |  | 
 | 2292 | 		old_retry_short = rdev->wiphy.retry_short; | 
 | 2293 | 		old_retry_long = rdev->wiphy.retry_long; | 
 | 2294 | 		old_frag_threshold = rdev->wiphy.frag_threshold; | 
 | 2295 | 		old_rts_threshold = rdev->wiphy.rts_threshold; | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2296 | 		old_coverage_class = rdev->wiphy.coverage_class; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2297 |  | 
 | 2298 | 		if (changed & WIPHY_PARAM_RETRY_SHORT) | 
 | 2299 | 			rdev->wiphy.retry_short = retry_short; | 
 | 2300 | 		if (changed & WIPHY_PARAM_RETRY_LONG) | 
 | 2301 | 			rdev->wiphy.retry_long = retry_long; | 
 | 2302 | 		if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | 
 | 2303 | 			rdev->wiphy.frag_threshold = frag_threshold; | 
 | 2304 | 		if (changed & WIPHY_PARAM_RTS_THRESHOLD) | 
 | 2305 | 			rdev->wiphy.rts_threshold = rts_threshold; | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2306 | 		if (changed & WIPHY_PARAM_COVERAGE_CLASS) | 
 | 2307 | 			rdev->wiphy.coverage_class = coverage_class; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2308 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2309 | 		result = rdev_set_wiphy_params(rdev, changed); | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2310 | 		if (result) { | 
 | 2311 | 			rdev->wiphy.retry_short = old_retry_short; | 
 | 2312 | 			rdev->wiphy.retry_long = old_retry_long; | 
 | 2313 | 			rdev->wiphy.frag_threshold = old_frag_threshold; | 
 | 2314 | 			rdev->wiphy.rts_threshold = old_rts_threshold; | 
| Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2315 | 			rdev->wiphy.coverage_class = old_coverage_class; | 
| Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2316 | 		} | 
 | 2317 | 	} | 
| Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2318 | 	return 0; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2319 | } | 
 | 2320 |  | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2321 | static inline u64 wdev_id(struct wireless_dev *wdev) | 
 | 2322 | { | 
 | 2323 | 	return (u64)wdev->identifier | | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2324 | 	       ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2325 | } | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2326 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2327 | static int nl80211_send_chandef(struct sk_buff *msg, | 
| Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2328 | 				const struct cfg80211_chan_def *chandef) | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2329 | { | 
| Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2330 | 	if (WARN_ON(!cfg80211_chandef_valid(chandef))) | 
 | 2331 | 		return -EINVAL; | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2332 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2333 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, | 
 | 2334 | 			chandef->chan->center_freq)) | 
 | 2335 | 		return -ENOBUFS; | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2336 | 	switch (chandef->width) { | 
 | 2337 | 	case NL80211_CHAN_WIDTH_20_NOHT: | 
 | 2338 | 	case NL80211_CHAN_WIDTH_20: | 
 | 2339 | 	case NL80211_CHAN_WIDTH_40: | 
 | 2340 | 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | 
 | 2341 | 				cfg80211_get_chandef_type(chandef))) | 
 | 2342 | 			return -ENOBUFS; | 
 | 2343 | 		break; | 
 | 2344 | 	default: | 
 | 2345 | 		break; | 
 | 2346 | 	} | 
 | 2347 | 	if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | 
 | 2348 | 		return -ENOBUFS; | 
 | 2349 | 	if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | 
 | 2350 | 		return -ENOBUFS; | 
 | 2351 | 	if (chandef->center_freq2 && | 
 | 2352 | 	    nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2353 | 		return -ENOBUFS; | 
 | 2354 | 	return 0; | 
 | 2355 | } | 
 | 2356 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2357 | 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] | 2358 | 			      struct cfg80211_registered_device *rdev, | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2359 | 			      struct wireless_dev *wdev, bool removal) | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2360 | { | 
| Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2361 | 	struct net_device *dev = wdev->netdev; | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2362 | 	u8 cmd = NL80211_CMD_NEW_INTERFACE; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2363 | 	void *hdr; | 
 | 2364 |  | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2365 | 	if (removal) | 
 | 2366 | 		cmd = NL80211_CMD_DEL_INTERFACE; | 
 | 2367 |  | 
 | 2368 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2369 | 	if (!hdr) | 
 | 2370 | 		return -1; | 
 | 2371 |  | 
| Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2372 | 	if (dev && | 
 | 2373 | 	    (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2374 | 	     nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) | 
| Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2375 | 		goto nla_put_failure; | 
 | 2376 |  | 
 | 2377 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 2378 | 	    nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2379 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2380 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2381 | 	    nla_put_u32(msg, NL80211_ATTR_GENERATION, | 
 | 2382 | 			rdev->devlist_generation ^ | 
 | 2383 | 			(cfg80211_rdev_list_generation << 2))) | 
 | 2384 | 		goto nla_put_failure; | 
| Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2385 |  | 
| Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2386 | 	if (rdev->ops->get_channel) { | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2387 | 		int ret; | 
 | 2388 | 		struct cfg80211_chan_def chandef; | 
| Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2389 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2390 | 		ret = rdev_get_channel(rdev, wdev, &chandef); | 
 | 2391 | 		if (ret == 0) { | 
 | 2392 | 			if (nl80211_send_chandef(msg, &chandef)) | 
 | 2393 | 				goto nla_put_failure; | 
 | 2394 | 		} | 
| Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2395 | 	} | 
 | 2396 |  | 
| Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2397 | 	if (wdev->ssid_len) { | 
 | 2398 | 		if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | 
 | 2399 | 			goto nla_put_failure; | 
 | 2400 | 	} | 
 | 2401 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2402 | 	return genlmsg_end(msg, hdr); | 
 | 2403 |  | 
 | 2404 |  nla_put_failure: | 
| Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2405 | 	genlmsg_cancel(msg, hdr); | 
 | 2406 | 	return -EMSGSIZE; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2407 | } | 
 | 2408 |  | 
 | 2409 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | 
 | 2410 | { | 
 | 2411 | 	int wp_idx = 0; | 
 | 2412 | 	int if_idx = 0; | 
 | 2413 | 	int wp_start = cb->args[0]; | 
 | 2414 | 	int if_start = cb->args[1]; | 
| Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2415 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2416 | 	struct wireless_dev *wdev; | 
 | 2417 |  | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2418 | 	rtnl_lock(); | 
| Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2419 | 	list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
 | 2420 | 		if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2421 | 			continue; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2422 | 		if (wp_idx < wp_start) { | 
 | 2423 | 			wp_idx++; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | 			continue; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2425 | 		} | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | 		if_idx = 0; | 
 | 2427 |  | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2428 | 		list_for_each_entry(wdev, &rdev->wdev_list, list) { | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2429 | 			if (if_idx < if_start) { | 
 | 2430 | 				if_idx++; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2431 | 				continue; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2432 | 			} | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2433 | 			if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | 					       cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2435 | 					       rdev, wdev, false) < 0) { | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2436 | 				goto out; | 
 | 2437 | 			} | 
 | 2438 | 			if_idx++; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2439 | 		} | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2440 |  | 
 | 2441 | 		wp_idx++; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2442 | 	} | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2443 |  out: | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2444 | 	rtnl_unlock(); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2445 |  | 
 | 2446 | 	cb->args[0] = wp_idx; | 
 | 2447 | 	cb->args[1] = if_idx; | 
 | 2448 |  | 
 | 2449 | 	return skb->len; | 
 | 2450 | } | 
 | 2451 |  | 
 | 2452 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | 
 | 2453 | { | 
 | 2454 | 	struct sk_buff *msg; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2455 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2456 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2457 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2458 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2459 | 	if (!msg) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2460 | 		return -ENOMEM; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2461 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2462 | 	if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2463 | 			       rdev, wdev, false) < 0) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2464 | 		nlmsg_free(msg); | 
 | 2465 | 		return -ENOBUFS; | 
 | 2466 | 	} | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 |  | 
| Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2468 | 	return genlmsg_reply(msg, info); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2469 | } | 
 | 2470 |  | 
| Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2471 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { | 
 | 2472 | 	[NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | 
 | 2473 | 	[NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | 
 | 2474 | 	[NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | 
 | 2475 | 	[NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | 
 | 2476 | 	[NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | 
| Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2477 | 	[NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, | 
| Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2478 | }; | 
 | 2479 |  | 
 | 2480 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | 
 | 2481 | { | 
 | 2482 | 	struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | 
 | 2483 | 	int flag; | 
 | 2484 |  | 
 | 2485 | 	*mntrflags = 0; | 
 | 2486 |  | 
 | 2487 | 	if (!nla) | 
 | 2488 | 		return -EINVAL; | 
 | 2489 |  | 
 | 2490 | 	if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | 
 | 2491 | 			     nla, mntr_flags_policy)) | 
 | 2492 | 		return -EINVAL; | 
 | 2493 |  | 
 | 2494 | 	for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | 
 | 2495 | 		if (flags[flag]) | 
 | 2496 | 			*mntrflags |= (1<<flag); | 
 | 2497 |  | 
 | 2498 | 	return 0; | 
 | 2499 | } | 
 | 2500 |  | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2501 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2502 | 			       struct net_device *netdev, u8 use_4addr, | 
 | 2503 | 			       enum nl80211_iftype iftype) | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2504 | { | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2505 | 	if (!use_4addr) { | 
| Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2506 | 		if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2507 | 			return -EBUSY; | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2508 | 		return 0; | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2509 | 	} | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2510 |  | 
 | 2511 | 	switch (iftype) { | 
 | 2512 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 2513 | 		if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | 
 | 2514 | 			return 0; | 
 | 2515 | 		break; | 
 | 2516 | 	case NL80211_IFTYPE_STATION: | 
 | 2517 | 		if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | 
 | 2518 | 			return 0; | 
 | 2519 | 		break; | 
 | 2520 | 	default: | 
 | 2521 | 		break; | 
 | 2522 | 	} | 
 | 2523 |  | 
 | 2524 | 	return -EOPNOTSUPP; | 
 | 2525 | } | 
 | 2526 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2527 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) | 
 | 2528 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2529 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2530 | 	struct vif_params params; | 
| Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2531 | 	int err; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2532 | 	enum nl80211_iftype otype, ntype; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2533 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2534 | 	u32 _flags, *flags = NULL; | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2535 | 	bool change = false; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2536 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2537 | 	memset(¶ms, 0, sizeof(params)); | 
 | 2538 |  | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2539 | 	otype = ntype = dev->ieee80211_ptr->iftype; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2540 |  | 
| Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2541 | 	if (info->attrs[NL80211_ATTR_IFTYPE]) { | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2542 | 		ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2543 | 		if (otype != ntype) | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2544 | 			change = true; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2545 | 		if (ntype > NL80211_IFTYPE_MAX) | 
 | 2546 | 			return -EINVAL; | 
| Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2547 | 	} | 
 | 2548 |  | 
| Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2549 | 	if (info->attrs[NL80211_ATTR_MESH_ID]) { | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2550 | 		struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 2551 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2552 | 		if (ntype != NL80211_IFTYPE_MESH_POINT) | 
 | 2553 | 			return -EINVAL; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2554 | 		if (netif_running(dev)) | 
 | 2555 | 			return -EBUSY; | 
 | 2556 |  | 
 | 2557 | 		wdev_lock(wdev); | 
 | 2558 | 		BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | 
 | 2559 | 			     IEEE80211_MAX_MESH_ID_LEN); | 
 | 2560 | 		wdev->mesh_id_up_len = | 
 | 2561 | 			nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
 | 2562 | 		memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | 
 | 2563 | 		       wdev->mesh_id_up_len); | 
 | 2564 | 		wdev_unlock(wdev); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2565 | 	} | 
 | 2566 |  | 
| Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2567 | 	if (info->attrs[NL80211_ATTR_4ADDR]) { | 
 | 2568 | 		params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | 
 | 2569 | 		change = true; | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2570 | 		err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2571 | 		if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2572 | 			return err; | 
| Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2573 | 	} else { | 
 | 2574 | 		params.use_4addr = -1; | 
 | 2575 | 	} | 
 | 2576 |  | 
| Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2577 | 	if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | 		if (ntype != NL80211_IFTYPE_MONITOR) | 
 | 2579 | 			return -EINVAL; | 
| Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2580 | 		err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | 
 | 2581 | 					  &_flags); | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2582 | 		if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2583 | 			return err; | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2584 |  | 
 | 2585 | 		flags = &_flags; | 
 | 2586 | 		change = true; | 
| Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2587 | 	} | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2588 |  | 
| Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2589 | 	if (flags && (*flags & MONITOR_FLAG_ACTIVE) && | 
| Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2590 | 	    !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | 
 | 2591 | 		return -EOPNOTSUPP; | 
 | 2592 |  | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2593 | 	if (change) | 
| Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2594 | 		err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); | 
| Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2595 | 	else | 
 | 2596 | 		err = 0; | 
| Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2597 |  | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2598 | 	if (!err && params.use_4addr != -1) | 
 | 2599 | 		dev->ieee80211_ptr->use_4addr = params.use_4addr; | 
 | 2600 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2601 | 	return err; | 
 | 2602 | } | 
 | 2603 |  | 
 | 2604 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | 
 | 2605 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2606 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2607 | 	struct vif_params params; | 
| Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2608 | 	struct wireless_dev *wdev; | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2609 | 	struct sk_buff *msg, *event; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2610 | 	int err; | 
 | 2611 | 	enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | 
| Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2612 | 	u32 flags; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2613 |  | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2614 | 	/* to avoid failing a new interface creation due to pending removal */ | 
 | 2615 | 	cfg80211_destroy_ifaces(rdev); | 
 | 2616 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2617 | 	memset(¶ms, 0, sizeof(params)); | 
 | 2618 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2619 | 	if (!info->attrs[NL80211_ATTR_IFNAME]) | 
 | 2620 | 		return -EINVAL; | 
 | 2621 |  | 
 | 2622 | 	if (info->attrs[NL80211_ATTR_IFTYPE]) { | 
 | 2623 | 		type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | 
 | 2624 | 		if (type > NL80211_IFTYPE_MAX) | 
 | 2625 | 			return -EINVAL; | 
 | 2626 | 	} | 
 | 2627 |  | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2628 | 	if (!rdev->ops->add_virtual_intf || | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2629 | 	    !(rdev->wiphy.interface_modes & (1 << type))) | 
 | 2630 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2631 |  | 
| Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2632 | 	if ((type == NL80211_IFTYPE_P2P_DEVICE || | 
 | 2633 | 	     rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | 
 | 2634 | 	    info->attrs[NL80211_ATTR_MAC]) { | 
| Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2635 | 		nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | 
 | 2636 | 			   ETH_ALEN); | 
 | 2637 | 		if (!is_valid_ether_addr(params.macaddr)) | 
 | 2638 | 			return -EADDRNOTAVAIL; | 
 | 2639 | 	} | 
 | 2640 |  | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2641 | 	if (info->attrs[NL80211_ATTR_4ADDR]) { | 
| Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2642 | 		params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | 
| Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2643 | 		err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2644 | 		if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2645 | 			return err; | 
| Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2646 | 	} | 
| Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2647 |  | 
| Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2648 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 2649 | 	if (!msg) | 
 | 2650 | 		return -ENOMEM; | 
 | 2651 |  | 
| Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2652 | 	err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? | 
 | 2653 | 				  info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | 
 | 2654 | 				  &flags); | 
| Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2655 |  | 
| Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2656 | 	if (!err && (flags & MONITOR_FLAG_ACTIVE) && | 
| Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2657 | 	    !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | 
 | 2658 | 		return -EOPNOTSUPP; | 
 | 2659 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2660 | 	wdev = rdev_add_virtual_intf(rdev, | 
 | 2661 | 				nla_data(info->attrs[NL80211_ATTR_IFNAME]), | 
 | 2662 | 				type, err ? NULL : &flags, ¶ms); | 
| Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2663 | 	if (WARN_ON(!wdev)) { | 
 | 2664 | 		nlmsg_free(msg); | 
 | 2665 | 		return -EPROTO; | 
 | 2666 | 	} else if (IS_ERR(wdev)) { | 
| Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2667 | 		nlmsg_free(msg); | 
| Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2668 | 		return PTR_ERR(wdev); | 
| Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2669 | 	} | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2670 |  | 
| Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2671 | 	if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2672 | 		wdev->owner_nlportid = info->snd_portid; | 
 | 2673 |  | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2674 | 	switch (type) { | 
 | 2675 | 	case NL80211_IFTYPE_MESH_POINT: | 
 | 2676 | 		if (!info->attrs[NL80211_ATTR_MESH_ID]) | 
 | 2677 | 			break; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2678 | 		wdev_lock(wdev); | 
 | 2679 | 		BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | 
 | 2680 | 			     IEEE80211_MAX_MESH_ID_LEN); | 
 | 2681 | 		wdev->mesh_id_up_len = | 
 | 2682 | 			nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
 | 2683 | 		memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | 
 | 2684 | 		       wdev->mesh_id_up_len); | 
 | 2685 | 		wdev_unlock(wdev); | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2686 | 		break; | 
 | 2687 | 	case NL80211_IFTYPE_P2P_DEVICE: | 
 | 2688 | 		/* | 
 | 2689 | 		 * P2P Device doesn't have a netdev, so doesn't go | 
 | 2690 | 		 * through the netdev notifier and must be added here | 
 | 2691 | 		 */ | 
 | 2692 | 		mutex_init(&wdev->mtx); | 
 | 2693 | 		INIT_LIST_HEAD(&wdev->event_list); | 
 | 2694 | 		spin_lock_init(&wdev->event_lock); | 
 | 2695 | 		INIT_LIST_HEAD(&wdev->mgmt_registrations); | 
 | 2696 | 		spin_lock_init(&wdev->mgmt_registrations_lock); | 
 | 2697 |  | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2698 | 		wdev->identifier = ++rdev->wdev_id; | 
 | 2699 | 		list_add_rcu(&wdev->list, &rdev->wdev_list); | 
 | 2700 | 		rdev->devlist_generation++; | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2701 | 		break; | 
 | 2702 | 	default: | 
 | 2703 | 		break; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2704 | 	} | 
 | 2705 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2706 | 	if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2707 | 			       rdev, wdev, false) < 0) { | 
| Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2708 | 		nlmsg_free(msg); | 
 | 2709 | 		return -ENOBUFS; | 
 | 2710 | 	} | 
 | 2711 |  | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2712 | 	event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 2713 | 	if (event) { | 
 | 2714 | 		if (nl80211_send_iface(event, 0, 0, 0, | 
 | 2715 | 				       rdev, wdev, false) < 0) { | 
 | 2716 | 			nlmsg_free(event); | 
 | 2717 | 			goto out; | 
 | 2718 | 		} | 
 | 2719 |  | 
 | 2720 | 		genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | 
 | 2721 | 					event, 0, NL80211_MCGRP_CONFIG, | 
 | 2722 | 					GFP_KERNEL); | 
 | 2723 | 	} | 
 | 2724 |  | 
 | 2725 | out: | 
| Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2726 | 	return genlmsg_reply(msg, info); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2727 | } | 
 | 2728 |  | 
 | 2729 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | 
 | 2730 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2731 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2732 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2733 | 	struct sk_buff *msg; | 
 | 2734 | 	int status; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2735 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2736 | 	if (!rdev->ops->del_virtual_intf) | 
 | 2737 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2738 |  | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2739 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 2740 | 	if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | 
 | 2741 | 		nlmsg_free(msg); | 
 | 2742 | 		msg = NULL; | 
 | 2743 | 	} | 
 | 2744 |  | 
| Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2745 | 	/* | 
 | 2746 | 	 * If we remove a wireless device without a netdev then clear | 
 | 2747 | 	 * user_ptr[1] so that nl80211_post_doit won't dereference it | 
 | 2748 | 	 * to check if it needs to do dev_put(). Otherwise it crashes | 
 | 2749 | 	 * since the wdev has been freed, unlike with a netdev where | 
 | 2750 | 	 * we need the dev_put() for the netdev to really be freed. | 
 | 2751 | 	 */ | 
 | 2752 | 	if (!wdev->netdev) | 
 | 2753 | 		info->user_ptr[1] = NULL; | 
 | 2754 |  | 
| Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2755 | 	status = rdev_del_virtual_intf(rdev, wdev); | 
 | 2756 | 	if (status >= 0 && msg) | 
 | 2757 | 		genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | 
 | 2758 | 					msg, 0, NL80211_MCGRP_CONFIG, | 
 | 2759 | 					GFP_KERNEL); | 
 | 2760 | 	else | 
 | 2761 | 		nlmsg_free(msg); | 
 | 2762 |  | 
 | 2763 | 	return status; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2764 | } | 
 | 2765 |  | 
| Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2766 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) | 
 | 2767 | { | 
 | 2768 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 2769 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 2770 | 	u16 noack_map; | 
 | 2771 |  | 
 | 2772 | 	if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | 
 | 2773 | 		return -EINVAL; | 
 | 2774 |  | 
 | 2775 | 	if (!rdev->ops->set_noack_map) | 
 | 2776 | 		return -EOPNOTSUPP; | 
 | 2777 |  | 
 | 2778 | 	noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | 
 | 2779 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2780 | 	return rdev_set_noack_map(rdev, dev, noack_map); | 
| Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2781 | } | 
 | 2782 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | struct get_key_cookie { | 
 | 2784 | 	struct sk_buff *msg; | 
 | 2785 | 	int error; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2786 | 	int idx; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | }; | 
 | 2788 |  | 
 | 2789 | static void get_key_callback(void *c, struct key_params *params) | 
 | 2790 | { | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2791 | 	struct nlattr *key; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2792 | 	struct get_key_cookie *cookie = c; | 
 | 2793 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2794 | 	if ((params->key && | 
 | 2795 | 	     nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | 
 | 2796 | 		     params->key_len, params->key)) || | 
 | 2797 | 	    (params->seq && | 
 | 2798 | 	     nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | 
 | 2799 | 		     params->seq_len, params->seq)) || | 
 | 2800 | 	    (params->cipher && | 
 | 2801 | 	     nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | 
 | 2802 | 			 params->cipher))) | 
 | 2803 | 		goto nla_put_failure; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2804 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2805 | 	key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); | 
 | 2806 | 	if (!key) | 
 | 2807 | 		goto nla_put_failure; | 
 | 2808 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2809 | 	if ((params->key && | 
 | 2810 | 	     nla_put(cookie->msg, NL80211_KEY_DATA, | 
 | 2811 | 		     params->key_len, params->key)) || | 
 | 2812 | 	    (params->seq && | 
 | 2813 | 	     nla_put(cookie->msg, NL80211_KEY_SEQ, | 
 | 2814 | 		     params->seq_len, params->seq)) || | 
 | 2815 | 	    (params->cipher && | 
 | 2816 | 	     nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | 
 | 2817 | 			 params->cipher))) | 
 | 2818 | 		goto nla_put_failure; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2819 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2820 | 	if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) | 
 | 2821 | 		goto nla_put_failure; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2822 |  | 
 | 2823 | 	nla_nest_end(cookie->msg, key); | 
 | 2824 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2825 | 	return; | 
 | 2826 |  nla_put_failure: | 
 | 2827 | 	cookie->error = 1; | 
 | 2828 | } | 
 | 2829 |  | 
 | 2830 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | 
 | 2831 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2832 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2833 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2834 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2835 | 	u8 key_idx = 0; | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2836 | 	const u8 *mac_addr = NULL; | 
 | 2837 | 	bool pairwise; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2838 | 	struct get_key_cookie cookie = { | 
 | 2839 | 		.error = 0, | 
 | 2840 | 	}; | 
 | 2841 | 	void *hdr; | 
 | 2842 | 	struct sk_buff *msg; | 
 | 2843 |  | 
 | 2844 | 	if (info->attrs[NL80211_ATTR_KEY_IDX]) | 
 | 2845 | 		key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | 
 | 2846 |  | 
| Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2847 | 	if (key_idx > 5) | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2848 | 		return -EINVAL; | 
 | 2849 |  | 
 | 2850 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
 | 2851 | 		mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 2852 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2853 | 	pairwise = !!mac_addr; | 
 | 2854 | 	if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | 
 | 2855 | 		u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | 
 | 2856 | 		if (kt >= NUM_NL80211_KEYTYPES) | 
 | 2857 | 			return -EINVAL; | 
 | 2858 | 		if (kt != NL80211_KEYTYPE_GROUP && | 
 | 2859 | 		    kt != NL80211_KEYTYPE_PAIRWISE) | 
 | 2860 | 			return -EINVAL; | 
 | 2861 | 		pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | 
 | 2862 | 	} | 
 | 2863 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | 	if (!rdev->ops->get_key) | 
 | 2865 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2867 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2868 | 	if (!msg) | 
 | 2869 | 		return -ENOMEM; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2870 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2871 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2872 | 			     NL80211_CMD_NEW_KEY); | 
| Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2873 | 	if (!hdr) | 
| Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2874 | 		goto nla_put_failure; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2875 |  | 
 | 2876 | 	cookie.msg = msg; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2877 | 	cookie.idx = key_idx; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2878 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2879 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 2880 | 	    nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | 
 | 2881 | 		goto nla_put_failure; | 
 | 2882 | 	if (mac_addr && | 
 | 2883 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | 
 | 2884 | 		goto nla_put_failure; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2885 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2886 | 	if (pairwise && mac_addr && | 
 | 2887 | 	    !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | 
 | 2888 | 		return -ENOENT; | 
 | 2889 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2890 | 	err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, | 
 | 2891 | 			   get_key_callback); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2892 |  | 
 | 2893 | 	if (err) | 
| Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2894 | 		goto free_msg; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 |  | 
 | 2896 | 	if (cookie.error) | 
 | 2897 | 		goto nla_put_failure; | 
 | 2898 |  | 
 | 2899 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2900 | 	return genlmsg_reply(msg, info); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2901 |  | 
 | 2902 |  nla_put_failure: | 
 | 2903 | 	err = -ENOBUFS; | 
| Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2904 |  free_msg: | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2905 | 	nlmsg_free(msg); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2906 | 	return err; | 
 | 2907 | } | 
 | 2908 |  | 
 | 2909 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | 
 | 2910 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2911 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2912 | 	struct key_parse key; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2913 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2914 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2916 | 	err = nl80211_parse_key(info, &key); | 
 | 2917 | 	if (err) | 
 | 2918 | 		return err; | 
 | 2919 |  | 
 | 2920 | 	if (key.idx < 0) | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2921 | 		return -EINVAL; | 
 | 2922 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2923 | 	/* only support setting default key */ | 
 | 2924 | 	if (!key.def && !key.defmgmt) | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2925 | 		return -EINVAL; | 
 | 2926 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2927 | 	wdev_lock(dev->ieee80211_ptr); | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2928 |  | 
 | 2929 | 	if (key.def) { | 
 | 2930 | 		if (!rdev->ops->set_default_key) { | 
 | 2931 | 			err = -EOPNOTSUPP; | 
 | 2932 | 			goto out; | 
 | 2933 | 		} | 
 | 2934 |  | 
 | 2935 | 		err = nl80211_key_allowed(dev->ieee80211_ptr); | 
 | 2936 | 		if (err) | 
 | 2937 | 			goto out; | 
 | 2938 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2939 | 		err = rdev_set_default_key(rdev, dev, key.idx, | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2940 | 						 key.def_uni, key.def_multi); | 
 | 2941 |  | 
 | 2942 | 		if (err) | 
 | 2943 | 			goto out; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2944 |  | 
| Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2945 | #ifdef CONFIG_CFG80211_WEXT | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2946 | 		dev->ieee80211_ptr->wext.default_key = key.idx; | 
| Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2947 | #endif | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2948 | 	} else { | 
 | 2949 | 		if (key.def_uni || !key.def_multi) { | 
 | 2950 | 			err = -EINVAL; | 
 | 2951 | 			goto out; | 
 | 2952 | 		} | 
 | 2953 |  | 
 | 2954 | 		if (!rdev->ops->set_default_mgmt_key) { | 
 | 2955 | 			err = -EOPNOTSUPP; | 
 | 2956 | 			goto out; | 
 | 2957 | 		} | 
 | 2958 |  | 
 | 2959 | 		err = nl80211_key_allowed(dev->ieee80211_ptr); | 
 | 2960 | 		if (err) | 
 | 2961 | 			goto out; | 
 | 2962 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2963 | 		err = rdev_set_default_mgmt_key(rdev, dev, key.idx); | 
| Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2964 | 		if (err) | 
 | 2965 | 			goto out; | 
 | 2966 |  | 
 | 2967 | #ifdef CONFIG_CFG80211_WEXT | 
 | 2968 | 		dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | 
 | 2969 | #endif | 
 | 2970 | 	} | 
 | 2971 |  | 
 | 2972 |  out: | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2973 | 	wdev_unlock(dev->ieee80211_ptr); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2974 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2975 | 	return err; | 
 | 2976 | } | 
 | 2977 |  | 
 | 2978 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | 
 | 2979 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2980 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2981 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2982 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2983 | 	struct key_parse key; | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2984 | 	const u8 *mac_addr = NULL; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2985 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2986 | 	err = nl80211_parse_key(info, &key); | 
 | 2987 | 	if (err) | 
 | 2988 | 		return err; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2989 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2990 | 	if (!key.p.key) | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2991 | 		return -EINVAL; | 
 | 2992 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2993 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
 | 2994 | 		mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 2995 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2996 | 	if (key.type == -1) { | 
 | 2997 | 		if (mac_addr) | 
 | 2998 | 			key.type = NL80211_KEYTYPE_PAIRWISE; | 
 | 2999 | 		else | 
 | 3000 | 			key.type = NL80211_KEYTYPE_GROUP; | 
 | 3001 | 	} | 
 | 3002 |  | 
 | 3003 | 	/* for now */ | 
 | 3004 | 	if (key.type != NL80211_KEYTYPE_PAIRWISE && | 
 | 3005 | 	    key.type != NL80211_KEYTYPE_GROUP) | 
 | 3006 | 		return -EINVAL; | 
 | 3007 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3008 | 	if (!rdev->ops->add_key) | 
 | 3009 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3010 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3011 | 	if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, | 
 | 3012 | 					   key.type == NL80211_KEYTYPE_PAIRWISE, | 
 | 3013 | 					   mac_addr)) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3014 | 		return -EINVAL; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3015 |  | 
 | 3016 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 3017 | 	err = nl80211_key_allowed(dev->ieee80211_ptr); | 
 | 3018 | 	if (!err) | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3019 | 		err = rdev_add_key(rdev, dev, key.idx, | 
 | 3020 | 				   key.type == NL80211_KEYTYPE_PAIRWISE, | 
 | 3021 | 				    mac_addr, &key.p); | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3022 | 	wdev_unlock(dev->ieee80211_ptr); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3023 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3024 | 	return err; | 
 | 3025 | } | 
 | 3026 |  | 
 | 3027 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | 
 | 3028 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3029 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3030 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3031 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3032 | 	u8 *mac_addr = NULL; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3033 | 	struct key_parse key; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3034 |  | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3035 | 	err = nl80211_parse_key(info, &key); | 
 | 3036 | 	if (err) | 
 | 3037 | 		return err; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 |  | 
 | 3039 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
 | 3040 | 		mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 3041 |  | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3042 | 	if (key.type == -1) { | 
 | 3043 | 		if (mac_addr) | 
 | 3044 | 			key.type = NL80211_KEYTYPE_PAIRWISE; | 
 | 3045 | 		else | 
 | 3046 | 			key.type = NL80211_KEYTYPE_GROUP; | 
 | 3047 | 	} | 
 | 3048 |  | 
 | 3049 | 	/* for now */ | 
 | 3050 | 	if (key.type != NL80211_KEYTYPE_PAIRWISE && | 
 | 3051 | 	    key.type != NL80211_KEYTYPE_GROUP) | 
 | 3052 | 		return -EINVAL; | 
 | 3053 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3054 | 	if (!rdev->ops->del_key) | 
 | 3055 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3056 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3057 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 3058 | 	err = nl80211_key_allowed(dev->ieee80211_ptr); | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3059 |  | 
 | 3060 | 	if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | 
 | 3061 | 	    !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | 
 | 3062 | 		err = -ENOENT; | 
 | 3063 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3064 | 	if (!err) | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3065 | 		err = rdev_del_key(rdev, dev, key.idx, | 
 | 3066 | 				   key.type == NL80211_KEYTYPE_PAIRWISE, | 
 | 3067 | 				   mac_addr); | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3068 |  | 
| Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3069 | #ifdef CONFIG_CFG80211_WEXT | 
| Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3070 | 	if (!err) { | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3071 | 		if (key.idx == dev->ieee80211_ptr->wext.default_key) | 
| Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3072 | 			dev->ieee80211_ptr->wext.default_key = -1; | 
| Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3073 | 		else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) | 
| Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3074 | 			dev->ieee80211_ptr->wext.default_mgmt_key = -1; | 
 | 3075 | 	} | 
 | 3076 | #endif | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3077 | 	wdev_unlock(dev->ieee80211_ptr); | 
| Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3078 |  | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3079 | 	return err; | 
 | 3080 | } | 
 | 3081 |  | 
| Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3082 | /* This function returns an error or the number of nested attributes */ | 
 | 3083 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | 
 | 3084 | { | 
 | 3085 | 	struct nlattr *attr; | 
 | 3086 | 	int n_entries = 0, tmp; | 
 | 3087 |  | 
 | 3088 | 	nla_for_each_nested(attr, nl_attr, tmp) { | 
 | 3089 | 		if (nla_len(attr) != ETH_ALEN) | 
 | 3090 | 			return -EINVAL; | 
 | 3091 |  | 
 | 3092 | 		n_entries++; | 
 | 3093 | 	} | 
 | 3094 |  | 
 | 3095 | 	return n_entries; | 
 | 3096 | } | 
 | 3097 |  | 
 | 3098 | /* | 
 | 3099 |  * This function parses ACL information and allocates memory for ACL data. | 
 | 3100 |  * On successful return, the calling function is responsible to free the | 
 | 3101 |  * ACL buffer returned by this function. | 
 | 3102 |  */ | 
 | 3103 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | 
 | 3104 | 						struct genl_info *info) | 
 | 3105 | { | 
 | 3106 | 	enum nl80211_acl_policy acl_policy; | 
 | 3107 | 	struct nlattr *attr; | 
 | 3108 | 	struct cfg80211_acl_data *acl; | 
 | 3109 | 	int i = 0, n_entries, tmp; | 
 | 3110 |  | 
 | 3111 | 	if (!wiphy->max_acl_mac_addrs) | 
 | 3112 | 		return ERR_PTR(-EOPNOTSUPP); | 
 | 3113 |  | 
 | 3114 | 	if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | 
 | 3115 | 		return ERR_PTR(-EINVAL); | 
 | 3116 |  | 
 | 3117 | 	acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | 
 | 3118 | 	if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | 
 | 3119 | 	    acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | 
 | 3120 | 		return ERR_PTR(-EINVAL); | 
 | 3121 |  | 
 | 3122 | 	if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | 
 | 3123 | 		return ERR_PTR(-EINVAL); | 
 | 3124 |  | 
 | 3125 | 	n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | 
 | 3126 | 	if (n_entries < 0) | 
 | 3127 | 		return ERR_PTR(n_entries); | 
 | 3128 |  | 
 | 3129 | 	if (n_entries > wiphy->max_acl_mac_addrs) | 
 | 3130 | 		return ERR_PTR(-ENOTSUPP); | 
 | 3131 |  | 
 | 3132 | 	acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | 
 | 3133 | 		      GFP_KERNEL); | 
 | 3134 | 	if (!acl) | 
 | 3135 | 		return ERR_PTR(-ENOMEM); | 
 | 3136 |  | 
 | 3137 | 	nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | 
 | 3138 | 		memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | 
 | 3139 | 		i++; | 
 | 3140 | 	} | 
 | 3141 |  | 
 | 3142 | 	acl->n_acl_entries = n_entries; | 
 | 3143 | 	acl->acl_policy = acl_policy; | 
 | 3144 |  | 
 | 3145 | 	return acl; | 
 | 3146 | } | 
 | 3147 |  | 
 | 3148 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | 
 | 3149 | { | 
 | 3150 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 3151 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 3152 | 	struct cfg80211_acl_data *acl; | 
 | 3153 | 	int err; | 
 | 3154 |  | 
 | 3155 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
 | 3156 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3157 | 		return -EOPNOTSUPP; | 
 | 3158 |  | 
 | 3159 | 	if (!dev->ieee80211_ptr->beacon_interval) | 
 | 3160 | 		return -EINVAL; | 
 | 3161 |  | 
 | 3162 | 	acl = parse_acl_data(&rdev->wiphy, info); | 
 | 3163 | 	if (IS_ERR(acl)) | 
 | 3164 | 		return PTR_ERR(acl); | 
 | 3165 |  | 
 | 3166 | 	err = rdev_set_mac_acl(rdev, dev, acl); | 
 | 3167 |  | 
 | 3168 | 	kfree(acl); | 
 | 3169 |  | 
 | 3170 | 	return err; | 
 | 3171 | } | 
 | 3172 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3173 | static int nl80211_parse_beacon(struct nlattr *attrs[], | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3174 | 				struct cfg80211_beacon_data *bcn) | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3175 | { | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3176 | 	bool haveinfo = false; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3177 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3178 | 	if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || | 
 | 3179 | 	    !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | 
 | 3180 | 	    !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | 
 | 3181 | 	    !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3182 | 		return -EINVAL; | 
 | 3183 |  | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3184 | 	memset(bcn, 0, sizeof(*bcn)); | 
| 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 (attrs[NL80211_ATTR_BEACON_HEAD]) { | 
 | 3187 | 		bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | 
 | 3188 | 		bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3189 | 		if (!bcn->head_len) | 
 | 3190 | 			return -EINVAL; | 
 | 3191 | 		haveinfo = true; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3192 | 	} | 
 | 3193 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3194 | 	if (attrs[NL80211_ATTR_BEACON_TAIL]) { | 
 | 3195 | 		bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | 
 | 3196 | 		bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3197 | 		haveinfo = true; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3198 | 	} | 
 | 3199 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3200 | 	if (!haveinfo) | 
 | 3201 | 		return -EINVAL; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3202 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3203 | 	if (attrs[NL80211_ATTR_IE]) { | 
 | 3204 | 		bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | 
 | 3205 | 		bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | 
| Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3206 | 	} | 
 | 3207 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3208 | 	if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3209 | 		bcn->proberesp_ies = | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3210 | 			nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3211 | 		bcn->proberesp_ies_len = | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3212 | 			nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); | 
| Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3213 | 	} | 
 | 3214 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3215 | 	if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3216 | 		bcn->assocresp_ies = | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3217 | 			nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3218 | 		bcn->assocresp_ies_len = | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3219 | 			nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); | 
| Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3220 | 	} | 
 | 3221 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3222 | 	if (attrs[NL80211_ATTR_PROBE_RESP]) { | 
 | 3223 | 		bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | 
 | 3224 | 		bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | 
| Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3225 | 	} | 
 | 3226 |  | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3227 | 	return 0; | 
 | 3228 | } | 
 | 3229 |  | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3230 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, | 
 | 3231 | 				   struct cfg80211_ap_settings *params) | 
 | 3232 | { | 
 | 3233 | 	struct wireless_dev *wdev; | 
 | 3234 | 	bool ret = false; | 
 | 3235 |  | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3236 | 	list_for_each_entry(wdev, &rdev->wdev_list, list) { | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3237 | 		if (wdev->iftype != NL80211_IFTYPE_AP && | 
 | 3238 | 		    wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3239 | 			continue; | 
 | 3240 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3241 | 		if (!wdev->preset_chandef.chan) | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3242 | 			continue; | 
 | 3243 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3244 | 		params->chandef = wdev->preset_chandef; | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3245 | 		ret = true; | 
 | 3246 | 		break; | 
 | 3247 | 	} | 
 | 3248 |  | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3249 | 	return ret; | 
 | 3250 | } | 
 | 3251 |  | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3252 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, | 
 | 3253 | 				    enum nl80211_auth_type auth_type, | 
 | 3254 | 				    enum nl80211_commands cmd) | 
 | 3255 | { | 
 | 3256 | 	if (auth_type > NL80211_AUTHTYPE_MAX) | 
 | 3257 | 		return false; | 
 | 3258 |  | 
 | 3259 | 	switch (cmd) { | 
 | 3260 | 	case NL80211_CMD_AUTHENTICATE: | 
 | 3261 | 		if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | 
 | 3262 | 		    auth_type == NL80211_AUTHTYPE_SAE) | 
 | 3263 | 			return false; | 
 | 3264 | 		return true; | 
 | 3265 | 	case NL80211_CMD_CONNECT: | 
 | 3266 | 	case NL80211_CMD_START_AP: | 
 | 3267 | 		/* SAE not supported yet */ | 
 | 3268 | 		if (auth_type == NL80211_AUTHTYPE_SAE) | 
 | 3269 | 			return false; | 
 | 3270 | 		return true; | 
 | 3271 | 	default: | 
 | 3272 | 		return false; | 
 | 3273 | 	} | 
 | 3274 | } | 
 | 3275 |  | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3276 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) | 
 | 3277 | { | 
 | 3278 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 3279 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 3280 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 3281 | 	struct cfg80211_ap_settings params; | 
 | 3282 | 	int err; | 
 | 3283 |  | 
 | 3284 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
 | 3285 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3286 | 		return -EOPNOTSUPP; | 
 | 3287 |  | 
 | 3288 | 	if (!rdev->ops->start_ap) | 
 | 3289 | 		return -EOPNOTSUPP; | 
 | 3290 |  | 
 | 3291 | 	if (wdev->beacon_interval) | 
 | 3292 | 		return -EALREADY; | 
 | 3293 |  | 
 | 3294 | 	memset(¶ms, 0, sizeof(params)); | 
 | 3295 |  | 
 | 3296 | 	/* these are required for START_AP */ | 
 | 3297 | 	if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | 
 | 3298 | 	    !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | 
 | 3299 | 	    !info->attrs[NL80211_ATTR_BEACON_HEAD]) | 
 | 3300 | 		return -EINVAL; | 
 | 3301 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3302 | 	err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3303 | 	if (err) | 
 | 3304 | 		return err; | 
 | 3305 |  | 
 | 3306 | 	params.beacon_interval = | 
 | 3307 | 		nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
 | 3308 | 	params.dtim_period = | 
 | 3309 | 		nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | 
 | 3310 |  | 
 | 3311 | 	err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | 
 | 3312 | 	if (err) | 
 | 3313 | 		return err; | 
 | 3314 |  | 
 | 3315 | 	/* | 
 | 3316 | 	 * In theory, some of these attributes should be required here | 
 | 3317 | 	 * but since they were not used when the command was originally | 
 | 3318 | 	 * added, keep them optional for old user space programs to let | 
 | 3319 | 	 * them continue to work with drivers that do not need the | 
 | 3320 | 	 * additional information -- drivers must check! | 
 | 3321 | 	 */ | 
 | 3322 | 	if (info->attrs[NL80211_ATTR_SSID]) { | 
 | 3323 | 		params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
 | 3324 | 		params.ssid_len = | 
 | 3325 | 			nla_len(info->attrs[NL80211_ATTR_SSID]); | 
 | 3326 | 		if (params.ssid_len == 0 || | 
 | 3327 | 		    params.ssid_len > IEEE80211_MAX_SSID_LEN) | 
 | 3328 | 			return -EINVAL; | 
 | 3329 | 	} | 
 | 3330 |  | 
 | 3331 | 	if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | 
 | 3332 | 		params.hidden_ssid = nla_get_u32( | 
 | 3333 | 			info->attrs[NL80211_ATTR_HIDDEN_SSID]); | 
 | 3334 | 		if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | 
 | 3335 | 		    params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | 
 | 3336 | 		    params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | 
 | 3337 | 			return -EINVAL; | 
 | 3338 | 	} | 
 | 3339 |  | 
 | 3340 | 	params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | 
 | 3341 |  | 
 | 3342 | 	if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | 
 | 3343 | 		params.auth_type = nla_get_u32( | 
 | 3344 | 			info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3345 | 		if (!nl80211_valid_auth_type(rdev, params.auth_type, | 
 | 3346 | 					     NL80211_CMD_START_AP)) | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3347 | 			return -EINVAL; | 
 | 3348 | 	} else | 
 | 3349 | 		params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | 
 | 3350 |  | 
 | 3351 | 	err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | 
 | 3352 | 				      NL80211_MAX_NR_CIPHER_SUITES); | 
 | 3353 | 	if (err) | 
 | 3354 | 		return err; | 
 | 3355 |  | 
| Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3356 | 	if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { | 
 | 3357 | 		if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | 
 | 3358 | 			return -EOPNOTSUPP; | 
 | 3359 | 		params.inactivity_timeout = nla_get_u16( | 
 | 3360 | 			info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | 
 | 3361 | 	} | 
 | 3362 |  | 
| Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3363 | 	if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { | 
 | 3364 | 		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3365 | 			return -EINVAL; | 
 | 3366 | 		params.p2p_ctwindow = | 
 | 3367 | 			nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | 
 | 3368 | 		if (params.p2p_ctwindow > 127) | 
 | 3369 | 			return -EINVAL; | 
 | 3370 | 		if (params.p2p_ctwindow != 0 && | 
 | 3371 | 		    !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | 
 | 3372 | 			return -EINVAL; | 
 | 3373 | 	} | 
 | 3374 |  | 
 | 3375 | 	if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | 
 | 3376 | 		u8 tmp; | 
 | 3377 |  | 
 | 3378 | 		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3379 | 			return -EINVAL; | 
 | 3380 | 		tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | 
 | 3381 | 		if (tmp > 1) | 
 | 3382 | 			return -EINVAL; | 
 | 3383 | 		params.p2p_opp_ps = tmp; | 
 | 3384 | 		if (params.p2p_opp_ps != 0 && | 
 | 3385 | 		    !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | 
 | 3386 | 			return -EINVAL; | 
 | 3387 | 	} | 
 | 3388 |  | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3389 | 	if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3390 | 		err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); | 
 | 3391 | 		if (err) | 
 | 3392 | 			return err; | 
 | 3393 | 	} else if (wdev->preset_chandef.chan) { | 
 | 3394 | 		params.chandef = wdev->preset_chandef; | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3395 | 	} else if (!nl80211_get_ap_channel(rdev, ¶ms)) | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3396 | 		return -EINVAL; | 
 | 3397 |  | 
| Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3398 | 	if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, | 
 | 3399 | 				     wdev->iftype)) | 
| Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3400 | 		return -EINVAL; | 
 | 3401 |  | 
| Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3402 | 	if (info->attrs[NL80211_ATTR_ACL_POLICY]) { | 
 | 3403 | 		params.acl = parse_acl_data(&rdev->wiphy, info); | 
 | 3404 | 		if (IS_ERR(params.acl)) | 
 | 3405 | 			return PTR_ERR(params.acl); | 
 | 3406 | 	} | 
 | 3407 |  | 
| Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3408 | 	if (info->attrs[NL80211_ATTR_SMPS_MODE]) { | 
 | 3409 | 		params.smps_mode = | 
 | 3410 | 			nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | 
 | 3411 | 		switch (params.smps_mode) { | 
 | 3412 | 		case NL80211_SMPS_OFF: | 
 | 3413 | 			break; | 
 | 3414 | 		case NL80211_SMPS_STATIC: | 
 | 3415 | 			if (!(rdev->wiphy.features & | 
 | 3416 | 			      NL80211_FEATURE_STATIC_SMPS)) | 
 | 3417 | 				return -EINVAL; | 
 | 3418 | 			break; | 
 | 3419 | 		case NL80211_SMPS_DYNAMIC: | 
 | 3420 | 			if (!(rdev->wiphy.features & | 
 | 3421 | 			      NL80211_FEATURE_DYNAMIC_SMPS)) | 
 | 3422 | 				return -EINVAL; | 
 | 3423 | 			break; | 
 | 3424 | 		default: | 
 | 3425 | 			return -EINVAL; | 
 | 3426 | 		} | 
 | 3427 | 	} else { | 
 | 3428 | 		params.smps_mode = NL80211_SMPS_OFF; | 
 | 3429 | 	} | 
 | 3430 |  | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3431 | 	wdev_lock(wdev); | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3432 | 	err = rdev_start_ap(rdev, dev, ¶ms); | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3433 | 	if (!err) { | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3434 | 		wdev->preset_chandef = params.chandef; | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3435 | 		wdev->beacon_interval = params.beacon_interval; | 
| Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3436 | 		wdev->chandef = params.chandef; | 
| Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3437 | 		wdev->ssid_len = params.ssid_len; | 
 | 3438 | 		memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | 
| Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3439 | 	} | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3440 | 	wdev_unlock(wdev); | 
| Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3441 |  | 
 | 3442 | 	kfree(params.acl); | 
 | 3443 |  | 
| Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3444 | 	return err; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3445 | } | 
 | 3446 |  | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3447 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) | 
 | 3448 | { | 
 | 3449 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 3450 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 3451 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 3452 | 	struct cfg80211_beacon_data params; | 
 | 3453 | 	int err; | 
 | 3454 |  | 
 | 3455 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
 | 3456 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 3457 | 		return -EOPNOTSUPP; | 
 | 3458 |  | 
 | 3459 | 	if (!rdev->ops->change_beacon) | 
 | 3460 | 		return -EOPNOTSUPP; | 
 | 3461 |  | 
 | 3462 | 	if (!wdev->beacon_interval) | 
 | 3463 | 		return -EINVAL; | 
 | 3464 |  | 
| Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3465 | 	err = nl80211_parse_beacon(info->attrs, ¶ms); | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3466 | 	if (err) | 
 | 3467 | 		return err; | 
 | 3468 |  | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3469 | 	wdev_lock(wdev); | 
 | 3470 | 	err = rdev_change_beacon(rdev, dev, ¶ms); | 
 | 3471 | 	wdev_unlock(wdev); | 
 | 3472 |  | 
 | 3473 | 	return err; | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3474 | } | 
 | 3475 |  | 
 | 3476 | 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] | 3477 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3478 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 3479 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3480 |  | 
| Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3481 | 	return cfg80211_stop_ap(rdev, dev, false); | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3482 | } | 
 | 3483 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3484 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { | 
 | 3485 | 	[NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | 
 | 3486 | 	[NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | 
 | 3487 | 	[NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | 
| Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3488 | 	[NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, | 
| Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3489 | 	[NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, | 
| Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3490 | 	[NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3491 | }; | 
 | 3492 |  | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3493 | static int parse_station_flags(struct genl_info *info, | 
| Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3494 | 			       enum nl80211_iftype iftype, | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3495 | 			       struct station_parameters *params) | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3496 | { | 
 | 3497 | 	struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3498 | 	struct nlattr *nla; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3499 | 	int flag; | 
 | 3500 |  | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3501 | 	/* | 
 | 3502 | 	 * Try parsing the new attribute first so userspace | 
 | 3503 | 	 * can specify both for older kernels. | 
 | 3504 | 	 */ | 
 | 3505 | 	nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | 
 | 3506 | 	if (nla) { | 
 | 3507 | 		struct nl80211_sta_flag_update *sta_flags; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3508 |  | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3509 | 		sta_flags = nla_data(nla); | 
 | 3510 | 		params->sta_flags_mask = sta_flags->mask; | 
 | 3511 | 		params->sta_flags_set = sta_flags->set; | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3512 | 		params->sta_flags_set &= params->sta_flags_mask; | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3513 | 		if ((params->sta_flags_mask | | 
 | 3514 | 		     params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | 
 | 3515 | 			return -EINVAL; | 
 | 3516 | 		return 0; | 
 | 3517 | 	} | 
 | 3518 |  | 
 | 3519 | 	/* if present, parse the old attribute */ | 
 | 3520 |  | 
 | 3521 | 	nla = info->attrs[NL80211_ATTR_STA_FLAGS]; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3522 | 	if (!nla) | 
 | 3523 | 		return 0; | 
 | 3524 |  | 
 | 3525 | 	if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | 
 | 3526 | 			     nla, sta_flags_policy)) | 
 | 3527 | 		return -EINVAL; | 
 | 3528 |  | 
| Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3529 | 	/* | 
 | 3530 | 	 * Only allow certain flags for interface types so that | 
 | 3531 | 	 * other attributes are silently ignored. Remember that | 
 | 3532 | 	 * this is backward compatibility code with old userspace | 
 | 3533 | 	 * and shouldn't be hit in other cases anyway. | 
 | 3534 | 	 */ | 
 | 3535 | 	switch (iftype) { | 
 | 3536 | 	case NL80211_IFTYPE_AP: | 
 | 3537 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 3538 | 	case NL80211_IFTYPE_P2P_GO: | 
 | 3539 | 		params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
 | 3540 | 					 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | 
 | 3541 | 					 BIT(NL80211_STA_FLAG_WME) | | 
 | 3542 | 					 BIT(NL80211_STA_FLAG_MFP); | 
 | 3543 | 		break; | 
 | 3544 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 3545 | 	case NL80211_IFTYPE_STATION: | 
 | 3546 | 		params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
 | 3547 | 					 BIT(NL80211_STA_FLAG_TDLS_PEER); | 
 | 3548 | 		break; | 
 | 3549 | 	case NL80211_IFTYPE_MESH_POINT: | 
 | 3550 | 		params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
 | 3551 | 					 BIT(NL80211_STA_FLAG_MFP) | | 
 | 3552 | 					 BIT(NL80211_STA_FLAG_AUTHORIZED); | 
 | 3553 | 	default: | 
 | 3554 | 		return -EINVAL; | 
 | 3555 | 	} | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3556 |  | 
| Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3557 | 	for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { | 
 | 3558 | 		if (flags[flag]) { | 
| Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3559 | 			params->sta_flags_set |= (1<<flag); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3560 |  | 
| Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3561 | 			/* no longer support new API additions in old API */ | 
 | 3562 | 			if (flag > NL80211_STA_FLAG_MAX_OLD_API) | 
 | 3563 | 				return -EINVAL; | 
 | 3564 | 		} | 
 | 3565 | 	} | 
 | 3566 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3567 | 	return 0; | 
 | 3568 | } | 
 | 3569 |  | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3570 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, | 
 | 3571 | 				 int attr) | 
 | 3572 | { | 
 | 3573 | 	struct nlattr *rate; | 
| Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3574 | 	u32 bitrate; | 
 | 3575 | 	u16 bitrate_compat; | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3576 |  | 
 | 3577 | 	rate = nla_nest_start(msg, attr); | 
 | 3578 | 	if (!rate) | 
| Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3579 | 		return false; | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3580 |  | 
 | 3581 | 	/* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | 
 | 3582 | 	bitrate = cfg80211_calculate_bitrate(info); | 
| Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3583 | 	/* report 16-bit bitrate only if we can */ | 
 | 3584 | 	bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | 
| Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3585 | 	if (bitrate > 0 && | 
 | 3586 | 	    nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | 
 | 3587 | 		return false; | 
 | 3588 | 	if (bitrate_compat > 0 && | 
 | 3589 | 	    nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | 
 | 3590 | 		return false; | 
 | 3591 |  | 
 | 3592 | 	if (info->flags & RATE_INFO_FLAGS_MCS) { | 
 | 3593 | 		if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | 
 | 3594 | 			return false; | 
 | 3595 | 		if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | 
 | 3596 | 		    nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | 
 | 3597 | 			return false; | 
 | 3598 | 		if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | 
 | 3599 | 		    nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | 
 | 3600 | 			return false; | 
 | 3601 | 	} else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | 
 | 3602 | 		if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | 
 | 3603 | 			return false; | 
 | 3604 | 		if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | 
 | 3605 | 			return false; | 
 | 3606 | 		if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | 
 | 3607 | 		    nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | 
 | 3608 | 			return false; | 
 | 3609 | 		if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | 
 | 3610 | 		    nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | 
 | 3611 | 			return false; | 
 | 3612 | 		if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | 
 | 3613 | 		    nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | 
 | 3614 | 			return false; | 
 | 3615 | 		if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | 
 | 3616 | 		    nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | 
 | 3617 | 			return false; | 
 | 3618 | 		if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | 
 | 3619 | 		    nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | 
 | 3620 | 			return false; | 
 | 3621 | 	} | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3622 |  | 
 | 3623 | 	nla_nest_end(msg, rate); | 
 | 3624 | 	return true; | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3625 | } | 
 | 3626 |  | 
| Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3627 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, | 
 | 3628 | 			       int id) | 
 | 3629 | { | 
 | 3630 | 	void *attr; | 
 | 3631 | 	int i = 0; | 
 | 3632 |  | 
 | 3633 | 	if (!mask) | 
 | 3634 | 		return true; | 
 | 3635 |  | 
 | 3636 | 	attr = nla_nest_start(msg, id); | 
 | 3637 | 	if (!attr) | 
 | 3638 | 		return false; | 
 | 3639 |  | 
 | 3640 | 	for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | 
 | 3641 | 		if (!(mask & BIT(i))) | 
 | 3642 | 			continue; | 
 | 3643 |  | 
 | 3644 | 		if (nla_put_u8(msg, i, signal[i])) | 
 | 3645 | 			return false; | 
 | 3646 | 	} | 
 | 3647 |  | 
 | 3648 | 	nla_nest_end(msg, attr); | 
 | 3649 |  | 
 | 3650 | 	return true; | 
 | 3651 | } | 
 | 3652 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3653 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, | 
| John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3654 | 				int flags, | 
 | 3655 | 				struct cfg80211_registered_device *rdev, | 
 | 3656 | 				struct net_device *dev, | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3657 | 				const u8 *mac_addr, struct station_info *sinfo) | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3658 | { | 
 | 3659 | 	void *hdr; | 
| Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3660 | 	struct nlattr *sinfoattr, *bss_param; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3661 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3662 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3663 | 	if (!hdr) | 
 | 3664 | 		return -1; | 
 | 3665 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3666 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 3667 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | 
 | 3668 | 	    nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | 
 | 3669 | 		goto nla_put_failure; | 
| Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3670 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3671 | 	sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); | 
 | 3672 | 	if (!sinfoattr) | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3673 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3674 | 	if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && | 
 | 3675 | 	    nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | 
 | 3676 | 			sinfo->connected_time)) | 
 | 3677 | 		goto nla_put_failure; | 
 | 3678 | 	if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | 
 | 3679 | 	    nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | 
 | 3680 | 			sinfo->inactive_time)) | 
 | 3681 | 		goto nla_put_failure; | 
| Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3682 | 	if ((sinfo->filled & (STATION_INFO_RX_BYTES | | 
 | 3683 | 			      STATION_INFO_RX_BYTES64)) && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3684 | 	    nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, | 
| Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3685 | 			(u32)sinfo->rx_bytes)) | 
 | 3686 | 		goto nla_put_failure; | 
 | 3687 | 	if ((sinfo->filled & (STATION_INFO_TX_BYTES | | 
| Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3688 | 			      STATION_INFO_TX_BYTES64)) && | 
| Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3689 | 	    nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, | 
 | 3690 | 			(u32)sinfo->tx_bytes)) | 
 | 3691 | 		goto nla_put_failure; | 
 | 3692 | 	if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | 
 | 3693 | 	    nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3694 | 			sinfo->rx_bytes)) | 
 | 3695 | 		goto nla_put_failure; | 
| Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3696 | 	if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | 
 | 3697 | 	    nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3698 | 			sinfo->tx_bytes)) | 
 | 3699 | 		goto nla_put_failure; | 
 | 3700 | 	if ((sinfo->filled & STATION_INFO_LLID) && | 
 | 3701 | 	    nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | 
 | 3702 | 		goto nla_put_failure; | 
 | 3703 | 	if ((sinfo->filled & STATION_INFO_PLID) && | 
 | 3704 | 	    nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | 
 | 3705 | 		goto nla_put_failure; | 
 | 3706 | 	if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | 
 | 3707 | 	    nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | 
 | 3708 | 		       sinfo->plink_state)) | 
 | 3709 | 		goto nla_put_failure; | 
| John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3710 | 	switch (rdev->wiphy.signal_type) { | 
 | 3711 | 	case CFG80211_SIGNAL_TYPE_MBM: | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3712 | 		if ((sinfo->filled & STATION_INFO_SIGNAL) && | 
 | 3713 | 		    nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | 
 | 3714 | 			       sinfo->signal)) | 
 | 3715 | 			goto nla_put_failure; | 
 | 3716 | 		if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | 
 | 3717 | 		    nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | 
 | 3718 | 			       sinfo->signal_avg)) | 
 | 3719 | 			goto nla_put_failure; | 
| John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3720 | 		break; | 
 | 3721 | 	default: | 
 | 3722 | 		break; | 
 | 3723 | 	} | 
| Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3724 | 	if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { | 
 | 3725 | 		if (!nl80211_put_signal(msg, sinfo->chains, | 
 | 3726 | 					sinfo->chain_signal, | 
 | 3727 | 					NL80211_STA_INFO_CHAIN_SIGNAL)) | 
 | 3728 | 			goto nla_put_failure; | 
 | 3729 | 	} | 
 | 3730 | 	if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | 
 | 3731 | 		if (!nl80211_put_signal(msg, sinfo->chains, | 
 | 3732 | 					sinfo->chain_signal_avg, | 
 | 3733 | 					NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | 
 | 3734 | 			goto nla_put_failure; | 
 | 3735 | 	} | 
| Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3736 | 	if (sinfo->filled & STATION_INFO_TX_BITRATE) { | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3737 | 		if (!nl80211_put_sta_rate(msg, &sinfo->txrate, | 
 | 3738 | 					  NL80211_STA_INFO_TX_BITRATE)) | 
| Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3739 | 			goto nla_put_failure; | 
| Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3740 | 	} | 
 | 3741 | 	if (sinfo->filled & STATION_INFO_RX_BITRATE) { | 
 | 3742 | 		if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | 
 | 3743 | 					  NL80211_STA_INFO_RX_BITRATE)) | 
 | 3744 | 			goto nla_put_failure; | 
| Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3745 | 	} | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3746 | 	if ((sinfo->filled & STATION_INFO_RX_PACKETS) && | 
 | 3747 | 	    nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | 
 | 3748 | 			sinfo->rx_packets)) | 
 | 3749 | 		goto nla_put_failure; | 
 | 3750 | 	if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | 
 | 3751 | 	    nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | 
 | 3752 | 			sinfo->tx_packets)) | 
 | 3753 | 		goto nla_put_failure; | 
 | 3754 | 	if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | 
 | 3755 | 	    nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | 
 | 3756 | 			sinfo->tx_retries)) | 
 | 3757 | 		goto nla_put_failure; | 
 | 3758 | 	if ((sinfo->filled & STATION_INFO_TX_FAILED) && | 
 | 3759 | 	    nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | 
 | 3760 | 			sinfo->tx_failed)) | 
 | 3761 | 		goto nla_put_failure; | 
| Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3762 | 	if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && | 
 | 3763 | 	    nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, | 
 | 3764 | 			sinfo->expected_throughput)) | 
 | 3765 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3766 | 	if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | 
 | 3767 | 	    nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | 
 | 3768 | 			sinfo->beacon_loss_count)) | 
 | 3769 | 		goto nla_put_failure; | 
| Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3770 | 	if ((sinfo->filled & STATION_INFO_LOCAL_PM) && | 
 | 3771 | 	    nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | 
 | 3772 | 			sinfo->local_pm)) | 
 | 3773 | 		goto nla_put_failure; | 
 | 3774 | 	if ((sinfo->filled & STATION_INFO_PEER_PM) && | 
 | 3775 | 	    nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | 
 | 3776 | 			sinfo->peer_pm)) | 
 | 3777 | 		goto nla_put_failure; | 
 | 3778 | 	if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | 
 | 3779 | 	    nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | 
 | 3780 | 			sinfo->nonpeer_pm)) | 
 | 3781 | 		goto nla_put_failure; | 
| Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3782 | 	if (sinfo->filled & STATION_INFO_BSS_PARAM) { | 
 | 3783 | 		bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | 
 | 3784 | 		if (!bss_param) | 
 | 3785 | 			goto nla_put_failure; | 
 | 3786 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3787 | 		if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && | 
 | 3788 | 		     nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | 
 | 3789 | 		    ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | 
 | 3790 | 		     nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | 
 | 3791 | 		    ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | 
 | 3792 | 		     nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | 
 | 3793 | 		    nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | 
 | 3794 | 			       sinfo->bss_param.dtim_period) || | 
 | 3795 | 		    nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | 
 | 3796 | 				sinfo->bss_param.beacon_interval)) | 
 | 3797 | 			goto nla_put_failure; | 
| Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3798 |  | 
 | 3799 | 		nla_nest_end(msg, bss_param); | 
 | 3800 | 	} | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3801 | 	if ((sinfo->filled & STATION_INFO_STA_FLAGS) && | 
 | 3802 | 	    nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | 
 | 3803 | 		    sizeof(struct nl80211_sta_flag_update), | 
 | 3804 | 		    &sinfo->sta_flags)) | 
 | 3805 | 		goto nla_put_failure; | 
| John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3806 | 	if ((sinfo->filled & STATION_INFO_T_OFFSET) && | 
 | 3807 | 		nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | 
 | 3808 | 			    sinfo->t_offset)) | 
 | 3809 | 		goto nla_put_failure; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3810 | 	nla_nest_end(msg, sinfoattr); | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3811 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3812 | 	if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && | 
 | 3813 | 	    nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | 
 | 3814 | 		    sinfo->assoc_req_ies)) | 
 | 3815 | 		goto nla_put_failure; | 
| Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3816 |  | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3817 | 	return genlmsg_end(msg, hdr); | 
 | 3818 |  | 
 | 3819 |  nla_put_failure: | 
| Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3820 | 	genlmsg_cancel(msg, hdr); | 
 | 3821 | 	return -EMSGSIZE; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3822 | } | 
 | 3823 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3824 | static int nl80211_dump_station(struct sk_buff *skb, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3825 | 				struct netlink_callback *cb) | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3826 | { | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3827 | 	struct station_info sinfo; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3828 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3829 | 	struct wireless_dev *wdev; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3830 | 	u8 mac_addr[ETH_ALEN]; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3831 | 	int sta_idx = cb->args[2]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3832 | 	int err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3833 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3834 | 	err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3835 | 	if (err) | 
 | 3836 | 		return err; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3837 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3838 | 	if (!wdev->netdev) { | 
 | 3839 | 		err = -EINVAL; | 
 | 3840 | 		goto out_err; | 
 | 3841 | 	} | 
 | 3842 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3843 | 	if (!rdev->ops->dump_station) { | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3844 | 		err = -EOPNOTSUPP; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3845 | 		goto out_err; | 
 | 3846 | 	} | 
 | 3847 |  | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3848 | 	while (1) { | 
| Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3849 | 		memset(&sinfo, 0, sizeof(sinfo)); | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3850 | 		err = rdev_dump_station(rdev, wdev->netdev, sta_idx, | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3851 | 					mac_addr, &sinfo); | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3852 | 		if (err == -ENOENT) | 
 | 3853 | 			break; | 
 | 3854 | 		if (err) | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3855 | 			goto out_err; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3856 |  | 
 | 3857 | 		if (nl80211_send_station(skb, | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3858 | 				NETLINK_CB(cb->skb).portid, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3859 | 				cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3860 | 				rdev, wdev->netdev, mac_addr, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3861 | 				&sinfo) < 0) | 
 | 3862 | 			goto out; | 
 | 3863 |  | 
 | 3864 | 		sta_idx++; | 
 | 3865 | 	} | 
 | 3866 |  | 
 | 3867 |  | 
 | 3868 |  out: | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3869 | 	cb->args[2] = sta_idx; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3870 | 	err = skb->len; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3871 |  out_err: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3872 | 	nl80211_finish_wdev_dump(rdev); | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3873 |  | 
 | 3874 | 	return err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3875 | } | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3876 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3877 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) | 
 | 3878 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3879 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 3880 | 	struct net_device *dev = info->user_ptr[1]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3881 | 	struct station_info sinfo; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3882 | 	struct sk_buff *msg; | 
 | 3883 | 	u8 *mac_addr = NULL; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3884 | 	int err; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3885 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3886 | 	memset(&sinfo, 0, sizeof(sinfo)); | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3887 |  | 
 | 3888 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 3889 | 		return -EINVAL; | 
 | 3890 |  | 
 | 3891 | 	mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 3892 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3893 | 	if (!rdev->ops->get_station) | 
 | 3894 | 		return -EOPNOTSUPP; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3895 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3896 | 	err = rdev_get_station(rdev, dev, mac_addr, &sinfo); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3897 | 	if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3898 | 		return err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3899 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3900 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3901 | 	if (!msg) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3902 | 		return -ENOMEM; | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3903 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3904 | 	if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, | 
| John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3905 | 				 rdev, dev, mac_addr, &sinfo) < 0) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3906 | 		nlmsg_free(msg); | 
 | 3907 | 		return -ENOBUFS; | 
 | 3908 | 	} | 
| Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3909 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3910 | 	return genlmsg_reply(msg, info); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3911 | } | 
 | 3912 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3913 | int cfg80211_check_station_change(struct wiphy *wiphy, | 
 | 3914 | 				  struct station_parameters *params, | 
 | 3915 | 				  enum cfg80211_station_type statype) | 
 | 3916 | { | 
 | 3917 | 	if (params->listen_interval != -1) | 
 | 3918 | 		return -EINVAL; | 
| Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3919 | 	if (params->aid && | 
 | 3920 | 	    !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3921 | 		return -EINVAL; | 
 | 3922 |  | 
 | 3923 | 	/* When you run into this, adjust the code below for the new flag */ | 
 | 3924 | 	BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | 
 | 3925 |  | 
 | 3926 | 	switch (statype) { | 
| Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3927 | 	case CFG80211_STA_MESH_PEER_KERNEL: | 
 | 3928 | 	case CFG80211_STA_MESH_PEER_USER: | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3929 | 		/* | 
 | 3930 | 		 * No ignoring the TDLS flag here -- the userspace mesh | 
 | 3931 | 		 * code doesn't have the bug of including TDLS in the | 
 | 3932 | 		 * mask everywhere. | 
 | 3933 | 		 */ | 
 | 3934 | 		if (params->sta_flags_mask & | 
 | 3935 | 				~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
 | 3936 | 				  BIT(NL80211_STA_FLAG_MFP) | | 
 | 3937 | 				  BIT(NL80211_STA_FLAG_AUTHORIZED))) | 
 | 3938 | 			return -EINVAL; | 
 | 3939 | 		break; | 
 | 3940 | 	case CFG80211_STA_TDLS_PEER_SETUP: | 
 | 3941 | 	case CFG80211_STA_TDLS_PEER_ACTIVE: | 
 | 3942 | 		if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | 
 | 3943 | 			return -EINVAL; | 
 | 3944 | 		/* ignore since it can't change */ | 
 | 3945 | 		params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
 | 3946 | 		break; | 
 | 3947 | 	default: | 
 | 3948 | 		/* disallow mesh-specific things */ | 
 | 3949 | 		if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | 
 | 3950 | 			return -EINVAL; | 
 | 3951 | 		if (params->local_pm) | 
 | 3952 | 			return -EINVAL; | 
 | 3953 | 		if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | 
 | 3954 | 			return -EINVAL; | 
 | 3955 | 	} | 
 | 3956 |  | 
 | 3957 | 	if (statype != CFG80211_STA_TDLS_PEER_SETUP && | 
 | 3958 | 	    statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | 
 | 3959 | 		/* TDLS can't be set, ... */ | 
 | 3960 | 		if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | 
 | 3961 | 			return -EINVAL; | 
 | 3962 | 		/* | 
 | 3963 | 		 * ... but don't bother the driver with it. This works around | 
 | 3964 | 		 * a hostapd/wpa_supplicant issue -- it always includes the | 
 | 3965 | 		 * TLDS_PEER flag in the mask even for AP mode. | 
 | 3966 | 		 */ | 
 | 3967 | 		params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
 | 3968 | 	} | 
 | 3969 |  | 
 | 3970 | 	if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | 
 | 3971 | 		/* reject other things that can't change */ | 
 | 3972 | 		if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | 
 | 3973 | 			return -EINVAL; | 
 | 3974 | 		if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | 
 | 3975 | 			return -EINVAL; | 
 | 3976 | 		if (params->supported_rates) | 
 | 3977 | 			return -EINVAL; | 
 | 3978 | 		if (params->ext_capab || params->ht_capa || params->vht_capa) | 
 | 3979 | 			return -EINVAL; | 
 | 3980 | 	} | 
 | 3981 |  | 
 | 3982 | 	if (statype != CFG80211_STA_AP_CLIENT) { | 
 | 3983 | 		if (params->vlan) | 
 | 3984 | 			return -EINVAL; | 
 | 3985 | 	} | 
 | 3986 |  | 
 | 3987 | 	switch (statype) { | 
 | 3988 | 	case CFG80211_STA_AP_MLME_CLIENT: | 
 | 3989 | 		/* Use this only for authorizing/unauthorizing a station */ | 
 | 3990 | 		if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | 
 | 3991 | 			return -EOPNOTSUPP; | 
 | 3992 | 		break; | 
 | 3993 | 	case CFG80211_STA_AP_CLIENT: | 
 | 3994 | 		/* accept only the listed bits */ | 
 | 3995 | 		if (params->sta_flags_mask & | 
 | 3996 | 				~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
 | 3997 | 				  BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
 | 3998 | 				  BIT(NL80211_STA_FLAG_ASSOCIATED) | | 
 | 3999 | 				  BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | 
 | 4000 | 				  BIT(NL80211_STA_FLAG_WME) | | 
 | 4001 | 				  BIT(NL80211_STA_FLAG_MFP))) | 
 | 4002 | 			return -EINVAL; | 
 | 4003 |  | 
 | 4004 | 		/* but authenticated/associated only if driver handles it */ | 
 | 4005 | 		if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | 
 | 4006 | 		    params->sta_flags_mask & | 
 | 4007 | 				(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
 | 4008 | 				 BIT(NL80211_STA_FLAG_ASSOCIATED))) | 
 | 4009 | 			return -EINVAL; | 
 | 4010 | 		break; | 
 | 4011 | 	case CFG80211_STA_IBSS: | 
 | 4012 | 	case CFG80211_STA_AP_STA: | 
 | 4013 | 		/* reject any changes other than AUTHORIZED */ | 
 | 4014 | 		if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | 
 | 4015 | 			return -EINVAL; | 
 | 4016 | 		break; | 
 | 4017 | 	case CFG80211_STA_TDLS_PEER_SETUP: | 
 | 4018 | 		/* reject any changes other than AUTHORIZED or WME */ | 
 | 4019 | 		if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | 
 | 4020 | 					       BIT(NL80211_STA_FLAG_WME))) | 
 | 4021 | 			return -EINVAL; | 
 | 4022 | 		/* force (at least) rates when authorizing */ | 
 | 4023 | 		if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | 
 | 4024 | 		    !params->supported_rates) | 
 | 4025 | 			return -EINVAL; | 
 | 4026 | 		break; | 
 | 4027 | 	case CFG80211_STA_TDLS_PEER_ACTIVE: | 
 | 4028 | 		/* reject any changes */ | 
 | 4029 | 		return -EINVAL; | 
| Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4030 | 	case CFG80211_STA_MESH_PEER_KERNEL: | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4031 | 		if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | 
 | 4032 | 			return -EINVAL; | 
 | 4033 | 		break; | 
| Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4034 | 	case CFG80211_STA_MESH_PEER_USER: | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4035 | 		if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | 
 | 4036 | 			return -EINVAL; | 
 | 4037 | 		break; | 
 | 4038 | 	} | 
 | 4039 |  | 
 | 4040 | 	return 0; | 
 | 4041 | } | 
 | 4042 | EXPORT_SYMBOL(cfg80211_check_station_change); | 
 | 4043 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4044 | /* | 
| Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4045 |  * 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] | 4046 |  */ | 
| Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4047 | static struct net_device *get_vlan(struct genl_info *info, | 
 | 4048 | 				   struct cfg80211_registered_device *rdev) | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4049 | { | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4050 | 	struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; | 
| Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4051 | 	struct net_device *v; | 
 | 4052 | 	int ret; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4053 |  | 
| Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4054 | 	if (!vlanattr) | 
 | 4055 | 		return NULL; | 
 | 4056 |  | 
 | 4057 | 	v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | 
 | 4058 | 	if (!v) | 
 | 4059 | 		return ERR_PTR(-ENODEV); | 
 | 4060 |  | 
 | 4061 | 	if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | 
 | 4062 | 		ret = -EINVAL; | 
 | 4063 | 		goto error; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4064 | 	} | 
| Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4065 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4066 | 	if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | 
 | 4067 | 	    v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
 | 4068 | 	    v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | 
 | 4069 | 		ret = -EINVAL; | 
 | 4070 | 		goto error; | 
 | 4071 | 	} | 
 | 4072 |  | 
| Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4073 | 	if (!netif_running(v)) { | 
 | 4074 | 		ret = -ENETDOWN; | 
 | 4075 | 		goto error; | 
 | 4076 | 	} | 
 | 4077 |  | 
 | 4078 | 	return v; | 
 | 4079 |  error: | 
 | 4080 | 	dev_put(v); | 
 | 4081 | 	return ERR_PTR(ret); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | } | 
 | 4083 |  | 
| Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4084 | static const struct nla_policy | 
 | 4085 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | 
| Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4086 | 	[NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | 
 | 4087 | 	[NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | 
 | 4088 | }; | 
 | 4089 |  | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4090 | static int nl80211_parse_sta_wme(struct genl_info *info, | 
 | 4091 | 				 struct station_parameters *params) | 
| Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4092 | { | 
| Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4093 | 	struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | 
 | 4094 | 	struct nlattr *nla; | 
 | 4095 | 	int err; | 
 | 4096 |  | 
| Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4097 | 	/* parse WME attributes if present */ | 
 | 4098 | 	if (!info->attrs[NL80211_ATTR_STA_WME]) | 
 | 4099 | 		return 0; | 
 | 4100 |  | 
 | 4101 | 	nla = info->attrs[NL80211_ATTR_STA_WME]; | 
 | 4102 | 	err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | 
 | 4103 | 			       nl80211_sta_wme_policy); | 
 | 4104 | 	if (err) | 
 | 4105 | 		return err; | 
 | 4106 |  | 
 | 4107 | 	if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | 
 | 4108 | 		params->uapsd_queues = nla_get_u8( | 
 | 4109 | 			tb[NL80211_STA_WME_UAPSD_QUEUES]); | 
 | 4110 | 	if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | 
 | 4111 | 		return -EINVAL; | 
 | 4112 |  | 
 | 4113 | 	if (tb[NL80211_STA_WME_MAX_SP]) | 
 | 4114 | 		params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | 
 | 4115 |  | 
 | 4116 | 	if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | 
 | 4117 | 		return -EINVAL; | 
 | 4118 |  | 
 | 4119 | 	params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | 
 | 4120 |  | 
 | 4121 | 	return 0; | 
 | 4122 | } | 
 | 4123 |  | 
| Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4124 | static int nl80211_parse_sta_channel_info(struct genl_info *info, | 
 | 4125 | 				      struct station_parameters *params) | 
 | 4126 | { | 
 | 4127 | 	if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | 
 | 4128 | 		params->supported_channels = | 
 | 4129 | 		     nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | 
 | 4130 | 		params->supported_channels_len = | 
 | 4131 | 		     nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | 
 | 4132 | 		/* | 
 | 4133 | 		 * Need to include at least one (first channel, number of | 
 | 4134 | 		 * channels) tuple for each subband, and must have proper | 
 | 4135 | 		 * tuples for the rest of the data as well. | 
 | 4136 | 		 */ | 
 | 4137 | 		if (params->supported_channels_len < 2) | 
 | 4138 | 			return -EINVAL; | 
 | 4139 | 		if (params->supported_channels_len % 2) | 
 | 4140 | 			return -EINVAL; | 
 | 4141 | 	} | 
 | 4142 |  | 
 | 4143 | 	if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | 
 | 4144 | 		params->supported_oper_classes = | 
 | 4145 | 		 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | 
 | 4146 | 		params->supported_oper_classes_len = | 
 | 4147 | 		  nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | 
 | 4148 | 		/* | 
 | 4149 | 		 * The value of the Length field of the Supported Operating | 
 | 4150 | 		 * Classes element is between 2 and 253. | 
 | 4151 | 		 */ | 
 | 4152 | 		if (params->supported_oper_classes_len < 2 || | 
 | 4153 | 		    params->supported_oper_classes_len > 253) | 
 | 4154 | 			return -EINVAL; | 
 | 4155 | 	} | 
 | 4156 | 	return 0; | 
 | 4157 | } | 
 | 4158 |  | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4159 | static int nl80211_set_station_tdls(struct genl_info *info, | 
 | 4160 | 				    struct station_parameters *params) | 
 | 4161 | { | 
| Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4162 | 	int err; | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4163 | 	/* Dummy STA entry gets updated once the peer capabilities are known */ | 
| Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4164 | 	if (info->attrs[NL80211_ATTR_PEER_AID]) | 
 | 4165 | 		params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4166 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | 
 | 4167 | 		params->ht_capa = | 
 | 4168 | 			nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | 
 | 4169 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | 
 | 4170 | 		params->vht_capa = | 
 | 4171 | 			nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | 
 | 4172 |  | 
| Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4173 | 	err = nl80211_parse_sta_channel_info(info, params); | 
 | 4174 | 	if (err) | 
 | 4175 | 		return err; | 
 | 4176 |  | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4177 | 	return nl80211_parse_sta_wme(info, params); | 
 | 4178 | } | 
 | 4179 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4180 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | 
 | 4181 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4182 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4183 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4184 | 	struct station_parameters params; | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4185 | 	u8 *mac_addr; | 
 | 4186 | 	int err; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4187 |  | 
 | 4188 | 	memset(¶ms, 0, sizeof(params)); | 
 | 4189 |  | 
 | 4190 | 	params.listen_interval = -1; | 
 | 4191 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4192 | 	if (!rdev->ops->change_station) | 
 | 4193 | 		return -EOPNOTSUPP; | 
 | 4194 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4195 | 	if (info->attrs[NL80211_ATTR_STA_AID]) | 
 | 4196 | 		return -EINVAL; | 
 | 4197 |  | 
 | 4198 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4199 | 		return -EINVAL; | 
 | 4200 |  | 
 | 4201 | 	mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4202 |  | 
 | 4203 | 	if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | 
 | 4204 | 		params.supported_rates = | 
 | 4205 | 			nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
 | 4206 | 		params.supported_rates_len = | 
 | 4207 | 			nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
 | 4208 | 	} | 
 | 4209 |  | 
| Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4210 | 	if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { | 
 | 4211 | 		params.capability = | 
 | 4212 | 			nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | 
 | 4213 | 		params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | 
 | 4214 | 	} | 
 | 4215 |  | 
 | 4216 | 	if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | 
 | 4217 | 		params.ext_capab = | 
 | 4218 | 			nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
 | 4219 | 		params.ext_capab_len = | 
 | 4220 | 			nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
 | 4221 | 	} | 
 | 4222 |  | 
| Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4223 | 	if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | 
| Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4224 | 		return -EINVAL; | 
| Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4225 |  | 
| Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4226 | 	if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4227 | 		return -EINVAL; | 
 | 4228 |  | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4229 | 	if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4230 | 		params.plink_action = | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4231 | 			nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | 
 | 4232 | 		if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | 
 | 4233 | 			return -EINVAL; | 
 | 4234 | 	} | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4235 |  | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4236 | 	if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { | 
| Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4237 | 		params.plink_state = | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4238 | 			nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | 
 | 4239 | 		if (params.plink_state >= NUM_NL80211_PLINK_STATES) | 
 | 4240 | 			return -EINVAL; | 
 | 4241 | 		params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | 
 | 4242 | 	} | 
| Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4243 |  | 
| Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4244 | 	if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { | 
 | 4245 | 		enum nl80211_mesh_power_mode pm = nla_get_u32( | 
 | 4246 | 			info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | 
 | 4247 |  | 
 | 4248 | 		if (pm <= NL80211_MESH_POWER_UNKNOWN || | 
 | 4249 | 		    pm > NL80211_MESH_POWER_MAX) | 
 | 4250 | 			return -EINVAL; | 
 | 4251 |  | 
 | 4252 | 		params.local_pm = pm; | 
 | 4253 | 	} | 
 | 4254 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4255 | 	/* Include parameters for TDLS peer (will check later) */ | 
 | 4256 | 	err = nl80211_set_station_tdls(info, ¶ms); | 
 | 4257 | 	if (err) | 
 | 4258 | 		return err; | 
 | 4259 |  | 
 | 4260 | 	params.vlan = get_vlan(info, rdev); | 
 | 4261 | 	if (IS_ERR(params.vlan)) | 
 | 4262 | 		return PTR_ERR(params.vlan); | 
 | 4263 |  | 
| Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4264 | 	switch (dev->ieee80211_ptr->iftype) { | 
 | 4265 | 	case NL80211_IFTYPE_AP: | 
 | 4266 | 	case NL80211_IFTYPE_AP_VLAN: | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4267 | 	case NL80211_IFTYPE_P2P_GO: | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4268 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
| Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4269 | 	case NL80211_IFTYPE_STATION: | 
| Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4270 | 	case NL80211_IFTYPE_ADHOC: | 
| Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4271 | 	case NL80211_IFTYPE_MESH_POINT: | 
| Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4272 | 		break; | 
 | 4273 | 	default: | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4274 | 		err = -EOPNOTSUPP; | 
 | 4275 | 		goto out_put_vlan; | 
| Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4276 | 	} | 
 | 4277 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4278 | 	/* driver will call cfg80211_check_station_change() */ | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4279 | 	err = rdev_change_station(rdev, dev, mac_addr, ¶ms); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4280 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4281 |  out_put_vlan: | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4282 | 	if (params.vlan) | 
 | 4283 | 		dev_put(params.vlan); | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4284 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4285 | 	return err; | 
 | 4286 | } | 
 | 4287 |  | 
 | 4288 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | 
 | 4289 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4290 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4291 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4292 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4293 | 	struct station_parameters params; | 
 | 4294 | 	u8 *mac_addr = NULL; | 
 | 4295 |  | 
 | 4296 | 	memset(¶ms, 0, sizeof(params)); | 
 | 4297 |  | 
| Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4298 | 	if (!rdev->ops->add_station) | 
 | 4299 | 		return -EOPNOTSUPP; | 
 | 4300 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4301 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4302 | 		return -EINVAL; | 
 | 4303 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4304 | 	if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | 
 | 4305 | 		return -EINVAL; | 
 | 4306 |  | 
 | 4307 | 	if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | 
 | 4308 | 		return -EINVAL; | 
 | 4309 |  | 
| Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4310 | 	if (!info->attrs[NL80211_ATTR_STA_AID] && | 
 | 4311 | 	    !info->attrs[NL80211_ATTR_PEER_AID]) | 
| Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4312 | 		return -EINVAL; | 
 | 4313 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4314 | 	mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4315 | 	params.supported_rates = | 
 | 4316 | 		nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
 | 4317 | 	params.supported_rates_len = | 
 | 4318 | 		nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | 
 | 4319 | 	params.listen_interval = | 
 | 4320 | 		nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | 
| Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4321 |  | 
| Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4322 | 	if (info->attrs[NL80211_ATTR_PEER_AID]) | 
| Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4323 | 		params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | 
| Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4324 | 	else | 
 | 4325 | 		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] | 4326 | 	if (!params.aid || params.aid > IEEE80211_MAX_AID) | 
 | 4327 | 		return -EINVAL; | 
| Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4328 |  | 
| Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4329 | 	if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { | 
 | 4330 | 		params.capability = | 
 | 4331 | 			nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | 
 | 4332 | 		params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | 
 | 4333 | 	} | 
 | 4334 |  | 
 | 4335 | 	if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | 
 | 4336 | 		params.ext_capab = | 
 | 4337 | 			nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
 | 4338 | 		params.ext_capab_len = | 
 | 4339 | 			nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | 
 | 4340 | 	} | 
 | 4341 |  | 
| Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4342 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) | 
 | 4343 | 		params.ht_capa = | 
 | 4344 | 			nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4345 |  | 
| Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4346 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | 
 | 4347 | 		params.vht_capa = | 
 | 4348 | 			nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | 
 | 4349 |  | 
| Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4350 | 	if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { | 
 | 4351 | 		params.opmode_notif_used = true; | 
 | 4352 | 		params.opmode_notif = | 
 | 4353 | 			nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | 
 | 4354 | 	} | 
 | 4355 |  | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4356 | 	if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { | 
| Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4357 | 		params.plink_action = | 
| Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4358 | 			nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | 
 | 4359 | 		if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | 
 | 4360 | 			return -EINVAL; | 
 | 4361 | 	} | 
| Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4362 |  | 
| Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4363 | 	err = nl80211_parse_sta_channel_info(info, ¶ms); | 
 | 4364 | 	if (err) | 
 | 4365 | 		return err; | 
 | 4366 |  | 
| Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4367 | 	err = nl80211_parse_sta_wme(info, ¶ms); | 
 | 4368 | 	if (err) | 
 | 4369 | 		return err; | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4370 |  | 
| Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4371 | 	if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4372 | 		return -EINVAL; | 
 | 4373 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4374 | 	/* When you run into this, adjust the code below for the new flag */ | 
 | 4375 | 	BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | 
 | 4376 |  | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4377 | 	switch (dev->ieee80211_ptr->iftype) { | 
 | 4378 | 	case NL80211_IFTYPE_AP: | 
 | 4379 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 4380 | 	case NL80211_IFTYPE_P2P_GO: | 
| Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4381 | 		/* ignore WME attributes if iface/sta is not capable */ | 
 | 4382 | 		if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | 
 | 4383 | 		    !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | 
 | 4384 | 			params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
| Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4385 |  | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4386 | 		/* TDLS peers cannot be added */ | 
| Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4387 | 		if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || | 
 | 4388 | 		    info->attrs[NL80211_ATTR_PEER_AID]) | 
| Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4389 | 			return -EINVAL; | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4390 | 		/* but don't bother the driver with it */ | 
 | 4391 | 		params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | 
| Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4392 |  | 
| Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4393 | 		/* allow authenticated/associated only if driver handles it */ | 
 | 4394 | 		if (!(rdev->wiphy.features & | 
 | 4395 | 				NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | 
 | 4396 | 		    params.sta_flags_mask & | 
 | 4397 | 				(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | 
 | 4398 | 				 BIT(NL80211_STA_FLAG_ASSOCIATED))) | 
 | 4399 | 			return -EINVAL; | 
 | 4400 |  | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4401 | 		/* must be last in here for error handling */ | 
 | 4402 | 		params.vlan = get_vlan(info, rdev); | 
 | 4403 | 		if (IS_ERR(params.vlan)) | 
 | 4404 | 			return PTR_ERR(params.vlan); | 
 | 4405 | 		break; | 
 | 4406 | 	case NL80211_IFTYPE_MESH_POINT: | 
| Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4407 | 		/* ignore uAPSD data */ | 
 | 4408 | 		params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
 | 4409 |  | 
| Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4410 | 		/* associated is disallowed */ | 
 | 4411 | 		if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | 
 | 4412 | 			return -EINVAL; | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4413 | 		/* TDLS peers cannot be added */ | 
| Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4414 | 		if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || | 
 | 4415 | 		    info->attrs[NL80211_ATTR_PEER_AID]) | 
| Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4416 | 			return -EINVAL; | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4417 | 		break; | 
 | 4418 | 	case NL80211_IFTYPE_STATION: | 
| Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4419 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
| Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4420 | 		/* ignore uAPSD data */ | 
 | 4421 | 		params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | 
 | 4422 |  | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4423 | 		/* these are disallowed */ | 
 | 4424 | 		if (params.sta_flags_mask & | 
 | 4425 | 				(BIT(NL80211_STA_FLAG_ASSOCIATED) | | 
 | 4426 | 				 BIT(NL80211_STA_FLAG_AUTHENTICATED))) | 
| Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4427 | 			return -EINVAL; | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4428 | 		/* Only TDLS peers can be added */ | 
 | 4429 | 		if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | 
 | 4430 | 			return -EINVAL; | 
 | 4431 | 		/* Can only add if TDLS ... */ | 
 | 4432 | 		if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | 
 | 4433 | 			return -EOPNOTSUPP; | 
 | 4434 | 		/* ... with external setup is supported */ | 
 | 4435 | 		if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | 
 | 4436 | 			return -EOPNOTSUPP; | 
| Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4437 | 		/* | 
 | 4438 | 		 * Older wpa_supplicant versions always mark the TDLS peer | 
 | 4439 | 		 * as authorized, but it shouldn't yet be. | 
 | 4440 | 		 */ | 
 | 4441 | 		params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4442 | 		break; | 
 | 4443 | 	default: | 
 | 4444 | 		return -EOPNOTSUPP; | 
| Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4445 | 	} | 
 | 4446 |  | 
| Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4447 | 	/* be aware of params.vlan when changing code here */ | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4448 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4449 | 	err = rdev_add_station(rdev, dev, mac_addr, ¶ms); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4450 |  | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4451 | 	if (params.vlan) | 
 | 4452 | 		dev_put(params.vlan); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4453 | 	return err; | 
 | 4454 | } | 
 | 4455 |  | 
 | 4456 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | 
 | 4457 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4458 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4459 | 	struct net_device *dev = info->user_ptr[1]; | 
| Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4460 | 	struct station_del_parameters params; | 
 | 4461 |  | 
 | 4462 | 	memset(¶ms, 0, sizeof(params)); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4463 |  | 
 | 4464 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
| Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4465 | 		params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4466 |  | 
| Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4467 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
| Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4468 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4469 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 4471 | 		return -EINVAL; | 
| Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4472 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | 	if (!rdev->ops->del_station) | 
 | 4474 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4475 |  | 
| Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4476 | 	if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { | 
 | 4477 | 		params.subtype = | 
 | 4478 | 			nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | 
 | 4479 | 		if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | 
 | 4480 | 		    params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | 
 | 4481 | 			return -EINVAL; | 
 | 4482 | 	} else { | 
 | 4483 | 		/* Default to Deauthentication frame */ | 
 | 4484 | 		params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | 
 | 4485 | 	} | 
 | 4486 |  | 
 | 4487 | 	if (info->attrs[NL80211_ATTR_REASON_CODE]) { | 
 | 4488 | 		params.reason_code = | 
 | 4489 | 			nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
 | 4490 | 		if (params.reason_code == 0) | 
 | 4491 | 			return -EINVAL; /* 0 is reserved */ | 
 | 4492 | 	} else { | 
 | 4493 | 		/* Default to reason code 2 */ | 
 | 4494 | 		params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | 
 | 4495 | 	} | 
 | 4496 |  | 
| Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4497 | 	return rdev_del_station(rdev, dev, ¶ms); | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4498 | } | 
 | 4499 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4500 | 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] | 4501 | 				int flags, struct net_device *dev, | 
 | 4502 | 				u8 *dst, u8 *next_hop, | 
 | 4503 | 				struct mpath_info *pinfo) | 
 | 4504 | { | 
 | 4505 | 	void *hdr; | 
 | 4506 | 	struct nlattr *pinfoattr; | 
 | 4507 |  | 
| Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4508 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4509 | 	if (!hdr) | 
 | 4510 | 		return -1; | 
 | 4511 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4512 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 4513 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | 
 | 4514 | 	    nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | 
 | 4515 | 	    nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | 
 | 4516 | 		goto nla_put_failure; | 
| Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4517 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4518 | 	pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); | 
 | 4519 | 	if (!pinfoattr) | 
 | 4520 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4521 | 	if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && | 
 | 4522 | 	    nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | 
 | 4523 | 			pinfo->frame_qlen)) | 
 | 4524 | 		goto nla_put_failure; | 
 | 4525 | 	if (((pinfo->filled & MPATH_INFO_SN) && | 
 | 4526 | 	     nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | 
 | 4527 | 	    ((pinfo->filled & MPATH_INFO_METRIC) && | 
 | 4528 | 	     nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | 
 | 4529 | 			 pinfo->metric)) || | 
 | 4530 | 	    ((pinfo->filled & MPATH_INFO_EXPTIME) && | 
 | 4531 | 	     nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | 
 | 4532 | 			 pinfo->exptime)) || | 
 | 4533 | 	    ((pinfo->filled & MPATH_INFO_FLAGS) && | 
 | 4534 | 	     nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | 
 | 4535 | 			pinfo->flags)) || | 
 | 4536 | 	    ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | 
 | 4537 | 	     nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | 
 | 4538 | 			 pinfo->discovery_timeout)) || | 
 | 4539 | 	    ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | 
 | 4540 | 	     nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | 
 | 4541 | 			pinfo->discovery_retries))) | 
 | 4542 | 		goto nla_put_failure; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4543 |  | 
 | 4544 | 	nla_nest_end(msg, pinfoattr); | 
 | 4545 |  | 
 | 4546 | 	return genlmsg_end(msg, hdr); | 
 | 4547 |  | 
 | 4548 |  nla_put_failure: | 
| Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4549 | 	genlmsg_cancel(msg, hdr); | 
 | 4550 | 	return -EMSGSIZE; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4551 | } | 
 | 4552 |  | 
 | 4553 | static int nl80211_dump_mpath(struct sk_buff *skb, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4554 | 			      struct netlink_callback *cb) | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4555 | { | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4556 | 	struct mpath_info pinfo; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4557 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4558 | 	struct wireless_dev *wdev; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4559 | 	u8 dst[ETH_ALEN]; | 
 | 4560 | 	u8 next_hop[ETH_ALEN]; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4561 | 	int path_idx = cb->args[2]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4562 | 	int err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4563 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4564 | 	err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4565 | 	if (err) | 
 | 4566 | 		return err; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4567 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4568 | 	if (!rdev->ops->dump_mpath) { | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4569 | 		err = -EOPNOTSUPP; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4570 | 		goto out_err; | 
 | 4571 | 	} | 
 | 4572 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4573 | 	if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4574 | 		err = -EOPNOTSUPP; | 
| Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4575 | 		goto out_err; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4576 | 	} | 
 | 4577 |  | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4578 | 	while (1) { | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4579 | 		err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4580 | 				      next_hop, &pinfo); | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4581 | 		if (err == -ENOENT) | 
 | 4582 | 			break; | 
 | 4583 | 		if (err) | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4584 | 			goto out_err; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4585 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4586 | 		if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4587 | 				       cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4588 | 				       wdev->netdev, dst, next_hop, | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4589 | 				       &pinfo) < 0) | 
 | 4590 | 			goto out; | 
 | 4591 |  | 
 | 4592 | 		path_idx++; | 
 | 4593 | 	} | 
 | 4594 |  | 
 | 4595 |  | 
 | 4596 |  out: | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4597 | 	cb->args[2] = path_idx; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4598 | 	err = skb->len; | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4599 |  out_err: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4600 | 	nl80211_finish_wdev_dump(rdev); | 
| Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4601 | 	return err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4602 | } | 
 | 4603 |  | 
 | 4604 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | 
 | 4605 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4606 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4607 | 	int err; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4608 | 	struct net_device *dev = info->user_ptr[1]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4609 | 	struct mpath_info pinfo; | 
 | 4610 | 	struct sk_buff *msg; | 
 | 4611 | 	u8 *dst = NULL; | 
 | 4612 | 	u8 next_hop[ETH_ALEN]; | 
 | 4613 |  | 
 | 4614 | 	memset(&pinfo, 0, sizeof(pinfo)); | 
 | 4615 |  | 
 | 4616 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4617 | 		return -EINVAL; | 
 | 4618 |  | 
 | 4619 | 	dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4620 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4621 | 	if (!rdev->ops->get_mpath) | 
 | 4622 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4623 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4624 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 4625 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4626 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4627 | 	err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4628 | 	if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4629 | 		return err; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4630 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4631 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4632 | 	if (!msg) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4633 | 		return -ENOMEM; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4634 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4635 | 	if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | 				 dev, dst, next_hop, &pinfo) < 0) { | 
 | 4637 | 		nlmsg_free(msg); | 
 | 4638 | 		return -ENOBUFS; | 
 | 4639 | 	} | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4640 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | 	return genlmsg_reply(msg, info); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4642 | } | 
 | 4643 |  | 
 | 4644 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | 
 | 4645 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4646 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4647 | 	struct net_device *dev = info->user_ptr[1]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4648 | 	u8 *dst = NULL; | 
 | 4649 | 	u8 *next_hop = NULL; | 
 | 4650 |  | 
 | 4651 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4652 | 		return -EINVAL; | 
 | 4653 |  | 
 | 4654 | 	if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | 
 | 4655 | 		return -EINVAL; | 
 | 4656 |  | 
 | 4657 | 	dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4658 | 	next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 
 | 4659 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4660 | 	if (!rdev->ops->change_mpath) | 
 | 4661 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4662 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4663 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 4664 | 		return -EOPNOTSUPP; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4665 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4666 | 	return rdev_change_mpath(rdev, dev, dst, next_hop); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4667 | } | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 |  | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4669 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | 
 | 4670 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4671 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4672 | 	struct net_device *dev = info->user_ptr[1]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4673 | 	u8 *dst = NULL; | 
 | 4674 | 	u8 *next_hop = NULL; | 
 | 4675 |  | 
 | 4676 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4677 | 		return -EINVAL; | 
 | 4678 |  | 
 | 4679 | 	if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | 
 | 4680 | 		return -EINVAL; | 
 | 4681 |  | 
 | 4682 | 	dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4683 | 	next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 
 | 4684 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4685 | 	if (!rdev->ops->add_mpath) | 
 | 4686 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4687 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4688 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 4689 | 		return -EOPNOTSUPP; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4690 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4691 | 	return rdev_add_mpath(rdev, dev, dst, next_hop); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4692 | } | 
 | 4693 |  | 
 | 4694 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | 
 | 4695 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4696 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4697 | 	struct net_device *dev = info->user_ptr[1]; | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4698 | 	u8 *dst = NULL; | 
 | 4699 |  | 
 | 4700 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
 | 4701 | 		dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4702 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4703 | 	if (!rdev->ops->del_mpath) | 
 | 4704 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4705 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4706 | 	return rdev_del_mpath(rdev, dev, dst); | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4707 | } | 
 | 4708 |  | 
| Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4709 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) | 
 | 4710 | { | 
 | 4711 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4712 | 	int err; | 
 | 4713 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 4714 | 	struct mpath_info pinfo; | 
 | 4715 | 	struct sk_buff *msg; | 
 | 4716 | 	u8 *dst = NULL; | 
 | 4717 | 	u8 mpp[ETH_ALEN]; | 
 | 4718 |  | 
 | 4719 | 	memset(&pinfo, 0, sizeof(pinfo)); | 
 | 4720 |  | 
 | 4721 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 4722 | 		return -EINVAL; | 
 | 4723 |  | 
 | 4724 | 	dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 4725 |  | 
 | 4726 | 	if (!rdev->ops->get_mpp) | 
 | 4727 | 		return -EOPNOTSUPP; | 
 | 4728 |  | 
 | 4729 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 4730 | 		return -EOPNOTSUPP; | 
 | 4731 |  | 
 | 4732 | 	err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | 
 | 4733 | 	if (err) | 
 | 4734 | 		return err; | 
 | 4735 |  | 
 | 4736 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 4737 | 	if (!msg) | 
 | 4738 | 		return -ENOMEM; | 
 | 4739 |  | 
 | 4740 | 	if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | 
 | 4741 | 			       dev, dst, mpp, &pinfo) < 0) { | 
 | 4742 | 		nlmsg_free(msg); | 
 | 4743 | 		return -ENOBUFS; | 
 | 4744 | 	} | 
 | 4745 |  | 
 | 4746 | 	return genlmsg_reply(msg, info); | 
 | 4747 | } | 
 | 4748 |  | 
 | 4749 | static int nl80211_dump_mpp(struct sk_buff *skb, | 
 | 4750 | 			    struct netlink_callback *cb) | 
 | 4751 | { | 
 | 4752 | 	struct mpath_info pinfo; | 
 | 4753 | 	struct cfg80211_registered_device *rdev; | 
 | 4754 | 	struct wireless_dev *wdev; | 
 | 4755 | 	u8 dst[ETH_ALEN]; | 
 | 4756 | 	u8 mpp[ETH_ALEN]; | 
 | 4757 | 	int path_idx = cb->args[2]; | 
 | 4758 | 	int err; | 
 | 4759 |  | 
 | 4760 | 	err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
 | 4761 | 	if (err) | 
 | 4762 | 		return err; | 
 | 4763 |  | 
 | 4764 | 	if (!rdev->ops->dump_mpp) { | 
 | 4765 | 		err = -EOPNOTSUPP; | 
 | 4766 | 		goto out_err; | 
 | 4767 | 	} | 
 | 4768 |  | 
 | 4769 | 	if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | 
 | 4770 | 		err = -EOPNOTSUPP; | 
 | 4771 | 		goto out_err; | 
 | 4772 | 	} | 
 | 4773 |  | 
 | 4774 | 	while (1) { | 
 | 4775 | 		err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | 
 | 4776 | 				    mpp, &pinfo); | 
 | 4777 | 		if (err == -ENOENT) | 
 | 4778 | 			break; | 
 | 4779 | 		if (err) | 
 | 4780 | 			goto out_err; | 
 | 4781 |  | 
 | 4782 | 		if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | 
 | 4783 | 				       cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
 | 4784 | 				       wdev->netdev, dst, mpp, | 
 | 4785 | 				       &pinfo) < 0) | 
 | 4786 | 			goto out; | 
 | 4787 |  | 
 | 4788 | 		path_idx++; | 
 | 4789 | 	} | 
 | 4790 |  | 
 | 4791 |  out: | 
 | 4792 | 	cb->args[2] = path_idx; | 
 | 4793 | 	err = skb->len; | 
 | 4794 |  out_err: | 
 | 4795 | 	nl80211_finish_wdev_dump(rdev); | 
 | 4796 | 	return err; | 
 | 4797 | } | 
 | 4798 |  | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4799 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) | 
 | 4800 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4801 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 4802 | 	struct net_device *dev = info->user_ptr[1]; | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4803 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4804 | 	struct bss_parameters params; | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4805 | 	int err; | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4806 |  | 
 | 4807 | 	memset(¶ms, 0, sizeof(params)); | 
 | 4808 | 	/* default to not changing parameters */ | 
 | 4809 | 	params.use_cts_prot = -1; | 
 | 4810 | 	params.use_short_preamble = -1; | 
 | 4811 | 	params.use_short_slot_time = -1; | 
| Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4812 | 	params.ap_isolate = -1; | 
| Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4813 | 	params.ht_opmode = -1; | 
| Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4814 | 	params.p2p_ctwindow = -1; | 
 | 4815 | 	params.p2p_opp_ps = -1; | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4816 |  | 
 | 4817 | 	if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | 
 | 4818 | 		params.use_cts_prot = | 
 | 4819 | 		    nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | 
 | 4820 | 	if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | 
 | 4821 | 		params.use_short_preamble = | 
 | 4822 | 		    nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | 
 | 4823 | 	if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | 
 | 4824 | 		params.use_short_slot_time = | 
 | 4825 | 		    nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | 
| Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4826 | 	if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
 | 4827 | 		params.basic_rates = | 
 | 4828 | 			nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 4829 | 		params.basic_rates_len = | 
 | 4830 | 			nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 4831 | 	} | 
| Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4832 | 	if (info->attrs[NL80211_ATTR_AP_ISOLATE]) | 
 | 4833 | 		params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | 
| Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4834 | 	if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) | 
 | 4835 | 		params.ht_opmode = | 
 | 4836 | 			nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4837 |  | 
| Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4838 | 	if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { | 
 | 4839 | 		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 4840 | 			return -EINVAL; | 
 | 4841 | 		params.p2p_ctwindow = | 
 | 4842 | 			nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | 
 | 4843 | 		if (params.p2p_ctwindow < 0) | 
 | 4844 | 			return -EINVAL; | 
 | 4845 | 		if (params.p2p_ctwindow != 0 && | 
 | 4846 | 		    !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | 
 | 4847 | 			return -EINVAL; | 
 | 4848 | 	} | 
 | 4849 |  | 
 | 4850 | 	if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | 
 | 4851 | 		u8 tmp; | 
 | 4852 |  | 
 | 4853 | 		if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 4854 | 			return -EINVAL; | 
 | 4855 | 		tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | 
 | 4856 | 		if (tmp > 1) | 
 | 4857 | 			return -EINVAL; | 
 | 4858 | 		params.p2p_opp_ps = tmp; | 
 | 4859 | 		if (params.p2p_opp_ps && | 
 | 4860 | 		    !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | 
 | 4861 | 			return -EINVAL; | 
 | 4862 | 	} | 
 | 4863 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4864 | 	if (!rdev->ops->change_bss) | 
 | 4865 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4866 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4867 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 4869 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4870 |  | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4871 | 	wdev_lock(wdev); | 
 | 4872 | 	err = rdev_change_bss(rdev, dev, ¶ms); | 
 | 4873 | 	wdev_unlock(wdev); | 
 | 4874 |  | 
 | 4875 | 	return err; | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4876 | } | 
 | 4877 |  | 
| Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4878 | 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] | 4879 | 	[NL80211_ATTR_REG_RULE_FLAGS]		= { .type = NLA_U32 }, | 
 | 4880 | 	[NL80211_ATTR_FREQ_RANGE_START]		= { .type = NLA_U32 }, | 
 | 4881 | 	[NL80211_ATTR_FREQ_RANGE_END]		= { .type = NLA_U32 }, | 
 | 4882 | 	[NL80211_ATTR_FREQ_RANGE_MAX_BW]	= { .type = NLA_U32 }, | 
 | 4883 | 	[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]	= { .type = NLA_U32 }, | 
 | 4884 | 	[NL80211_ATTR_POWER_RULE_MAX_EIRP]	= { .type = NLA_U32 }, | 
| Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4885 | 	[NL80211_ATTR_DFS_CAC_TIME]		= { .type = NLA_U32 }, | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4886 | }; | 
 | 4887 |  | 
 | 4888 | static int parse_reg_rule(struct nlattr *tb[], | 
 | 4889 | 	struct ieee80211_reg_rule *reg_rule) | 
 | 4890 | { | 
 | 4891 | 	struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | 
 | 4892 | 	struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | 
 | 4893 |  | 
 | 4894 | 	if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | 
 | 4895 | 		return -EINVAL; | 
 | 4896 | 	if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | 
 | 4897 | 		return -EINVAL; | 
 | 4898 | 	if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | 
 | 4899 | 		return -EINVAL; | 
| Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4900 | 	if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | 
 | 4901 | 		return -EINVAL; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4902 | 	if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | 
 | 4903 | 		return -EINVAL; | 
 | 4904 |  | 
 | 4905 | 	reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | 
 | 4906 |  | 
 | 4907 | 	freq_range->start_freq_khz = | 
 | 4908 | 		nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | 
 | 4909 | 	freq_range->end_freq_khz = | 
 | 4910 | 		nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | 
| Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4911 | 	freq_range->max_bandwidth_khz = | 
 | 4912 | 		nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4913 |  | 
 | 4914 | 	power_rule->max_eirp = | 
 | 4915 | 		nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | 
 | 4916 |  | 
 | 4917 | 	if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | 
 | 4918 | 		power_rule->max_antenna_gain = | 
 | 4919 | 			nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | 
 | 4920 |  | 
| Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4921 | 	if (tb[NL80211_ATTR_DFS_CAC_TIME]) | 
 | 4922 | 		reg_rule->dfs_cac_ms = | 
 | 4923 | 			nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | 
 | 4924 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4925 | 	return 0; | 
 | 4926 | } | 
 | 4927 |  | 
 | 4928 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | 
 | 4929 | { | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4930 | 	char *data = NULL; | 
| Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4931 | 	enum nl80211_user_reg_hint_type user_reg_hint_type; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4932 |  | 
| Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4933 | 	/* | 
 | 4934 | 	 * You should only get this when cfg80211 hasn't yet initialized | 
 | 4935 | 	 * completely when built-in to the kernel right between the time | 
 | 4936 | 	 * window between nl80211_init() and regulatory_init(), if that is | 
 | 4937 | 	 * even possible. | 
 | 4938 | 	 */ | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4939 | 	if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) | 
| Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4940 | 		return -EINPROGRESS; | 
| Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4941 |  | 
| Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4942 | 	if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) | 
 | 4943 | 		user_reg_hint_type = | 
 | 4944 | 		  nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | 
 | 4945 | 	else | 
 | 4946 | 		user_reg_hint_type = NL80211_USER_REG_HINT_USER; | 
 | 4947 |  | 
 | 4948 | 	switch (user_reg_hint_type) { | 
 | 4949 | 	case NL80211_USER_REG_HINT_USER: | 
 | 4950 | 	case NL80211_USER_REG_HINT_CELL_BASE: | 
| Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4951 | 		if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | 
 | 4952 | 			return -EINVAL; | 
 | 4953 |  | 
 | 4954 | 		data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | 
 | 4955 | 		return regulatory_hint_user(data, user_reg_hint_type); | 
 | 4956 | 	case NL80211_USER_REG_HINT_INDOOR: | 
 | 4957 | 		return regulatory_hint_indoor_user(); | 
| Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4958 | 	default: | 
 | 4959 | 		return -EINVAL; | 
 | 4960 | 	} | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4961 | } | 
 | 4962 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4963 | static int nl80211_get_mesh_config(struct sk_buff *skb, | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4964 | 				   struct genl_info *info) | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4965 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4966 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4967 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4968 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 4969 | 	struct mesh_config cur_params; | 
 | 4970 | 	int err = 0; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4971 | 	void *hdr; | 
 | 4972 | 	struct nlattr *pinfoattr; | 
 | 4973 | 	struct sk_buff *msg; | 
 | 4974 |  | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4975 | 	if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 4976 | 		return -EOPNOTSUPP; | 
 | 4977 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4978 | 	if (!rdev->ops->get_mesh_config) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4979 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4980 |  | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4981 | 	wdev_lock(wdev); | 
 | 4982 | 	/* If not connected, get default parameters */ | 
 | 4983 | 	if (!wdev->mesh_id_len) | 
 | 4984 | 		memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | 
 | 4985 | 	else | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4986 | 		err = rdev_get_mesh_config(rdev, dev, &cur_params); | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4987 | 	wdev_unlock(wdev); | 
 | 4988 |  | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4989 | 	if (err) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4990 | 		return err; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4991 |  | 
 | 4992 | 	/* Draw up a netlink message to send back */ | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4993 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4994 | 	if (!msg) | 
 | 4995 | 		return -ENOMEM; | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4996 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4997 | 			     NL80211_CMD_GET_MESH_CONFIG); | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4998 | 	if (!hdr) | 
| Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4999 | 		goto out; | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5000 | 	pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5001 | 	if (!pinfoattr) | 
 | 5002 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5003 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 5004 | 	    nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | 
 | 5005 | 			cur_params.dot11MeshRetryTimeout) || | 
 | 5006 | 	    nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | 
 | 5007 | 			cur_params.dot11MeshConfirmTimeout) || | 
 | 5008 | 	    nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | 
 | 5009 | 			cur_params.dot11MeshHoldingTimeout) || | 
 | 5010 | 	    nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | 
 | 5011 | 			cur_params.dot11MeshMaxPeerLinks) || | 
 | 5012 | 	    nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | 
 | 5013 | 		       cur_params.dot11MeshMaxRetries) || | 
 | 5014 | 	    nla_put_u8(msg, NL80211_MESHCONF_TTL, | 
 | 5015 | 		       cur_params.dot11MeshTTL) || | 
 | 5016 | 	    nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | 
 | 5017 | 		       cur_params.element_ttl) || | 
 | 5018 | 	    nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 
 | 5019 | 		       cur_params.auto_open_plinks) || | 
| John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5020 | 	    nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | 
 | 5021 | 			cur_params.dot11MeshNbrOffsetMaxNeighbor) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5022 | 	    nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | 
 | 5023 | 		       cur_params.dot11MeshHWMPmaxPREQretries) || | 
 | 5024 | 	    nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | 
 | 5025 | 			cur_params.path_refresh_time) || | 
 | 5026 | 	    nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | 
 | 5027 | 			cur_params.min_discovery_timeout) || | 
 | 5028 | 	    nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | 
 | 5029 | 			cur_params.dot11MeshHWMPactivePathTimeout) || | 
 | 5030 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | 
 | 5031 | 			cur_params.dot11MeshHWMPpreqMinInterval) || | 
 | 5032 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | 
 | 5033 | 			cur_params.dot11MeshHWMPperrMinInterval) || | 
 | 5034 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | 
 | 5035 | 			cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | 
 | 5036 | 	    nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | 
 | 5037 | 		       cur_params.dot11MeshHWMPRootMode) || | 
 | 5038 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | 
 | 5039 | 			cur_params.dot11MeshHWMPRannInterval) || | 
 | 5040 | 	    nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | 
 | 5041 | 		       cur_params.dot11MeshGateAnnouncementProtocol) || | 
 | 5042 | 	    nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | 
 | 5043 | 		       cur_params.dot11MeshForwarding) || | 
 | 5044 | 	    nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | 
| Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5045 | 			cur_params.rssi_threshold) || | 
 | 5046 | 	    nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | 
| Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5047 | 			cur_params.ht_opmode) || | 
 | 5048 | 	    nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | 
 | 5049 | 			cur_params.dot11MeshHWMPactivePathToRootTimeout) || | 
 | 5050 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | 
| Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5051 | 			cur_params.dot11MeshHWMProotInterval) || | 
 | 5052 | 	    nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | 
| Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5053 | 			cur_params.dot11MeshHWMPconfirmationInterval) || | 
 | 5054 | 	    nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | 
 | 5055 | 			cur_params.power_mode) || | 
 | 5056 | 	    nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | 
| Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5057 | 			cur_params.dot11MeshAwakeWindowDuration) || | 
 | 5058 | 	    nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | 
 | 5059 | 			cur_params.plink_timeout)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5060 | 		goto nla_put_failure; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5061 | 	nla_nest_end(msg, pinfoattr); | 
 | 5062 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5063 | 	return genlmsg_reply(msg, info); | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5064 |  | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5065 |  nla_put_failure: | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5066 | 	genlmsg_cancel(msg, hdr); | 
| Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5067 |  out: | 
| Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5068 | 	nlmsg_free(msg); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5069 | 	return -ENOBUFS; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5070 | } | 
 | 5071 |  | 
| Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5072 | 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] | 5073 | 	[NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, | 
 | 5074 | 	[NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | 
 | 5075 | 	[NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | 
 | 5076 | 	[NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | 
 | 5077 | 	[NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | 
 | 5078 | 	[NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | 
| Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5079 | 	[NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5080 | 	[NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | 
| Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5081 | 	[NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5082 | 	[NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | 
 | 5083 | 	[NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | 
 | 5084 | 	[NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | 
 | 5085 | 	[NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | 
 | 5086 | 	[NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | 
| Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5087 | 	[NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5088 | 	[NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | 
| Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5089 | 	[NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, | 
| Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5090 | 	[NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, | 
| Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5091 | 	[NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, | 
| Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5092 | 	[NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5093 | 	[NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, | 
 | 5094 | 	[NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | 
| Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5095 | 	[NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, | 
 | 5096 | 	[NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | 
| Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5097 | 	[NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, | 
| Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5098 | 	[NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, | 
 | 5099 | 	[NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | 
| Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5100 | 	[NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5101 | }; | 
 | 5102 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5103 | static const struct nla_policy | 
 | 5104 | 	nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | 
| Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5105 | 	[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5106 | 	[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, | 
 | 5107 | 	[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | 
| Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5108 | 	[NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, | 
| Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5109 | 	[NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, | 
| Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5110 | 	[NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, | 
| Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5111 | 	[NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5112 | 				    .len = IEEE80211_MAX_DATA_LEN }, | 
| Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5113 | 	[NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5114 | }; | 
 | 5115 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5116 | static int nl80211_parse_mesh_config(struct genl_info *info, | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5117 | 				     struct mesh_config *cfg, | 
 | 5118 | 				     u32 *mask_out) | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5119 | { | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5120 | 	struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5121 | 	u32 mask = 0; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5122 |  | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5123 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ | 
 | 5124 | do {									    \ | 
 | 5125 | 	if (tb[attr]) {							    \ | 
 | 5126 | 		if (fn(tb[attr]) < min || fn(tb[attr]) > max)		    \ | 
 | 5127 | 			return -EINVAL;					    \ | 
 | 5128 | 		cfg->param = fn(tb[attr]);				    \ | 
 | 5129 | 		mask |= (1 << (attr - 1));				    \ | 
 | 5130 | 	}								    \ | 
 | 5131 | } while (0) | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5132 |  | 
 | 5133 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5134 | 	if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5135 | 		return -EINVAL; | 
 | 5136 | 	if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5137 | 			     info->attrs[NL80211_ATTR_MESH_CONFIG], | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5138 | 			     nl80211_meshconf_params_policy)) | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5139 | 		return -EINVAL; | 
 | 5140 |  | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5141 | 	/* This makes sure that there aren't more than 32 mesh config | 
 | 5142 | 	 * parameters (otherwise our bitfield scheme would not work.) */ | 
 | 5143 | 	BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | 
 | 5144 |  | 
 | 5145 | 	/* Fill in the params struct */ | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5146 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5147 | 				  mask, NL80211_MESHCONF_RETRY_TIMEOUT, | 
 | 5148 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5149 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5150 | 				  mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, | 
 | 5151 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5152 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5153 | 				  mask, NL80211_MESHCONF_HOLDING_TIMEOUT, | 
 | 5154 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5155 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5156 | 				  mask, NL80211_MESHCONF_MAX_PEER_LINKS, | 
 | 5157 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5158 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5159 | 				  mask, NL80211_MESHCONF_MAX_RETRIES, | 
 | 5160 | 				  nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5161 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5162 | 				  mask, NL80211_MESHCONF_TTL, nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5163 | 	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] | 5164 | 				  mask, NL80211_MESHCONF_ELEMENT_TTL, | 
 | 5165 | 				  nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5166 | 	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] | 5167 | 				  mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 
 | 5168 | 				  nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5169 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, | 
 | 5170 | 				  1, 255, mask, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5171 | 				  NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | 
 | 5172 | 				  nla_get_u32); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5173 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5174 | 				  mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | 
 | 5175 | 				  nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5176 | 	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] | 5177 | 				  mask, NL80211_MESHCONF_PATH_REFRESH_TIME, | 
 | 5178 | 				  nla_get_u32); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5179 | 	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] | 5180 | 				  mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | 
 | 5181 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5182 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | 
 | 5183 | 				  1, 65535, mask, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5184 | 				  NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | 
 | 5185 | 				  nla_get_u32); | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5186 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5187 | 				  1, 65535, mask, | 
 | 5188 | 				  NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5189 | 				  nla_get_u16); | 
| Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5190 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5191 | 				  1, 65535, mask, | 
 | 5192 | 				  NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5193 | 				  nla_get_u16); | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5194 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5195 | 				  dot11MeshHWMPnetDiameterTraversalTime, | 
 | 5196 | 				  1, 65535, mask, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5197 | 				  NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | 
 | 5198 | 				  nla_get_u16); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5199 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, | 
 | 5200 | 				  mask, NL80211_MESHCONF_HWMP_ROOTMODE, | 
 | 5201 | 				  nla_get_u8); | 
 | 5202 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | 
 | 5203 | 				  mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5204 | 				  nla_get_u16); | 
| Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5205 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5206 | 				  dot11MeshGateAnnouncementProtocol, 0, 1, | 
 | 5207 | 				  mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5208 | 				  nla_get_u8); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5209 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, | 
| Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5210 | 				  mask, NL80211_MESHCONF_FORWARDING, | 
 | 5211 | 				  nla_get_u8); | 
| Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5212 | 	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] | 5213 | 				  mask, NL80211_MESHCONF_RSSI_THRESHOLD, | 
| Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5214 | 				  nla_get_s32); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5215 | 	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] | 5216 | 				  mask, NL80211_MESHCONF_HT_OPMODE, | 
 | 5217 | 				  nla_get_u16); | 
| Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5218 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5219 | 				  1, 65535, mask, | 
| Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5220 | 				  NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | 
 | 5221 | 				  nla_get_u32); | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5222 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, | 
| Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5223 | 				  mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | 
 | 5224 | 				  nla_get_u16); | 
| Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5225 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | 
| Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5226 | 				  dot11MeshHWMPconfirmationInterval, | 
 | 5227 | 				  1, 65535, mask, | 
| Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5228 | 				  NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | 
 | 5229 | 				  nla_get_u16); | 
| Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5230 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, | 
 | 5231 | 				  NL80211_MESH_POWER_ACTIVE, | 
 | 5232 | 				  NL80211_MESH_POWER_MAX, | 
 | 5233 | 				  mask, NL80211_MESHCONF_POWER_MODE, | 
 | 5234 | 				  nla_get_u32); | 
 | 5235 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | 
 | 5236 | 				  0, 65535, mask, | 
 | 5237 | 				  NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | 
| Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5238 | 	FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, | 
 | 5239 | 				  mask, NL80211_MESHCONF_PLINK_TIMEOUT, | 
 | 5240 | 				  nla_get_u32); | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5241 | 	if (mask_out) | 
 | 5242 | 		*mask_out = mask; | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5243 |  | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5244 | 	return 0; | 
 | 5245 |  | 
 | 5246 | #undef FILL_IN_MESH_PARAM_IF_SET | 
 | 5247 | } | 
 | 5248 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5249 | static int nl80211_parse_mesh_setup(struct genl_info *info, | 
 | 5250 | 				     struct mesh_setup *setup) | 
 | 5251 | { | 
| Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5252 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5253 | 	struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | 
 | 5254 |  | 
 | 5255 | 	if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | 
 | 5256 | 		return -EINVAL; | 
 | 5257 | 	if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | 
 | 5258 | 			     info->attrs[NL80211_ATTR_MESH_SETUP], | 
 | 5259 | 			     nl80211_mesh_setup_params_policy)) | 
 | 5260 | 		return -EINVAL; | 
 | 5261 |  | 
| Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5262 | 	if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) | 
 | 5263 | 		setup->sync_method = | 
 | 5264 | 		(nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | 
 | 5265 | 		 IEEE80211_SYNC_METHOD_VENDOR : | 
 | 5266 | 		 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | 
 | 5267 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5268 | 	if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) | 
 | 5269 | 		setup->path_sel_proto = | 
 | 5270 | 		(nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | 
 | 5271 | 		 IEEE80211_PATH_PROTOCOL_VENDOR : | 
 | 5272 | 		 IEEE80211_PATH_PROTOCOL_HWMP; | 
 | 5273 |  | 
 | 5274 | 	if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | 
 | 5275 | 		setup->path_metric = | 
 | 5276 | 		(nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | 
 | 5277 | 		 IEEE80211_PATH_METRIC_VENDOR : | 
 | 5278 | 		 IEEE80211_PATH_METRIC_AIRTIME; | 
 | 5279 |  | 
| Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5280 |  | 
 | 5281 | 	if (tb[NL80211_MESH_SETUP_IE]) { | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5282 | 		struct nlattr *ieattr = | 
| Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5283 | 			tb[NL80211_MESH_SETUP_IE]; | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5284 | 		if (!is_valid_ie_attr(ieattr)) | 
 | 5285 | 			return -EINVAL; | 
| Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5286 | 		setup->ie = nla_data(ieattr); | 
 | 5287 | 		setup->ie_len = nla_len(ieattr); | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5288 | 	} | 
| Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5289 | 	if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && | 
 | 5290 | 	    !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | 
 | 5291 | 		return -EINVAL; | 
 | 5292 | 	setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | 
| Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5293 | 	setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); | 
 | 5294 | 	setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | 
| Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5295 | 	if (setup->is_secure) | 
 | 5296 | 		setup->user_mpm = true; | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5297 |  | 
| Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5298 | 	if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { | 
 | 5299 | 		if (!setup->user_mpm) | 
 | 5300 | 			return -EINVAL; | 
 | 5301 | 		setup->auth_id = | 
 | 5302 | 			nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | 
 | 5303 | 	} | 
 | 5304 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5305 | 	return 0; | 
 | 5306 | } | 
 | 5307 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5308 | static int nl80211_update_mesh_config(struct sk_buff *skb, | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5309 | 				      struct genl_info *info) | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5310 | { | 
 | 5311 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 5312 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5313 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5314 | 	struct mesh_config cfg; | 
 | 5315 | 	u32 mask; | 
 | 5316 | 	int err; | 
 | 5317 |  | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5318 | 	if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 5319 | 		return -EOPNOTSUPP; | 
 | 5320 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5321 | 	if (!rdev->ops->update_mesh_config) | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5322 | 		return -EOPNOTSUPP; | 
 | 5323 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5324 | 	err = nl80211_parse_mesh_config(info, &cfg, &mask); | 
| Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5325 | 	if (err) | 
 | 5326 | 		return err; | 
 | 5327 |  | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5328 | 	wdev_lock(wdev); | 
 | 5329 | 	if (!wdev->mesh_id_len) | 
 | 5330 | 		err = -ENOLINK; | 
 | 5331 |  | 
 | 5332 | 	if (!err) | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5333 | 		err = rdev_update_mesh_config(rdev, dev, mask, &cfg); | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5334 |  | 
 | 5335 | 	wdev_unlock(wdev); | 
 | 5336 |  | 
 | 5337 | 	return err; | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5338 | } | 
 | 5339 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5340 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, | 
 | 5341 | 			      struct sk_buff *msg) | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5342 | { | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5343 | 	struct nlattr *nl_reg_rules; | 
 | 5344 | 	unsigned int i; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5345 |  | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5346 | 	if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | 
 | 5347 | 	    (regdom->dfs_region && | 
 | 5348 | 	     nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5349 | 		goto nla_put_failure; | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5350 |  | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5351 | 	nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | 
 | 5352 | 	if (!nl_reg_rules) | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5353 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5354 |  | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5355 | 	for (i = 0; i < regdom->n_reg_rules; i++) { | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5356 | 		struct nlattr *nl_reg_rule; | 
 | 5357 | 		const struct ieee80211_reg_rule *reg_rule; | 
 | 5358 | 		const struct ieee80211_freq_range *freq_range; | 
 | 5359 | 		const struct ieee80211_power_rule *power_rule; | 
| Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5360 | 		unsigned int max_bandwidth_khz; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5361 |  | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5362 | 		reg_rule = ®dom->reg_rules[i]; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5363 | 		freq_range = ®_rule->freq_range; | 
 | 5364 | 		power_rule = ®_rule->power_rule; | 
 | 5365 |  | 
 | 5366 | 		nl_reg_rule = nla_nest_start(msg, i); | 
 | 5367 | 		if (!nl_reg_rule) | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5368 | 			goto nla_put_failure; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5369 |  | 
| Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5370 | 		max_bandwidth_khz = freq_range->max_bandwidth_khz; | 
 | 5371 | 		if (!max_bandwidth_khz) | 
 | 5372 | 			max_bandwidth_khz = reg_get_max_bandwidth(regdom, | 
 | 5373 | 								  reg_rule); | 
 | 5374 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5375 | 		if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, | 
 | 5376 | 				reg_rule->flags) || | 
 | 5377 | 		    nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | 
 | 5378 | 				freq_range->start_freq_khz) || | 
 | 5379 | 		    nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | 
 | 5380 | 				freq_range->end_freq_khz) || | 
 | 5381 | 		    nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | 
| Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5382 | 				max_bandwidth_khz) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5383 | 		    nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | 
 | 5384 | 				power_rule->max_antenna_gain) || | 
 | 5385 | 		    nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | 
| Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5386 | 				power_rule->max_eirp) || | 
 | 5387 | 		    nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | 
 | 5388 | 				reg_rule->dfs_cac_ms)) | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5389 | 			goto nla_put_failure; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5390 |  | 
 | 5391 | 		nla_nest_end(msg, nl_reg_rule); | 
 | 5392 | 	} | 
 | 5393 |  | 
 | 5394 | 	nla_nest_end(msg, nl_reg_rules); | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5395 | 	return 0; | 
 | 5396 |  | 
 | 5397 | nla_put_failure: | 
 | 5398 | 	return -EMSGSIZE; | 
 | 5399 | } | 
 | 5400 |  | 
 | 5401 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | 
 | 5402 | { | 
 | 5403 | 	const struct ieee80211_regdomain *regdom = NULL; | 
 | 5404 | 	struct cfg80211_registered_device *rdev; | 
 | 5405 | 	struct wiphy *wiphy = NULL; | 
 | 5406 | 	struct sk_buff *msg; | 
 | 5407 | 	void *hdr; | 
 | 5408 |  | 
 | 5409 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 5410 | 	if (!msg) | 
 | 5411 | 		return -ENOBUFS; | 
 | 5412 |  | 
 | 5413 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
 | 5414 | 			     NL80211_CMD_GET_REG); | 
 | 5415 | 	if (!hdr) | 
 | 5416 | 		goto put_failure; | 
 | 5417 |  | 
 | 5418 | 	if (info->attrs[NL80211_ATTR_WIPHY]) { | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5419 | 		bool self_managed; | 
 | 5420 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5421 | 		rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); | 
 | 5422 | 		if (IS_ERR(rdev)) { | 
 | 5423 | 			nlmsg_free(msg); | 
 | 5424 | 			return PTR_ERR(rdev); | 
 | 5425 | 		} | 
 | 5426 |  | 
 | 5427 | 		wiphy = &rdev->wiphy; | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5428 | 		self_managed = wiphy->regulatory_flags & | 
 | 5429 | 			       REGULATORY_WIPHY_SELF_MANAGED; | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5430 | 		regdom = get_wiphy_regdom(wiphy); | 
 | 5431 |  | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5432 | 		/* a self-managed-reg device must have a private regdom */ | 
 | 5433 | 		if (WARN_ON(!regdom && self_managed)) { | 
 | 5434 | 			nlmsg_free(msg); | 
 | 5435 | 			return -EINVAL; | 
 | 5436 | 		} | 
 | 5437 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5438 | 		if (regdom && | 
 | 5439 | 		    nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
 | 5440 | 			goto nla_put_failure; | 
 | 5441 | 	} | 
 | 5442 |  | 
 | 5443 | 	if (!wiphy && reg_last_request_cell_base() && | 
 | 5444 | 	    nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | 
 | 5445 | 			NL80211_USER_REG_HINT_CELL_BASE)) | 
 | 5446 | 		goto nla_put_failure; | 
 | 5447 |  | 
 | 5448 | 	rcu_read_lock(); | 
 | 5449 |  | 
 | 5450 | 	if (!regdom) | 
 | 5451 | 		regdom = rcu_dereference(cfg80211_regdomain); | 
 | 5452 |  | 
 | 5453 | 	if (nl80211_put_regdom(regdom, msg)) | 
 | 5454 | 		goto nla_put_failure_rcu; | 
 | 5455 |  | 
 | 5456 | 	rcu_read_unlock(); | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5457 |  | 
 | 5458 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5459 | 	return genlmsg_reply(msg, info); | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5460 |  | 
| Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5461 | nla_put_failure_rcu: | 
 | 5462 | 	rcu_read_unlock(); | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5463 | nla_put_failure: | 
 | 5464 | 	genlmsg_cancel(msg, hdr); | 
| Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5465 | put_failure: | 
| Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5466 | 	nlmsg_free(msg); | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5467 | 	return -EMSGSIZE; | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5468 | } | 
 | 5469 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5470 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, | 
 | 5471 | 			       u32 seq, int flags, struct wiphy *wiphy, | 
 | 5472 | 			       const struct ieee80211_regdomain *regdom) | 
 | 5473 | { | 
 | 5474 | 	void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | 
 | 5475 | 				   NL80211_CMD_GET_REG); | 
 | 5476 |  | 
 | 5477 | 	if (!hdr) | 
 | 5478 | 		return -1; | 
 | 5479 |  | 
 | 5480 | 	genl_dump_check_consistent(cb, hdr, &nl80211_fam); | 
 | 5481 |  | 
 | 5482 | 	if (nl80211_put_regdom(regdom, msg)) | 
 | 5483 | 		goto nla_put_failure; | 
 | 5484 |  | 
 | 5485 | 	if (!wiphy && reg_last_request_cell_base() && | 
 | 5486 | 	    nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | 
 | 5487 | 			NL80211_USER_REG_HINT_CELL_BASE)) | 
 | 5488 | 		goto nla_put_failure; | 
 | 5489 |  | 
 | 5490 | 	if (wiphy && | 
 | 5491 | 	    nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
 | 5492 | 		goto nla_put_failure; | 
 | 5493 |  | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5494 | 	if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
 | 5495 | 	    nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
 | 5496 | 		goto nla_put_failure; | 
 | 5497 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5498 | 	return genlmsg_end(msg, hdr); | 
 | 5499 |  | 
 | 5500 | nla_put_failure: | 
 | 5501 | 	genlmsg_cancel(msg, hdr); | 
 | 5502 | 	return -EMSGSIZE; | 
 | 5503 | } | 
 | 5504 |  | 
 | 5505 | static int nl80211_get_reg_dump(struct sk_buff *skb, | 
 | 5506 | 				struct netlink_callback *cb) | 
 | 5507 | { | 
 | 5508 | 	const struct ieee80211_regdomain *regdom = NULL; | 
 | 5509 | 	struct cfg80211_registered_device *rdev; | 
 | 5510 | 	int err, reg_idx, start = cb->args[2]; | 
 | 5511 |  | 
 | 5512 | 	rtnl_lock(); | 
 | 5513 |  | 
 | 5514 | 	if (cfg80211_regdomain && start == 0) { | 
 | 5515 | 		err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | 
 | 5516 | 					  NLM_F_MULTI, NULL, | 
 | 5517 | 					  rtnl_dereference(cfg80211_regdomain)); | 
 | 5518 | 		if (err < 0) | 
 | 5519 | 			goto out_err; | 
 | 5520 | 	} | 
 | 5521 |  | 
 | 5522 | 	/* the global regdom is idx 0 */ | 
 | 5523 | 	reg_idx = 1; | 
 | 5524 | 	list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | 
 | 5525 | 		regdom = get_wiphy_regdom(&rdev->wiphy); | 
 | 5526 | 		if (!regdom) | 
 | 5527 | 			continue; | 
 | 5528 |  | 
 | 5529 | 		if (++reg_idx <= start) | 
 | 5530 | 			continue; | 
 | 5531 |  | 
 | 5532 | 		err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | 
 | 5533 | 					  NLM_F_MULTI, &rdev->wiphy, regdom); | 
 | 5534 | 		if (err < 0) { | 
 | 5535 | 			reg_idx--; | 
 | 5536 | 			break; | 
 | 5537 | 		} | 
 | 5538 | 	} | 
 | 5539 |  | 
 | 5540 | 	cb->args[2] = reg_idx; | 
 | 5541 | 	err = skb->len; | 
 | 5542 | out_err: | 
 | 5543 | 	rtnl_unlock(); | 
 | 5544 | 	return err; | 
 | 5545 | } | 
 | 5546 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5547 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | 
 | 5548 | { | 
 | 5549 | 	struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | 
 | 5550 | 	struct nlattr *nl_reg_rule; | 
| Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5551 | 	char *alpha2; | 
 | 5552 | 	int rem_reg_rules, r; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5553 | 	u32 num_rules = 0, rule_idx = 0, size_of_regd; | 
| Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5554 | 	enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; | 
| Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5555 | 	struct ieee80211_regdomain *rd; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5556 |  | 
 | 5557 | 	if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | 
 | 5558 | 		return -EINVAL; | 
 | 5559 |  | 
 | 5560 | 	if (!info->attrs[NL80211_ATTR_REG_RULES]) | 
 | 5561 | 		return -EINVAL; | 
 | 5562 |  | 
 | 5563 | 	alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | 
 | 5564 |  | 
| Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5565 | 	if (info->attrs[NL80211_ATTR_DFS_REGION]) | 
 | 5566 | 		dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | 
 | 5567 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5568 | 	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] | 5569 | 			    rem_reg_rules) { | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5570 | 		num_rules++; | 
 | 5571 | 		if (num_rules > NL80211_MAX_SUPP_REG_RULES) | 
| Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5572 | 			return -EINVAL; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5573 | 	} | 
 | 5574 |  | 
| Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5575 | 	if (!reg_is_valid_request(alpha2)) | 
 | 5576 | 		return -EINVAL; | 
 | 5577 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5578 | 	size_of_regd = sizeof(struct ieee80211_regdomain) + | 
| Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5579 | 		       num_rules * sizeof(struct ieee80211_reg_rule); | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5580 |  | 
 | 5581 | 	rd = kzalloc(size_of_regd, GFP_KERNEL); | 
| Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5582 | 	if (!rd) | 
 | 5583 | 		return -ENOMEM; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5584 |  | 
 | 5585 | 	rd->n_reg_rules = num_rules; | 
 | 5586 | 	rd->alpha2[0] = alpha2[0]; | 
 | 5587 | 	rd->alpha2[1] = alpha2[1]; | 
 | 5588 |  | 
| Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5589 | 	/* | 
 | 5590 | 	 * Disable DFS master mode if the DFS region was | 
 | 5591 | 	 * not supported or known on this kernel. | 
 | 5592 | 	 */ | 
 | 5593 | 	if (reg_supported_dfs_region(dfs_region)) | 
 | 5594 | 		rd->dfs_region = dfs_region; | 
 | 5595 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5596 | 	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] | 5597 | 			    rem_reg_rules) { | 
| Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5598 | 		r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | 
 | 5599 | 			      nla_data(nl_reg_rule), nla_len(nl_reg_rule), | 
 | 5600 | 			      reg_rule_policy); | 
 | 5601 | 		if (r) | 
 | 5602 | 			goto bad_reg; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5603 | 		r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | 
 | 5604 | 		if (r) | 
 | 5605 | 			goto bad_reg; | 
 | 5606 |  | 
 | 5607 | 		rule_idx++; | 
 | 5608 |  | 
| Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5609 | 		if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { | 
 | 5610 | 			r = -EINVAL; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5611 | 			goto bad_reg; | 
| Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5612 | 		} | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5613 | 	} | 
 | 5614 |  | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5615 | 	r = set_regdom(rd); | 
| Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5616 | 	/* set_regdom took ownership */ | 
| Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5617 | 	rd = NULL; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5618 |  | 
| Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5619 |  bad_reg: | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5620 | 	kfree(rd); | 
| Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5621 | 	return r; | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5622 | } | 
 | 5623 |  | 
| Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5624 | static int validate_scan_freqs(struct nlattr *freqs) | 
 | 5625 | { | 
 | 5626 | 	struct nlattr *attr1, *attr2; | 
 | 5627 | 	int n_channels = 0, tmp1, tmp2; | 
 | 5628 |  | 
 | 5629 | 	nla_for_each_nested(attr1, freqs, tmp1) { | 
 | 5630 | 		n_channels++; | 
 | 5631 | 		/* | 
 | 5632 | 		 * Some hardware has a limited channel list for | 
 | 5633 | 		 * scanning, and it is pretty much nonsensical | 
 | 5634 | 		 * to scan for a channel twice, so disallow that | 
 | 5635 | 		 * and don't require drivers to check that the | 
 | 5636 | 		 * channel list they get isn't longer than what | 
 | 5637 | 		 * they can scan, as long as they can scan all | 
 | 5638 | 		 * the channels they registered at once. | 
 | 5639 | 		 */ | 
 | 5640 | 		nla_for_each_nested(attr2, freqs, tmp2) | 
 | 5641 | 			if (attr1 != attr2 && | 
 | 5642 | 			    nla_get_u32(attr1) == nla_get_u32(attr2)) | 
 | 5643 | 				return 0; | 
 | 5644 | 	} | 
 | 5645 |  | 
 | 5646 | 	return n_channels; | 
 | 5647 | } | 
 | 5648 |  | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5649 | static int nl80211_parse_random_mac(struct nlattr **attrs, | 
 | 5650 | 				    u8 *mac_addr, u8 *mac_addr_mask) | 
 | 5651 | { | 
 | 5652 | 	int i; | 
 | 5653 |  | 
 | 5654 | 	if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | 
 | 5655 | 		memset(mac_addr, 0, ETH_ALEN); | 
 | 5656 | 		memset(mac_addr_mask, 0, ETH_ALEN); | 
 | 5657 | 		mac_addr[0] = 0x2; | 
 | 5658 | 		mac_addr_mask[0] = 0x3; | 
 | 5659 |  | 
 | 5660 | 		return 0; | 
 | 5661 | 	} | 
 | 5662 |  | 
 | 5663 | 	/* need both or none */ | 
 | 5664 | 	if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | 
 | 5665 | 		return -EINVAL; | 
 | 5666 |  | 
 | 5667 | 	memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | 
 | 5668 | 	memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | 
 | 5669 |  | 
 | 5670 | 	/* don't allow or configure an mcast address */ | 
 | 5671 | 	if (!is_multicast_ether_addr(mac_addr_mask) || | 
 | 5672 | 	    is_multicast_ether_addr(mac_addr)) | 
 | 5673 | 		return -EINVAL; | 
 | 5674 |  | 
 | 5675 | 	/* | 
 | 5676 | 	 * allow users to pass a MAC address that has bits set outside | 
 | 5677 | 	 * of the mask, but don't bother drivers with having to deal | 
 | 5678 | 	 * with such bits | 
 | 5679 | 	 */ | 
 | 5680 | 	for (i = 0; i < ETH_ALEN; i++) | 
 | 5681 | 		mac_addr[i] &= mac_addr_mask[i]; | 
 | 5682 |  | 
 | 5683 | 	return 0; | 
 | 5684 | } | 
 | 5685 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5686 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | 
 | 5687 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5688 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5689 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5690 | 	struct cfg80211_scan_request *request; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5691 | 	struct nlattr *attr; | 
 | 5692 | 	struct wiphy *wiphy; | 
| Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5693 | 	int err, tmp, n_ssids = 0, n_channels, i; | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5694 | 	size_t ie_len; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5695 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5696 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 5697 | 		return -EINVAL; | 
 | 5698 |  | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5699 | 	wiphy = &rdev->wiphy; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5700 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5701 | 	if (!rdev->ops->scan) | 
 | 5702 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5703 |  | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5704 | 	if (rdev->scan_req || rdev->scan_msg) { | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5705 | 		err = -EBUSY; | 
 | 5706 | 		goto unlock; | 
 | 5707 | 	} | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5708 |  | 
 | 5709 | 	if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
| Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5710 | 		n_channels = validate_scan_freqs( | 
 | 5711 | 				info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5712 | 		if (!n_channels) { | 
 | 5713 | 			err = -EINVAL; | 
 | 5714 | 			goto unlock; | 
 | 5715 | 		} | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5716 | 	} else { | 
| Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5717 | 		n_channels = ieee80211_get_num_supported_channels(wiphy); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5718 | 	} | 
 | 5719 |  | 
 | 5720 | 	if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | 
 | 5721 | 		nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | 
 | 5722 | 			n_ssids++; | 
 | 5723 |  | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5724 | 	if (n_ssids > wiphy->max_scan_ssids) { | 
 | 5725 | 		err = -EINVAL; | 
 | 5726 | 		goto unlock; | 
 | 5727 | 	} | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5728 |  | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5729 | 	if (info->attrs[NL80211_ATTR_IE]) | 
 | 5730 | 		ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
 | 5731 | 	else | 
 | 5732 | 		ie_len = 0; | 
 | 5733 |  | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5734 | 	if (ie_len > wiphy->max_scan_ie_len) { | 
 | 5735 | 		err = -EINVAL; | 
 | 5736 | 		goto unlock; | 
 | 5737 | 	} | 
| Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5738 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5739 | 	request = kzalloc(sizeof(*request) | 
| Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5740 | 			+ sizeof(*request->ssids) * n_ssids | 
 | 5741 | 			+ sizeof(*request->channels) * n_channels | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5742 | 			+ ie_len, GFP_KERNEL); | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5743 | 	if (!request) { | 
 | 5744 | 		err = -ENOMEM; | 
 | 5745 | 		goto unlock; | 
 | 5746 | 	} | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5747 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5748 | 	if (n_ssids) | 
| Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5749 | 		request->ssids = (void *)&request->channels[n_channels]; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5750 | 	request->n_ssids = n_ssids; | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5751 | 	if (ie_len) { | 
 | 5752 | 		if (request->ssids) | 
 | 5753 | 			request->ie = (void *)(request->ssids + n_ssids); | 
 | 5754 | 		else | 
 | 5755 | 			request->ie = (void *)(request->channels + n_channels); | 
 | 5756 | 	} | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5757 |  | 
| Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5758 | 	i = 0; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5759 | 	if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
 | 5760 | 		/* user specified, bail out if channel not found */ | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5761 | 		nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { | 
| Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5762 | 			struct ieee80211_channel *chan; | 
 | 5763 |  | 
 | 5764 | 			chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | 
 | 5765 |  | 
 | 5766 | 			if (!chan) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5767 | 				err = -EINVAL; | 
 | 5768 | 				goto out_free; | 
 | 5769 | 			} | 
| Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5770 |  | 
 | 5771 | 			/* ignore disabled channels */ | 
 | 5772 | 			if (chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 5773 | 				continue; | 
 | 5774 |  | 
 | 5775 | 			request->channels[i] = chan; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5776 | 			i++; | 
 | 5777 | 		} | 
 | 5778 | 	} else { | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5779 | 		enum ieee80211_band band; | 
 | 5780 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5781 | 		/* all channels */ | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5782 | 		for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 
 | 5783 | 			int j; | 
 | 5784 | 			if (!wiphy->bands[band]) | 
 | 5785 | 				continue; | 
 | 5786 | 			for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | 
| Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5787 | 				struct ieee80211_channel *chan; | 
 | 5788 |  | 
 | 5789 | 				chan = &wiphy->bands[band]->channels[j]; | 
 | 5790 |  | 
 | 5791 | 				if (chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 5792 | 					continue; | 
 | 5793 |  | 
 | 5794 | 				request->channels[i] = chan; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5795 | 				i++; | 
 | 5796 | 			} | 
 | 5797 | 		} | 
 | 5798 | 	} | 
 | 5799 |  | 
| Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5800 | 	if (!i) { | 
 | 5801 | 		err = -EINVAL; | 
 | 5802 | 		goto out_free; | 
 | 5803 | 	} | 
 | 5804 |  | 
 | 5805 | 	request->n_channels = i; | 
 | 5806 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5807 | 	i = 0; | 
 | 5808 | 	if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | 
 | 5809 | 		nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | 
| Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5810 | 			if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5811 | 				err = -EINVAL; | 
 | 5812 | 				goto out_free; | 
 | 5813 | 			} | 
| Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5814 | 			request->ssids[i].ssid_len = nla_len(attr); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5815 | 			memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5816 | 			i++; | 
 | 5817 | 		} | 
 | 5818 | 	} | 
 | 5819 |  | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5820 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
 | 5821 | 		request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
| Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5822 | 		memcpy((void *)request->ie, | 
 | 5823 | 		       nla_data(info->attrs[NL80211_ATTR_IE]), | 
| Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5824 | 		       request->ie_len); | 
 | 5825 | 	} | 
 | 5826 |  | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5827 | 	for (i = 0; i < IEEE80211_NUM_BANDS; i++) | 
| Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5828 | 		if (wiphy->bands[i]) | 
 | 5829 | 			request->rates[i] = | 
 | 5830 | 				(1 << wiphy->bands[i]->n_bitrates) - 1; | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5831 |  | 
 | 5832 | 	if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | 
 | 5833 | 		nla_for_each_nested(attr, | 
 | 5834 | 				    info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | 
 | 5835 | 				    tmp) { | 
 | 5836 | 			enum ieee80211_band band = nla_type(attr); | 
 | 5837 |  | 
| Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5838 | 			if (band < 0 || band >= IEEE80211_NUM_BANDS) { | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5839 | 				err = -EINVAL; | 
 | 5840 | 				goto out_free; | 
 | 5841 | 			} | 
| Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5842 |  | 
 | 5843 | 			if (!wiphy->bands[band]) | 
 | 5844 | 				continue; | 
 | 5845 |  | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5846 | 			err = ieee80211_get_ratemask(wiphy->bands[band], | 
 | 5847 | 						     nla_data(attr), | 
 | 5848 | 						     nla_len(attr), | 
 | 5849 | 						     &request->rates[band]); | 
 | 5850 | 			if (err) | 
 | 5851 | 				goto out_free; | 
 | 5852 | 		} | 
 | 5853 | 	} | 
 | 5854 |  | 
| Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5855 | 	if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { | 
| Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5856 | 		request->flags = nla_get_u32( | 
 | 5857 | 			info->attrs[NL80211_ATTR_SCAN_FLAGS]); | 
| Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5858 | 		if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && | 
 | 5859 | 		    !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | 
| Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5860 | 			err = -EOPNOTSUPP; | 
 | 5861 | 			goto out_free; | 
 | 5862 | 		} | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5863 |  | 
 | 5864 | 		if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | 
 | 5865 | 			if (!(wiphy->features & | 
 | 5866 | 					NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | 
 | 5867 | 				err = -EOPNOTSUPP; | 
 | 5868 | 				goto out_free; | 
 | 5869 | 			} | 
 | 5870 |  | 
 | 5871 | 			if (wdev->current_bss) { | 
 | 5872 | 				err = -EOPNOTSUPP; | 
 | 5873 | 				goto out_free; | 
 | 5874 | 			} | 
 | 5875 |  | 
 | 5876 | 			err = nl80211_parse_random_mac(info->attrs, | 
 | 5877 | 						       request->mac_addr, | 
 | 5878 | 						       request->mac_addr_mask); | 
 | 5879 | 			if (err) | 
 | 5880 | 				goto out_free; | 
 | 5881 | 		} | 
| Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5882 | 	} | 
| Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5883 |  | 
| Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5884 | 	request->no_cck = | 
 | 5885 | 		nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | 
 | 5886 |  | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5887 | 	request->wdev = wdev; | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5888 | 	request->wiphy = &rdev->wiphy; | 
| Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5889 | 	request->scan_start = jiffies; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5890 |  | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5891 | 	rdev->scan_req = request; | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5892 | 	err = rdev_scan(rdev, request); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5893 |  | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5894 | 	if (!err) { | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5895 | 		nl80211_send_scan_start(rdev, wdev); | 
 | 5896 | 		if (wdev->netdev) | 
 | 5897 | 			dev_hold(wdev->netdev); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | 	} else { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 |  out_free: | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5900 | 		rdev->scan_req = NULL; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5901 | 		kfree(request); | 
 | 5902 | 	} | 
| Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5903 |  | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5904 |  unlock: | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5905 | 	return err; | 
 | 5906 | } | 
 | 5907 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5908 | static struct cfg80211_sched_scan_request * | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5909 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5910 | 			 struct nlattr **attrs) | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5911 | { | 
 | 5912 | 	struct cfg80211_sched_scan_request *request; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5913 | 	struct nlattr *attr; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5914 | 	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] | 5915 | 	u32 interval; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5916 | 	enum ieee80211_band band; | 
 | 5917 | 	size_t ie_len; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5918 | 	struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5919 | 	s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5920 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5921 | 	if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) | 
 | 5922 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5923 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5924 | 	if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | 
 | 5925 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5926 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5927 | 	interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | 
| Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5928 | 	if (interval == 0) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5929 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5930 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5931 | 	if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5932 | 		n_channels = validate_scan_freqs( | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5933 | 				attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5934 | 		if (!n_channels) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5935 | 			return ERR_PTR(-EINVAL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5936 | 	} else { | 
| Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5937 | 		n_channels = ieee80211_get_num_supported_channels(wiphy); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5938 | 	} | 
 | 5939 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5940 | 	if (attrs[NL80211_ATTR_SCAN_SSIDS]) | 
 | 5941 | 		nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5942 | 				    tmp) | 
 | 5943 | 			n_ssids++; | 
 | 5944 |  | 
| Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5945 | 	if (n_ssids > wiphy->max_sched_scan_ssids) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5946 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5947 |  | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5948 | 	/* | 
 | 5949 | 	 * First, count the number of 'real' matchsets. Due to an issue with | 
 | 5950 | 	 * the old implementation, matchsets containing only the RSSI attribute | 
 | 5951 | 	 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | 
 | 5952 | 	 * RSSI for all matchsets, rather than their own matchset for reporting | 
 | 5953 | 	 * all APs with a strong RSSI. This is needed to be compatible with | 
 | 5954 | 	 * older userspace that treated a matchset with only the RSSI as the | 
 | 5955 | 	 * global RSSI for all other matchsets - if there are other matchsets. | 
 | 5956 | 	 */ | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5957 | 	if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5958 | 		nla_for_each_nested(attr, | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5959 | 				    attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5960 | 				    tmp) { | 
 | 5961 | 			struct nlattr *rssi; | 
 | 5962 |  | 
 | 5963 | 			err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | 
 | 5964 | 					nla_data(attr), nla_len(attr), | 
 | 5965 | 					nl80211_match_policy); | 
 | 5966 | 			if (err) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5967 | 				return ERR_PTR(err); | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5968 | 			/* add other standalone attributes here */ | 
 | 5969 | 			if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | 
 | 5970 | 				n_match_sets++; | 
 | 5971 | 				continue; | 
 | 5972 | 			} | 
 | 5973 | 			rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | 
 | 5974 | 			if (rssi) | 
 | 5975 | 				default_match_rssi = nla_get_s32(rssi); | 
 | 5976 | 		} | 
 | 5977 | 	} | 
 | 5978 |  | 
 | 5979 | 	/* However, if there's no other matchset, add the RSSI one */ | 
 | 5980 | 	if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | 
 | 5981 | 		n_match_sets = 1; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5982 |  | 
 | 5983 | 	if (n_match_sets > wiphy->max_match_sets) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5984 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5985 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5986 | 	if (attrs[NL80211_ATTR_IE]) | 
 | 5987 | 		ie_len = nla_len(attrs[NL80211_ATTR_IE]); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5988 | 	else | 
 | 5989 | 		ie_len = 0; | 
 | 5990 |  | 
| Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5991 | 	if (ie_len > wiphy->max_sched_scan_ie_len) | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5992 | 		return ERR_PTR(-EINVAL); | 
| Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5993 |  | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5994 | 	request = kzalloc(sizeof(*request) | 
| Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5995 | 			+ sizeof(*request->ssids) * n_ssids | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5996 | 			+ sizeof(*request->match_sets) * n_match_sets | 
| Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5997 | 			+ sizeof(*request->channels) * n_channels | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5998 | 			+ ie_len, GFP_KERNEL); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5999 | 	if (!request) | 
 | 6000 | 		return ERR_PTR(-ENOMEM); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6001 |  | 
 | 6002 | 	if (n_ssids) | 
 | 6003 | 		request->ssids = (void *)&request->channels[n_channels]; | 
 | 6004 | 	request->n_ssids = n_ssids; | 
 | 6005 | 	if (ie_len) { | 
 | 6006 | 		if (request->ssids) | 
 | 6007 | 			request->ie = (void *)(request->ssids + n_ssids); | 
 | 6008 | 		else | 
 | 6009 | 			request->ie = (void *)(request->channels + n_channels); | 
 | 6010 | 	} | 
 | 6011 |  | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6012 | 	if (n_match_sets) { | 
 | 6013 | 		if (request->ie) | 
 | 6014 | 			request->match_sets = (void *)(request->ie + ie_len); | 
 | 6015 | 		else if (request->ssids) | 
 | 6016 | 			request->match_sets = | 
 | 6017 | 				(void *)(request->ssids + n_ssids); | 
 | 6018 | 		else | 
 | 6019 | 			request->match_sets = | 
 | 6020 | 				(void *)(request->channels + n_channels); | 
 | 6021 | 	} | 
 | 6022 | 	request->n_match_sets = n_match_sets; | 
 | 6023 |  | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6024 | 	i = 0; | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6025 | 	if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6026 | 		/* user specified, bail out if channel not found */ | 
 | 6027 | 		nla_for_each_nested(attr, | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6028 | 				    attrs[NL80211_ATTR_SCAN_FREQUENCIES], | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6029 | 				    tmp) { | 
 | 6030 | 			struct ieee80211_channel *chan; | 
 | 6031 |  | 
 | 6032 | 			chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | 
 | 6033 |  | 
 | 6034 | 			if (!chan) { | 
 | 6035 | 				err = -EINVAL; | 
 | 6036 | 				goto out_free; | 
 | 6037 | 			} | 
 | 6038 |  | 
 | 6039 | 			/* ignore disabled channels */ | 
 | 6040 | 			if (chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 6041 | 				continue; | 
 | 6042 |  | 
 | 6043 | 			request->channels[i] = chan; | 
 | 6044 | 			i++; | 
 | 6045 | 		} | 
 | 6046 | 	} else { | 
 | 6047 | 		/* all channels */ | 
 | 6048 | 		for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 
 | 6049 | 			int j; | 
 | 6050 | 			if (!wiphy->bands[band]) | 
 | 6051 | 				continue; | 
 | 6052 | 			for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | 
 | 6053 | 				struct ieee80211_channel *chan; | 
 | 6054 |  | 
 | 6055 | 				chan = &wiphy->bands[band]->channels[j]; | 
 | 6056 |  | 
 | 6057 | 				if (chan->flags & IEEE80211_CHAN_DISABLED) | 
 | 6058 | 					continue; | 
 | 6059 |  | 
 | 6060 | 				request->channels[i] = chan; | 
 | 6061 | 				i++; | 
 | 6062 | 			} | 
 | 6063 | 		} | 
 | 6064 | 	} | 
 | 6065 |  | 
 | 6066 | 	if (!i) { | 
 | 6067 | 		err = -EINVAL; | 
 | 6068 | 		goto out_free; | 
 | 6069 | 	} | 
 | 6070 |  | 
 | 6071 | 	request->n_channels = i; | 
 | 6072 |  | 
 | 6073 | 	i = 0; | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6074 | 	if (attrs[NL80211_ATTR_SCAN_SSIDS]) { | 
 | 6075 | 		nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6076 | 				    tmp) { | 
| Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6077 | 			if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6078 | 				err = -EINVAL; | 
 | 6079 | 				goto out_free; | 
 | 6080 | 			} | 
| Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6081 | 			request->ssids[i].ssid_len = nla_len(attr); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6082 | 			memcpy(request->ssids[i].ssid, nla_data(attr), | 
 | 6083 | 			       nla_len(attr)); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6084 | 			i++; | 
 | 6085 | 		} | 
 | 6086 | 	} | 
 | 6087 |  | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6088 | 	i = 0; | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6089 | 	if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6090 | 		nla_for_each_nested(attr, | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6091 | 				    attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6092 | 				    tmp) { | 
| Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6093 | 			struct nlattr *ssid, *rssi; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6094 |  | 
| Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6095 | 			err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | 
 | 6096 | 					nla_data(attr), nla_len(attr), | 
 | 6097 | 					nl80211_match_policy); | 
 | 6098 | 			if (err) | 
 | 6099 | 				goto out_free; | 
| Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6100 | 			ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6101 | 			if (ssid) { | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6102 | 				if (WARN_ON(i >= n_match_sets)) { | 
 | 6103 | 					/* this indicates a programming error, | 
 | 6104 | 					 * the loop above should have verified | 
 | 6105 | 					 * things properly | 
 | 6106 | 					 */ | 
 | 6107 | 					err = -EINVAL; | 
 | 6108 | 					goto out_free; | 
 | 6109 | 				} | 
 | 6110 |  | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6111 | 				if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | 
 | 6112 | 					err = -EINVAL; | 
 | 6113 | 					goto out_free; | 
 | 6114 | 				} | 
 | 6115 | 				memcpy(request->match_sets[i].ssid.ssid, | 
 | 6116 | 				       nla_data(ssid), nla_len(ssid)); | 
 | 6117 | 				request->match_sets[i].ssid.ssid_len = | 
 | 6118 | 					nla_len(ssid); | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6119 | 				/* special attribute - old implemenation w/a */ | 
 | 6120 | 				request->match_sets[i].rssi_thold = | 
 | 6121 | 					default_match_rssi; | 
 | 6122 | 				rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | 
 | 6123 | 				if (rssi) | 
 | 6124 | 					request->match_sets[i].rssi_thold = | 
 | 6125 | 						nla_get_s32(rssi); | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6126 | 			} | 
 | 6127 | 			i++; | 
 | 6128 | 		} | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6129 |  | 
 | 6130 | 		/* there was no other matchset, so the RSSI one is alone */ | 
| Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6131 | 		if (i == 0 && n_match_sets) | 
| Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6132 | 			request->match_sets[0].rssi_thold = default_match_rssi; | 
 | 6133 |  | 
 | 6134 | 		request->min_rssi_thold = INT_MAX; | 
 | 6135 | 		for (i = 0; i < n_match_sets; i++) | 
 | 6136 | 			request->min_rssi_thold = | 
 | 6137 | 				min(request->match_sets[i].rssi_thold, | 
 | 6138 | 				    request->min_rssi_thold); | 
 | 6139 | 	} else { | 
 | 6140 | 		request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | 
| Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6141 | 	} | 
 | 6142 |  | 
| Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6143 | 	if (ie_len) { | 
 | 6144 | 		request->ie_len = ie_len; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6145 | 		memcpy((void *)request->ie, | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6146 | 		       nla_data(attrs[NL80211_ATTR_IE]), | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6147 | 		       request->ie_len); | 
 | 6148 | 	} | 
 | 6149 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6150 | 	if (attrs[NL80211_ATTR_SCAN_FLAGS]) { | 
| Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6151 | 		request->flags = nla_get_u32( | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6152 | 			attrs[NL80211_ATTR_SCAN_FLAGS]); | 
| Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6153 | 		if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && | 
 | 6154 | 		    !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | 
| Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6155 | 			err = -EOPNOTSUPP; | 
 | 6156 | 			goto out_free; | 
 | 6157 | 		} | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6158 |  | 
 | 6159 | 		if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | 
 | 6160 | 			u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | 
 | 6161 |  | 
 | 6162 | 			if (!wdev) /* must be net-detect */ | 
 | 6163 | 				flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | 
 | 6164 |  | 
 | 6165 | 			if (!(wiphy->features & flg)) { | 
 | 6166 | 				err = -EOPNOTSUPP; | 
 | 6167 | 				goto out_free; | 
 | 6168 | 			} | 
 | 6169 |  | 
 | 6170 | 			if (wdev && wdev->current_bss) { | 
 | 6171 | 				err = -EOPNOTSUPP; | 
 | 6172 | 				goto out_free; | 
 | 6173 | 			} | 
 | 6174 |  | 
 | 6175 | 			err = nl80211_parse_random_mac(attrs, request->mac_addr, | 
 | 6176 | 						       request->mac_addr_mask); | 
 | 6177 | 			if (err) | 
 | 6178 | 				goto out_free; | 
 | 6179 | 		} | 
| Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6180 | 	} | 
| Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6181 |  | 
| Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 6182 | 	request->interval = interval; | 
| Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6183 | 	request->scan_start = jiffies; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6184 |  | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6185 | 	return request; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6186 |  | 
 | 6187 | out_free: | 
 | 6188 | 	kfree(request); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6189 | 	return ERR_PTR(err); | 
 | 6190 | } | 
 | 6191 |  | 
 | 6192 | static int nl80211_start_sched_scan(struct sk_buff *skb, | 
 | 6193 | 				    struct genl_info *info) | 
 | 6194 | { | 
 | 6195 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 6196 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6197 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6198 | 	struct cfg80211_sched_scan_request *sched_scan_req; | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6199 | 	int err; | 
 | 6200 |  | 
 | 6201 | 	if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | 
 | 6202 | 	    !rdev->ops->sched_scan_start) | 
 | 6203 | 		return -EOPNOTSUPP; | 
 | 6204 |  | 
 | 6205 | 	if (rdev->sched_scan_req) | 
 | 6206 | 		return -EINPROGRESS; | 
 | 6207 |  | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6208 | 	sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, | 
 | 6209 | 						  info->attrs); | 
 | 6210 |  | 
 | 6211 | 	err = PTR_ERR_OR_ZERO(sched_scan_req); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6212 | 	if (err) | 
 | 6213 | 		goto out_err; | 
 | 6214 |  | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6215 | 	err = rdev_sched_scan_start(rdev, dev, sched_scan_req); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6216 | 	if (err) | 
 | 6217 | 		goto out_free; | 
 | 6218 |  | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6219 | 	sched_scan_req->dev = dev; | 
 | 6220 | 	sched_scan_req->wiphy = &rdev->wiphy; | 
 | 6221 |  | 
| Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6222 | 	if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) | 
 | 6223 | 		sched_scan_req->owner_nlportid = info->snd_portid; | 
 | 6224 |  | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6225 | 	rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6226 |  | 
 | 6227 | 	nl80211_send_sched_scan(rdev, dev, | 
 | 6228 | 				NL80211_CMD_START_SCHED_SCAN); | 
 | 6229 | 	return 0; | 
 | 6230 |  | 
 | 6231 | out_free: | 
| Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6232 | 	kfree(sched_scan_req); | 
| Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6233 | out_err: | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6234 | 	return err; | 
 | 6235 | } | 
 | 6236 |  | 
 | 6237 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | 
 | 6238 | 				   struct genl_info *info) | 
 | 6239 | { | 
 | 6240 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 6241 |  | 
 | 6242 | 	if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | 
 | 6243 | 	    !rdev->ops->sched_scan_stop) | 
 | 6244 | 		return -EOPNOTSUPP; | 
 | 6245 |  | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6246 | 	return __cfg80211_stop_sched_scan(rdev, false); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6247 | } | 
 | 6248 |  | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6249 | static int nl80211_start_radar_detection(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]; | 
 | 6254 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 6255 | 	struct cfg80211_chan_def chandef; | 
| Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6256 | 	enum nl80211_dfs_regions dfs_region; | 
| Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6257 | 	unsigned int cac_time_ms; | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6258 | 	int err; | 
 | 6259 |  | 
| Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6260 | 	dfs_region = reg_get_dfs_region(wdev->wiphy); | 
 | 6261 | 	if (dfs_region == NL80211_DFS_UNSET) | 
 | 6262 | 		return -EINVAL; | 
 | 6263 |  | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6264 | 	err = nl80211_parse_chandef(rdev, info, &chandef); | 
 | 6265 | 	if (err) | 
 | 6266 | 		return err; | 
 | 6267 |  | 
| Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6268 | 	if (netif_carrier_ok(dev)) | 
 | 6269 | 		return -EBUSY; | 
 | 6270 |  | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6271 | 	if (wdev->cac_started) | 
 | 6272 | 		return -EBUSY; | 
 | 6273 |  | 
| Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6274 | 	err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, | 
| Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6275 | 					    wdev->iftype); | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6276 | 	if (err < 0) | 
 | 6277 | 		return err; | 
 | 6278 |  | 
 | 6279 | 	if (err == 0) | 
 | 6280 | 		return -EINVAL; | 
 | 6281 |  | 
| Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6282 | 	if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6283 | 		return -EINVAL; | 
 | 6284 |  | 
 | 6285 | 	if (!rdev->ops->start_radar_detection) | 
 | 6286 | 		return -EOPNOTSUPP; | 
 | 6287 |  | 
| Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6288 | 	cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); | 
 | 6289 | 	if (WARN_ON(!cac_time_ms)) | 
 | 6290 | 		cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | 
 | 6291 |  | 
 | 6292 | 	err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | 
 | 6293 | 					       cac_time_ms); | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6294 | 	if (!err) { | 
| Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6295 | 		wdev->chandef = chandef; | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6296 | 		wdev->cac_started = true; | 
 | 6297 | 		wdev->cac_start_time = jiffies; | 
| Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6298 | 		wdev->cac_time_ms = cac_time_ms; | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6299 | 	} | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6300 | 	return err; | 
 | 6301 | } | 
 | 6302 |  | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6303 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) | 
 | 6304 | { | 
 | 6305 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 6306 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 6307 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 6308 | 	struct cfg80211_csa_settings params; | 
 | 6309 | 	/* csa_attrs is defined static to avoid waste of stack size - this | 
 | 6310 | 	 * function is called under RTNL lock, so this should not be a problem. | 
 | 6311 | 	 */ | 
 | 6312 | 	static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6313 | 	int err; | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6314 | 	bool need_new_beacon = false; | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6315 | 	int len, i; | 
| Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6316 | 	u32 cs_count; | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6317 |  | 
 | 6318 | 	if (!rdev->ops->channel_switch || | 
 | 6319 | 	    !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | 
 | 6320 | 		return -EOPNOTSUPP; | 
 | 6321 |  | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6322 | 	switch (dev->ieee80211_ptr->iftype) { | 
 | 6323 | 	case NL80211_IFTYPE_AP: | 
 | 6324 | 	case NL80211_IFTYPE_P2P_GO: | 
 | 6325 | 		need_new_beacon = true; | 
 | 6326 |  | 
 | 6327 | 		/* useless if AP is not running */ | 
 | 6328 | 		if (!wdev->beacon_interval) | 
| Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6329 | 			return -ENOTCONN; | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6330 | 		break; | 
 | 6331 | 	case NL80211_IFTYPE_ADHOC: | 
| Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6332 | 		if (!wdev->ssid_len) | 
 | 6333 | 			return -ENOTCONN; | 
 | 6334 | 		break; | 
| Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6335 | 	case NL80211_IFTYPE_MESH_POINT: | 
| Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6336 | 		if (!wdev->mesh_id_len) | 
 | 6337 | 			return -ENOTCONN; | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6338 | 		break; | 
 | 6339 | 	default: | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6340 | 		return -EOPNOTSUPP; | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6341 | 	} | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6342 |  | 
 | 6343 | 	memset(¶ms, 0, sizeof(params)); | 
 | 6344 |  | 
 | 6345 | 	if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | 
 | 6346 | 	    !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | 
 | 6347 | 		return -EINVAL; | 
 | 6348 |  | 
 | 6349 | 	/* only important for AP, IBSS and mesh create IEs internally */ | 
| Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6350 | 	if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6351 | 		return -EINVAL; | 
 | 6352 |  | 
| Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6353 | 	/* Even though the attribute is u32, the specification says | 
 | 6354 | 	 * u8, so let's make sure we don't overflow. | 
 | 6355 | 	 */ | 
 | 6356 | 	cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | 
 | 6357 | 	if (cs_count > 255) | 
 | 6358 | 		return -EINVAL; | 
 | 6359 |  | 
 | 6360 | 	params.count = cs_count; | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6361 |  | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6362 | 	if (!need_new_beacon) | 
 | 6363 | 		goto skip_beacons; | 
 | 6364 |  | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6365 | 	err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); | 
 | 6366 | 	if (err) | 
 | 6367 | 		return err; | 
 | 6368 |  | 
 | 6369 | 	err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | 
 | 6370 | 			       info->attrs[NL80211_ATTR_CSA_IES], | 
 | 6371 | 			       nl80211_policy); | 
 | 6372 | 	if (err) | 
 | 6373 | 		return err; | 
 | 6374 |  | 
 | 6375 | 	err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | 
 | 6376 | 	if (err) | 
 | 6377 | 		return err; | 
 | 6378 |  | 
 | 6379 | 	if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | 
 | 6380 | 		return -EINVAL; | 
 | 6381 |  | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6382 | 	len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | 
 | 6383 | 	if (!len || (len % sizeof(u16))) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6384 | 		return -EINVAL; | 
 | 6385 |  | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6386 | 	params.n_counter_offsets_beacon = len / sizeof(u16); | 
 | 6387 | 	if (rdev->wiphy.max_num_csa_counters && | 
 | 6388 | 	    (params.n_counter_offsets_beacon > | 
 | 6389 | 	     rdev->wiphy.max_num_csa_counters)) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6390 | 		return -EINVAL; | 
 | 6391 |  | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6392 | 	params.counter_offsets_beacon = | 
 | 6393 | 		nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | 
 | 6394 |  | 
 | 6395 | 	/* sanity checks - counters should fit and be the same */ | 
 | 6396 | 	for (i = 0; i < params.n_counter_offsets_beacon; i++) { | 
 | 6397 | 		u16 offset = params.counter_offsets_beacon[i]; | 
 | 6398 |  | 
 | 6399 | 		if (offset >= params.beacon_csa.tail_len) | 
 | 6400 | 			return -EINVAL; | 
 | 6401 |  | 
 | 6402 | 		if (params.beacon_csa.tail[offset] != params.count) | 
 | 6403 | 			return -EINVAL; | 
 | 6404 | 	} | 
 | 6405 |  | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6406 | 	if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6407 | 		len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | 
 | 6408 | 		if (!len || (len % sizeof(u16))) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6409 | 			return -EINVAL; | 
 | 6410 |  | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6411 | 		params.n_counter_offsets_presp = len / sizeof(u16); | 
 | 6412 | 		if (rdev->wiphy.max_num_csa_counters && | 
 | 6413 | 		    (params.n_counter_offsets_beacon > | 
 | 6414 | 		     rdev->wiphy.max_num_csa_counters)) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6415 | 			return -EINVAL; | 
| Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6416 |  | 
 | 6417 | 		params.counter_offsets_presp = | 
 | 6418 | 			nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | 
 | 6419 |  | 
 | 6420 | 		/* sanity checks - counters should fit and be the same */ | 
 | 6421 | 		for (i = 0; i < params.n_counter_offsets_presp; i++) { | 
 | 6422 | 			u16 offset = params.counter_offsets_presp[i]; | 
 | 6423 |  | 
 | 6424 | 			if (offset >= params.beacon_csa.probe_resp_len) | 
 | 6425 | 				return -EINVAL; | 
 | 6426 |  | 
 | 6427 | 			if (params.beacon_csa.probe_resp[offset] != | 
 | 6428 | 			    params.count) | 
 | 6429 | 				return -EINVAL; | 
 | 6430 | 		} | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6431 | 	} | 
 | 6432 |  | 
| Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6433 | skip_beacons: | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6434 | 	err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); | 
 | 6435 | 	if (err) | 
 | 6436 | 		return err; | 
 | 6437 |  | 
| Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6438 | 	if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, | 
 | 6439 | 				     wdev->iftype)) | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6440 | 		return -EINVAL; | 
 | 6441 |  | 
| Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6442 | 	err = cfg80211_chandef_dfs_required(wdev->wiphy, | 
 | 6443 | 					    ¶ms.chandef, | 
 | 6444 | 					    wdev->iftype); | 
 | 6445 | 	if (err < 0) | 
 | 6446 | 		return err; | 
 | 6447 |  | 
| Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6448 | 	if (err > 0) | 
| Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6449 | 		params.radar_required = true; | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6450 |  | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6451 | 	if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | 
 | 6452 | 		params.block_tx = true; | 
 | 6453 |  | 
| Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6454 | 	wdev_lock(wdev); | 
 | 6455 | 	err = rdev_channel_switch(rdev, dev, ¶ms); | 
 | 6456 | 	wdev_unlock(wdev); | 
 | 6457 |  | 
 | 6458 | 	return err; | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6459 | } | 
 | 6460 |  | 
| Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6461 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, | 
 | 6462 | 			    u32 seq, int flags, | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6463 | 			    struct cfg80211_registered_device *rdev, | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6464 | 			    struct wireless_dev *wdev, | 
 | 6465 | 			    struct cfg80211_internal_bss *intbss) | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6466 | { | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6467 | 	struct cfg80211_bss *res = &intbss->pub; | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6468 | 	const struct cfg80211_bss_ies *ies; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6469 | 	void *hdr; | 
 | 6470 | 	struct nlattr *bss; | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6471 |  | 
 | 6472 | 	ASSERT_WDEV_LOCK(wdev); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6473 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6474 | 	hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6475 | 			     NL80211_CMD_NEW_SCAN_RESULTS); | 
 | 6476 | 	if (!hdr) | 
 | 6477 | 		return -1; | 
 | 6478 |  | 
| Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6479 | 	genl_dump_check_consistent(cb, hdr, &nl80211_fam); | 
 | 6480 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6481 | 	if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) | 
 | 6482 | 		goto nla_put_failure; | 
 | 6483 | 	if (wdev->netdev && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6484 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | 
 | 6485 | 		goto nla_put_failure; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6486 | 	if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
 | 6487 | 		goto nla_put_failure; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6488 |  | 
 | 6489 | 	bss = nla_nest_start(msg, NL80211_ATTR_BSS); | 
 | 6490 | 	if (!bss) | 
 | 6491 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6492 | 	if ((!is_zero_ether_addr(res->bssid) && | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6493 | 	     nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6494 | 		goto nla_put_failure; | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6495 |  | 
 | 6496 | 	rcu_read_lock(); | 
| Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6497 | 	/* indicate whether we have probe response data or not */ | 
 | 6498 | 	if (rcu_access_pointer(res->proberesp_ies) && | 
 | 6499 | 	    nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | 
 | 6500 | 		goto fail_unlock_rcu; | 
 | 6501 |  | 
 | 6502 | 	/* this pointer prefers to be pointed to probe response data | 
 | 6503 | 	 * but is always valid | 
 | 6504 | 	 */ | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6505 | 	ies = rcu_dereference(res->ies); | 
| Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6506 | 	if (ies) { | 
 | 6507 | 		if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | 
 | 6508 | 			goto fail_unlock_rcu; | 
| Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6509 | 		if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | 
 | 6510 | 					ies->len, ies->data)) | 
 | 6511 | 			goto fail_unlock_rcu; | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6512 | 	} | 
| Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6513 |  | 
 | 6514 | 	/* and this pointer is always (unless driver didn't know) beacon data */ | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6515 | 	ies = rcu_dereference(res->beacon_ies); | 
| Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6516 | 	if (ies && ies->from_beacon) { | 
 | 6517 | 		if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | 
| Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6518 | 			goto fail_unlock_rcu; | 
 | 6519 | 		if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | 
 | 6520 | 					ies->len, ies->data)) | 
 | 6521 | 			goto fail_unlock_rcu; | 
| Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6522 | 	} | 
 | 6523 | 	rcu_read_unlock(); | 
 | 6524 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6525 | 	if (res->beacon_interval && | 
 | 6526 | 	    nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | 
 | 6527 | 		goto nla_put_failure; | 
 | 6528 | 	if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | 
 | 6529 | 	    nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | 
| Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6530 | 	    nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6531 | 	    nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | 
 | 6532 | 			jiffies_to_msecs(jiffies - intbss->ts))) | 
 | 6533 | 		goto nla_put_failure; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6534 |  | 
| Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6535 | 	switch (rdev->wiphy.signal_type) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6536 | 	case CFG80211_SIGNAL_TYPE_MBM: | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6537 | 		if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) | 
 | 6538 | 			goto nla_put_failure; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6539 | 		break; | 
 | 6540 | 	case CFG80211_SIGNAL_TYPE_UNSPEC: | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6541 | 		if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) | 
 | 6542 | 			goto nla_put_failure; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6543 | 		break; | 
 | 6544 | 	default: | 
 | 6545 | 		break; | 
 | 6546 | 	} | 
 | 6547 |  | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6548 | 	switch (wdev->iftype) { | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6549 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6550 | 	case NL80211_IFTYPE_STATION: | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6551 | 		if (intbss == wdev->current_bss && | 
 | 6552 | 		    nla_put_u32(msg, NL80211_BSS_STATUS, | 
 | 6553 | 				NL80211_BSS_STATUS_ASSOCIATED)) | 
 | 6554 | 			goto nla_put_failure; | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6555 | 		break; | 
 | 6556 | 	case NL80211_IFTYPE_ADHOC: | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6557 | 		if (intbss == wdev->current_bss && | 
 | 6558 | 		    nla_put_u32(msg, NL80211_BSS_STATUS, | 
 | 6559 | 				NL80211_BSS_STATUS_IBSS_JOINED)) | 
 | 6560 | 			goto nla_put_failure; | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6561 | 		break; | 
 | 6562 | 	default: | 
 | 6563 | 		break; | 
 | 6564 | 	} | 
 | 6565 |  | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6566 | 	nla_nest_end(msg, bss); | 
 | 6567 |  | 
 | 6568 | 	return genlmsg_end(msg, hdr); | 
 | 6569 |  | 
| Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6570 |  fail_unlock_rcu: | 
 | 6571 | 	rcu_read_unlock(); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6572 |  nla_put_failure: | 
 | 6573 | 	genlmsg_cancel(msg, hdr); | 
 | 6574 | 	return -EMSGSIZE; | 
 | 6575 | } | 
 | 6576 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6577 | 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] | 6578 | { | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6579 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6580 | 	struct cfg80211_internal_bss *scan; | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6581 | 	struct wireless_dev *wdev; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6582 | 	int start = cb->args[2], idx = 0; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6583 | 	int err; | 
 | 6584 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6585 | 	err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6586 | 	if (err) | 
 | 6587 | 		return err; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6588 |  | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6589 | 	wdev_lock(wdev); | 
 | 6590 | 	spin_lock_bh(&rdev->bss_lock); | 
 | 6591 | 	cfg80211_bss_expire(rdev); | 
 | 6592 |  | 
| Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6593 | 	cb->seq = rdev->bss_generation; | 
 | 6594 |  | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6595 | 	list_for_each_entry(scan, &rdev->bss_list, list) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6596 | 		if (++idx <= start) | 
 | 6597 | 			continue; | 
| Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6598 | 		if (nl80211_send_bss(skb, cb, | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6599 | 				cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6600 | 				rdev, wdev, scan) < 0) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6601 | 			idx--; | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6602 | 			break; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6603 | 		} | 
 | 6604 | 	} | 
 | 6605 |  | 
| Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6606 | 	spin_unlock_bh(&rdev->bss_lock); | 
 | 6607 | 	wdev_unlock(wdev); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6608 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6609 | 	cb->args[2] = idx; | 
 | 6610 | 	nl80211_finish_wdev_dump(rdev); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6611 |  | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6612 | 	return skb->len; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6613 | } | 
 | 6614 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6615 | 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^] | 6616 | 			       int flags, struct net_device *dev, | 
 | 6617 | 			       bool allow_radio_stats, | 
 | 6618 | 			       struct survey_info *survey) | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6619 | { | 
 | 6620 | 	void *hdr; | 
 | 6621 | 	struct nlattr *infoattr; | 
 | 6622 |  | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6623 | 	/* skip radio stats if userspace didn't request them */ | 
 | 6624 | 	if (!survey->channel && !allow_radio_stats) | 
 | 6625 | 		return 0; | 
 | 6626 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6627 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6628 | 			     NL80211_CMD_NEW_SURVEY_RESULTS); | 
 | 6629 | 	if (!hdr) | 
 | 6630 | 		return -ENOMEM; | 
 | 6631 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6632 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | 
 | 6633 | 		goto nla_put_failure; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6634 |  | 
 | 6635 | 	infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | 
 | 6636 | 	if (!infoattr) | 
 | 6637 | 		goto nla_put_failure; | 
 | 6638 |  | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6639 | 	if (survey->channel && | 
 | 6640 | 	    nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6641 | 			survey->channel->center_freq)) | 
 | 6642 | 		goto nla_put_failure; | 
 | 6643 |  | 
 | 6644 | 	if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | 
 | 6645 | 	    nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | 
 | 6646 | 		goto nla_put_failure; | 
 | 6647 | 	if ((survey->filled & SURVEY_INFO_IN_USE) && | 
 | 6648 | 	    nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | 
 | 6649 | 		goto nla_put_failure; | 
| Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6650 | 	if ((survey->filled & SURVEY_INFO_TIME) && | 
 | 6651 | 	    nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | 
 | 6652 | 			survey->time)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6653 | 		goto nla_put_failure; | 
| Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6654 | 	if ((survey->filled & SURVEY_INFO_TIME_BUSY) && | 
 | 6655 | 	    nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | 
 | 6656 | 			survey->time_busy)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6657 | 		goto nla_put_failure; | 
| Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6658 | 	if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && | 
 | 6659 | 	    nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | 
 | 6660 | 			survey->time_ext_busy)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6661 | 		goto nla_put_failure; | 
| Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6662 | 	if ((survey->filled & SURVEY_INFO_TIME_RX) && | 
 | 6663 | 	    nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | 
 | 6664 | 			survey->time_rx)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6665 | 		goto nla_put_failure; | 
| Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 6666 | 	if ((survey->filled & SURVEY_INFO_TIME_TX) && | 
 | 6667 | 	    nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | 
 | 6668 | 			survey->time_tx)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6669 | 		goto nla_put_failure; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6670 |  | 
 | 6671 | 	nla_nest_end(msg, infoattr); | 
 | 6672 |  | 
 | 6673 | 	return genlmsg_end(msg, hdr); | 
 | 6674 |  | 
 | 6675 |  nla_put_failure: | 
 | 6676 | 	genlmsg_cancel(msg, hdr); | 
 | 6677 | 	return -EMSGSIZE; | 
 | 6678 | } | 
 | 6679 |  | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6680 | 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] | 6681 | { | 
 | 6682 | 	struct survey_info survey; | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6683 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6684 | 	struct wireless_dev *wdev; | 
 | 6685 | 	int survey_idx = cb->args[2]; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6686 | 	int res; | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6687 | 	bool radio_stats; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6688 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6689 | 	res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | 
| Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6690 | 	if (res) | 
 | 6691 | 		return res; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6692 |  | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6693 | 	/* prepare_wdev_dump parsed the attributes */ | 
 | 6694 | 	radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | 
 | 6695 |  | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6696 | 	if (!wdev->netdev) { | 
 | 6697 | 		res = -EINVAL; | 
 | 6698 | 		goto out_err; | 
 | 6699 | 	} | 
 | 6700 |  | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6701 | 	if (!rdev->ops->dump_survey) { | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6702 | 		res = -EOPNOTSUPP; | 
 | 6703 | 		goto out_err; | 
 | 6704 | 	} | 
 | 6705 |  | 
 | 6706 | 	while (1) { | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6707 | 		res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6708 | 		if (res == -ENOENT) | 
 | 6709 | 			break; | 
 | 6710 | 		if (res) | 
 | 6711 | 			goto out_err; | 
 | 6712 |  | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6713 | 		/* don't send disabled channels, but do send non-channel data */ | 
 | 6714 | 		if (survey.channel && | 
 | 6715 | 		    survey.channel->flags & IEEE80211_CHAN_DISABLED) { | 
| Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6716 | 			survey_idx++; | 
 | 6717 | 			continue; | 
 | 6718 | 		} | 
 | 6719 |  | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6720 | 		if (nl80211_send_survey(skb, | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6721 | 				NETLINK_CB(cb->skb).portid, | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6722 | 				cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
| Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame^] | 6723 | 				wdev->netdev, radio_stats, &survey) < 0) | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6724 | 			goto out; | 
 | 6725 | 		survey_idx++; | 
 | 6726 | 	} | 
 | 6727 |  | 
 | 6728 |  out: | 
| Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6729 | 	cb->args[2] = survey_idx; | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6730 | 	res = skb->len; | 
 | 6731 |  out_err: | 
| Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6732 | 	nl80211_finish_wdev_dump(rdev); | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6733 | 	return res; | 
 | 6734 | } | 
 | 6735 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6736 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | 
 | 6737 | { | 
 | 6738 | 	return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | 
 | 6739 | 				  NL80211_WPA_VERSION_2)); | 
 | 6740 | } | 
 | 6741 |  | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6742 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | 
 | 6743 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6744 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 6745 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6746 | 	struct ieee80211_channel *chan; | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6747 | 	const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; | 
 | 6748 | 	int err, ssid_len, ie_len = 0, sae_data_len = 0; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6749 | 	enum nl80211_auth_type auth_type; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6750 | 	struct key_parse key; | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6751 | 	bool local_state_change; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6752 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6753 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 6754 | 		return -EINVAL; | 
 | 6755 |  | 
 | 6756 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 6757 | 		return -EINVAL; | 
 | 6758 |  | 
| Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6759 | 	if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) | 
 | 6760 | 		return -EINVAL; | 
 | 6761 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6762 | 	if (!info->attrs[NL80211_ATTR_SSID]) | 
 | 6763 | 		return -EINVAL; | 
 | 6764 |  | 
 | 6765 | 	if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
 | 6766 | 		return -EINVAL; | 
 | 6767 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6768 | 	err = nl80211_parse_key(info, &key); | 
 | 6769 | 	if (err) | 
 | 6770 | 		return err; | 
 | 6771 |  | 
 | 6772 | 	if (key.idx >= 0) { | 
| Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6773 | 		if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) | 
 | 6774 | 			return -EINVAL; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6775 | 		if (!key.p.key || !key.p.key_len) | 
 | 6776 | 			return -EINVAL; | 
 | 6777 | 		if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | 
 | 6778 | 		     key.p.key_len != WLAN_KEY_LEN_WEP40) && | 
 | 6779 | 		    (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | 
 | 6780 | 		     key.p.key_len != WLAN_KEY_LEN_WEP104)) | 
 | 6781 | 			return -EINVAL; | 
 | 6782 | 		if (key.idx > 4) | 
 | 6783 | 			return -EINVAL; | 
 | 6784 | 	} else { | 
 | 6785 | 		key.p.key_len = 0; | 
 | 6786 | 		key.p.key = NULL; | 
 | 6787 | 	} | 
 | 6788 |  | 
| Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6789 | 	if (key.idx >= 0) { | 
 | 6790 | 		int i; | 
 | 6791 | 		bool ok = false; | 
 | 6792 | 		for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | 
 | 6793 | 			if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | 
 | 6794 | 				ok = true; | 
 | 6795 | 				break; | 
 | 6796 | 			} | 
 | 6797 | 		} | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6798 | 		if (!ok) | 
 | 6799 | 			return -EINVAL; | 
| Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6800 | 	} | 
 | 6801 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6802 | 	if (!rdev->ops->auth) | 
 | 6803 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6804 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6805 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6806 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 6807 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6808 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6809 | 	bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6810 | 	chan = nl80211_get_valid_chan(&rdev->wiphy, | 
 | 6811 | 				      info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
 | 6812 | 	if (!chan) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6813 | 		return -EINVAL; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6814 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6815 | 	ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
 | 6816 | 	ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
 | 6817 |  | 
 | 6818 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
 | 6819 | 		ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 6820 | 		ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
 | 6821 | 	} | 
 | 6822 |  | 
 | 6823 | 	auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6824 | 	if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6825 | 		return -EINVAL; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6826 |  | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6827 | 	if (auth_type == NL80211_AUTHTYPE_SAE && | 
 | 6828 | 	    !info->attrs[NL80211_ATTR_SAE_DATA]) | 
 | 6829 | 		return -EINVAL; | 
 | 6830 |  | 
 | 6831 | 	if (info->attrs[NL80211_ATTR_SAE_DATA]) { | 
 | 6832 | 		if (auth_type != NL80211_AUTHTYPE_SAE) | 
 | 6833 | 			return -EINVAL; | 
 | 6834 | 		sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | 
 | 6835 | 		sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | 
 | 6836 | 		/* need to include at least Auth Transaction and Status Code */ | 
 | 6837 | 		if (sae_data_len < 4) | 
 | 6838 | 			return -EINVAL; | 
 | 6839 | 	} | 
 | 6840 |  | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6841 | 	local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
 | 6842 |  | 
| Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6843 | 	/* | 
 | 6844 | 	 * Since we no longer track auth state, ignore | 
 | 6845 | 	 * requests to only change local state. | 
 | 6846 | 	 */ | 
 | 6847 | 	if (local_state_change) | 
 | 6848 | 		return 0; | 
 | 6849 |  | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6850 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 6851 | 	err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | 
 | 6852 | 				 ssid, ssid_len, ie, ie_len, | 
 | 6853 | 				 key.p.key, key.p.key_len, key.idx, | 
 | 6854 | 				 sae_data, sae_data_len); | 
 | 6855 | 	wdev_unlock(dev->ieee80211_ptr); | 
 | 6856 | 	return err; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6857 | } | 
 | 6858 |  | 
| Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6859 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, | 
 | 6860 | 				   struct genl_info *info, | 
| Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6861 | 				   struct cfg80211_crypto_settings *settings, | 
 | 6862 | 				   int cipher_limit) | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6863 | { | 
| Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6864 | 	memset(settings, 0, sizeof(*settings)); | 
 | 6865 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6866 | 	settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; | 
 | 6867 |  | 
| Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6868 | 	if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | 
 | 6869 | 		u16 proto; | 
 | 6870 | 		proto = nla_get_u16( | 
 | 6871 | 			info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | 
 | 6872 | 		settings->control_port_ethertype = cpu_to_be16(proto); | 
 | 6873 | 		if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | 
 | 6874 | 		    proto != ETH_P_PAE) | 
 | 6875 | 			return -EINVAL; | 
 | 6876 | 		if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | 
 | 6877 | 			settings->control_port_no_encrypt = true; | 
 | 6878 | 	} else | 
 | 6879 | 		settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | 
 | 6880 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6881 | 	if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { | 
 | 6882 | 		void *data; | 
 | 6883 | 		int len, i; | 
 | 6884 |  | 
 | 6885 | 		data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | 
 | 6886 | 		len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | 
 | 6887 | 		settings->n_ciphers_pairwise = len / sizeof(u32); | 
 | 6888 |  | 
 | 6889 | 		if (len % sizeof(u32)) | 
 | 6890 | 			return -EINVAL; | 
 | 6891 |  | 
| Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6892 | 		if (settings->n_ciphers_pairwise > cipher_limit) | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6893 | 			return -EINVAL; | 
 | 6894 |  | 
 | 6895 | 		memcpy(settings->ciphers_pairwise, data, len); | 
 | 6896 |  | 
 | 6897 | 		for (i = 0; i < settings->n_ciphers_pairwise; i++) | 
| Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6898 | 			if (!cfg80211_supported_cipher_suite( | 
 | 6899 | 					&rdev->wiphy, | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6900 | 					settings->ciphers_pairwise[i])) | 
 | 6901 | 				return -EINVAL; | 
 | 6902 | 	} | 
 | 6903 |  | 
 | 6904 | 	if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | 
 | 6905 | 		settings->cipher_group = | 
 | 6906 | 			nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | 
| Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6907 | 		if (!cfg80211_supported_cipher_suite(&rdev->wiphy, | 
 | 6908 | 						     settings->cipher_group)) | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6909 | 			return -EINVAL; | 
 | 6910 | 	} | 
 | 6911 |  | 
 | 6912 | 	if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | 
 | 6913 | 		settings->wpa_versions = | 
 | 6914 | 			nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | 
 | 6915 | 		if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | 
 | 6916 | 			return -EINVAL; | 
 | 6917 | 	} | 
 | 6918 |  | 
 | 6919 | 	if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | 
 | 6920 | 		void *data; | 
| Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6921 | 		int len; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6922 |  | 
 | 6923 | 		data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | 
 | 6924 | 		len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | 
 | 6925 | 		settings->n_akm_suites = len / sizeof(u32); | 
 | 6926 |  | 
 | 6927 | 		if (len % sizeof(u32)) | 
 | 6928 | 			return -EINVAL; | 
 | 6929 |  | 
| Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6930 | 		if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) | 
 | 6931 | 			return -EINVAL; | 
 | 6932 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6933 | 		memcpy(settings->akm_suites, data, len); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6934 | 	} | 
 | 6935 |  | 
 | 6936 | 	return 0; | 
 | 6937 | } | 
 | 6938 |  | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6939 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | 
 | 6940 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6941 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 6942 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6943 | 	struct ieee80211_channel *chan; | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6944 | 	struct cfg80211_assoc_request req = {}; | 
 | 6945 | 	const u8 *bssid, *ssid; | 
 | 6946 | 	int err, ssid_len = 0; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6947 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6948 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 6949 | 		return -EINVAL; | 
 | 6950 |  | 
 | 6951 | 	if (!info->attrs[NL80211_ATTR_MAC] || | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6952 | 	    !info->attrs[NL80211_ATTR_SSID] || | 
 | 6953 | 	    !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6954 | 		return -EINVAL; | 
 | 6955 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6956 | 	if (!rdev->ops->assoc) | 
 | 6957 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6958 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6959 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6960 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 6961 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6962 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6963 | 	bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6964 |  | 
| Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6965 | 	chan = nl80211_get_valid_chan(&rdev->wiphy, | 
 | 6966 | 				      info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
 | 6967 | 	if (!chan) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6968 | 		return -EINVAL; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6969 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6970 | 	ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
 | 6971 | 	ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6972 |  | 
 | 6973 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6974 | 		req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 6975 | 		req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6976 | 	} | 
 | 6977 |  | 
| Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6978 | 	if (info->attrs[NL80211_ATTR_USE_MFP]) { | 
| Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6979 | 		enum nl80211_mfp mfp = | 
| Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6980 | 			nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | 
| Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6981 | 		if (mfp == NL80211_MFP_REQUIRED) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6982 | 			req.use_mfp = true; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6983 | 		else if (mfp != NL80211_MFP_NO) | 
 | 6984 | 			return -EINVAL; | 
| Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6985 | 	} | 
 | 6986 |  | 
| Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6987 | 	if (info->attrs[NL80211_ATTR_PREV_BSSID]) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6988 | 		req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | 
| Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6989 |  | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6990 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6991 | 		req.flags |= ASSOC_REQ_DISABLE_HT; | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6992 |  | 
 | 6993 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6994 | 		memcpy(&req.ht_capa_mask, | 
 | 6995 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
 | 6996 | 		       sizeof(req.ht_capa_mask)); | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6997 |  | 
 | 6998 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6999 | 		if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7000 | 			return -EINVAL; | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7001 | 		memcpy(&req.ht_capa, | 
 | 7002 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
 | 7003 | 		       sizeof(req.ht_capa)); | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7004 | 	} | 
 | 7005 |  | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7006 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7007 | 		req.flags |= ASSOC_REQ_DISABLE_VHT; | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7008 |  | 
 | 7009 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7010 | 		memcpy(&req.vht_capa_mask, | 
 | 7011 | 		       nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | 
 | 7012 | 		       sizeof(req.vht_capa_mask)); | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7013 |  | 
 | 7014 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7015 | 		if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7016 | 			return -EINVAL; | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7017 | 		memcpy(&req.vht_capa, | 
 | 7018 | 		       nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | 
 | 7019 | 		       sizeof(req.vht_capa)); | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7020 | 	} | 
 | 7021 |  | 
| Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7022 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { | 
 | 7023 | 		if (!(rdev->wiphy.features & | 
 | 7024 | 		      NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | 
 | 7025 | 		    !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | 
 | 7026 | 			return -EINVAL; | 
 | 7027 | 		req.flags |= ASSOC_REQ_USE_RRM; | 
 | 7028 | 	} | 
 | 7029 |  | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7030 | 	err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7031 | 	if (!err) { | 
 | 7032 | 		wdev_lock(dev->ieee80211_ptr); | 
| Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7033 | 		err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, | 
 | 7034 | 					  ssid, ssid_len, &req); | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7035 | 		wdev_unlock(dev->ieee80211_ptr); | 
 | 7036 | 	} | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7037 |  | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7038 | 	return err; | 
 | 7039 | } | 
 | 7040 |  | 
 | 7041 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | 
 | 7042 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7043 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7044 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7045 | 	const u8 *ie = NULL, *bssid; | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7046 | 	int ie_len = 0, err; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7047 | 	u16 reason_code; | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7048 | 	bool local_state_change; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7049 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7050 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 7051 | 		return -EINVAL; | 
 | 7052 |  | 
 | 7053 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 7054 | 		return -EINVAL; | 
 | 7055 |  | 
 | 7056 | 	if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
 | 7057 | 		return -EINVAL; | 
 | 7058 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7059 | 	if (!rdev->ops->deauth) | 
 | 7060 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7061 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7062 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7063 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7064 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7065 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7066 | 	bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7067 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7068 | 	reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
 | 7069 | 	if (reason_code == 0) { | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7070 | 		/* Reason Code 0 is reserved */ | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | 		return -EINVAL; | 
| Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7072 | 	} | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7073 |  | 
 | 7074 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7075 | 		ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 7076 | 		ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7077 | 	} | 
 | 7078 |  | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7079 | 	local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
 | 7080 |  | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7081 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 7082 | 	err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | 
 | 7083 | 				   local_state_change); | 
 | 7084 | 	wdev_unlock(dev->ieee80211_ptr); | 
 | 7085 | 	return err; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7086 | } | 
 | 7087 |  | 
 | 7088 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | 
 | 7089 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7090 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7091 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7092 | 	const u8 *ie = NULL, *bssid; | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7093 | 	int ie_len = 0, err; | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7094 | 	u16 reason_code; | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7095 | 	bool local_state_change; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7096 |  | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7097 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 7098 | 		return -EINVAL; | 
 | 7099 |  | 
 | 7100 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 7101 | 		return -EINVAL; | 
 | 7102 |  | 
 | 7103 | 	if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
 | 7104 | 		return -EINVAL; | 
 | 7105 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | 	if (!rdev->ops->disassoc) | 
 | 7107 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7108 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7109 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7110 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7111 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7112 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7113 | 	bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7114 |  | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7115 | 	reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
 | 7116 | 	if (reason_code == 0) { | 
| Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7117 | 		/* Reason Code 0 is reserved */ | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7118 | 		return -EINVAL; | 
| Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7119 | 	} | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7120 |  | 
 | 7121 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
| Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7122 | 		ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 7123 | 		ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7124 | 	} | 
 | 7125 |  | 
| Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7126 | 	local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 
 | 7127 |  | 
| Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7128 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 7129 | 	err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | 
 | 7130 | 				     local_state_change); | 
 | 7131 | 	wdev_unlock(dev->ieee80211_ptr); | 
 | 7132 | 	return err; | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7133 | } | 
 | 7134 |  | 
| Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7135 | static bool | 
 | 7136 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | 
 | 7137 | 			 int mcast_rate[IEEE80211_NUM_BANDS], | 
 | 7138 | 			 int rateval) | 
 | 7139 | { | 
 | 7140 | 	struct wiphy *wiphy = &rdev->wiphy; | 
 | 7141 | 	bool found = false; | 
 | 7142 | 	int band, i; | 
 | 7143 |  | 
 | 7144 | 	for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 
 | 7145 | 		struct ieee80211_supported_band *sband; | 
 | 7146 |  | 
 | 7147 | 		sband = wiphy->bands[band]; | 
 | 7148 | 		if (!sband) | 
 | 7149 | 			continue; | 
 | 7150 |  | 
 | 7151 | 		for (i = 0; i < sband->n_bitrates; i++) { | 
 | 7152 | 			if (sband->bitrates[i].bitrate == rateval) { | 
 | 7153 | 				mcast_rate[band] = i + 1; | 
 | 7154 | 				found = true; | 
 | 7155 | 				break; | 
 | 7156 | 			} | 
 | 7157 | 		} | 
 | 7158 | 	} | 
 | 7159 |  | 
 | 7160 | 	return found; | 
 | 7161 | } | 
 | 7162 |  | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7163 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | 
 | 7164 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7165 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7166 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7167 | 	struct cfg80211_ibss_params ibss; | 
 | 7168 | 	struct wiphy *wiphy; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7169 | 	struct cfg80211_cached_keys *connkeys = NULL; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7170 | 	int err; | 
 | 7171 |  | 
| Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7172 | 	memset(&ibss, 0, sizeof(ibss)); | 
 | 7173 |  | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7174 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 7175 | 		return -EINVAL; | 
 | 7176 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7177 | 	if (!info->attrs[NL80211_ATTR_SSID] || | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7178 | 	    !nla_len(info->attrs[NL80211_ATTR_SSID])) | 
 | 7179 | 		return -EINVAL; | 
 | 7180 |  | 
| Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7181 | 	ibss.beacon_interval = 100; | 
 | 7182 |  | 
 | 7183 | 	if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | 
 | 7184 | 		ibss.beacon_interval = | 
 | 7185 | 			nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
 | 7186 | 		if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | 
 | 7187 | 			return -EINVAL; | 
 | 7188 | 	} | 
 | 7189 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7190 | 	if (!rdev->ops->join_ibss) | 
 | 7191 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7192 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7193 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) | 
 | 7194 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7195 |  | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7196 | 	wiphy = &rdev->wiphy; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7197 |  | 
| Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7198 | 	if (info->attrs[NL80211_ATTR_MAC]) { | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7199 | 		ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7200 |  | 
 | 7201 | 		if (!is_valid_ether_addr(ibss.bssid)) | 
 | 7202 | 			return -EINVAL; | 
 | 7203 | 	} | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7204 | 	ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
 | 7205 | 	ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
 | 7206 |  | 
 | 7207 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
 | 7208 | 		ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 7209 | 		ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
 | 7210 | 	} | 
 | 7211 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7212 | 	err = nl80211_parse_chandef(rdev, info, &ibss.chandef); | 
 | 7213 | 	if (err) | 
 | 7214 | 		return err; | 
| Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7215 |  | 
| Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7216 | 	if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, | 
 | 7217 | 				     NL80211_IFTYPE_ADHOC)) | 
| Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7218 | 		return -EINVAL; | 
 | 7219 |  | 
| Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7220 | 	switch (ibss.chandef.width) { | 
| Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7221 | 	case NL80211_CHAN_WIDTH_5: | 
 | 7222 | 	case NL80211_CHAN_WIDTH_10: | 
| Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7223 | 	case NL80211_CHAN_WIDTH_20_NOHT: | 
 | 7224 | 		break; | 
 | 7225 | 	case NL80211_CHAN_WIDTH_20: | 
 | 7226 | 	case NL80211_CHAN_WIDTH_40: | 
 | 7227 | 		if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | 
 | 7228 | 			break; | 
 | 7229 | 	default: | 
| Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7230 | 		return -EINVAL; | 
| Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7231 | 	} | 
| Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7232 |  | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7233 | 	ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7234 | 	ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7235 |  | 
| Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7236 | 	if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
 | 7237 | 		u8 *rates = | 
 | 7238 | 			nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 7239 | 		int n_rates = | 
 | 7240 | 			nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 7241 | 		struct ieee80211_supported_band *sband = | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7242 | 			wiphy->bands[ibss.chandef.chan->band]; | 
| Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7243 |  | 
| Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7244 | 		err = ieee80211_get_ratemask(sband, rates, n_rates, | 
 | 7245 | 					     &ibss.basic_rates); | 
 | 7246 | 		if (err) | 
 | 7247 | 			return err; | 
| Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7248 | 	} | 
| Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7249 |  | 
| Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7250 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
 | 7251 | 		memcpy(&ibss.ht_capa_mask, | 
 | 7252 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
 | 7253 | 		       sizeof(ibss.ht_capa_mask)); | 
 | 7254 |  | 
 | 7255 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
 | 7256 | 		if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
 | 7257 | 			return -EINVAL; | 
 | 7258 | 		memcpy(&ibss.ht_capa, | 
 | 7259 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
 | 7260 | 		       sizeof(ibss.ht_capa)); | 
 | 7261 | 	} | 
 | 7262 |  | 
| Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7263 | 	if (info->attrs[NL80211_ATTR_MCAST_RATE] && | 
 | 7264 | 	    !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | 
 | 7265 | 			nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | 
 | 7266 | 		return -EINVAL; | 
| Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7267 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7268 | 	if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7269 | 		bool no_ht = false; | 
 | 7270 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7271 | 		connkeys = nl80211_parse_connkeys(rdev, | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7272 | 					  info->attrs[NL80211_ATTR_KEYS], | 
 | 7273 | 					  &no_ht); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7274 | 		if (IS_ERR(connkeys)) | 
 | 7275 | 			return PTR_ERR(connkeys); | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7276 |  | 
| Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7277 | 		if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && | 
 | 7278 | 		    no_ht) { | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7279 | 			kfree(connkeys); | 
 | 7280 | 			return -EINVAL; | 
 | 7281 | 		} | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7282 | 	} | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7283 |  | 
| Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7284 | 	ibss.control_port = | 
 | 7285 | 		nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | 
 | 7286 |  | 
| Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7287 | 	ibss.userspace_handles_dfs = | 
 | 7288 | 		nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | 
 | 7289 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | 	err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7291 | 	if (err) | 
| Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7292 | 		kzfree(connkeys); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7293 | 	return err; | 
 | 7294 | } | 
 | 7295 |  | 
 | 7296 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | 
 | 7297 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7298 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7299 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7300 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7301 | 	if (!rdev->ops->leave_ibss) | 
 | 7302 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7303 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7304 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) | 
 | 7305 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7306 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7307 | 	return cfg80211_leave_ibss(rdev, dev, false); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7308 | } | 
 | 7309 |  | 
| Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7310 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) | 
 | 7311 | { | 
 | 7312 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7313 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 7314 | 	int mcast_rate[IEEE80211_NUM_BANDS]; | 
 | 7315 | 	u32 nla_rate; | 
 | 7316 | 	int err; | 
 | 7317 |  | 
 | 7318 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | 
 | 7319 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | 
 | 7320 | 		return -EOPNOTSUPP; | 
 | 7321 |  | 
 | 7322 | 	if (!rdev->ops->set_mcast_rate) | 
 | 7323 | 		return -EOPNOTSUPP; | 
 | 7324 |  | 
 | 7325 | 	memset(mcast_rate, 0, sizeof(mcast_rate)); | 
 | 7326 |  | 
 | 7327 | 	if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | 
 | 7328 | 		return -EINVAL; | 
 | 7329 |  | 
 | 7330 | 	nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | 
 | 7331 | 	if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | 
 | 7332 | 		return -EINVAL; | 
 | 7333 |  | 
 | 7334 | 	err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | 
 | 7335 |  | 
 | 7336 | 	return err; | 
 | 7337 | } | 
 | 7338 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7339 | static struct sk_buff * | 
 | 7340 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | 
 | 7341 | 			    int approxlen, u32 portid, u32 seq, | 
 | 7342 | 			    enum nl80211_commands cmd, | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7343 | 			    enum nl80211_attrs attr, | 
 | 7344 | 			    const struct nl80211_vendor_cmd_info *info, | 
 | 7345 | 			    gfp_t gfp) | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7346 | { | 
 | 7347 | 	struct sk_buff *skb; | 
 | 7348 | 	void *hdr; | 
 | 7349 | 	struct nlattr *data; | 
 | 7350 |  | 
 | 7351 | 	skb = nlmsg_new(approxlen + 100, gfp); | 
 | 7352 | 	if (!skb) | 
 | 7353 | 		return NULL; | 
 | 7354 |  | 
 | 7355 | 	hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | 
 | 7356 | 	if (!hdr) { | 
 | 7357 | 		kfree_skb(skb); | 
 | 7358 | 		return NULL; | 
 | 7359 | 	} | 
 | 7360 |  | 
 | 7361 | 	if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | 
 | 7362 | 		goto nla_put_failure; | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7363 |  | 
 | 7364 | 	if (info) { | 
 | 7365 | 		if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | 
 | 7366 | 				info->vendor_id)) | 
 | 7367 | 			goto nla_put_failure; | 
 | 7368 | 		if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | 
 | 7369 | 				info->subcmd)) | 
 | 7370 | 			goto nla_put_failure; | 
 | 7371 | 	} | 
 | 7372 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7373 | 	data = nla_nest_start(skb, attr); | 
 | 7374 |  | 
 | 7375 | 	((void **)skb->cb)[0] = rdev; | 
 | 7376 | 	((void **)skb->cb)[1] = hdr; | 
 | 7377 | 	((void **)skb->cb)[2] = data; | 
 | 7378 |  | 
 | 7379 | 	return skb; | 
 | 7380 |  | 
 | 7381 |  nla_put_failure: | 
 | 7382 | 	kfree_skb(skb); | 
 | 7383 | 	return NULL; | 
 | 7384 | } | 
| Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7385 |  | 
| Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7386 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, | 
 | 7387 | 					   enum nl80211_commands cmd, | 
 | 7388 | 					   enum nl80211_attrs attr, | 
 | 7389 | 					   int vendor_event_idx, | 
 | 7390 | 					   int approxlen, gfp_t gfp) | 
 | 7391 | { | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7392 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7393 | 	const struct nl80211_vendor_cmd_info *info; | 
 | 7394 |  | 
 | 7395 | 	switch (cmd) { | 
 | 7396 | 	case NL80211_CMD_TESTMODE: | 
 | 7397 | 		if (WARN_ON(vendor_event_idx != -1)) | 
 | 7398 | 			return NULL; | 
 | 7399 | 		info = NULL; | 
 | 7400 | 		break; | 
 | 7401 | 	case NL80211_CMD_VENDOR: | 
 | 7402 | 		if (WARN_ON(vendor_event_idx < 0 || | 
 | 7403 | 			    vendor_event_idx >= wiphy->n_vendor_events)) | 
 | 7404 | 			return NULL; | 
 | 7405 | 		info = &wiphy->vendor_events[vendor_event_idx]; | 
 | 7406 | 		break; | 
 | 7407 | 	default: | 
 | 7408 | 		WARN_ON(1); | 
 | 7409 | 		return NULL; | 
 | 7410 | 	} | 
 | 7411 |  | 
 | 7412 | 	return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | 
 | 7413 | 					   cmd, attr, info, gfp); | 
 | 7414 | } | 
 | 7415 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | 
 | 7416 |  | 
 | 7417 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | 
 | 7418 | { | 
 | 7419 | 	struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | 
 | 7420 | 	void *hdr = ((void **)skb->cb)[1]; | 
 | 7421 | 	struct nlattr *data = ((void **)skb->cb)[2]; | 
 | 7422 | 	enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | 
 | 7423 |  | 
| Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7424 | 	/* clear CB data for netlink core to own from now on */ | 
 | 7425 | 	memset(skb->cb, 0, sizeof(skb->cb)); | 
 | 7426 |  | 
| Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7427 | 	nla_nest_end(skb, data); | 
 | 7428 | 	genlmsg_end(skb, hdr); | 
 | 7429 |  | 
 | 7430 | 	if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | 
 | 7431 | 		mcgrp = NL80211_MCGRP_VENDOR; | 
 | 7432 |  | 
 | 7433 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | 
 | 7434 | 				mcgrp, gfp); | 
 | 7435 | } | 
 | 7436 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | 
 | 7437 |  | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7438 | #ifdef CONFIG_NL80211_TESTMODE | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7439 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | 
 | 7440 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7441 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7442 | 	struct wireless_dev *wdev = | 
 | 7443 | 		__cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7444 | 	int err; | 
 | 7445 |  | 
| David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7446 | 	if (!rdev->ops->testmode_cmd) | 
 | 7447 | 		return -EOPNOTSUPP; | 
 | 7448 |  | 
 | 7449 | 	if (IS_ERR(wdev)) { | 
 | 7450 | 		err = PTR_ERR(wdev); | 
 | 7451 | 		if (err != -EINVAL) | 
 | 7452 | 			return err; | 
 | 7453 | 		wdev = NULL; | 
 | 7454 | 	} else if (wdev->wiphy != &rdev->wiphy) { | 
 | 7455 | 		return -EINVAL; | 
 | 7456 | 	} | 
 | 7457 |  | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7458 | 	if (!info->attrs[NL80211_ATTR_TESTDATA]) | 
 | 7459 | 		return -EINVAL; | 
 | 7460 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7461 | 	rdev->cur_cmd_info = info; | 
| David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7462 | 	err = rdev_testmode_cmd(rdev, wdev, | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7463 | 				nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | 
 | 7464 | 				nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7465 | 	rdev->cur_cmd_info = NULL; | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7466 |  | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7467 | 	return err; | 
 | 7468 | } | 
 | 7469 |  | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7470 | static int nl80211_testmode_dump(struct sk_buff *skb, | 
 | 7471 | 				 struct netlink_callback *cb) | 
 | 7472 | { | 
| Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7473 | 	struct cfg80211_registered_device *rdev; | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7474 | 	int err; | 
 | 7475 | 	long phy_idx; | 
 | 7476 | 	void *data = NULL; | 
 | 7477 | 	int data_len = 0; | 
 | 7478 |  | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7479 | 	rtnl_lock(); | 
 | 7480 |  | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7481 | 	if (cb->args[0]) { | 
 | 7482 | 		/* | 
 | 7483 | 		 * 0 is a valid index, but not valid for args[0], | 
 | 7484 | 		 * so we need to offset by 1. | 
 | 7485 | 		 */ | 
 | 7486 | 		phy_idx = cb->args[0] - 1; | 
 | 7487 | 	} else { | 
 | 7488 | 		err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | 
 | 7489 | 				  nl80211_fam.attrbuf, nl80211_fam.maxattr, | 
 | 7490 | 				  nl80211_policy); | 
 | 7491 | 		if (err) | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7492 | 			goto out_err; | 
| Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7493 |  | 
| Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7494 | 		rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | 
 | 7495 | 						  nl80211_fam.attrbuf); | 
 | 7496 | 		if (IS_ERR(rdev)) { | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7497 | 			err = PTR_ERR(rdev); | 
 | 7498 | 			goto out_err; | 
| Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7499 | 		} | 
| Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7500 | 		phy_idx = rdev->wiphy_idx; | 
 | 7501 | 		rdev = NULL; | 
| Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7502 |  | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7503 | 		if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) | 
 | 7504 | 			cb->args[1] = | 
 | 7505 | 				(long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | 
 | 7506 | 	} | 
 | 7507 |  | 
 | 7508 | 	if (cb->args[1]) { | 
 | 7509 | 		data = nla_data((void *)cb->args[1]); | 
 | 7510 | 		data_len = nla_len((void *)cb->args[1]); | 
 | 7511 | 	} | 
 | 7512 |  | 
| Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7513 | 	rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); | 
 | 7514 | 	if (!rdev) { | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7515 | 		err = -ENOENT; | 
 | 7516 | 		goto out_err; | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7517 | 	} | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7518 |  | 
| Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7519 | 	if (!rdev->ops->testmode_dump) { | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7520 | 		err = -EOPNOTSUPP; | 
 | 7521 | 		goto out_err; | 
 | 7522 | 	} | 
 | 7523 |  | 
 | 7524 | 	while (1) { | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7525 | 		void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7526 | 					   cb->nlh->nlmsg_seq, NLM_F_MULTI, | 
 | 7527 | 					   NL80211_CMD_TESTMODE); | 
 | 7528 | 		struct nlattr *tmdata; | 
 | 7529 |  | 
| Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7530 | 		if (!hdr) | 
 | 7531 | 			break; | 
 | 7532 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7533 | 		if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7534 | 			genlmsg_cancel(skb, hdr); | 
 | 7535 | 			break; | 
 | 7536 | 		} | 
 | 7537 |  | 
 | 7538 | 		tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | 
 | 7539 | 		if (!tmdata) { | 
 | 7540 | 			genlmsg_cancel(skb, hdr); | 
 | 7541 | 			break; | 
 | 7542 | 		} | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7543 | 		err = rdev_testmode_dump(rdev, skb, cb, data, data_len); | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7544 | 		nla_nest_end(skb, tmdata); | 
 | 7545 |  | 
 | 7546 | 		if (err == -ENOBUFS || err == -ENOENT) { | 
 | 7547 | 			genlmsg_cancel(skb, hdr); | 
 | 7548 | 			break; | 
 | 7549 | 		} else if (err) { | 
 | 7550 | 			genlmsg_cancel(skb, hdr); | 
 | 7551 | 			goto out_err; | 
 | 7552 | 		} | 
 | 7553 |  | 
 | 7554 | 		genlmsg_end(skb, hdr); | 
 | 7555 | 	} | 
 | 7556 |  | 
 | 7557 | 	err = skb->len; | 
 | 7558 | 	/* see above */ | 
 | 7559 | 	cb->args[0] = phy_idx + 1; | 
 | 7560 |  out_err: | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7561 | 	rtnl_unlock(); | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7562 | 	return err; | 
 | 7563 | } | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7564 | #endif | 
 | 7565 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7566 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) | 
 | 7567 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7568 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7569 | 	struct net_device *dev = info->user_ptr[1]; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7570 | 	struct cfg80211_connect_params connect; | 
 | 7571 | 	struct wiphy *wiphy; | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7572 | 	struct cfg80211_cached_keys *connkeys = NULL; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7573 | 	int err; | 
 | 7574 |  | 
 | 7575 | 	memset(&connect, 0, sizeof(connect)); | 
 | 7576 |  | 
 | 7577 | 	if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 7578 | 		return -EINVAL; | 
 | 7579 |  | 
 | 7580 | 	if (!info->attrs[NL80211_ATTR_SSID] || | 
 | 7581 | 	    !nla_len(info->attrs[NL80211_ATTR_SSID])) | 
 | 7582 | 		return -EINVAL; | 
 | 7583 |  | 
 | 7584 | 	if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | 
 | 7585 | 		connect.auth_type = | 
 | 7586 | 			nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 
| Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7587 | 		if (!nl80211_valid_auth_type(rdev, connect.auth_type, | 
 | 7588 | 					     NL80211_CMD_CONNECT)) | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7589 | 			return -EINVAL; | 
 | 7590 | 	} else | 
 | 7591 | 		connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | 
 | 7592 |  | 
 | 7593 | 	connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | 
 | 7594 |  | 
| Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7595 | 	err = nl80211_crypto_settings(rdev, info, &connect.crypto, | 
| Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7596 | 				      NL80211_MAX_NR_CIPHER_SUITES); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7597 | 	if (err) | 
 | 7598 | 		return err; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7599 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7600 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7601 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7602 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7603 |  | 
| Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7604 | 	wiphy = &rdev->wiphy; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7605 |  | 
| Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7606 | 	connect.bg_scan_period = -1; | 
 | 7607 | 	if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | 
 | 7608 | 		(wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | 
 | 7609 | 		connect.bg_scan_period = | 
 | 7610 | 			nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | 
 | 7611 | 	} | 
 | 7612 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7613 | 	if (info->attrs[NL80211_ATTR_MAC]) | 
 | 7614 | 		connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
| Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7615 | 	else if (info->attrs[NL80211_ATTR_MAC_HINT]) | 
 | 7616 | 		connect.bssid_hint = | 
 | 7617 | 			nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7618 | 	connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 
 | 7619 | 	connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 
 | 7620 |  | 
 | 7621 | 	if (info->attrs[NL80211_ATTR_IE]) { | 
 | 7622 | 		connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 7623 | 		connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
 | 7624 | 	} | 
 | 7625 |  | 
| Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7626 | 	if (info->attrs[NL80211_ATTR_USE_MFP]) { | 
 | 7627 | 		connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | 
 | 7628 | 		if (connect.mfp != NL80211_MFP_REQUIRED && | 
 | 7629 | 		    connect.mfp != NL80211_MFP_NO) | 
 | 7630 | 			return -EINVAL; | 
 | 7631 | 	} else { | 
 | 7632 | 		connect.mfp = NL80211_MFP_NO; | 
 | 7633 | 	} | 
 | 7634 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7635 | 	if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
| Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7636 | 		connect.channel = nl80211_get_valid_chan( | 
 | 7637 | 			wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 
 | 7638 | 		if (!connect.channel) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7639 | 			return -EINVAL; | 
| Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7640 | 	} else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | 
| Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7641 | 		connect.channel_hint = nl80211_get_valid_chan( | 
 | 7642 | 			wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | 
 | 7643 | 		if (!connect.channel_hint) | 
| Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7644 | 			return -EINVAL; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7645 | 	} | 
 | 7646 |  | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7647 | 	if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { | 
 | 7648 | 		connkeys = nl80211_parse_connkeys(rdev, | 
| Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7649 | 					  info->attrs[NL80211_ATTR_KEYS], NULL); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7650 | 		if (IS_ERR(connkeys)) | 
 | 7651 | 			return PTR_ERR(connkeys); | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7652 | 	} | 
 | 7653 |  | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7654 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) | 
 | 7655 | 		connect.flags |= ASSOC_REQ_DISABLE_HT; | 
 | 7656 |  | 
 | 7657 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | 
 | 7658 | 		memcpy(&connect.ht_capa_mask, | 
 | 7659 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | 
 | 7660 | 		       sizeof(connect.ht_capa_mask)); | 
 | 7661 |  | 
 | 7662 | 	if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | 
| Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7663 | 		if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { | 
| Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7664 | 			kzfree(connkeys); | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7665 | 			return -EINVAL; | 
| Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7666 | 		} | 
| Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7667 | 		memcpy(&connect.ht_capa, | 
 | 7668 | 		       nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | 
 | 7669 | 		       sizeof(connect.ht_capa)); | 
 | 7670 | 	} | 
 | 7671 |  | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7672 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) | 
 | 7673 | 		connect.flags |= ASSOC_REQ_DISABLE_VHT; | 
 | 7674 |  | 
 | 7675 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | 
 | 7676 | 		memcpy(&connect.vht_capa_mask, | 
 | 7677 | 		       nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | 
 | 7678 | 		       sizeof(connect.vht_capa_mask)); | 
 | 7679 |  | 
 | 7680 | 	if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | 
 | 7681 | 		if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | 
| Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7682 | 			kzfree(connkeys); | 
| Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7683 | 			return -EINVAL; | 
 | 7684 | 		} | 
 | 7685 | 		memcpy(&connect.vht_capa, | 
 | 7686 | 		       nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | 
 | 7687 | 		       sizeof(connect.vht_capa)); | 
 | 7688 | 	} | 
 | 7689 |  | 
| Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7690 | 	if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { | 
 | 7691 | 		if (!(rdev->wiphy.features & | 
 | 7692 | 		      NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | 
 | 7693 | 		    !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | 
 | 7694 | 			return -EINVAL; | 
 | 7695 | 		connect.flags |= ASSOC_REQ_USE_RRM; | 
 | 7696 | 	} | 
 | 7697 |  | 
| Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7698 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 7699 | 	err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | 
 | 7700 | 	wdev_unlock(dev->ieee80211_ptr); | 
| Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7701 | 	if (err) | 
| Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7702 | 		kzfree(connkeys); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7703 | 	return err; | 
 | 7704 | } | 
 | 7705 |  | 
 | 7706 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | 
 | 7707 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7708 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7709 | 	struct net_device *dev = info->user_ptr[1]; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7710 | 	u16 reason; | 
| Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7711 | 	int ret; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7712 |  | 
 | 7713 | 	if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 
 | 7714 | 		reason = WLAN_REASON_DEAUTH_LEAVING; | 
 | 7715 | 	else | 
 | 7716 | 		reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 
 | 7717 |  | 
 | 7718 | 	if (reason == 0) | 
 | 7719 | 		return -EINVAL; | 
 | 7720 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7721 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7722 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7723 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7724 |  | 
| Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7725 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 7726 | 	ret = cfg80211_disconnect(rdev, dev, reason, true); | 
 | 7727 | 	wdev_unlock(dev->ieee80211_ptr); | 
 | 7728 | 	return ret; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7729 | } | 
 | 7730 |  | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7731 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) | 
 | 7732 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7733 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7734 | 	struct net *net; | 
 | 7735 | 	int err; | 
 | 7736 | 	u32 pid; | 
 | 7737 |  | 
 | 7738 | 	if (!info->attrs[NL80211_ATTR_PID]) | 
 | 7739 | 		return -EINVAL; | 
 | 7740 |  | 
 | 7741 | 	pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | 
 | 7742 |  | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7743 | 	net = get_net_ns_by_pid(pid); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7744 | 	if (IS_ERR(net)) | 
 | 7745 | 		return PTR_ERR(net); | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7746 |  | 
 | 7747 | 	err = 0; | 
 | 7748 |  | 
 | 7749 | 	/* check if anything to do */ | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7750 | 	if (!net_eq(wiphy_net(&rdev->wiphy), net)) | 
 | 7751 | 		err = cfg80211_switch_netns(rdev, net); | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7752 |  | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7753 | 	put_net(net); | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7754 | 	return err; | 
 | 7755 | } | 
 | 7756 |  | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7757 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) | 
 | 7758 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7759 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7760 | 	int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, | 
 | 7761 | 			struct cfg80211_pmksa *pmksa) = NULL; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7762 | 	struct net_device *dev = info->user_ptr[1]; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7763 | 	struct cfg80211_pmksa pmksa; | 
 | 7764 |  | 
 | 7765 | 	memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | 
 | 7766 |  | 
 | 7767 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 7768 | 		return -EINVAL; | 
 | 7769 |  | 
 | 7770 | 	if (!info->attrs[NL80211_ATTR_PMKID]) | 
 | 7771 | 		return -EINVAL; | 
 | 7772 |  | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7773 | 	pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | 
 | 7774 | 	pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 7775 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7776 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7777 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7778 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7779 |  | 
 | 7780 | 	switch (info->genlhdr->cmd) { | 
 | 7781 | 	case NL80211_CMD_SET_PMKSA: | 
 | 7782 | 		rdev_ops = rdev->ops->set_pmksa; | 
 | 7783 | 		break; | 
 | 7784 | 	case NL80211_CMD_DEL_PMKSA: | 
 | 7785 | 		rdev_ops = rdev->ops->del_pmksa; | 
 | 7786 | 		break; | 
 | 7787 | 	default: | 
 | 7788 | 		WARN_ON(1); | 
 | 7789 | 		break; | 
 | 7790 | 	} | 
 | 7791 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7792 | 	if (!rdev_ops) | 
 | 7793 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7794 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7795 | 	return rdev_ops(&rdev->wiphy, dev, &pmksa); | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7796 | } | 
 | 7797 |  | 
 | 7798 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | 
 | 7799 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7800 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7801 | 	struct net_device *dev = info->user_ptr[1]; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7802 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7803 | 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7804 | 	    dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 7805 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7806 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7807 | 	if (!rdev->ops->flush_pmksa) | 
 | 7808 | 		return -EOPNOTSUPP; | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7809 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7810 | 	return rdev_flush_pmksa(rdev, dev); | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7811 | } | 
 | 7812 |  | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7813 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) | 
 | 7814 | { | 
 | 7815 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7816 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 7817 | 	u8 action_code, dialog_token; | 
| Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7818 | 	u32 peer_capability = 0; | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7819 | 	u16 status_code; | 
 | 7820 | 	u8 *peer; | 
| Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7821 | 	bool initiator; | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7822 |  | 
 | 7823 | 	if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | 
 | 7824 | 	    !rdev->ops->tdls_mgmt) | 
 | 7825 | 		return -EOPNOTSUPP; | 
 | 7826 |  | 
 | 7827 | 	if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | 
 | 7828 | 	    !info->attrs[NL80211_ATTR_STATUS_CODE] || | 
 | 7829 | 	    !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | 
 | 7830 | 	    !info->attrs[NL80211_ATTR_IE] || | 
 | 7831 | 	    !info->attrs[NL80211_ATTR_MAC]) | 
 | 7832 | 		return -EINVAL; | 
 | 7833 |  | 
 | 7834 | 	peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 7835 | 	action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | 
 | 7836 | 	status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | 
 | 7837 | 	dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | 
| Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7838 | 	initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); | 
| Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7839 | 	if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) | 
 | 7840 | 		peer_capability = | 
 | 7841 | 			nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7842 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7843 | 	return rdev_tdls_mgmt(rdev, dev, peer, action_code, | 
| Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7844 | 			      dialog_token, status_code, peer_capability, | 
| Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7845 | 			      initiator, | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7846 | 			      nla_data(info->attrs[NL80211_ATTR_IE]), | 
 | 7847 | 			      nla_len(info->attrs[NL80211_ATTR_IE])); | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7848 | } | 
 | 7849 |  | 
 | 7850 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | 
 | 7851 | { | 
 | 7852 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 7853 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 7854 | 	enum nl80211_tdls_operation operation; | 
 | 7855 | 	u8 *peer; | 
 | 7856 |  | 
 | 7857 | 	if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | 
 | 7858 | 	    !rdev->ops->tdls_oper) | 
 | 7859 | 		return -EOPNOTSUPP; | 
 | 7860 |  | 
 | 7861 | 	if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | 
 | 7862 | 	    !info->attrs[NL80211_ATTR_MAC]) | 
 | 7863 | 		return -EINVAL; | 
 | 7864 |  | 
 | 7865 | 	operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | 
 | 7866 | 	peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 7867 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7868 | 	return rdev_tdls_oper(rdev, dev, peer, operation); | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7869 | } | 
 | 7870 |  | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7871 | static int nl80211_remain_on_channel(struct sk_buff *skb, | 
 | 7872 | 				     struct genl_info *info) | 
 | 7873 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7874 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7875 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7876 | 	struct cfg80211_chan_def chandef; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7877 | 	struct sk_buff *msg; | 
 | 7878 | 	void *hdr; | 
 | 7879 | 	u64 cookie; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7880 | 	u32 duration; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7881 | 	int err; | 
 | 7882 |  | 
 | 7883 | 	if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | 
 | 7884 | 	    !info->attrs[NL80211_ATTR_DURATION]) | 
 | 7885 | 		return -EINVAL; | 
 | 7886 |  | 
 | 7887 | 	duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | 
 | 7888 |  | 
| Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7889 | 	if (!rdev->ops->remain_on_channel || | 
 | 7890 | 	    !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7891 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7892 |  | 
| Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7893 | 	/* | 
 | 7894 | 	 * We should be on that channel for at least a minimum amount of | 
 | 7895 | 	 * time (10ms) but no longer than the driver supports. | 
 | 7896 | 	 */ | 
 | 7897 | 	if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | 
 | 7898 | 	    duration > rdev->wiphy.max_remain_on_channel_duration) | 
 | 7899 | 		return -EINVAL; | 
 | 7900 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7901 | 	err = nl80211_parse_chandef(rdev, info, &chandef); | 
 | 7902 | 	if (err) | 
 | 7903 | 		return err; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7904 |  | 
 | 7905 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7906 | 	if (!msg) | 
 | 7907 | 		return -ENOMEM; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7908 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7909 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7910 | 			     NL80211_CMD_REMAIN_ON_CHANNEL); | 
| Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7911 | 	if (!hdr) { | 
 | 7912 | 		err = -ENOBUFS; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7913 | 		goto free_msg; | 
 | 7914 | 	} | 
 | 7915 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7916 | 	err = rdev_remain_on_channel(rdev, wdev, chandef.chan, | 
 | 7917 | 				     duration, &cookie); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7918 |  | 
 | 7919 | 	if (err) | 
 | 7920 | 		goto free_msg; | 
 | 7921 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7922 | 	if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | 
 | 7923 | 		goto nla_put_failure; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7924 |  | 
 | 7925 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7926 |  | 
 | 7927 | 	return genlmsg_reply(msg, info); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7928 |  | 
 | 7929 |  nla_put_failure: | 
 | 7930 | 	err = -ENOBUFS; | 
 | 7931 |  free_msg: | 
 | 7932 | 	nlmsg_free(msg); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7933 | 	return err; | 
 | 7934 | } | 
 | 7935 |  | 
 | 7936 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | 
 | 7937 | 					    struct genl_info *info) | 
 | 7938 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7939 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7940 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7941 | 	u64 cookie; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7942 |  | 
 | 7943 | 	if (!info->attrs[NL80211_ATTR_COOKIE]) | 
 | 7944 | 		return -EINVAL; | 
 | 7945 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7946 | 	if (!rdev->ops->cancel_remain_on_channel) | 
 | 7947 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7948 |  | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7949 | 	cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
 | 7950 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7951 | 	return rdev_cancel_remain_on_channel(rdev, wdev, cookie); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7952 | } | 
 | 7953 |  | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7954 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, | 
 | 7955 | 			   u8 *rates, u8 rates_len) | 
 | 7956 | { | 
 | 7957 | 	u8 i; | 
 | 7958 | 	u32 mask = 0; | 
 | 7959 |  | 
 | 7960 | 	for (i = 0; i < rates_len; i++) { | 
 | 7961 | 		int rate = (rates[i] & 0x7f) * 5; | 
 | 7962 | 		int ridx; | 
 | 7963 | 		for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | 
 | 7964 | 			struct ieee80211_rate *srate = | 
 | 7965 | 				&sband->bitrates[ridx]; | 
 | 7966 | 			if (rate == srate->bitrate) { | 
 | 7967 | 				mask |= 1 << ridx; | 
 | 7968 | 				break; | 
 | 7969 | 			} | 
 | 7970 | 		} | 
 | 7971 | 		if (ridx == sband->n_bitrates) | 
 | 7972 | 			return 0; /* rate not found */ | 
 | 7973 | 	} | 
 | 7974 |  | 
 | 7975 | 	return mask; | 
 | 7976 | } | 
 | 7977 |  | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7978 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | 
 | 7979 | 			       u8 *rates, u8 rates_len, | 
 | 7980 | 			       u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | 
 | 7981 | { | 
 | 7982 | 	u8 i; | 
 | 7983 |  | 
 | 7984 | 	memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | 
 | 7985 |  | 
 | 7986 | 	for (i = 0; i < rates_len; i++) { | 
 | 7987 | 		int ridx, rbit; | 
 | 7988 |  | 
 | 7989 | 		ridx = rates[i] / 8; | 
 | 7990 | 		rbit = BIT(rates[i] % 8); | 
 | 7991 |  | 
 | 7992 | 		/* check validity */ | 
| Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7993 | 		if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7994 | 			return false; | 
 | 7995 |  | 
 | 7996 | 		/* check availability */ | 
 | 7997 | 		if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | 
 | 7998 | 			mcs[ridx] |= rbit; | 
 | 7999 | 		else | 
 | 8000 | 			return false; | 
 | 8001 | 	} | 
 | 8002 |  | 
 | 8003 | 	return true; | 
 | 8004 | } | 
 | 8005 |  | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8006 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | 
 | 8007 | { | 
 | 8008 | 	u16 mcs_mask = 0; | 
 | 8009 |  | 
 | 8010 | 	switch (vht_mcs_map) { | 
 | 8011 | 	case IEEE80211_VHT_MCS_NOT_SUPPORTED: | 
 | 8012 | 		break; | 
 | 8013 | 	case IEEE80211_VHT_MCS_SUPPORT_0_7: | 
 | 8014 | 		mcs_mask = 0x00FF; | 
 | 8015 | 		break; | 
 | 8016 | 	case IEEE80211_VHT_MCS_SUPPORT_0_8: | 
 | 8017 | 		mcs_mask = 0x01FF; | 
 | 8018 | 		break; | 
 | 8019 | 	case IEEE80211_VHT_MCS_SUPPORT_0_9: | 
 | 8020 | 		mcs_mask = 0x03FF; | 
 | 8021 | 		break; | 
 | 8022 | 	default: | 
 | 8023 | 		break; | 
 | 8024 | 	} | 
 | 8025 |  | 
 | 8026 | 	return mcs_mask; | 
 | 8027 | } | 
 | 8028 |  | 
 | 8029 | static void vht_build_mcs_mask(u16 vht_mcs_map, | 
 | 8030 | 			       u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | 
 | 8031 | { | 
 | 8032 | 	u8 nss; | 
 | 8033 |  | 
 | 8034 | 	for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | 
 | 8035 | 		vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | 
 | 8036 | 		vht_mcs_map >>= 2; | 
 | 8037 | 	} | 
 | 8038 | } | 
 | 8039 |  | 
 | 8040 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | 
 | 8041 | 			     struct nl80211_txrate_vht *txrate, | 
 | 8042 | 			     u16 mcs[NL80211_VHT_NSS_MAX]) | 
 | 8043 | { | 
 | 8044 | 	u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | 
 | 8045 | 	u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | 
 | 8046 | 	u8 i; | 
 | 8047 |  | 
 | 8048 | 	if (!sband->vht_cap.vht_supported) | 
 | 8049 | 		return false; | 
 | 8050 |  | 
 | 8051 | 	memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | 
 | 8052 |  | 
 | 8053 | 	/* Build vht_mcs_mask from VHT capabilities */ | 
 | 8054 | 	vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | 
 | 8055 |  | 
 | 8056 | 	for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | 
 | 8057 | 		if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | 
 | 8058 | 			mcs[i] = txrate->mcs[i]; | 
 | 8059 | 		else | 
 | 8060 | 			return false; | 
 | 8061 | 	} | 
 | 8062 |  | 
 | 8063 | 	return true; | 
 | 8064 | } | 
 | 8065 |  | 
| Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8066 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8067 | 	[NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | 
 | 8068 | 				    .len = NL80211_MAX_SUPP_RATES }, | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8069 | 	[NL80211_TXRATE_HT] = { .type = NLA_BINARY, | 
 | 8070 | 				.len = NL80211_MAX_SUPP_HT_RATES }, | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8071 | 	[NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | 
| Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8072 | 	[NL80211_TXRATE_GI] = { .type = NLA_U8 }, | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8073 | }; | 
 | 8074 |  | 
 | 8075 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | 
 | 8076 | 				       struct genl_info *info) | 
 | 8077 | { | 
 | 8078 | 	struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8079 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8080 | 	struct cfg80211_bitrate_mask mask; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8081 | 	int rem, i; | 
 | 8082 | 	struct net_device *dev = info->user_ptr[1]; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8083 | 	struct nlattr *tx_rates; | 
 | 8084 | 	struct ieee80211_supported_band *sband; | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8085 | 	u16 vht_tx_mcs_map; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8086 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8087 | 	if (!rdev->ops->set_bitrate_mask) | 
 | 8088 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8089 |  | 
 | 8090 | 	memset(&mask, 0, sizeof(mask)); | 
 | 8091 | 	/* Default to all rates enabled */ | 
 | 8092 | 	for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | 
 | 8093 | 		sband = rdev->wiphy.bands[i]; | 
| Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8094 |  | 
 | 8095 | 		if (!sband) | 
 | 8096 | 			continue; | 
 | 8097 |  | 
 | 8098 | 		mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8099 | 		memcpy(mask.control[i].ht_mcs, | 
| Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8100 | 		       sband->ht_cap.mcs.rx_mask, | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8101 | 		       sizeof(mask.control[i].ht_mcs)); | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8102 |  | 
 | 8103 | 		if (!sband->vht_cap.vht_supported) | 
 | 8104 | 			continue; | 
 | 8105 |  | 
 | 8106 | 		vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | 
 | 8107 | 		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] | 8108 | 	} | 
 | 8109 |  | 
| Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8110 | 	/* if no rates are given set it back to the defaults */ | 
 | 8111 | 	if (!info->attrs[NL80211_ATTR_TX_RATES]) | 
 | 8112 | 		goto out; | 
 | 8113 |  | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8114 | 	/* | 
 | 8115 | 	 * The nested attribute uses enum nl80211_band as the index. This maps | 
 | 8116 | 	 * directly to the enum ieee80211_band values used in cfg80211. | 
 | 8117 | 	 */ | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8118 | 	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] | 8119 | 	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] | 8120 | 		enum ieee80211_band band = nla_type(tx_rates); | 
| Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8121 | 		int err; | 
 | 8122 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8123 | 		if (band < 0 || band >= IEEE80211_NUM_BANDS) | 
 | 8124 | 			return -EINVAL; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8125 | 		sband = rdev->wiphy.bands[band]; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8126 | 		if (sband == NULL) | 
 | 8127 | 			return -EINVAL; | 
| Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8128 | 		err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | 
 | 8129 | 				nla_len(tx_rates), nl80211_txattr_policy); | 
 | 8130 | 		if (err) | 
 | 8131 | 			return err; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8132 | 		if (tb[NL80211_TXRATE_LEGACY]) { | 
 | 8133 | 			mask.control[band].legacy = rateset_to_mask( | 
 | 8134 | 				sband, | 
 | 8135 | 				nla_data(tb[NL80211_TXRATE_LEGACY]), | 
 | 8136 | 				nla_len(tb[NL80211_TXRATE_LEGACY])); | 
| Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8137 | 			if ((mask.control[band].legacy == 0) && | 
 | 8138 | 			    nla_len(tb[NL80211_TXRATE_LEGACY])) | 
 | 8139 | 				return -EINVAL; | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8140 | 		} | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8141 | 		if (tb[NL80211_TXRATE_HT]) { | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8142 | 			if (!ht_rateset_to_mask( | 
 | 8143 | 					sband, | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8144 | 					nla_data(tb[NL80211_TXRATE_HT]), | 
 | 8145 | 					nla_len(tb[NL80211_TXRATE_HT]), | 
 | 8146 | 					mask.control[band].ht_mcs)) | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8147 | 				return -EINVAL; | 
 | 8148 | 		} | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8149 | 		if (tb[NL80211_TXRATE_VHT]) { | 
 | 8150 | 			if (!vht_set_mcs_mask( | 
 | 8151 | 					sband, | 
 | 8152 | 					nla_data(tb[NL80211_TXRATE_VHT]), | 
 | 8153 | 					mask.control[band].vht_mcs)) | 
 | 8154 | 				return -EINVAL; | 
 | 8155 | 		} | 
| Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8156 | 		if (tb[NL80211_TXRATE_GI]) { | 
 | 8157 | 			mask.control[band].gi = | 
 | 8158 | 				nla_get_u8(tb[NL80211_TXRATE_GI]); | 
 | 8159 | 			if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | 
 | 8160 | 				return -EINVAL; | 
 | 8161 | 		} | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8162 |  | 
 | 8163 | 		if (mask.control[band].legacy == 0) { | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8164 | 			/* don't allow empty legacy rates if HT or VHT | 
 | 8165 | 			 * are not even supported. | 
 | 8166 | 			 */ | 
 | 8167 | 			if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | 
 | 8168 | 			      rdev->wiphy.bands[band]->vht_cap.vht_supported)) | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8169 | 				return -EINVAL; | 
 | 8170 |  | 
 | 8171 | 			for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | 
| Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8172 | 				if (mask.control[band].ht_mcs[i]) | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8173 | 					goto out; | 
 | 8174 |  | 
 | 8175 | 			for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | 
 | 8176 | 				if (mask.control[band].vht_mcs[i]) | 
 | 8177 | 					goto out; | 
| Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8178 |  | 
 | 8179 | 			/* legacy and mcs rates may not be both empty */ | 
| Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8180 | 			return -EINVAL; | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8181 | 		} | 
 | 8182 | 	} | 
 | 8183 |  | 
| Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8184 | out: | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8185 | 	return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8186 | } | 
 | 8187 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8188 | 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] | 8189 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8190 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8191 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8192 | 	u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8193 |  | 
 | 8194 | 	if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | 
 | 8195 | 		return -EINVAL; | 
 | 8196 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8197 | 	if (info->attrs[NL80211_ATTR_FRAME_TYPE]) | 
 | 8198 | 		frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8199 |  | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8200 | 	switch (wdev->iftype) { | 
 | 8201 | 	case NL80211_IFTYPE_STATION: | 
 | 8202 | 	case NL80211_IFTYPE_ADHOC: | 
 | 8203 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 8204 | 	case NL80211_IFTYPE_AP: | 
 | 8205 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 8206 | 	case NL80211_IFTYPE_MESH_POINT: | 
 | 8207 | 	case NL80211_IFTYPE_P2P_GO: | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8208 | 	case NL80211_IFTYPE_P2P_DEVICE: | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8209 | 		break; | 
 | 8210 | 	default: | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8211 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8212 | 	} | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8213 |  | 
 | 8214 | 	/* not much point in registering if we can't reply */ | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | 	if (!rdev->ops->mgmt_tx) | 
 | 8216 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8217 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8218 | 	return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8219 | 			nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), | 
 | 8220 | 			nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8221 | } | 
 | 8222 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8223 | 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] | 8224 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8225 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8226 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8227 | 	struct cfg80211_chan_def chandef; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8228 | 	int err; | 
| Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8229 | 	void *hdr = NULL; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8230 | 	u64 cookie; | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8231 | 	struct sk_buff *msg = NULL; | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8232 | 	struct cfg80211_mgmt_tx_params params = { | 
 | 8233 | 		.dont_wait_for_ack = | 
 | 8234 | 			info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | 
 | 8235 | 	}; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8236 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8237 | 	if (!info->attrs[NL80211_ATTR_FRAME]) | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8238 | 		return -EINVAL; | 
 | 8239 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8240 | 	if (!rdev->ops->mgmt_tx) | 
 | 8241 | 		return -EOPNOTSUPP; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8242 |  | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8243 | 	switch (wdev->iftype) { | 
| Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8244 | 	case NL80211_IFTYPE_P2P_DEVICE: | 
 | 8245 | 		if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 
 | 8246 | 			return -EINVAL; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8247 | 	case NL80211_IFTYPE_STATION: | 
 | 8248 | 	case NL80211_IFTYPE_ADHOC: | 
 | 8249 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 8250 | 	case NL80211_IFTYPE_AP: | 
 | 8251 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 8252 | 	case NL80211_IFTYPE_MESH_POINT: | 
 | 8253 | 	case NL80211_IFTYPE_P2P_GO: | 
 | 8254 | 		break; | 
 | 8255 | 	default: | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8256 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8257 | 	} | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8258 |  | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8259 | 	if (info->attrs[NL80211_ATTR_DURATION]) { | 
| Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8260 | 		if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8261 | 			return -EINVAL; | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8262 | 		params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | 
| Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8263 |  | 
 | 8264 | 		/* | 
 | 8265 | 		 * We should wait on the channel for at least a minimum amount | 
 | 8266 | 		 * of time (10ms) but no longer than the driver supports. | 
 | 8267 | 		 */ | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8268 | 		if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | 
 | 8269 | 		    params.wait > rdev->wiphy.max_remain_on_channel_duration) | 
| Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8270 | 			return -EINVAL; | 
 | 8271 |  | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8272 | 	} | 
 | 8273 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8274 | 	params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8275 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8276 | 	if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) | 
| Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8277 | 		return -EINVAL; | 
 | 8278 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8279 | 	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] | 8280 |  | 
| Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8281 | 	/* get the channel if any has been specified, otherwise pass NULL to | 
 | 8282 | 	 * the driver. The latter will use the current one | 
 | 8283 | 	 */ | 
 | 8284 | 	chandef.chan = NULL; | 
 | 8285 | 	if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
 | 8286 | 		err = nl80211_parse_chandef(rdev, info, &chandef); | 
 | 8287 | 		if (err) | 
 | 8288 | 			return err; | 
 | 8289 | 	} | 
 | 8290 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8291 | 	if (!chandef.chan && params.offchan) | 
| Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8292 | 		return -EINVAL; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8293 |  | 
| Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8294 | 	params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); | 
 | 8295 | 	params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | 
 | 8296 |  | 
 | 8297 | 	if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | 
 | 8298 | 		int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | 
 | 8299 | 		int i; | 
 | 8300 |  | 
 | 8301 | 		if (len % sizeof(u16)) | 
 | 8302 | 			return -EINVAL; | 
 | 8303 |  | 
 | 8304 | 		params.n_csa_offsets = len / sizeof(u16); | 
 | 8305 | 		params.csa_offsets = | 
 | 8306 | 			nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | 
 | 8307 |  | 
 | 8308 | 		/* check that all the offsets fit the frame */ | 
 | 8309 | 		for (i = 0; i < params.n_csa_offsets; i++) { | 
 | 8310 | 			if (params.csa_offsets[i] >= params.len) | 
 | 8311 | 				return -EINVAL; | 
 | 8312 | 		} | 
 | 8313 | 	} | 
 | 8314 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8315 | 	if (!params.dont_wait_for_ack) { | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8316 | 		msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 8317 | 		if (!msg) | 
 | 8318 | 			return -ENOMEM; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8319 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8320 | 		hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8321 | 				     NL80211_CMD_FRAME); | 
| Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8322 | 		if (!hdr) { | 
 | 8323 | 			err = -ENOBUFS; | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8324 | 			goto free_msg; | 
 | 8325 | 		} | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8326 | 	} | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8327 |  | 
| Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8328 | 	params.chan = chandef.chan; | 
 | 8329 | 	err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8330 | 	if (err) | 
 | 8331 | 		goto free_msg; | 
 | 8332 |  | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8333 | 	if (msg) { | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8334 | 		if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | 
 | 8335 | 			goto nla_put_failure; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8336 |  | 
| Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8337 | 		genlmsg_end(msg, hdr); | 
 | 8338 | 		return genlmsg_reply(msg, info); | 
 | 8339 | 	} | 
 | 8340 |  | 
 | 8341 | 	return 0; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8342 |  | 
 | 8343 |  nla_put_failure: | 
 | 8344 | 	err = -ENOBUFS; | 
 | 8345 |  free_msg: | 
 | 8346 | 	nlmsg_free(msg); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8347 | 	return err; | 
 | 8348 | } | 
 | 8349 |  | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8350 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) | 
 | 8351 | { | 
 | 8352 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8353 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8354 | 	u64 cookie; | 
 | 8355 |  | 
 | 8356 | 	if (!info->attrs[NL80211_ATTR_COOKIE]) | 
 | 8357 | 		return -EINVAL; | 
 | 8358 |  | 
 | 8359 | 	if (!rdev->ops->mgmt_tx_cancel_wait) | 
 | 8360 | 		return -EOPNOTSUPP; | 
 | 8361 |  | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8362 | 	switch (wdev->iftype) { | 
 | 8363 | 	case NL80211_IFTYPE_STATION: | 
 | 8364 | 	case NL80211_IFTYPE_ADHOC: | 
 | 8365 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 8366 | 	case NL80211_IFTYPE_AP: | 
 | 8367 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 8368 | 	case NL80211_IFTYPE_P2P_GO: | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8369 | 	case NL80211_IFTYPE_P2P_DEVICE: | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8370 | 		break; | 
 | 8371 | 	default: | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8372 | 		return -EOPNOTSUPP; | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8373 | 	} | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8374 |  | 
 | 8375 | 	cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 
 | 8376 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8377 | 	return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8378 | } | 
 | 8379 |  | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8380 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) | 
 | 8381 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8382 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8383 | 	struct wireless_dev *wdev; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8384 | 	struct net_device *dev = info->user_ptr[1]; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8385 | 	u8 ps_state; | 
 | 8386 | 	bool state; | 
 | 8387 | 	int err; | 
 | 8388 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8389 | 	if (!info->attrs[NL80211_ATTR_PS_STATE]) | 
 | 8390 | 		return -EINVAL; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8391 |  | 
 | 8392 | 	ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | 
 | 8393 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8394 | 	if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) | 
 | 8395 | 		return -EINVAL; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8396 |  | 
 | 8397 | 	wdev = dev->ieee80211_ptr; | 
 | 8398 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8399 | 	if (!rdev->ops->set_power_mgmt) | 
 | 8400 | 		return -EOPNOTSUPP; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8401 |  | 
 | 8402 | 	state = (ps_state == NL80211_PS_ENABLED) ? true : false; | 
 | 8403 |  | 
 | 8404 | 	if (state == wdev->ps) | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8405 | 		return 0; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8406 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8407 | 	err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8408 | 	if (!err) | 
 | 8409 | 		wdev->ps = state; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8410 | 	return err; | 
 | 8411 | } | 
 | 8412 |  | 
 | 8413 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | 
 | 8414 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8415 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8416 | 	enum nl80211_ps_state ps_state; | 
 | 8417 | 	struct wireless_dev *wdev; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8418 | 	struct net_device *dev = info->user_ptr[1]; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8419 | 	struct sk_buff *msg; | 
 | 8420 | 	void *hdr; | 
 | 8421 | 	int err; | 
 | 8422 |  | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8423 | 	wdev = dev->ieee80211_ptr; | 
 | 8424 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8425 | 	if (!rdev->ops->set_power_mgmt) | 
 | 8426 | 		return -EOPNOTSUPP; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8427 |  | 
 | 8428 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8429 | 	if (!msg) | 
 | 8430 | 		return -ENOMEM; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8431 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8432 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8433 | 			     NL80211_CMD_GET_POWER_SAVE); | 
 | 8434 | 	if (!hdr) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8435 | 		err = -ENOBUFS; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8436 | 		goto free_msg; | 
 | 8437 | 	} | 
 | 8438 |  | 
 | 8439 | 	if (wdev->ps) | 
 | 8440 | 		ps_state = NL80211_PS_ENABLED; | 
 | 8441 | 	else | 
 | 8442 | 		ps_state = NL80211_PS_DISABLED; | 
 | 8443 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8444 | 	if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) | 
 | 8445 | 		goto nla_put_failure; | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8446 |  | 
 | 8447 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8448 | 	return genlmsg_reply(msg, info); | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8449 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8450 |  nla_put_failure: | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8451 | 	err = -ENOBUFS; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8452 |  free_msg: | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8453 | 	nlmsg_free(msg); | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8454 | 	return err; | 
 | 8455 | } | 
 | 8456 |  | 
| Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8457 | static const struct nla_policy | 
 | 8458 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8459 | 	[NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | 
 | 8460 | 	[NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | 
 | 8461 | 	[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8462 | 	[NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, | 
 | 8463 | 	[NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | 
 | 8464 | 	[NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8465 | }; | 
 | 8466 |  | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8467 | static int nl80211_set_cqm_txe(struct genl_info *info, | 
| Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8468 | 			       u32 rate, u32 pkts, u32 intvl) | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8469 | { | 
 | 8470 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8471 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8472 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8473 |  | 
| Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8474 | 	if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8475 | 		return -EINVAL; | 
 | 8476 |  | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8477 | 	if (!rdev->ops->set_cqm_txe_config) | 
 | 8478 | 		return -EOPNOTSUPP; | 
 | 8479 |  | 
 | 8480 | 	if (wdev->iftype != NL80211_IFTYPE_STATION && | 
 | 8481 | 	    wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 8482 | 		return -EOPNOTSUPP; | 
 | 8483 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8484 | 	return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8485 | } | 
 | 8486 |  | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8487 | static int nl80211_set_cqm_rssi(struct genl_info *info, | 
 | 8488 | 				s32 threshold, u32 hysteresis) | 
 | 8489 | { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8490 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | 	struct net_device *dev = info->user_ptr[1]; | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8492 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8493 |  | 
 | 8494 | 	if (threshold > 0) | 
 | 8495 | 		return -EINVAL; | 
 | 8496 |  | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8497 | 	/* disabling - hysteresis should also be zero then */ | 
 | 8498 | 	if (threshold == 0) | 
 | 8499 | 		hysteresis = 0; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8500 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8501 | 	if (!rdev->ops->set_cqm_rssi_config) | 
 | 8502 | 		return -EOPNOTSUPP; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8503 |  | 
| Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8504 | 	if (wdev->iftype != NL80211_IFTYPE_STATION && | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8505 | 	    wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | 
 | 8506 | 		return -EOPNOTSUPP; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8507 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8508 | 	return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8509 | } | 
 | 8510 |  | 
 | 8511 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | 
 | 8512 | { | 
 | 8513 | 	struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | 
 | 8514 | 	struct nlattr *cqm; | 
 | 8515 | 	int err; | 
 | 8516 |  | 
 | 8517 | 	cqm = info->attrs[NL80211_ATTR_CQM]; | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8518 | 	if (!cqm) | 
 | 8519 | 		return -EINVAL; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8520 |  | 
 | 8521 | 	err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | 
 | 8522 | 			       nl80211_attr_cqm_policy); | 
 | 8523 | 	if (err) | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8524 | 		return err; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8525 |  | 
 | 8526 | 	if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | 
 | 8527 | 	    attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8528 | 		s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | 
 | 8529 | 		u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8530 |  | 
| Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8531 | 		return nl80211_set_cqm_rssi(info, threshold, hysteresis); | 
 | 8532 | 	} | 
 | 8533 |  | 
 | 8534 | 	if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | 
 | 8535 | 	    attrs[NL80211_ATTR_CQM_TXE_PKTS] && | 
 | 8536 | 	    attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | 
 | 8537 | 		u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | 
 | 8538 | 		u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | 
 | 8539 | 		u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | 
 | 8540 |  | 
 | 8541 | 		return nl80211_set_cqm_txe(info, rate, pkts, intvl); | 
 | 8542 | 	} | 
 | 8543 |  | 
 | 8544 | 	return -EINVAL; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8545 | } | 
 | 8546 |  | 
| Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8547 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) | 
 | 8548 | { | 
 | 8549 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8550 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 8551 | 	struct ocb_setup setup = {}; | 
 | 8552 | 	int err; | 
 | 8553 |  | 
 | 8554 | 	err = nl80211_parse_chandef(rdev, info, &setup.chandef); | 
 | 8555 | 	if (err) | 
 | 8556 | 		return err; | 
 | 8557 |  | 
 | 8558 | 	return cfg80211_join_ocb(rdev, dev, &setup); | 
 | 8559 | } | 
 | 8560 |  | 
 | 8561 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | 
 | 8562 | { | 
 | 8563 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8564 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 8565 |  | 
 | 8566 | 	return cfg80211_leave_ocb(rdev, dev); | 
 | 8567 | } | 
 | 8568 |  | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8569 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) | 
 | 8570 | { | 
 | 8571 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8572 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 8573 | 	struct mesh_config cfg; | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8574 | 	struct mesh_setup setup; | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8575 | 	int err; | 
 | 8576 |  | 
 | 8577 | 	/* start with default */ | 
 | 8578 | 	memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8579 | 	memcpy(&setup, &default_mesh_setup, sizeof(setup)); | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8580 |  | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8581 | 	if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8582 | 		/* and parse parameters if given */ | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8583 | 		err = nl80211_parse_mesh_config(info, &cfg, NULL); | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8584 | 		if (err) | 
 | 8585 | 			return err; | 
 | 8586 | 	} | 
 | 8587 |  | 
 | 8588 | 	if (!info->attrs[NL80211_ATTR_MESH_ID] || | 
 | 8589 | 	    !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | 
 | 8590 | 		return -EINVAL; | 
 | 8591 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8592 | 	setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | 
 | 8593 | 	setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 
 | 8594 |  | 
| Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8595 | 	if (info->attrs[NL80211_ATTR_MCAST_RATE] && | 
 | 8596 | 	    !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | 
 | 8597 | 			    nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | 
 | 8598 | 			return -EINVAL; | 
 | 8599 |  | 
| Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8600 | 	if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | 
 | 8601 | 		setup.beacon_interval = | 
 | 8602 | 			nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | 
 | 8603 | 		if (setup.beacon_interval < 10 || | 
 | 8604 | 		    setup.beacon_interval > 10000) | 
 | 8605 | 			return -EINVAL; | 
 | 8606 | 	} | 
 | 8607 |  | 
 | 8608 | 	if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | 
 | 8609 | 		setup.dtim_period = | 
 | 8610 | 			nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | 
 | 8611 | 		if (setup.dtim_period < 1 || setup.dtim_period > 100) | 
 | 8612 | 			return -EINVAL; | 
 | 8613 | 	} | 
 | 8614 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8615 | 	if (info->attrs[NL80211_ATTR_MESH_SETUP]) { | 
 | 8616 | 		/* parse additional setup parameters if given */ | 
 | 8617 | 		err = nl80211_parse_mesh_setup(info, &setup); | 
 | 8618 | 		if (err) | 
 | 8619 | 			return err; | 
 | 8620 | 	} | 
 | 8621 |  | 
| Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8622 | 	if (setup.user_mpm) | 
 | 8623 | 		cfg.auto_open_plinks = false; | 
 | 8624 |  | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8625 | 	if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8626 | 		err = nl80211_parse_chandef(rdev, info, &setup.chandef); | 
 | 8627 | 		if (err) | 
 | 8628 | 			return err; | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8629 | 	} else { | 
 | 8630 | 		/* cfg80211_join_mesh() will sort it out */ | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8631 | 		setup.chandef.chan = NULL; | 
| Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8632 | 	} | 
 | 8633 |  | 
| Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8634 | 	if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 
 | 8635 | 		u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 8636 | 		int n_rates = | 
 | 8637 | 			nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 
 | 8638 | 		struct ieee80211_supported_band *sband; | 
 | 8639 |  | 
 | 8640 | 		if (!setup.chandef.chan) | 
 | 8641 | 			return -EINVAL; | 
 | 8642 |  | 
 | 8643 | 		sband = rdev->wiphy.bands[setup.chandef.chan->band]; | 
 | 8644 |  | 
 | 8645 | 		err = ieee80211_get_ratemask(sband, rates, n_rates, | 
 | 8646 | 					     &setup.basic_rates); | 
 | 8647 | 		if (err) | 
 | 8648 | 			return err; | 
 | 8649 | 	} | 
 | 8650 |  | 
| Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8651 | 	return cfg80211_join_mesh(rdev, dev, &setup, &cfg); | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8652 | } | 
 | 8653 |  | 
 | 8654 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | 
 | 8655 | { | 
 | 8656 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8657 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 8658 |  | 
 | 8659 | 	return cfg80211_leave_mesh(rdev, dev); | 
 | 8660 | } | 
 | 8661 |  | 
| Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8662 | #ifdef CONFIG_PM | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8663 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, | 
 | 8664 | 					struct cfg80211_registered_device *rdev) | 
 | 8665 | { | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8666 | 	struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8667 | 	struct nlattr *nl_pats, *nl_pat; | 
 | 8668 | 	int i, pat_len; | 
 | 8669 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8670 | 	if (!wowlan->n_patterns) | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8671 | 		return 0; | 
 | 8672 |  | 
 | 8673 | 	nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | 
 | 8674 | 	if (!nl_pats) | 
 | 8675 | 		return -ENOBUFS; | 
 | 8676 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8677 | 	for (i = 0; i < wowlan->n_patterns; i++) { | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8678 | 		nl_pat = nla_nest_start(msg, i + 1); | 
 | 8679 | 		if (!nl_pat) | 
 | 8680 | 			return -ENOBUFS; | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8681 | 		pat_len = wowlan->patterns[i].pattern_len; | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8682 | 		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] | 8683 | 			    wowlan->patterns[i].mask) || | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8684 | 		    nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | 
 | 8685 | 			    wowlan->patterns[i].pattern) || | 
 | 8686 | 		    nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8687 | 				wowlan->patterns[i].pkt_offset)) | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8688 | 			return -ENOBUFS; | 
 | 8689 | 		nla_nest_end(msg, nl_pat); | 
 | 8690 | 	} | 
 | 8691 | 	nla_nest_end(msg, nl_pats); | 
 | 8692 |  | 
 | 8693 | 	return 0; | 
 | 8694 | } | 
 | 8695 |  | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8696 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, | 
 | 8697 | 				   struct cfg80211_wowlan_tcp *tcp) | 
 | 8698 | { | 
 | 8699 | 	struct nlattr *nl_tcp; | 
 | 8700 |  | 
 | 8701 | 	if (!tcp) | 
 | 8702 | 		return 0; | 
 | 8703 |  | 
 | 8704 | 	nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | 
 | 8705 | 	if (!nl_tcp) | 
 | 8706 | 		return -ENOBUFS; | 
 | 8707 |  | 
 | 8708 | 	if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | 
 | 8709 | 	    nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | 
 | 8710 | 	    nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | 
 | 8711 | 	    nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | 
 | 8712 | 	    nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | 
 | 8713 | 	    nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | 
 | 8714 | 		    tcp->payload_len, tcp->payload) || | 
 | 8715 | 	    nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | 
 | 8716 | 			tcp->data_interval) || | 
 | 8717 | 	    nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | 
 | 8718 | 		    tcp->wake_len, tcp->wake_data) || | 
 | 8719 | 	    nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | 
 | 8720 | 		    DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | 
 | 8721 | 		return -ENOBUFS; | 
 | 8722 |  | 
 | 8723 | 	if (tcp->payload_seq.len && | 
 | 8724 | 	    nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | 
 | 8725 | 		    sizeof(tcp->payload_seq), &tcp->payload_seq)) | 
 | 8726 | 		return -ENOBUFS; | 
 | 8727 |  | 
 | 8728 | 	if (tcp->payload_tok.len && | 
 | 8729 | 	    nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | 
 | 8730 | 		    sizeof(tcp->payload_tok) + tcp->tokens_size, | 
 | 8731 | 		    &tcp->payload_tok)) | 
 | 8732 | 		return -ENOBUFS; | 
 | 8733 |  | 
| Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8734 | 	nla_nest_end(msg, nl_tcp); | 
 | 8735 |  | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8736 | 	return 0; | 
 | 8737 | } | 
 | 8738 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8739 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) | 
 | 8740 | { | 
 | 8741 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8742 | 	struct sk_buff *msg; | 
 | 8743 | 	void *hdr; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8744 | 	u32 size = NLMSG_DEFAULT_SIZE; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8745 |  | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8746 | 	if (!rdev->wiphy.wowlan) | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8747 | 		return -EOPNOTSUPP; | 
 | 8748 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8749 | 	if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8750 | 		/* adjust size to have room for all the data */ | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8751 | 		size += rdev->wiphy.wowlan_config->tcp->tokens_size + | 
 | 8752 | 			rdev->wiphy.wowlan_config->tcp->payload_len + | 
 | 8753 | 			rdev->wiphy.wowlan_config->tcp->wake_len + | 
 | 8754 | 			rdev->wiphy.wowlan_config->tcp->wake_len / 8; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8755 | 	} | 
 | 8756 |  | 
 | 8757 | 	msg = nlmsg_new(size, GFP_KERNEL); | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8758 | 	if (!msg) | 
 | 8759 | 		return -ENOMEM; | 
 | 8760 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8761 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8762 | 			     NL80211_CMD_GET_WOWLAN); | 
 | 8763 | 	if (!hdr) | 
 | 8764 | 		goto nla_put_failure; | 
 | 8765 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8766 | 	if (rdev->wiphy.wowlan_config) { | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8767 | 		struct nlattr *nl_wowlan; | 
 | 8768 |  | 
 | 8769 | 		nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | 
 | 8770 | 		if (!nl_wowlan) | 
 | 8771 | 			goto nla_put_failure; | 
 | 8772 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8773 | 		if ((rdev->wiphy.wowlan_config->any && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8774 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8775 | 		    (rdev->wiphy.wowlan_config->disconnect && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8776 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8777 | 		    (rdev->wiphy.wowlan_config->magic_pkt && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8778 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8779 | 		    (rdev->wiphy.wowlan_config->gtk_rekey_failure && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8780 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8781 | 		    (rdev->wiphy.wowlan_config->eap_identity_req && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8782 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8783 | 		    (rdev->wiphy.wowlan_config->four_way_handshake && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8784 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8785 | 		    (rdev->wiphy.wowlan_config->rfkill_release && | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8786 | 		     nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | 
 | 8787 | 			goto nla_put_failure; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8788 |  | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8789 | 		if (nl80211_send_wowlan_patterns(msg, rdev)) | 
 | 8790 | 			goto nla_put_failure; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8791 |  | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8792 | 		if (nl80211_send_wowlan_tcp(msg, | 
 | 8793 | 					    rdev->wiphy.wowlan_config->tcp)) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8794 | 			goto nla_put_failure; | 
 | 8795 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8796 | 		nla_nest_end(msg, nl_wowlan); | 
 | 8797 | 	} | 
 | 8798 |  | 
 | 8799 | 	genlmsg_end(msg, hdr); | 
 | 8800 | 	return genlmsg_reply(msg, info); | 
 | 8801 |  | 
 | 8802 | nla_put_failure: | 
 | 8803 | 	nlmsg_free(msg); | 
 | 8804 | 	return -ENOBUFS; | 
 | 8805 | } | 
 | 8806 |  | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8807 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, | 
 | 8808 | 				    struct nlattr *attr, | 
 | 8809 | 				    struct cfg80211_wowlan *trig) | 
 | 8810 | { | 
 | 8811 | 	struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | 
 | 8812 | 	struct cfg80211_wowlan_tcp *cfg; | 
 | 8813 | 	struct nl80211_wowlan_tcp_data_token *tok = NULL; | 
 | 8814 | 	struct nl80211_wowlan_tcp_data_seq *seq = NULL; | 
 | 8815 | 	u32 size; | 
 | 8816 | 	u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | 
 | 8817 | 	int err, port; | 
 | 8818 |  | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8819 | 	if (!rdev->wiphy.wowlan->tcp) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8820 | 		return -EINVAL; | 
 | 8821 |  | 
 | 8822 | 	err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | 
 | 8823 | 			nla_data(attr), nla_len(attr), | 
 | 8824 | 			nl80211_wowlan_tcp_policy); | 
 | 8825 | 	if (err) | 
 | 8826 | 		return err; | 
 | 8827 |  | 
 | 8828 | 	if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | 
 | 8829 | 	    !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | 
 | 8830 | 	    !tb[NL80211_WOWLAN_TCP_DST_MAC] || | 
 | 8831 | 	    !tb[NL80211_WOWLAN_TCP_DST_PORT] || | 
 | 8832 | 	    !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | 
 | 8833 | 	    !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | 
 | 8834 | 	    !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | 
 | 8835 | 	    !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | 
 | 8836 | 		return -EINVAL; | 
 | 8837 |  | 
 | 8838 | 	data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8839 | 	if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8840 | 		return -EINVAL; | 
 | 8841 |  | 
 | 8842 | 	if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8843 | 			rdev->wiphy.wowlan->tcp->data_interval_max || | 
| Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8844 | 	    nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8845 | 		return -EINVAL; | 
 | 8846 |  | 
 | 8847 | 	wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8848 | 	if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8849 | 		return -EINVAL; | 
 | 8850 |  | 
 | 8851 | 	wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | 
 | 8852 | 	if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | 
 | 8853 | 		return -EINVAL; | 
 | 8854 |  | 
 | 8855 | 	if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | 
 | 8856 | 		u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | 
 | 8857 |  | 
 | 8858 | 		tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | 
 | 8859 | 		tokens_size = tokln - sizeof(*tok); | 
 | 8860 |  | 
 | 8861 | 		if (!tok->len || tokens_size % tok->len) | 
 | 8862 | 			return -EINVAL; | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8863 | 		if (!rdev->wiphy.wowlan->tcp->tok) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8864 | 			return -EINVAL; | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8865 | 		if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8866 | 			return -EINVAL; | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8867 | 		if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8868 | 			return -EINVAL; | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8869 | 		if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8870 | 			return -EINVAL; | 
 | 8871 | 		if (tok->offset + tok->len > data_size) | 
 | 8872 | 			return -EINVAL; | 
 | 8873 | 	} | 
 | 8874 |  | 
 | 8875 | 	if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | 
 | 8876 | 		seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8877 | 		if (!rdev->wiphy.wowlan->tcp->seq) | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8878 | 			return -EINVAL; | 
 | 8879 | 		if (seq->len == 0 || seq->len > 4) | 
 | 8880 | 			return -EINVAL; | 
 | 8881 | 		if (seq->len + seq->offset > data_size) | 
 | 8882 | 			return -EINVAL; | 
 | 8883 | 	} | 
 | 8884 |  | 
 | 8885 | 	size = sizeof(*cfg); | 
 | 8886 | 	size += data_size; | 
 | 8887 | 	size += wake_size + wake_mask_size; | 
 | 8888 | 	size += tokens_size; | 
 | 8889 |  | 
 | 8890 | 	cfg = kzalloc(size, GFP_KERNEL); | 
 | 8891 | 	if (!cfg) | 
 | 8892 | 		return -ENOMEM; | 
 | 8893 | 	cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | 
 | 8894 | 	cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | 
 | 8895 | 	memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | 
 | 8896 | 	       ETH_ALEN); | 
 | 8897 | 	if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | 
 | 8898 | 		port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | 
 | 8899 | 	else | 
 | 8900 | 		port = 0; | 
 | 8901 | #ifdef CONFIG_INET | 
 | 8902 | 	/* allocate a socket and port for it and use it */ | 
 | 8903 | 	err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | 
 | 8904 | 			    IPPROTO_TCP, &cfg->sock, 1); | 
 | 8905 | 	if (err) { | 
 | 8906 | 		kfree(cfg); | 
 | 8907 | 		return err; | 
 | 8908 | 	} | 
 | 8909 | 	if (inet_csk_get_port(cfg->sock->sk, port)) { | 
 | 8910 | 		sock_release(cfg->sock); | 
 | 8911 | 		kfree(cfg); | 
 | 8912 | 		return -EADDRINUSE; | 
 | 8913 | 	} | 
 | 8914 | 	cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | 
 | 8915 | #else | 
 | 8916 | 	if (!port) { | 
 | 8917 | 		kfree(cfg); | 
 | 8918 | 		return -EINVAL; | 
 | 8919 | 	} | 
 | 8920 | 	cfg->src_port = port; | 
 | 8921 | #endif | 
 | 8922 |  | 
 | 8923 | 	cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | 
 | 8924 | 	cfg->payload_len = data_size; | 
 | 8925 | 	cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | 
 | 8926 | 	memcpy((void *)cfg->payload, | 
 | 8927 | 	       nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | 
 | 8928 | 	       data_size); | 
 | 8929 | 	if (seq) | 
 | 8930 | 		cfg->payload_seq = *seq; | 
 | 8931 | 	cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | 
 | 8932 | 	cfg->wake_len = wake_size; | 
 | 8933 | 	cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | 
 | 8934 | 	memcpy((void *)cfg->wake_data, | 
 | 8935 | 	       nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | 
 | 8936 | 	       wake_size); | 
 | 8937 | 	cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | 
 | 8938 | 			 data_size + wake_size; | 
 | 8939 | 	memcpy((void *)cfg->wake_mask, | 
 | 8940 | 	       nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | 
 | 8941 | 	       wake_mask_size); | 
 | 8942 | 	if (tok) { | 
 | 8943 | 		cfg->tokens_size = tokens_size; | 
 | 8944 | 		memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | 
 | 8945 | 	} | 
 | 8946 |  | 
 | 8947 | 	trig->tcp = cfg; | 
 | 8948 |  | 
 | 8949 | 	return 0; | 
 | 8950 | } | 
 | 8951 |  | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8952 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, | 
 | 8953 | 				   const struct wiphy_wowlan_support *wowlan, | 
 | 8954 | 				   struct nlattr *attr, | 
 | 8955 | 				   struct cfg80211_wowlan *trig) | 
 | 8956 | { | 
 | 8957 | 	struct nlattr **tb; | 
 | 8958 | 	int err; | 
 | 8959 |  | 
 | 8960 | 	tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | 
 | 8961 | 	if (!tb) | 
 | 8962 | 		return -ENOMEM; | 
 | 8963 |  | 
 | 8964 | 	if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | 
 | 8965 | 		err = -EOPNOTSUPP; | 
 | 8966 | 		goto out; | 
 | 8967 | 	} | 
 | 8968 |  | 
 | 8969 | 	err = nla_parse(tb, NL80211_ATTR_MAX, | 
 | 8970 | 			nla_data(attr), nla_len(attr), | 
 | 8971 | 			nl80211_policy); | 
 | 8972 | 	if (err) | 
 | 8973 | 		goto out; | 
 | 8974 |  | 
| Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8975 | 	trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8976 | 	err = PTR_ERR_OR_ZERO(trig->nd_config); | 
 | 8977 | 	if (err) | 
 | 8978 | 		trig->nd_config = NULL; | 
 | 8979 |  | 
 | 8980 | out: | 
 | 8981 | 	kfree(tb); | 
 | 8982 | 	return err; | 
 | 8983 | } | 
 | 8984 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8985 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | 
 | 8986 | { | 
 | 8987 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 8988 | 	struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8989 | 	struct cfg80211_wowlan new_triggers = {}; | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8990 | 	struct cfg80211_wowlan *ntrig; | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8991 | 	const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8992 | 	int err, i; | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8993 | 	bool prev_enabled = rdev->wiphy.wowlan_config; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8994 |  | 
| Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8995 | 	if (!wowlan) | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8996 | 		return -EOPNOTSUPP; | 
 | 8997 |  | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8998 | 	if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { | 
 | 8999 | 		cfg80211_rdev_free_wowlan(rdev); | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9000 | 		rdev->wiphy.wowlan_config = NULL; | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9001 | 		goto set_wakeup; | 
 | 9002 | 	} | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9003 |  | 
 | 9004 | 	err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | 
 | 9005 | 			nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | 
 | 9006 | 			nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | 
 | 9007 | 			nl80211_wowlan_policy); | 
 | 9008 | 	if (err) | 
 | 9009 | 		return err; | 
 | 9010 |  | 
 | 9011 | 	if (tb[NL80211_WOWLAN_TRIG_ANY]) { | 
 | 9012 | 		if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | 
 | 9013 | 			return -EINVAL; | 
 | 9014 | 		new_triggers.any = true; | 
 | 9015 | 	} | 
 | 9016 |  | 
 | 9017 | 	if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | 
 | 9018 | 		if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | 
 | 9019 | 			return -EINVAL; | 
 | 9020 | 		new_triggers.disconnect = true; | 
 | 9021 | 	} | 
 | 9022 |  | 
 | 9023 | 	if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | 
 | 9024 | 		if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | 
 | 9025 | 			return -EINVAL; | 
 | 9026 | 		new_triggers.magic_pkt = true; | 
 | 9027 | 	} | 
 | 9028 |  | 
| Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9029 | 	if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) | 
 | 9030 | 		return -EINVAL; | 
 | 9031 |  | 
 | 9032 | 	if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | 
 | 9033 | 		if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | 
 | 9034 | 			return -EINVAL; | 
 | 9035 | 		new_triggers.gtk_rekey_failure = true; | 
 | 9036 | 	} | 
 | 9037 |  | 
 | 9038 | 	if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | 
 | 9039 | 		if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | 
 | 9040 | 			return -EINVAL; | 
 | 9041 | 		new_triggers.eap_identity_req = true; | 
 | 9042 | 	} | 
 | 9043 |  | 
 | 9044 | 	if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | 
 | 9045 | 		if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | 
 | 9046 | 			return -EINVAL; | 
 | 9047 | 		new_triggers.four_way_handshake = true; | 
 | 9048 | 	} | 
 | 9049 |  | 
 | 9050 | 	if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | 
 | 9051 | 		if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | 
 | 9052 | 			return -EINVAL; | 
 | 9053 | 		new_triggers.rfkill_release = true; | 
 | 9054 | 	} | 
 | 9055 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9056 | 	if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { | 
 | 9057 | 		struct nlattr *pat; | 
 | 9058 | 		int n_patterns = 0; | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9059 | 		int rem, pat_len, mask_len, pkt_offset; | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9060 | 		struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9061 |  | 
 | 9062 | 		nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | 
 | 9063 | 				    rem) | 
 | 9064 | 			n_patterns++; | 
 | 9065 | 		if (n_patterns > wowlan->n_patterns) | 
 | 9066 | 			return -EINVAL; | 
 | 9067 |  | 
 | 9068 | 		new_triggers.patterns = kcalloc(n_patterns, | 
 | 9069 | 						sizeof(new_triggers.patterns[0]), | 
 | 9070 | 						GFP_KERNEL); | 
 | 9071 | 		if (!new_triggers.patterns) | 
 | 9072 | 			return -ENOMEM; | 
 | 9073 |  | 
 | 9074 | 		new_triggers.n_patterns = n_patterns; | 
 | 9075 | 		i = 0; | 
 | 9076 |  | 
 | 9077 | 		nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | 
 | 9078 | 				    rem) { | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9079 | 			u8 *mask_pat; | 
 | 9080 |  | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9081 | 			nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | 
 | 9082 | 				  nla_len(pat), NULL); | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9083 | 			err = -EINVAL; | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9084 | 			if (!pat_tb[NL80211_PKTPAT_MASK] || | 
 | 9085 | 			    !pat_tb[NL80211_PKTPAT_PATTERN]) | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9086 | 				goto error; | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9087 | 			pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9088 | 			mask_len = DIV_ROUND_UP(pat_len, 8); | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9089 | 			if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9090 | 				goto error; | 
 | 9091 | 			if (pat_len > wowlan->pattern_max_len || | 
 | 9092 | 			    pat_len < wowlan->pattern_min_len) | 
 | 9093 | 				goto error; | 
 | 9094 |  | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9095 | 			if (!pat_tb[NL80211_PKTPAT_OFFSET]) | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9096 | 				pkt_offset = 0; | 
 | 9097 | 			else | 
 | 9098 | 				pkt_offset = nla_get_u32( | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9099 | 					pat_tb[NL80211_PKTPAT_OFFSET]); | 
| Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9100 | 			if (pkt_offset > wowlan->max_pkt_offset) | 
 | 9101 | 				goto error; | 
 | 9102 | 			new_triggers.patterns[i].pkt_offset = pkt_offset; | 
 | 9103 |  | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9104 | 			mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); | 
 | 9105 | 			if (!mask_pat) { | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9106 | 				err = -ENOMEM; | 
 | 9107 | 				goto error; | 
 | 9108 | 			} | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9109 | 			new_triggers.patterns[i].mask = mask_pat; | 
 | 9110 | 			memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9111 | 			       mask_len); | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9112 | 			mask_pat += mask_len; | 
 | 9113 | 			new_triggers.patterns[i].pattern = mask_pat; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9114 | 			new_triggers.patterns[i].pattern_len = pat_len; | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9115 | 			memcpy(mask_pat, | 
| Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9116 | 			       nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9117 | 			       pat_len); | 
 | 9118 | 			i++; | 
 | 9119 | 		} | 
 | 9120 | 	} | 
 | 9121 |  | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9122 | 	if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { | 
 | 9123 | 		err = nl80211_parse_wowlan_tcp( | 
 | 9124 | 			rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | 
 | 9125 | 			&new_triggers); | 
 | 9126 | 		if (err) | 
 | 9127 | 			goto error; | 
 | 9128 | 	} | 
 | 9129 |  | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9130 | 	if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { | 
 | 9131 | 		err = nl80211_parse_wowlan_nd( | 
 | 9132 | 			rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | 
 | 9133 | 			&new_triggers); | 
 | 9134 | 		if (err) | 
 | 9135 | 			goto error; | 
 | 9136 | 	} | 
 | 9137 |  | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9138 | 	ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); | 
 | 9139 | 	if (!ntrig) { | 
 | 9140 | 		err = -ENOMEM; | 
 | 9141 | 		goto error; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9142 | 	} | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9143 | 	cfg80211_rdev_free_wowlan(rdev); | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9144 | 	rdev->wiphy.wowlan_config = ntrig; | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9145 |  | 
| Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9146 |  set_wakeup: | 
| Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9147 | 	if (rdev->ops->set_wakeup && | 
 | 9148 | 	    prev_enabled != !!rdev->wiphy.wowlan_config) | 
 | 9149 | 		rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | 
| Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9150 |  | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9151 | 	return 0; | 
 | 9152 |  error: | 
 | 9153 | 	for (i = 0; i < new_triggers.n_patterns; i++) | 
 | 9154 | 		kfree(new_triggers.patterns[i].mask); | 
 | 9155 | 	kfree(new_triggers.patterns); | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9156 | 	if (new_triggers.tcp && new_triggers.tcp->sock) | 
 | 9157 | 		sock_release(new_triggers.tcp->sock); | 
 | 9158 | 	kfree(new_triggers.tcp); | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9159 | 	return err; | 
 | 9160 | } | 
| Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9161 | #endif | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9162 |  | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9163 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, | 
 | 9164 | 				       struct cfg80211_registered_device *rdev) | 
 | 9165 | { | 
 | 9166 | 	struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | 
 | 9167 | 	int i, j, pat_len; | 
 | 9168 | 	struct cfg80211_coalesce_rules *rule; | 
 | 9169 |  | 
 | 9170 | 	if (!rdev->coalesce->n_rules) | 
 | 9171 | 		return 0; | 
 | 9172 |  | 
 | 9173 | 	nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | 
 | 9174 | 	if (!nl_rules) | 
 | 9175 | 		return -ENOBUFS; | 
 | 9176 |  | 
 | 9177 | 	for (i = 0; i < rdev->coalesce->n_rules; i++) { | 
 | 9178 | 		nl_rule = nla_nest_start(msg, i + 1); | 
 | 9179 | 		if (!nl_rule) | 
 | 9180 | 			return -ENOBUFS; | 
 | 9181 |  | 
 | 9182 | 		rule = &rdev->coalesce->rules[i]; | 
 | 9183 | 		if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | 
 | 9184 | 				rule->delay)) | 
 | 9185 | 			return -ENOBUFS; | 
 | 9186 |  | 
 | 9187 | 		if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | 
 | 9188 | 				rule->condition)) | 
 | 9189 | 			return -ENOBUFS; | 
 | 9190 |  | 
 | 9191 | 		nl_pats = nla_nest_start(msg, | 
 | 9192 | 				NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | 
 | 9193 | 		if (!nl_pats) | 
 | 9194 | 			return -ENOBUFS; | 
 | 9195 |  | 
 | 9196 | 		for (j = 0; j < rule->n_patterns; j++) { | 
 | 9197 | 			nl_pat = nla_nest_start(msg, j + 1); | 
 | 9198 | 			if (!nl_pat) | 
 | 9199 | 				return -ENOBUFS; | 
 | 9200 | 			pat_len = rule->patterns[j].pattern_len; | 
 | 9201 | 			if (nla_put(msg, NL80211_PKTPAT_MASK, | 
 | 9202 | 				    DIV_ROUND_UP(pat_len, 8), | 
 | 9203 | 				    rule->patterns[j].mask) || | 
 | 9204 | 			    nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | 
 | 9205 | 				    rule->patterns[j].pattern) || | 
 | 9206 | 			    nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | 
 | 9207 | 					rule->patterns[j].pkt_offset)) | 
 | 9208 | 				return -ENOBUFS; | 
 | 9209 | 			nla_nest_end(msg, nl_pat); | 
 | 9210 | 		} | 
 | 9211 | 		nla_nest_end(msg, nl_pats); | 
 | 9212 | 		nla_nest_end(msg, nl_rule); | 
 | 9213 | 	} | 
 | 9214 | 	nla_nest_end(msg, nl_rules); | 
 | 9215 |  | 
 | 9216 | 	return 0; | 
 | 9217 | } | 
 | 9218 |  | 
 | 9219 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | 
 | 9220 | { | 
 | 9221 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9222 | 	struct sk_buff *msg; | 
 | 9223 | 	void *hdr; | 
 | 9224 |  | 
 | 9225 | 	if (!rdev->wiphy.coalesce) | 
 | 9226 | 		return -EOPNOTSUPP; | 
 | 9227 |  | 
 | 9228 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 9229 | 	if (!msg) | 
 | 9230 | 		return -ENOMEM; | 
 | 9231 |  | 
 | 9232 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
 | 9233 | 			     NL80211_CMD_GET_COALESCE); | 
 | 9234 | 	if (!hdr) | 
 | 9235 | 		goto nla_put_failure; | 
 | 9236 |  | 
 | 9237 | 	if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | 
 | 9238 | 		goto nla_put_failure; | 
 | 9239 |  | 
 | 9240 | 	genlmsg_end(msg, hdr); | 
 | 9241 | 	return genlmsg_reply(msg, info); | 
 | 9242 |  | 
 | 9243 | nla_put_failure: | 
 | 9244 | 	nlmsg_free(msg); | 
 | 9245 | 	return -ENOBUFS; | 
 | 9246 | } | 
 | 9247 |  | 
 | 9248 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | 
 | 9249 | { | 
 | 9250 | 	struct cfg80211_coalesce *coalesce = rdev->coalesce; | 
 | 9251 | 	int i, j; | 
 | 9252 | 	struct cfg80211_coalesce_rules *rule; | 
 | 9253 |  | 
 | 9254 | 	if (!coalesce) | 
 | 9255 | 		return; | 
 | 9256 |  | 
 | 9257 | 	for (i = 0; i < coalesce->n_rules; i++) { | 
 | 9258 | 		rule = &coalesce->rules[i]; | 
 | 9259 | 		for (j = 0; j < rule->n_patterns; j++) | 
 | 9260 | 			kfree(rule->patterns[j].mask); | 
 | 9261 | 		kfree(rule->patterns); | 
 | 9262 | 	} | 
 | 9263 | 	kfree(coalesce->rules); | 
 | 9264 | 	kfree(coalesce); | 
 | 9265 | 	rdev->coalesce = NULL; | 
 | 9266 | } | 
 | 9267 |  | 
 | 9268 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | 
 | 9269 | 				       struct nlattr *rule, | 
 | 9270 | 				       struct cfg80211_coalesce_rules *new_rule) | 
 | 9271 | { | 
 | 9272 | 	int err, i; | 
 | 9273 | 	const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | 
 | 9274 | 	struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | 
 | 9275 | 	int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | 
 | 9276 | 	struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | 
 | 9277 |  | 
 | 9278 | 	err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | 
 | 9279 | 			nla_len(rule), nl80211_coalesce_policy); | 
 | 9280 | 	if (err) | 
 | 9281 | 		return err; | 
 | 9282 |  | 
 | 9283 | 	if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | 
 | 9284 | 		new_rule->delay = | 
 | 9285 | 			nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | 
 | 9286 | 	if (new_rule->delay > coalesce->max_delay) | 
 | 9287 | 		return -EINVAL; | 
 | 9288 |  | 
 | 9289 | 	if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | 
 | 9290 | 		new_rule->condition = | 
 | 9291 | 			nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | 
 | 9292 | 	if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | 
 | 9293 | 	    new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | 
 | 9294 | 		return -EINVAL; | 
 | 9295 |  | 
 | 9296 | 	if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | 
 | 9297 | 		return -EINVAL; | 
 | 9298 |  | 
 | 9299 | 	nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | 
 | 9300 | 			    rem) | 
 | 9301 | 		n_patterns++; | 
 | 9302 | 	if (n_patterns > coalesce->n_patterns) | 
 | 9303 | 		return -EINVAL; | 
 | 9304 |  | 
 | 9305 | 	new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | 
 | 9306 | 				     GFP_KERNEL); | 
 | 9307 | 	if (!new_rule->patterns) | 
 | 9308 | 		return -ENOMEM; | 
 | 9309 |  | 
 | 9310 | 	new_rule->n_patterns = n_patterns; | 
 | 9311 | 	i = 0; | 
 | 9312 |  | 
 | 9313 | 	nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | 
 | 9314 | 			    rem) { | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9315 | 		u8 *mask_pat; | 
 | 9316 |  | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9317 | 		nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | 
 | 9318 | 			  nla_len(pat), NULL); | 
 | 9319 | 		if (!pat_tb[NL80211_PKTPAT_MASK] || | 
 | 9320 | 		    !pat_tb[NL80211_PKTPAT_PATTERN]) | 
 | 9321 | 			return -EINVAL; | 
 | 9322 | 		pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | 
 | 9323 | 		mask_len = DIV_ROUND_UP(pat_len, 8); | 
 | 9324 | 		if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | 
 | 9325 | 			return -EINVAL; | 
 | 9326 | 		if (pat_len > coalesce->pattern_max_len || | 
 | 9327 | 		    pat_len < coalesce->pattern_min_len) | 
 | 9328 | 			return -EINVAL; | 
 | 9329 |  | 
 | 9330 | 		if (!pat_tb[NL80211_PKTPAT_OFFSET]) | 
 | 9331 | 			pkt_offset = 0; | 
 | 9332 | 		else | 
 | 9333 | 			pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | 
 | 9334 | 		if (pkt_offset > coalesce->max_pkt_offset) | 
 | 9335 | 			return -EINVAL; | 
 | 9336 | 		new_rule->patterns[i].pkt_offset = pkt_offset; | 
 | 9337 |  | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9338 | 		mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); | 
 | 9339 | 		if (!mask_pat) | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9340 | 			return -ENOMEM; | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9341 |  | 
 | 9342 | 		new_rule->patterns[i].mask = mask_pat; | 
 | 9343 | 		memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | 
 | 9344 | 		       mask_len); | 
 | 9345 |  | 
 | 9346 | 		mask_pat += mask_len; | 
 | 9347 | 		new_rule->patterns[i].pattern = mask_pat; | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9348 | 		new_rule->patterns[i].pattern_len = pat_len; | 
| Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9349 | 		memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), | 
 | 9350 | 		       pat_len); | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9351 | 		i++; | 
 | 9352 | 	} | 
 | 9353 |  | 
 | 9354 | 	return 0; | 
 | 9355 | } | 
 | 9356 |  | 
 | 9357 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | 
 | 9358 | { | 
 | 9359 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9360 | 	const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | 
 | 9361 | 	struct cfg80211_coalesce new_coalesce = {}; | 
 | 9362 | 	struct cfg80211_coalesce *n_coalesce; | 
 | 9363 | 	int err, rem_rule, n_rules = 0, i, j; | 
 | 9364 | 	struct nlattr *rule; | 
 | 9365 | 	struct cfg80211_coalesce_rules *tmp_rule; | 
 | 9366 |  | 
 | 9367 | 	if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | 
 | 9368 | 		return -EOPNOTSUPP; | 
 | 9369 |  | 
 | 9370 | 	if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | 
 | 9371 | 		cfg80211_rdev_free_coalesce(rdev); | 
 | 9372 | 		rdev->ops->set_coalesce(&rdev->wiphy, NULL); | 
 | 9373 | 		return 0; | 
 | 9374 | 	} | 
 | 9375 |  | 
 | 9376 | 	nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | 
 | 9377 | 			    rem_rule) | 
 | 9378 | 		n_rules++; | 
 | 9379 | 	if (n_rules > coalesce->n_rules) | 
 | 9380 | 		return -EINVAL; | 
 | 9381 |  | 
 | 9382 | 	new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | 
 | 9383 | 				     GFP_KERNEL); | 
 | 9384 | 	if (!new_coalesce.rules) | 
 | 9385 | 		return -ENOMEM; | 
 | 9386 |  | 
 | 9387 | 	new_coalesce.n_rules = n_rules; | 
 | 9388 | 	i = 0; | 
 | 9389 |  | 
 | 9390 | 	nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | 
 | 9391 | 			    rem_rule) { | 
 | 9392 | 		err = nl80211_parse_coalesce_rule(rdev, rule, | 
 | 9393 | 						  &new_coalesce.rules[i]); | 
 | 9394 | 		if (err) | 
 | 9395 | 			goto error; | 
 | 9396 |  | 
 | 9397 | 		i++; | 
 | 9398 | 	} | 
 | 9399 |  | 
 | 9400 | 	err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | 
 | 9401 | 	if (err) | 
 | 9402 | 		goto error; | 
 | 9403 |  | 
 | 9404 | 	n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | 
 | 9405 | 	if (!n_coalesce) { | 
 | 9406 | 		err = -ENOMEM; | 
 | 9407 | 		goto error; | 
 | 9408 | 	} | 
 | 9409 | 	cfg80211_rdev_free_coalesce(rdev); | 
 | 9410 | 	rdev->coalesce = n_coalesce; | 
 | 9411 |  | 
 | 9412 | 	return 0; | 
 | 9413 | error: | 
 | 9414 | 	for (i = 0; i < new_coalesce.n_rules; i++) { | 
 | 9415 | 		tmp_rule = &new_coalesce.rules[i]; | 
 | 9416 | 		for (j = 0; j < tmp_rule->n_patterns; j++) | 
 | 9417 | 			kfree(tmp_rule->patterns[j].mask); | 
 | 9418 | 		kfree(tmp_rule->patterns); | 
 | 9419 | 	} | 
 | 9420 | 	kfree(new_coalesce.rules); | 
 | 9421 |  | 
 | 9422 | 	return err; | 
 | 9423 | } | 
 | 9424 |  | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9425 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) | 
 | 9426 | { | 
 | 9427 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9428 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9429 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9430 | 	struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | 
 | 9431 | 	struct cfg80211_gtk_rekey_data rekey_data; | 
 | 9432 | 	int err; | 
 | 9433 |  | 
 | 9434 | 	if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | 
 | 9435 | 		return -EINVAL; | 
 | 9436 |  | 
 | 9437 | 	err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | 
 | 9438 | 			nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | 
 | 9439 | 			nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | 
 | 9440 | 			nl80211_rekey_policy); | 
 | 9441 | 	if (err) | 
 | 9442 | 		return err; | 
 | 9443 |  | 
 | 9444 | 	if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | 
 | 9445 | 		return -ERANGE; | 
 | 9446 | 	if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | 
 | 9447 | 		return -ERANGE; | 
 | 9448 | 	if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | 
 | 9449 | 		return -ERANGE; | 
 | 9450 |  | 
| Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9451 | 	rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); | 
 | 9452 | 	rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | 
 | 9453 | 	rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9454 |  | 
 | 9455 | 	wdev_lock(wdev); | 
 | 9456 | 	if (!wdev->current_bss) { | 
 | 9457 | 		err = -ENOTCONN; | 
 | 9458 | 		goto out; | 
 | 9459 | 	} | 
 | 9460 |  | 
 | 9461 | 	if (!rdev->ops->set_rekey_data) { | 
 | 9462 | 		err = -EOPNOTSUPP; | 
 | 9463 | 		goto out; | 
 | 9464 | 	} | 
 | 9465 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9466 | 	err = rdev_set_rekey_data(rdev, dev, &rekey_data); | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9467 |  out: | 
 | 9468 | 	wdev_unlock(wdev); | 
 | 9469 | 	return err; | 
 | 9470 | } | 
 | 9471 |  | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9472 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, | 
 | 9473 | 					     struct genl_info *info) | 
 | 9474 | { | 
 | 9475 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9476 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9477 |  | 
 | 9478 | 	if (wdev->iftype != NL80211_IFTYPE_AP && | 
 | 9479 | 	    wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 9480 | 		return -EINVAL; | 
 | 9481 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9482 | 	if (wdev->ap_unexpected_nlportid) | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9483 | 		return -EBUSY; | 
 | 9484 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9485 | 	wdev->ap_unexpected_nlportid = info->snd_portid; | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9486 | 	return 0; | 
 | 9487 | } | 
 | 9488 |  | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9489 | static int nl80211_probe_client(struct sk_buff *skb, | 
 | 9490 | 				struct genl_info *info) | 
 | 9491 | { | 
 | 9492 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9493 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9494 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9495 | 	struct sk_buff *msg; | 
 | 9496 | 	void *hdr; | 
 | 9497 | 	const u8 *addr; | 
 | 9498 | 	u64 cookie; | 
 | 9499 | 	int err; | 
 | 9500 |  | 
 | 9501 | 	if (wdev->iftype != NL80211_IFTYPE_AP && | 
 | 9502 | 	    wdev->iftype != NL80211_IFTYPE_P2P_GO) | 
 | 9503 | 		return -EOPNOTSUPP; | 
 | 9504 |  | 
 | 9505 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 9506 | 		return -EINVAL; | 
 | 9507 |  | 
 | 9508 | 	if (!rdev->ops->probe_client) | 
 | 9509 | 		return -EOPNOTSUPP; | 
 | 9510 |  | 
 | 9511 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 9512 | 	if (!msg) | 
 | 9513 | 		return -ENOMEM; | 
 | 9514 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9515 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9516 | 			     NL80211_CMD_PROBE_CLIENT); | 
| Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9517 | 	if (!hdr) { | 
 | 9518 | 		err = -ENOBUFS; | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9519 | 		goto free_msg; | 
 | 9520 | 	} | 
 | 9521 |  | 
 | 9522 | 	addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 9523 |  | 
| Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9524 | 	err = rdev_probe_client(rdev, dev, addr, &cookie); | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9525 | 	if (err) | 
 | 9526 | 		goto free_msg; | 
 | 9527 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9528 | 	if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | 
 | 9529 | 		goto nla_put_failure; | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9530 |  | 
 | 9531 | 	genlmsg_end(msg, hdr); | 
 | 9532 |  | 
 | 9533 | 	return genlmsg_reply(msg, info); | 
 | 9534 |  | 
 | 9535 |  nla_put_failure: | 
 | 9536 | 	err = -ENOBUFS; | 
 | 9537 |  free_msg: | 
 | 9538 | 	nlmsg_free(msg); | 
 | 9539 | 	return err; | 
 | 9540 | } | 
 | 9541 |  | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9542 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) | 
 | 9543 | { | 
 | 9544 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9545 | 	struct cfg80211_beacon_registration *reg, *nreg; | 
 | 9546 | 	int rv; | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9547 |  | 
 | 9548 | 	if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | 
 | 9549 | 		return -EOPNOTSUPP; | 
 | 9550 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9551 | 	nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); | 
 | 9552 | 	if (!nreg) | 
 | 9553 | 		return -ENOMEM; | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9554 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9555 | 	/* First, check if already registered. */ | 
 | 9556 | 	spin_lock_bh(&rdev->beacon_registrations_lock); | 
 | 9557 | 	list_for_each_entry(reg, &rdev->beacon_registrations, list) { | 
 | 9558 | 		if (reg->nlportid == info->snd_portid) { | 
 | 9559 | 			rv = -EALREADY; | 
 | 9560 | 			goto out_err; | 
 | 9561 | 		} | 
 | 9562 | 	} | 
 | 9563 | 	/* Add it to the list */ | 
 | 9564 | 	nreg->nlportid = info->snd_portid; | 
 | 9565 | 	list_add(&nreg->list, &rdev->beacon_registrations); | 
 | 9566 |  | 
 | 9567 | 	spin_unlock_bh(&rdev->beacon_registrations_lock); | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9568 |  | 
 | 9569 | 	return 0; | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9570 | out_err: | 
 | 9571 | 	spin_unlock_bh(&rdev->beacon_registrations_lock); | 
 | 9572 | 	kfree(nreg); | 
 | 9573 | 	return rv; | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9574 | } | 
 | 9575 |  | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9576 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) | 
 | 9577 | { | 
 | 9578 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9579 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
 | 9580 | 	int err; | 
 | 9581 |  | 
 | 9582 | 	if (!rdev->ops->start_p2p_device) | 
 | 9583 | 		return -EOPNOTSUPP; | 
 | 9584 |  | 
 | 9585 | 	if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | 
 | 9586 | 		return -EOPNOTSUPP; | 
 | 9587 |  | 
 | 9588 | 	if (wdev->p2p_started) | 
 | 9589 | 		return 0; | 
 | 9590 |  | 
| Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9591 | 	if (rfkill_blocked(rdev->rfkill)) | 
 | 9592 | 		return -ERFKILL; | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9593 |  | 
| Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9594 | 	err = rdev_start_p2p_device(rdev, wdev); | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9595 | 	if (err) | 
 | 9596 | 		return err; | 
 | 9597 |  | 
 | 9598 | 	wdev->p2p_started = true; | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9599 | 	rdev->opencount++; | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9600 |  | 
 | 9601 | 	return 0; | 
 | 9602 | } | 
 | 9603 |  | 
 | 9604 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | 
 | 9605 | { | 
 | 9606 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9607 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
 | 9608 |  | 
 | 9609 | 	if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | 
 | 9610 | 		return -EOPNOTSUPP; | 
 | 9611 |  | 
 | 9612 | 	if (!rdev->ops->stop_p2p_device) | 
 | 9613 | 		return -EOPNOTSUPP; | 
 | 9614 |  | 
| Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9615 | 	cfg80211_stop_p2p_device(rdev, wdev); | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9616 |  | 
 | 9617 | 	return 0; | 
 | 9618 | } | 
 | 9619 |  | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9620 | static int nl80211_get_protocol_features(struct sk_buff *skb, | 
 | 9621 | 					 struct genl_info *info) | 
 | 9622 | { | 
 | 9623 | 	void *hdr; | 
 | 9624 | 	struct sk_buff *msg; | 
 | 9625 |  | 
 | 9626 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 9627 | 	if (!msg) | 
 | 9628 | 		return -ENOMEM; | 
 | 9629 |  | 
 | 9630 | 	hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | 
 | 9631 | 			     NL80211_CMD_GET_PROTOCOL_FEATURES); | 
 | 9632 | 	if (!hdr) | 
 | 9633 | 		goto nla_put_failure; | 
 | 9634 |  | 
 | 9635 | 	if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | 
 | 9636 | 			NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | 
 | 9637 | 		goto nla_put_failure; | 
 | 9638 |  | 
 | 9639 | 	genlmsg_end(msg, hdr); | 
 | 9640 | 	return genlmsg_reply(msg, info); | 
 | 9641 |  | 
 | 9642 |  nla_put_failure: | 
 | 9643 | 	kfree_skb(msg); | 
 | 9644 | 	return -ENOBUFS; | 
 | 9645 | } | 
 | 9646 |  | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9647 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) | 
 | 9648 | { | 
 | 9649 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9650 | 	struct cfg80211_update_ft_ies_params ft_params; | 
 | 9651 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9652 |  | 
 | 9653 | 	if (!rdev->ops->update_ft_ies) | 
 | 9654 | 		return -EOPNOTSUPP; | 
 | 9655 |  | 
 | 9656 | 	if (!info->attrs[NL80211_ATTR_MDID] || | 
 | 9657 | 	    !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 
 | 9658 | 		return -EINVAL; | 
 | 9659 |  | 
 | 9660 | 	memset(&ft_params, 0, sizeof(ft_params)); | 
 | 9661 | 	ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | 
 | 9662 | 	ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | 
 | 9663 | 	ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 
 | 9664 |  | 
 | 9665 | 	return rdev_update_ft_ies(rdev, dev, &ft_params); | 
 | 9666 | } | 
 | 9667 |  | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9668 | static int nl80211_crit_protocol_start(struct sk_buff *skb, | 
 | 9669 | 				       struct genl_info *info) | 
 | 9670 | { | 
 | 9671 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9672 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
 | 9673 | 	enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | 
 | 9674 | 	u16 duration; | 
 | 9675 | 	int ret; | 
 | 9676 |  | 
 | 9677 | 	if (!rdev->ops->crit_proto_start) | 
 | 9678 | 		return -EOPNOTSUPP; | 
 | 9679 |  | 
 | 9680 | 	if (WARN_ON(!rdev->ops->crit_proto_stop)) | 
 | 9681 | 		return -EINVAL; | 
 | 9682 |  | 
 | 9683 | 	if (rdev->crit_proto_nlportid) | 
 | 9684 | 		return -EBUSY; | 
 | 9685 |  | 
 | 9686 | 	/* determine protocol if provided */ | 
 | 9687 | 	if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | 
 | 9688 | 		proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | 
 | 9689 |  | 
 | 9690 | 	if (proto >= NUM_NL80211_CRIT_PROTO) | 
 | 9691 | 		return -EINVAL; | 
 | 9692 |  | 
 | 9693 | 	/* timeout must be provided */ | 
 | 9694 | 	if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | 
 | 9695 | 		return -EINVAL; | 
 | 9696 |  | 
 | 9697 | 	duration = | 
 | 9698 | 		nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | 
 | 9699 |  | 
 | 9700 | 	if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | 
 | 9701 | 		return -ERANGE; | 
 | 9702 |  | 
 | 9703 | 	ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | 
 | 9704 | 	if (!ret) | 
 | 9705 | 		rdev->crit_proto_nlportid = info->snd_portid; | 
 | 9706 |  | 
 | 9707 | 	return ret; | 
 | 9708 | } | 
 | 9709 |  | 
 | 9710 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | 
 | 9711 | 				      struct genl_info *info) | 
 | 9712 | { | 
 | 9713 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9714 | 	struct wireless_dev *wdev = info->user_ptr[1]; | 
 | 9715 |  | 
 | 9716 | 	if (!rdev->ops->crit_proto_stop) | 
 | 9717 | 		return -EOPNOTSUPP; | 
 | 9718 |  | 
 | 9719 | 	if (rdev->crit_proto_nlportid) { | 
 | 9720 | 		rdev->crit_proto_nlportid = 0; | 
 | 9721 | 		rdev_crit_proto_stop(rdev, wdev); | 
 | 9722 | 	} | 
 | 9723 | 	return 0; | 
 | 9724 | } | 
 | 9725 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9726 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) | 
 | 9727 | { | 
 | 9728 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9729 | 	struct wireless_dev *wdev = | 
 | 9730 | 		__cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | 
 | 9731 | 	int i, err; | 
 | 9732 | 	u32 vid, subcmd; | 
 | 9733 |  | 
 | 9734 | 	if (!rdev->wiphy.vendor_commands) | 
 | 9735 | 		return -EOPNOTSUPP; | 
 | 9736 |  | 
 | 9737 | 	if (IS_ERR(wdev)) { | 
 | 9738 | 		err = PTR_ERR(wdev); | 
 | 9739 | 		if (err != -EINVAL) | 
 | 9740 | 			return err; | 
 | 9741 | 		wdev = NULL; | 
 | 9742 | 	} else if (wdev->wiphy != &rdev->wiphy) { | 
 | 9743 | 		return -EINVAL; | 
 | 9744 | 	} | 
 | 9745 |  | 
 | 9746 | 	if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | 
 | 9747 | 	    !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | 
 | 9748 | 		return -EINVAL; | 
 | 9749 |  | 
 | 9750 | 	vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | 
 | 9751 | 	subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | 
 | 9752 | 	for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | 
 | 9753 | 		const struct wiphy_vendor_command *vcmd; | 
 | 9754 | 		void *data = NULL; | 
 | 9755 | 		int len = 0; | 
 | 9756 |  | 
 | 9757 | 		vcmd = &rdev->wiphy.vendor_commands[i]; | 
 | 9758 |  | 
 | 9759 | 		if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | 
 | 9760 | 			continue; | 
 | 9761 |  | 
 | 9762 | 		if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | 
 | 9763 | 				   WIPHY_VENDOR_CMD_NEED_NETDEV)) { | 
 | 9764 | 			if (!wdev) | 
 | 9765 | 				return -EINVAL; | 
 | 9766 | 			if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | 
 | 9767 | 			    !wdev->netdev) | 
 | 9768 | 				return -EINVAL; | 
 | 9769 |  | 
 | 9770 | 			if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | 
 | 9771 | 				if (wdev->netdev && | 
 | 9772 | 				    !netif_running(wdev->netdev)) | 
 | 9773 | 					return -ENETDOWN; | 
 | 9774 | 				if (!wdev->netdev && !wdev->p2p_started) | 
 | 9775 | 					return -ENETDOWN; | 
 | 9776 | 			} | 
 | 9777 | 		} else { | 
 | 9778 | 			wdev = NULL; | 
 | 9779 | 		} | 
 | 9780 |  | 
 | 9781 | 		if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | 
 | 9782 | 			data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | 
 | 9783 | 			len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | 
 | 9784 | 		} | 
 | 9785 |  | 
 | 9786 | 		rdev->cur_cmd_info = info; | 
 | 9787 | 		err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | 
 | 9788 | 							  data, len); | 
 | 9789 | 		rdev->cur_cmd_info = NULL; | 
 | 9790 | 		return err; | 
 | 9791 | 	} | 
 | 9792 |  | 
 | 9793 | 	return -EOPNOTSUPP; | 
 | 9794 | } | 
 | 9795 |  | 
 | 9796 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | 
 | 9797 | 					   enum nl80211_commands cmd, | 
 | 9798 | 					   enum nl80211_attrs attr, | 
 | 9799 | 					   int approxlen) | 
 | 9800 | { | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9801 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9802 |  | 
 | 9803 | 	if (WARN_ON(!rdev->cur_cmd_info)) | 
 | 9804 | 		return NULL; | 
 | 9805 |  | 
 | 9806 | 	return __cfg80211_alloc_vendor_skb(rdev, approxlen, | 
 | 9807 | 					   rdev->cur_cmd_info->snd_portid, | 
 | 9808 | 					   rdev->cur_cmd_info->snd_seq, | 
| Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9809 | 					   cmd, attr, NULL, GFP_KERNEL); | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9810 | } | 
 | 9811 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | 
 | 9812 |  | 
 | 9813 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | 
 | 9814 | { | 
 | 9815 | 	struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | 
 | 9816 | 	void *hdr = ((void **)skb->cb)[1]; | 
 | 9817 | 	struct nlattr *data = ((void **)skb->cb)[2]; | 
 | 9818 |  | 
| Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9819 | 	/* clear CB data for netlink core to own from now on */ | 
 | 9820 | 	memset(skb->cb, 0, sizeof(skb->cb)); | 
 | 9821 |  | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9822 | 	if (WARN_ON(!rdev->cur_cmd_info)) { | 
 | 9823 | 		kfree_skb(skb); | 
 | 9824 | 		return -EINVAL; | 
 | 9825 | 	} | 
 | 9826 |  | 
 | 9827 | 	nla_nest_end(skb, data); | 
 | 9828 | 	genlmsg_end(skb, hdr); | 
 | 9829 | 	return genlmsg_reply(skb, rdev->cur_cmd_info); | 
 | 9830 | } | 
 | 9831 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | 
 | 9832 |  | 
 | 9833 |  | 
| Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9834 | static int nl80211_set_qos_map(struct sk_buff *skb, | 
 | 9835 | 			       struct genl_info *info) | 
 | 9836 | { | 
 | 9837 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9838 | 	struct cfg80211_qos_map *qos_map = NULL; | 
 | 9839 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9840 | 	u8 *pos, len, num_des, des_len, des; | 
 | 9841 | 	int ret; | 
 | 9842 |  | 
 | 9843 | 	if (!rdev->ops->set_qos_map) | 
 | 9844 | 		return -EOPNOTSUPP; | 
 | 9845 |  | 
 | 9846 | 	if (info->attrs[NL80211_ATTR_QOS_MAP]) { | 
 | 9847 | 		pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | 
 | 9848 | 		len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | 
 | 9849 |  | 
 | 9850 | 		if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | 
 | 9851 | 		    len > IEEE80211_QOS_MAP_LEN_MAX) | 
 | 9852 | 			return -EINVAL; | 
 | 9853 |  | 
 | 9854 | 		qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | 
 | 9855 | 		if (!qos_map) | 
 | 9856 | 			return -ENOMEM; | 
 | 9857 |  | 
 | 9858 | 		num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | 
 | 9859 | 		if (num_des) { | 
 | 9860 | 			des_len = num_des * | 
 | 9861 | 				sizeof(struct cfg80211_dscp_exception); | 
 | 9862 | 			memcpy(qos_map->dscp_exception, pos, des_len); | 
 | 9863 | 			qos_map->num_des = num_des; | 
 | 9864 | 			for (des = 0; des < num_des; des++) { | 
 | 9865 | 				if (qos_map->dscp_exception[des].up > 7) { | 
 | 9866 | 					kfree(qos_map); | 
 | 9867 | 					return -EINVAL; | 
 | 9868 | 				} | 
 | 9869 | 			} | 
 | 9870 | 			pos += des_len; | 
 | 9871 | 		} | 
 | 9872 | 		memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | 
 | 9873 | 	} | 
 | 9874 |  | 
 | 9875 | 	wdev_lock(dev->ieee80211_ptr); | 
 | 9876 | 	ret = nl80211_key_allowed(dev->ieee80211_ptr); | 
 | 9877 | 	if (!ret) | 
 | 9878 | 		ret = rdev_set_qos_map(rdev, dev, qos_map); | 
 | 9879 | 	wdev_unlock(dev->ieee80211_ptr); | 
 | 9880 |  | 
 | 9881 | 	kfree(qos_map); | 
 | 9882 | 	return ret; | 
 | 9883 | } | 
 | 9884 |  | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9885 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) | 
 | 9886 | { | 
 | 9887 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9888 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9889 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9890 | 	const u8 *peer; | 
 | 9891 | 	u8 tsid, up; | 
 | 9892 | 	u16 admitted_time = 0; | 
 | 9893 | 	int err; | 
 | 9894 |  | 
| Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9895 | 	if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9896 | 		return -EOPNOTSUPP; | 
 | 9897 |  | 
 | 9898 | 	if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | 
 | 9899 | 	    !info->attrs[NL80211_ATTR_USER_PRIO]) | 
 | 9900 | 		return -EINVAL; | 
 | 9901 |  | 
 | 9902 | 	tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | 
 | 9903 | 	if (tsid >= IEEE80211_NUM_TIDS) | 
 | 9904 | 		return -EINVAL; | 
 | 9905 |  | 
 | 9906 | 	up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | 
 | 9907 | 	if (up >= IEEE80211_NUM_UPS) | 
 | 9908 | 		return -EINVAL; | 
 | 9909 |  | 
 | 9910 | 	/* WMM uses TIDs 0-7 even for TSPEC */ | 
| Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9911 | 	if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9912 | 		/* TODO: handle 802.11 TSPEC/admission control | 
| Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9913 | 		 * need more attributes for that (e.g. BA session requirement); | 
 | 9914 | 		 * change the WMM adminssion test above to allow both then | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9915 | 		 */ | 
 | 9916 | 		return -EINVAL; | 
 | 9917 | 	} | 
 | 9918 |  | 
 | 9919 | 	peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 9920 |  | 
 | 9921 | 	if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | 
 | 9922 | 		admitted_time = | 
 | 9923 | 			nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | 
 | 9924 | 		if (!admitted_time) | 
 | 9925 | 			return -EINVAL; | 
 | 9926 | 	} | 
 | 9927 |  | 
 | 9928 | 	wdev_lock(wdev); | 
 | 9929 | 	switch (wdev->iftype) { | 
 | 9930 | 	case NL80211_IFTYPE_STATION: | 
 | 9931 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 9932 | 		if (wdev->current_bss) | 
 | 9933 | 			break; | 
 | 9934 | 		err = -ENOTCONN; | 
 | 9935 | 		goto out; | 
 | 9936 | 	default: | 
 | 9937 | 		err = -EOPNOTSUPP; | 
 | 9938 | 		goto out; | 
 | 9939 | 	} | 
 | 9940 |  | 
 | 9941 | 	err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | 
 | 9942 |  | 
 | 9943 |  out: | 
 | 9944 | 	wdev_unlock(wdev); | 
 | 9945 | 	return err; | 
 | 9946 | } | 
 | 9947 |  | 
 | 9948 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | 
 | 9949 | { | 
 | 9950 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9951 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9952 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9953 | 	const u8 *peer; | 
 | 9954 | 	u8 tsid; | 
 | 9955 | 	int err; | 
 | 9956 |  | 
 | 9957 | 	if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | 
 | 9958 | 		return -EINVAL; | 
 | 9959 |  | 
 | 9960 | 	tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | 
 | 9961 | 	peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 9962 |  | 
 | 9963 | 	wdev_lock(wdev); | 
 | 9964 | 	err = rdev_del_tx_ts(rdev, dev, tsid, peer); | 
 | 9965 | 	wdev_unlock(wdev); | 
 | 9966 |  | 
 | 9967 | 	return err; | 
 | 9968 | } | 
 | 9969 |  | 
| Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 9970 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, | 
 | 9971 | 				       struct genl_info *info) | 
 | 9972 | { | 
 | 9973 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 9974 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 9975 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 9976 | 	struct cfg80211_chan_def chandef = {}; | 
 | 9977 | 	const u8 *addr; | 
 | 9978 | 	u8 oper_class; | 
 | 9979 | 	int err; | 
 | 9980 |  | 
 | 9981 | 	if (!rdev->ops->tdls_channel_switch || | 
 | 9982 | 	    !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | 
 | 9983 | 		return -EOPNOTSUPP; | 
 | 9984 |  | 
 | 9985 | 	switch (dev->ieee80211_ptr->iftype) { | 
 | 9986 | 	case NL80211_IFTYPE_STATION: | 
 | 9987 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 9988 | 		break; | 
 | 9989 | 	default: | 
 | 9990 | 		return -EOPNOTSUPP; | 
 | 9991 | 	} | 
 | 9992 |  | 
 | 9993 | 	if (!info->attrs[NL80211_ATTR_MAC] || | 
 | 9994 | 	    !info->attrs[NL80211_ATTR_OPER_CLASS]) | 
 | 9995 | 		return -EINVAL; | 
 | 9996 |  | 
 | 9997 | 	err = nl80211_parse_chandef(rdev, info, &chandef); | 
 | 9998 | 	if (err) | 
 | 9999 | 		return err; | 
 | 10000 |  | 
 | 10001 | 	/* | 
 | 10002 | 	 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | 
 | 10003 | 	 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | 
 | 10004 | 	 * specification is not defined for them. | 
 | 10005 | 	 */ | 
 | 10006 | 	if (chandef.chan->band == IEEE80211_BAND_2GHZ && | 
 | 10007 | 	    chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | 
 | 10008 | 	    chandef.width != NL80211_CHAN_WIDTH_20) | 
 | 10009 | 		return -EINVAL; | 
 | 10010 |  | 
 | 10011 | 	/* we will be active on the TDLS link */ | 
 | 10012 | 	if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | 
 | 10013 | 		return -EINVAL; | 
 | 10014 |  | 
 | 10015 | 	/* don't allow switching to DFS channels */ | 
 | 10016 | 	if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | 
 | 10017 | 		return -EINVAL; | 
 | 10018 |  | 
 | 10019 | 	addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 10020 | 	oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | 
 | 10021 |  | 
 | 10022 | 	wdev_lock(wdev); | 
 | 10023 | 	err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | 
 | 10024 | 	wdev_unlock(wdev); | 
 | 10025 |  | 
 | 10026 | 	return err; | 
 | 10027 | } | 
 | 10028 |  | 
 | 10029 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | 
 | 10030 | 					      struct genl_info *info) | 
 | 10031 | { | 
 | 10032 | 	struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 
 | 10033 | 	struct net_device *dev = info->user_ptr[1]; | 
 | 10034 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 10035 | 	const u8 *addr; | 
 | 10036 |  | 
 | 10037 | 	if (!rdev->ops->tdls_channel_switch || | 
 | 10038 | 	    !rdev->ops->tdls_cancel_channel_switch || | 
 | 10039 | 	    !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | 
 | 10040 | 		return -EOPNOTSUPP; | 
 | 10041 |  | 
 | 10042 | 	switch (dev->ieee80211_ptr->iftype) { | 
 | 10043 | 	case NL80211_IFTYPE_STATION: | 
 | 10044 | 	case NL80211_IFTYPE_P2P_CLIENT: | 
 | 10045 | 		break; | 
 | 10046 | 	default: | 
 | 10047 | 		return -EOPNOTSUPP; | 
 | 10048 | 	} | 
 | 10049 |  | 
 | 10050 | 	if (!info->attrs[NL80211_ATTR_MAC]) | 
 | 10051 | 		return -EINVAL; | 
 | 10052 |  | 
 | 10053 | 	addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 
 | 10054 |  | 
 | 10055 | 	wdev_lock(wdev); | 
 | 10056 | 	rdev_tdls_cancel_channel_switch(rdev, dev, addr); | 
 | 10057 | 	wdev_unlock(wdev); | 
 | 10058 |  | 
 | 10059 | 	return 0; | 
 | 10060 | } | 
 | 10061 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10062 | #define NL80211_FLAG_NEED_WIPHY		0x01 | 
 | 10063 | #define NL80211_FLAG_NEED_NETDEV	0x02 | 
 | 10064 | #define NL80211_FLAG_NEED_RTNL		0x04 | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10065 | #define NL80211_FLAG_CHECK_NETDEV_UP	0x08 | 
 | 10066 | #define NL80211_FLAG_NEED_NETDEV_UP	(NL80211_FLAG_NEED_NETDEV |\ | 
 | 10067 | 					 NL80211_FLAG_CHECK_NETDEV_UP) | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10068 | #define NL80211_FLAG_NEED_WDEV		0x10 | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10069 | /* 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] | 10070 | #define NL80211_FLAG_NEED_WDEV_UP	(NL80211_FLAG_NEED_WDEV |\ | 
 | 10071 | 					 NL80211_FLAG_CHECK_NETDEV_UP) | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10072 | #define NL80211_FLAG_CLEAR_SKB		0x20 | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10073 |  | 
| Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10074 | 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] | 10075 | 			    struct genl_info *info) | 
 | 10076 | { | 
 | 10077 | 	struct cfg80211_registered_device *rdev; | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10078 | 	struct wireless_dev *wdev; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10079 | 	struct net_device *dev; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10080 | 	bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | 
 | 10081 |  | 
 | 10082 | 	if (rtnl) | 
 | 10083 | 		rtnl_lock(); | 
 | 10084 |  | 
 | 10085 | 	if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | 
| Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10086 | 		rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10087 | 		if (IS_ERR(rdev)) { | 
 | 10088 | 			if (rtnl) | 
 | 10089 | 				rtnl_unlock(); | 
 | 10090 | 			return PTR_ERR(rdev); | 
 | 10091 | 		} | 
 | 10092 | 		info->user_ptr[0] = rdev; | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10093 | 	} else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || | 
 | 10094 | 		   ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10095 | 		ASSERT_RTNL(); | 
 | 10096 |  | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10097 | 		wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), | 
 | 10098 | 						  info->attrs); | 
 | 10099 | 		if (IS_ERR(wdev)) { | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10100 | 			if (rtnl) | 
 | 10101 | 				rtnl_unlock(); | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10102 | 			return PTR_ERR(wdev); | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10103 | 		} | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10104 |  | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10105 | 		dev = wdev->netdev; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10106 | 		rdev = wiphy_to_rdev(wdev->wiphy); | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10107 |  | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10108 | 		if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | 
 | 10109 | 			if (!dev) { | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10110 | 				if (rtnl) | 
 | 10111 | 					rtnl_unlock(); | 
 | 10112 | 				return -EINVAL; | 
 | 10113 | 			} | 
 | 10114 |  | 
 | 10115 | 			info->user_ptr[1] = dev; | 
 | 10116 | 		} else { | 
 | 10117 | 			info->user_ptr[1] = wdev; | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10118 | 		} | 
| Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10119 |  | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10120 | 		if (dev) { | 
 | 10121 | 			if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | 
 | 10122 | 			    !netif_running(dev)) { | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10123 | 				if (rtnl) | 
 | 10124 | 					rtnl_unlock(); | 
 | 10125 | 				return -ENETDOWN; | 
 | 10126 | 			} | 
 | 10127 |  | 
 | 10128 | 			dev_hold(dev); | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10129 | 		} else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { | 
 | 10130 | 			if (!wdev->p2p_started) { | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10131 | 				if (rtnl) | 
 | 10132 | 					rtnl_unlock(); | 
 | 10133 | 				return -ENETDOWN; | 
 | 10134 | 			} | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10135 | 		} | 
 | 10136 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10137 | 		info->user_ptr[0] = rdev; | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10138 | 	} | 
 | 10139 |  | 
 | 10140 | 	return 0; | 
 | 10141 | } | 
 | 10142 |  | 
| Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10143 | 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] | 10144 | 			      struct genl_info *info) | 
 | 10145 | { | 
| Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10146 | 	if (info->user_ptr[1]) { | 
 | 10147 | 		if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | 
 | 10148 | 			struct wireless_dev *wdev = info->user_ptr[1]; | 
 | 10149 |  | 
 | 10150 | 			if (wdev->netdev) | 
 | 10151 | 				dev_put(wdev->netdev); | 
 | 10152 | 		} else { | 
 | 10153 | 			dev_put(info->user_ptr[1]); | 
 | 10154 | 		} | 
 | 10155 | 	} | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10156 |  | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10157 | 	if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | 
 | 10158 | 		rtnl_unlock(); | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10159 |  | 
 | 10160 | 	/* If needed, clear the netlink message payload from the SKB | 
 | 10161 | 	 * as it might contain key data that shouldn't stick around on | 
 | 10162 | 	 * the heap after the SKB is freed. The netlink message header | 
 | 10163 | 	 * is still needed for further processing, so leave it intact. | 
 | 10164 | 	 */ | 
 | 10165 | 	if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | 
 | 10166 | 		struct nlmsghdr *nlh = nlmsg_hdr(skb); | 
 | 10167 |  | 
 | 10168 | 		memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | 
 | 10169 | 	} | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10170 | } | 
 | 10171 |  | 
| Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10172 | static const struct genl_ops nl80211_ops[] = { | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10173 | 	{ | 
 | 10174 | 		.cmd = NL80211_CMD_GET_WIPHY, | 
 | 10175 | 		.doit = nl80211_get_wiphy, | 
 | 10176 | 		.dumpit = nl80211_dump_wiphy, | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10177 | 		.done = nl80211_dump_wiphy_done, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10178 | 		.policy = nl80211_policy, | 
 | 10179 | 		/* can be retrieved by unprivileged users */ | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10180 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10181 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10182 | 	}, | 
 | 10183 | 	{ | 
 | 10184 | 		.cmd = NL80211_CMD_SET_WIPHY, | 
 | 10185 | 		.doit = nl80211_set_wiphy, | 
 | 10186 | 		.policy = nl80211_policy, | 
 | 10187 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10188 | 		.internal_flags = NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10189 | 	}, | 
 | 10190 | 	{ | 
 | 10191 | 		.cmd = NL80211_CMD_GET_INTERFACE, | 
 | 10192 | 		.doit = nl80211_get_interface, | 
 | 10193 | 		.dumpit = nl80211_dump_interface, | 
 | 10194 | 		.policy = nl80211_policy, | 
 | 10195 | 		/* can be retrieved by unprivileged users */ | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10196 | 		.internal_flags = NL80211_FLAG_NEED_WDEV | | 
 | 10197 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10198 | 	}, | 
 | 10199 | 	{ | 
 | 10200 | 		.cmd = NL80211_CMD_SET_INTERFACE, | 
 | 10201 | 		.doit = nl80211_set_interface, | 
 | 10202 | 		.policy = nl80211_policy, | 
 | 10203 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10204 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10205 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10206 | 	}, | 
 | 10207 | 	{ | 
 | 10208 | 		.cmd = NL80211_CMD_NEW_INTERFACE, | 
 | 10209 | 		.doit = nl80211_new_interface, | 
 | 10210 | 		.policy = nl80211_policy, | 
 | 10211 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10212 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10213 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10214 | 	}, | 
 | 10215 | 	{ | 
 | 10216 | 		.cmd = NL80211_CMD_DEL_INTERFACE, | 
 | 10217 | 		.doit = nl80211_del_interface, | 
 | 10218 | 		.policy = nl80211_policy, | 
 | 10219 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10220 | 		.internal_flags = NL80211_FLAG_NEED_WDEV | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10221 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10222 | 	}, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10223 | 	{ | 
 | 10224 | 		.cmd = NL80211_CMD_GET_KEY, | 
 | 10225 | 		.doit = nl80211_get_key, | 
 | 10226 | 		.policy = nl80211_policy, | 
 | 10227 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10228 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10229 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10230 | 	}, | 
 | 10231 | 	{ | 
 | 10232 | 		.cmd = NL80211_CMD_SET_KEY, | 
 | 10233 | 		.doit = nl80211_set_key, | 
 | 10234 | 		.policy = nl80211_policy, | 
 | 10235 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10236 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10237 | 				  NL80211_FLAG_NEED_RTNL | | 
 | 10238 | 				  NL80211_FLAG_CLEAR_SKB, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10239 | 	}, | 
 | 10240 | 	{ | 
 | 10241 | 		.cmd = NL80211_CMD_NEW_KEY, | 
 | 10242 | 		.doit = nl80211_new_key, | 
 | 10243 | 		.policy = nl80211_policy, | 
 | 10244 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10245 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10246 | 				  NL80211_FLAG_NEED_RTNL | | 
 | 10247 | 				  NL80211_FLAG_CLEAR_SKB, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10248 | 	}, | 
 | 10249 | 	{ | 
 | 10250 | 		.cmd = NL80211_CMD_DEL_KEY, | 
 | 10251 | 		.doit = nl80211_del_key, | 
 | 10252 | 		.policy = nl80211_policy, | 
 | 10253 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10254 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10255 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10256 | 	}, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10257 | 	{ | 
 | 10258 | 		.cmd = NL80211_CMD_SET_BEACON, | 
 | 10259 | 		.policy = nl80211_policy, | 
 | 10260 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10261 | 		.doit = nl80211_set_beacon, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10262 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10263 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10264 | 	}, | 
 | 10265 | 	{ | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10266 | 		.cmd = NL80211_CMD_START_AP, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10267 | 		.policy = nl80211_policy, | 
 | 10268 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10269 | 		.doit = nl80211_start_ap, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10270 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10271 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10272 | 	}, | 
 | 10273 | 	{ | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10274 | 		.cmd = NL80211_CMD_STOP_AP, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10275 | 		.policy = nl80211_policy, | 
 | 10276 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10277 | 		.doit = nl80211_stop_ap, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10278 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10279 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10280 | 	}, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10281 | 	{ | 
 | 10282 | 		.cmd = NL80211_CMD_GET_STATION, | 
 | 10283 | 		.doit = nl80211_get_station, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10284 | 		.dumpit = nl80211_dump_station, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10285 | 		.policy = nl80211_policy, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10286 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10287 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10288 | 	}, | 
 | 10289 | 	{ | 
 | 10290 | 		.cmd = NL80211_CMD_SET_STATION, | 
 | 10291 | 		.doit = nl80211_set_station, | 
 | 10292 | 		.policy = nl80211_policy, | 
 | 10293 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10294 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10295 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10296 | 	}, | 
 | 10297 | 	{ | 
 | 10298 | 		.cmd = NL80211_CMD_NEW_STATION, | 
 | 10299 | 		.doit = nl80211_new_station, | 
 | 10300 | 		.policy = nl80211_policy, | 
 | 10301 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10302 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10303 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10304 | 	}, | 
 | 10305 | 	{ | 
 | 10306 | 		.cmd = NL80211_CMD_DEL_STATION, | 
 | 10307 | 		.doit = nl80211_del_station, | 
 | 10308 | 		.policy = nl80211_policy, | 
 | 10309 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10310 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10311 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10312 | 	}, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10313 | 	{ | 
 | 10314 | 		.cmd = NL80211_CMD_GET_MPATH, | 
 | 10315 | 		.doit = nl80211_get_mpath, | 
 | 10316 | 		.dumpit = nl80211_dump_mpath, | 
 | 10317 | 		.policy = nl80211_policy, | 
 | 10318 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10319 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10320 | 				  NL80211_FLAG_NEED_RTNL, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10321 | 	}, | 
 | 10322 | 	{ | 
| Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10323 | 		.cmd = NL80211_CMD_GET_MPP, | 
 | 10324 | 		.doit = nl80211_get_mpp, | 
 | 10325 | 		.dumpit = nl80211_dump_mpp, | 
 | 10326 | 		.policy = nl80211_policy, | 
 | 10327 | 		.flags = GENL_ADMIN_PERM, | 
 | 10328 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10329 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10330 | 	}, | 
 | 10331 | 	{ | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10332 | 		.cmd = NL80211_CMD_SET_MPATH, | 
 | 10333 | 		.doit = nl80211_set_mpath, | 
 | 10334 | 		.policy = nl80211_policy, | 
 | 10335 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10336 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10337 | 				  NL80211_FLAG_NEED_RTNL, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10338 | 	}, | 
 | 10339 | 	{ | 
 | 10340 | 		.cmd = NL80211_CMD_NEW_MPATH, | 
 | 10341 | 		.doit = nl80211_new_mpath, | 
 | 10342 | 		.policy = nl80211_policy, | 
 | 10343 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10344 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10345 | 				  NL80211_FLAG_NEED_RTNL, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10346 | 	}, | 
 | 10347 | 	{ | 
 | 10348 | 		.cmd = NL80211_CMD_DEL_MPATH, | 
 | 10349 | 		.doit = nl80211_del_mpath, | 
 | 10350 | 		.policy = nl80211_policy, | 
 | 10351 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10352 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10353 | 				  NL80211_FLAG_NEED_RTNL, | 
| Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10354 | 	}, | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10355 | 	{ | 
 | 10356 | 		.cmd = NL80211_CMD_SET_BSS, | 
 | 10357 | 		.doit = nl80211_set_bss, | 
 | 10358 | 		.policy = nl80211_policy, | 
 | 10359 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10360 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10361 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10362 | 	}, | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10363 | 	{ | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10364 | 		.cmd = NL80211_CMD_GET_REG, | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10365 | 		.doit = nl80211_get_reg_do, | 
 | 10366 | 		.dumpit = nl80211_get_reg_dump, | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10367 | 		.policy = nl80211_policy, | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10368 | 		.internal_flags = NL80211_FLAG_NEED_RTNL, | 
| Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10369 | 		/* can be retrieved by unprivileged users */ | 
 | 10370 | 	}, | 
 | 10371 | 	{ | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10372 | 		.cmd = NL80211_CMD_SET_REG, | 
 | 10373 | 		.doit = nl80211_set_reg, | 
 | 10374 | 		.policy = nl80211_policy, | 
 | 10375 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10376 | 		.internal_flags = NL80211_FLAG_NEED_RTNL, | 
| Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10377 | 	}, | 
 | 10378 | 	{ | 
 | 10379 | 		.cmd = NL80211_CMD_REQ_SET_REG, | 
 | 10380 | 		.doit = nl80211_req_set_reg, | 
 | 10381 | 		.policy = nl80211_policy, | 
 | 10382 | 		.flags = GENL_ADMIN_PERM, | 
 | 10383 | 	}, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10384 | 	{ | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10385 | 		.cmd = NL80211_CMD_GET_MESH_CONFIG, | 
 | 10386 | 		.doit = nl80211_get_mesh_config, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10387 | 		.policy = nl80211_policy, | 
 | 10388 | 		/* can be retrieved by unprivileged users */ | 
| 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, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10391 | 	}, | 
 | 10392 | 	{ | 
| Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10393 | 		.cmd = NL80211_CMD_SET_MESH_CONFIG, | 
 | 10394 | 		.doit = nl80211_update_mesh_config, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10395 | 		.policy = nl80211_policy, | 
 | 10396 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10397 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10398 | 				  NL80211_FLAG_NEED_RTNL, | 
| colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10399 | 	}, | 
| Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10400 | 	{ | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10401 | 		.cmd = NL80211_CMD_TRIGGER_SCAN, | 
 | 10402 | 		.doit = nl80211_trigger_scan, | 
 | 10403 | 		.policy = nl80211_policy, | 
 | 10404 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10405 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10406 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10407 | 	}, | 
 | 10408 | 	{ | 
 | 10409 | 		.cmd = NL80211_CMD_GET_SCAN, | 
 | 10410 | 		.policy = nl80211_policy, | 
 | 10411 | 		.dumpit = nl80211_dump_scan, | 
 | 10412 | 	}, | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10413 | 	{ | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10414 | 		.cmd = NL80211_CMD_START_SCHED_SCAN, | 
 | 10415 | 		.doit = nl80211_start_sched_scan, | 
 | 10416 | 		.policy = nl80211_policy, | 
 | 10417 | 		.flags = GENL_ADMIN_PERM, | 
 | 10418 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10419 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10420 | 	}, | 
 | 10421 | 	{ | 
 | 10422 | 		.cmd = NL80211_CMD_STOP_SCHED_SCAN, | 
 | 10423 | 		.doit = nl80211_stop_sched_scan, | 
 | 10424 | 		.policy = nl80211_policy, | 
 | 10425 | 		.flags = GENL_ADMIN_PERM, | 
 | 10426 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10427 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10428 | 	}, | 
 | 10429 | 	{ | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10430 | 		.cmd = NL80211_CMD_AUTHENTICATE, | 
 | 10431 | 		.doit = nl80211_authenticate, | 
 | 10432 | 		.policy = nl80211_policy, | 
 | 10433 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10434 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10435 | 				  NL80211_FLAG_NEED_RTNL | | 
 | 10436 | 				  NL80211_FLAG_CLEAR_SKB, | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10437 | 	}, | 
 | 10438 | 	{ | 
 | 10439 | 		.cmd = NL80211_CMD_ASSOCIATE, | 
 | 10440 | 		.doit = nl80211_associate, | 
 | 10441 | 		.policy = nl80211_policy, | 
 | 10442 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10443 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10444 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10445 | 	}, | 
 | 10446 | 	{ | 
 | 10447 | 		.cmd = NL80211_CMD_DEAUTHENTICATE, | 
 | 10448 | 		.doit = nl80211_deauthenticate, | 
 | 10449 | 		.policy = nl80211_policy, | 
 | 10450 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10451 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10452 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10453 | 	}, | 
 | 10454 | 	{ | 
 | 10455 | 		.cmd = NL80211_CMD_DISASSOCIATE, | 
 | 10456 | 		.doit = nl80211_disassociate, | 
 | 10457 | 		.policy = nl80211_policy, | 
 | 10458 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10459 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10460 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10461 | 	}, | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10462 | 	{ | 
 | 10463 | 		.cmd = NL80211_CMD_JOIN_IBSS, | 
 | 10464 | 		.doit = nl80211_join_ibss, | 
 | 10465 | 		.policy = nl80211_policy, | 
 | 10466 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10467 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10468 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10469 | 	}, | 
 | 10470 | 	{ | 
 | 10471 | 		.cmd = NL80211_CMD_LEAVE_IBSS, | 
 | 10472 | 		.doit = nl80211_leave_ibss, | 
 | 10473 | 		.policy = nl80211_policy, | 
 | 10474 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10475 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10476 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10477 | 	}, | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10478 | #ifdef CONFIG_NL80211_TESTMODE | 
 | 10479 | 	{ | 
 | 10480 | 		.cmd = NL80211_CMD_TESTMODE, | 
 | 10481 | 		.doit = nl80211_testmode_do, | 
| Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10482 | 		.dumpit = nl80211_testmode_dump, | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10483 | 		.policy = nl80211_policy, | 
 | 10484 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10485 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10486 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10487 | 	}, | 
 | 10488 | #endif | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10489 | 	{ | 
 | 10490 | 		.cmd = NL80211_CMD_CONNECT, | 
 | 10491 | 		.doit = nl80211_connect, | 
 | 10492 | 		.policy = nl80211_policy, | 
 | 10493 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10494 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10495 | 				  NL80211_FLAG_NEED_RTNL, | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10496 | 	}, | 
 | 10497 | 	{ | 
 | 10498 | 		.cmd = NL80211_CMD_DISCONNECT, | 
 | 10499 | 		.doit = nl80211_disconnect, | 
 | 10500 | 		.policy = nl80211_policy, | 
 | 10501 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10502 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10503 | 				  NL80211_FLAG_NEED_RTNL, | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10504 | 	}, | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10505 | 	{ | 
 | 10506 | 		.cmd = NL80211_CMD_SET_WIPHY_NETNS, | 
 | 10507 | 		.doit = nl80211_wiphy_netns, | 
 | 10508 | 		.policy = nl80211_policy, | 
 | 10509 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10510 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10511 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10512 | 	}, | 
| Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10513 | 	{ | 
 | 10514 | 		.cmd = NL80211_CMD_GET_SURVEY, | 
 | 10515 | 		.policy = nl80211_policy, | 
 | 10516 | 		.dumpit = nl80211_dump_survey, | 
 | 10517 | 	}, | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10518 | 	{ | 
 | 10519 | 		.cmd = NL80211_CMD_SET_PMKSA, | 
 | 10520 | 		.doit = nl80211_setdel_pmksa, | 
 | 10521 | 		.policy = nl80211_policy, | 
 | 10522 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10523 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10524 | 				  NL80211_FLAG_NEED_RTNL, | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10525 | 	}, | 
 | 10526 | 	{ | 
 | 10527 | 		.cmd = NL80211_CMD_DEL_PMKSA, | 
 | 10528 | 		.doit = nl80211_setdel_pmksa, | 
 | 10529 | 		.policy = nl80211_policy, | 
 | 10530 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10531 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10532 | 				  NL80211_FLAG_NEED_RTNL, | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10533 | 	}, | 
 | 10534 | 	{ | 
 | 10535 | 		.cmd = NL80211_CMD_FLUSH_PMKSA, | 
 | 10536 | 		.doit = nl80211_flush_pmksa, | 
 | 10537 | 		.policy = nl80211_policy, | 
 | 10538 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10539 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10540 | 				  NL80211_FLAG_NEED_RTNL, | 
| Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10541 | 	}, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10542 | 	{ | 
 | 10543 | 		.cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | 
 | 10544 | 		.doit = nl80211_remain_on_channel, | 
 | 10545 | 		.policy = nl80211_policy, | 
 | 10546 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10547 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10548 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10549 | 	}, | 
 | 10550 | 	{ | 
 | 10551 | 		.cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | 
 | 10552 | 		.doit = nl80211_cancel_remain_on_channel, | 
 | 10553 | 		.policy = nl80211_policy, | 
 | 10554 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10555 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10556 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10557 | 	}, | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10558 | 	{ | 
 | 10559 | 		.cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | 
 | 10560 | 		.doit = nl80211_set_tx_bitrate_mask, | 
 | 10561 | 		.policy = nl80211_policy, | 
 | 10562 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10563 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10564 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10565 | 	}, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10566 | 	{ | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10567 | 		.cmd = NL80211_CMD_REGISTER_FRAME, | 
 | 10568 | 		.doit = nl80211_register_mgmt, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10569 | 		.policy = nl80211_policy, | 
 | 10570 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10571 | 		.internal_flags = NL80211_FLAG_NEED_WDEV | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10572 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10573 | 	}, | 
 | 10574 | 	{ | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10575 | 		.cmd = NL80211_CMD_FRAME, | 
 | 10576 | 		.doit = nl80211_tx_mgmt, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10577 | 		.policy = nl80211_policy, | 
 | 10578 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10579 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10580 | 				  NL80211_FLAG_NEED_RTNL, | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10581 | 	}, | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10582 | 	{ | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10583 | 		.cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | 
 | 10584 | 		.doit = nl80211_tx_mgmt_cancel_wait, | 
 | 10585 | 		.policy = nl80211_policy, | 
 | 10586 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10587 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
| Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10588 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10589 | 	}, | 
 | 10590 | 	{ | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10591 | 		.cmd = NL80211_CMD_SET_POWER_SAVE, | 
 | 10592 | 		.doit = nl80211_set_power_save, | 
 | 10593 | 		.policy = nl80211_policy, | 
 | 10594 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10595 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10596 | 				  NL80211_FLAG_NEED_RTNL, | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10597 | 	}, | 
 | 10598 | 	{ | 
 | 10599 | 		.cmd = NL80211_CMD_GET_POWER_SAVE, | 
 | 10600 | 		.doit = nl80211_get_power_save, | 
 | 10601 | 		.policy = nl80211_policy, | 
 | 10602 | 		/* can be retrieved by unprivileged users */ | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10603 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10604 | 				  NL80211_FLAG_NEED_RTNL, | 
| Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10605 | 	}, | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10606 | 	{ | 
 | 10607 | 		.cmd = NL80211_CMD_SET_CQM, | 
 | 10608 | 		.doit = nl80211_set_cqm, | 
 | 10609 | 		.policy = nl80211_policy, | 
 | 10610 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10611 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10612 | 				  NL80211_FLAG_NEED_RTNL, | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10613 | 	}, | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10614 | 	{ | 
 | 10615 | 		.cmd = NL80211_CMD_SET_CHANNEL, | 
 | 10616 | 		.doit = nl80211_set_channel, | 
 | 10617 | 		.policy = nl80211_policy, | 
 | 10618 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10619 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10620 | 				  NL80211_FLAG_NEED_RTNL, | 
| Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10621 | 	}, | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10622 | 	{ | 
 | 10623 | 		.cmd = NL80211_CMD_SET_WDS_PEER, | 
 | 10624 | 		.doit = nl80211_set_wds_peer, | 
 | 10625 | 		.policy = nl80211_policy, | 
 | 10626 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10627 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10628 | 				  NL80211_FLAG_NEED_RTNL, | 
| Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10629 | 	}, | 
| Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10630 | 	{ | 
 | 10631 | 		.cmd = NL80211_CMD_JOIN_MESH, | 
 | 10632 | 		.doit = nl80211_join_mesh, | 
 | 10633 | 		.policy = nl80211_policy, | 
 | 10634 | 		.flags = GENL_ADMIN_PERM, | 
 | 10635 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10636 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10637 | 	}, | 
 | 10638 | 	{ | 
 | 10639 | 		.cmd = NL80211_CMD_LEAVE_MESH, | 
 | 10640 | 		.doit = nl80211_leave_mesh, | 
 | 10641 | 		.policy = nl80211_policy, | 
 | 10642 | 		.flags = GENL_ADMIN_PERM, | 
 | 10643 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10644 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10645 | 	}, | 
| Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10646 | 	{ | 
 | 10647 | 		.cmd = NL80211_CMD_JOIN_OCB, | 
 | 10648 | 		.doit = nl80211_join_ocb, | 
 | 10649 | 		.policy = nl80211_policy, | 
 | 10650 | 		.flags = GENL_ADMIN_PERM, | 
 | 10651 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10652 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10653 | 	}, | 
 | 10654 | 	{ | 
 | 10655 | 		.cmd = NL80211_CMD_LEAVE_OCB, | 
 | 10656 | 		.doit = nl80211_leave_ocb, | 
 | 10657 | 		.policy = nl80211_policy, | 
 | 10658 | 		.flags = GENL_ADMIN_PERM, | 
 | 10659 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10660 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10661 | 	}, | 
| Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10662 | #ifdef CONFIG_PM | 
| Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10663 | 	{ | 
 | 10664 | 		.cmd = NL80211_CMD_GET_WOWLAN, | 
 | 10665 | 		.doit = nl80211_get_wowlan, | 
 | 10666 | 		.policy = nl80211_policy, | 
 | 10667 | 		/* can be retrieved by unprivileged users */ | 
 | 10668 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10669 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10670 | 	}, | 
 | 10671 | 	{ | 
 | 10672 | 		.cmd = NL80211_CMD_SET_WOWLAN, | 
 | 10673 | 		.doit = nl80211_set_wowlan, | 
 | 10674 | 		.policy = nl80211_policy, | 
 | 10675 | 		.flags = GENL_ADMIN_PERM, | 
 | 10676 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10677 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10678 | 	}, | 
| Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10679 | #endif | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10680 | 	{ | 
 | 10681 | 		.cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | 
 | 10682 | 		.doit = nl80211_set_rekey_data, | 
 | 10683 | 		.policy = nl80211_policy, | 
 | 10684 | 		.flags = GENL_ADMIN_PERM, | 
 | 10685 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10686 | 				  NL80211_FLAG_NEED_RTNL | | 
 | 10687 | 				  NL80211_FLAG_CLEAR_SKB, | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10688 | 	}, | 
| Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10689 | 	{ | 
 | 10690 | 		.cmd = NL80211_CMD_TDLS_MGMT, | 
 | 10691 | 		.doit = nl80211_tdls_mgmt, | 
 | 10692 | 		.policy = nl80211_policy, | 
 | 10693 | 		.flags = GENL_ADMIN_PERM, | 
 | 10694 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10695 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10696 | 	}, | 
 | 10697 | 	{ | 
 | 10698 | 		.cmd = NL80211_CMD_TDLS_OPER, | 
 | 10699 | 		.doit = nl80211_tdls_oper, | 
 | 10700 | 		.policy = nl80211_policy, | 
 | 10701 | 		.flags = GENL_ADMIN_PERM, | 
 | 10702 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10703 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10704 | 	}, | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10705 | 	{ | 
 | 10706 | 		.cmd = NL80211_CMD_UNEXPECTED_FRAME, | 
 | 10707 | 		.doit = nl80211_register_unexpected_frame, | 
 | 10708 | 		.policy = nl80211_policy, | 
 | 10709 | 		.flags = GENL_ADMIN_PERM, | 
 | 10710 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10711 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10712 | 	}, | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10713 | 	{ | 
 | 10714 | 		.cmd = NL80211_CMD_PROBE_CLIENT, | 
 | 10715 | 		.doit = nl80211_probe_client, | 
 | 10716 | 		.policy = nl80211_policy, | 
 | 10717 | 		.flags = GENL_ADMIN_PERM, | 
| Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10718 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10719 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10720 | 	}, | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10721 | 	{ | 
 | 10722 | 		.cmd = NL80211_CMD_REGISTER_BEACONS, | 
 | 10723 | 		.doit = nl80211_register_beacons, | 
 | 10724 | 		.policy = nl80211_policy, | 
 | 10725 | 		.flags = GENL_ADMIN_PERM, | 
 | 10726 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10727 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10728 | 	}, | 
| Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10729 | 	{ | 
 | 10730 | 		.cmd = NL80211_CMD_SET_NOACK_MAP, | 
 | 10731 | 		.doit = nl80211_set_noack_map, | 
 | 10732 | 		.policy = nl80211_policy, | 
 | 10733 | 		.flags = GENL_ADMIN_PERM, | 
 | 10734 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10735 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10736 | 	}, | 
| Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10737 | 	{ | 
 | 10738 | 		.cmd = NL80211_CMD_START_P2P_DEVICE, | 
 | 10739 | 		.doit = nl80211_start_p2p_device, | 
 | 10740 | 		.policy = nl80211_policy, | 
 | 10741 | 		.flags = GENL_ADMIN_PERM, | 
 | 10742 | 		.internal_flags = NL80211_FLAG_NEED_WDEV | | 
 | 10743 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10744 | 	}, | 
 | 10745 | 	{ | 
 | 10746 | 		.cmd = NL80211_CMD_STOP_P2P_DEVICE, | 
 | 10747 | 		.doit = nl80211_stop_p2p_device, | 
 | 10748 | 		.policy = nl80211_policy, | 
 | 10749 | 		.flags = GENL_ADMIN_PERM, | 
 | 10750 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
 | 10751 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10752 | 	}, | 
| Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10753 | 	{ | 
 | 10754 | 		.cmd = NL80211_CMD_SET_MCAST_RATE, | 
 | 10755 | 		.doit = nl80211_set_mcast_rate, | 
 | 10756 | 		.policy = nl80211_policy, | 
 | 10757 | 		.flags = GENL_ADMIN_PERM, | 
 | 10758 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10759 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10760 | 	}, | 
| Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10761 | 	{ | 
 | 10762 | 		.cmd = NL80211_CMD_SET_MAC_ACL, | 
 | 10763 | 		.doit = nl80211_set_mac_acl, | 
 | 10764 | 		.policy = nl80211_policy, | 
 | 10765 | 		.flags = GENL_ADMIN_PERM, | 
 | 10766 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV | | 
 | 10767 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10768 | 	}, | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10769 | 	{ | 
 | 10770 | 		.cmd = NL80211_CMD_RADAR_DETECT, | 
 | 10771 | 		.doit = nl80211_start_radar_detection, | 
 | 10772 | 		.policy = nl80211_policy, | 
 | 10773 | 		.flags = GENL_ADMIN_PERM, | 
 | 10774 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10775 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10776 | 	}, | 
| Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10777 | 	{ | 
 | 10778 | 		.cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | 
 | 10779 | 		.doit = nl80211_get_protocol_features, | 
 | 10780 | 		.policy = nl80211_policy, | 
 | 10781 | 	}, | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10782 | 	{ | 
 | 10783 | 		.cmd = NL80211_CMD_UPDATE_FT_IES, | 
 | 10784 | 		.doit = nl80211_update_ft_ies, | 
 | 10785 | 		.policy = nl80211_policy, | 
 | 10786 | 		.flags = GENL_ADMIN_PERM, | 
 | 10787 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10788 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10789 | 	}, | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10790 | 	{ | 
 | 10791 | 		.cmd = NL80211_CMD_CRIT_PROTOCOL_START, | 
 | 10792 | 		.doit = nl80211_crit_protocol_start, | 
 | 10793 | 		.policy = nl80211_policy, | 
 | 10794 | 		.flags = GENL_ADMIN_PERM, | 
 | 10795 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
 | 10796 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10797 | 	}, | 
 | 10798 | 	{ | 
 | 10799 | 		.cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | 
 | 10800 | 		.doit = nl80211_crit_protocol_stop, | 
 | 10801 | 		.policy = nl80211_policy, | 
 | 10802 | 		.flags = GENL_ADMIN_PERM, | 
 | 10803 | 		.internal_flags = NL80211_FLAG_NEED_WDEV_UP | | 
 | 10804 | 				  NL80211_FLAG_NEED_RTNL, | 
| Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10805 | 	}, | 
 | 10806 | 	{ | 
 | 10807 | 		.cmd = NL80211_CMD_GET_COALESCE, | 
 | 10808 | 		.doit = nl80211_get_coalesce, | 
 | 10809 | 		.policy = nl80211_policy, | 
 | 10810 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10811 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10812 | 	}, | 
 | 10813 | 	{ | 
 | 10814 | 		.cmd = NL80211_CMD_SET_COALESCE, | 
 | 10815 | 		.doit = nl80211_set_coalesce, | 
 | 10816 | 		.policy = nl80211_policy, | 
 | 10817 | 		.flags = GENL_ADMIN_PERM, | 
 | 10818 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10819 | 				  NL80211_FLAG_NEED_RTNL, | 
| Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10820 | 	}, | 
 | 10821 | 	{ | 
 | 10822 | 		.cmd = NL80211_CMD_CHANNEL_SWITCH, | 
 | 10823 | 		.doit = nl80211_channel_switch, | 
 | 10824 | 		.policy = nl80211_policy, | 
 | 10825 | 		.flags = GENL_ADMIN_PERM, | 
 | 10826 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10827 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10828 | 	}, | 
| Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10829 | 	{ | 
 | 10830 | 		.cmd = NL80211_CMD_VENDOR, | 
 | 10831 | 		.doit = nl80211_vendor_cmd, | 
 | 10832 | 		.policy = nl80211_policy, | 
 | 10833 | 		.flags = GENL_ADMIN_PERM, | 
 | 10834 | 		.internal_flags = NL80211_FLAG_NEED_WIPHY | | 
 | 10835 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10836 | 	}, | 
| Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10837 | 	{ | 
 | 10838 | 		.cmd = NL80211_CMD_SET_QOS_MAP, | 
 | 10839 | 		.doit = nl80211_set_qos_map, | 
 | 10840 | 		.policy = nl80211_policy, | 
 | 10841 | 		.flags = GENL_ADMIN_PERM, | 
 | 10842 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10843 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10844 | 	}, | 
| Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10845 | 	{ | 
 | 10846 | 		.cmd = NL80211_CMD_ADD_TX_TS, | 
 | 10847 | 		.doit = nl80211_add_tx_ts, | 
 | 10848 | 		.policy = nl80211_policy, | 
 | 10849 | 		.flags = GENL_ADMIN_PERM, | 
 | 10850 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10851 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10852 | 	}, | 
 | 10853 | 	{ | 
 | 10854 | 		.cmd = NL80211_CMD_DEL_TX_TS, | 
 | 10855 | 		.doit = nl80211_del_tx_ts, | 
 | 10856 | 		.policy = nl80211_policy, | 
 | 10857 | 		.flags = GENL_ADMIN_PERM, | 
 | 10858 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10859 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10860 | 	}, | 
| Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10861 | 	{ | 
 | 10862 | 		.cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | 
 | 10863 | 		.doit = nl80211_tdls_channel_switch, | 
 | 10864 | 		.policy = nl80211_policy, | 
 | 10865 | 		.flags = GENL_ADMIN_PERM, | 
 | 10866 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10867 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10868 | 	}, | 
 | 10869 | 	{ | 
 | 10870 | 		.cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | 
 | 10871 | 		.doit = nl80211_tdls_cancel_channel_switch, | 
 | 10872 | 		.policy = nl80211_policy, | 
 | 10873 | 		.flags = GENL_ADMIN_PERM, | 
 | 10874 | 		.internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | 
 | 10875 | 				  NL80211_FLAG_NEED_RTNL, | 
 | 10876 | 	}, | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10877 | }; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10878 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10879 | /* notification functions */ | 
 | 10880 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10881 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, | 
 | 10882 | 			  enum nl80211_commands cmd) | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10883 | { | 
 | 10884 | 	struct sk_buff *msg; | 
| Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10885 | 	struct nl80211_dump_wiphy_state state = {}; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10886 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10887 | 	WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && | 
 | 10888 | 		cmd != NL80211_CMD_DEL_WIPHY); | 
 | 10889 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10890 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10891 | 	if (!msg) | 
 | 10892 | 		return; | 
 | 10893 |  | 
| Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10894 | 	if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10895 | 		nlmsg_free(msg); | 
 | 10896 | 		return; | 
 | 10897 | 	} | 
 | 10898 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10899 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10900 | 				NL80211_MCGRP_CONFIG, GFP_KERNEL); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10901 | } | 
 | 10902 |  | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10903 | static int nl80211_add_scan_req(struct sk_buff *msg, | 
 | 10904 | 				struct cfg80211_registered_device *rdev) | 
 | 10905 | { | 
 | 10906 | 	struct cfg80211_scan_request *req = rdev->scan_req; | 
 | 10907 | 	struct nlattr *nest; | 
 | 10908 | 	int i; | 
 | 10909 |  | 
 | 10910 | 	if (WARN_ON(!req)) | 
 | 10911 | 		return 0; | 
 | 10912 |  | 
 | 10913 | 	nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | 
 | 10914 | 	if (!nest) | 
 | 10915 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10916 | 	for (i = 0; i < req->n_ssids; i++) { | 
 | 10917 | 		if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | 
 | 10918 | 			goto nla_put_failure; | 
 | 10919 | 	} | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10920 | 	nla_nest_end(msg, nest); | 
 | 10921 |  | 
 | 10922 | 	nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | 
 | 10923 | 	if (!nest) | 
 | 10924 | 		goto nla_put_failure; | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10925 | 	for (i = 0; i < req->n_channels; i++) { | 
 | 10926 | 		if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | 
 | 10927 | 			goto nla_put_failure; | 
 | 10928 | 	} | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10929 | 	nla_nest_end(msg, nest); | 
 | 10930 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10931 | 	if (req->ie && | 
 | 10932 | 	    nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | 
 | 10933 | 		goto nla_put_failure; | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10934 |  | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10935 | 	if (req->flags && | 
 | 10936 | 	    nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | 
 | 10937 | 		goto nla_put_failure; | 
| Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10938 |  | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10939 | 	return 0; | 
 | 10940 |  nla_put_failure: | 
 | 10941 | 	return -ENOBUFS; | 
 | 10942 | } | 
 | 10943 |  | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10944 | static int nl80211_send_scan_msg(struct sk_buff *msg, | 
 | 10945 | 				 struct cfg80211_registered_device *rdev, | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10946 | 				 struct wireless_dev *wdev, | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10947 | 				 u32 portid, u32 seq, int flags, | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10948 | 				 u32 cmd) | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10949 | { | 
 | 10950 | 	void *hdr; | 
 | 10951 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10952 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10953 | 	if (!hdr) | 
 | 10954 | 		return -1; | 
 | 10955 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10956 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10957 | 	    (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
 | 10958 | 					 wdev->netdev->ifindex)) || | 
 | 10959 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10960 | 		goto nla_put_failure; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10961 |  | 
| Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10962 | 	/* ignore errors and send incomplete event anyway */ | 
 | 10963 | 	nl80211_add_scan_req(msg, rdev); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10964 |  | 
 | 10965 | 	return genlmsg_end(msg, hdr); | 
 | 10966 |  | 
 | 10967 |  nla_put_failure: | 
 | 10968 | 	genlmsg_cancel(msg, hdr); | 
 | 10969 | 	return -EMSGSIZE; | 
 | 10970 | } | 
 | 10971 |  | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10972 | static int | 
 | 10973 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | 
 | 10974 | 			    struct cfg80211_registered_device *rdev, | 
 | 10975 | 			    struct net_device *netdev, | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10976 | 			    u32 portid, u32 seq, int flags, u32 cmd) | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10977 | { | 
 | 10978 | 	void *hdr; | 
 | 10979 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10980 | 	hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10981 | 	if (!hdr) | 
 | 10982 | 		return -1; | 
 | 10983 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10984 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 10985 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | 
 | 10986 | 		goto nla_put_failure; | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10987 |  | 
 | 10988 | 	return genlmsg_end(msg, hdr); | 
 | 10989 |  | 
 | 10990 |  nla_put_failure: | 
 | 10991 | 	genlmsg_cancel(msg, hdr); | 
 | 10992 | 	return -EMSGSIZE; | 
 | 10993 | } | 
 | 10994 |  | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10995 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10996 | 			     struct wireless_dev *wdev) | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10997 | { | 
 | 10998 | 	struct sk_buff *msg; | 
 | 10999 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11000 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11001 | 	if (!msg) | 
 | 11002 | 		return; | 
 | 11003 |  | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11004 | 	if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11005 | 				  NL80211_CMD_TRIGGER_SCAN) < 0) { | 
 | 11006 | 		nlmsg_free(msg); | 
 | 11007 | 		return; | 
 | 11008 | 	} | 
 | 11009 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11010 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11011 | 				NL80211_MCGRP_SCAN, GFP_KERNEL); | 
| Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11012 | } | 
 | 11013 |  | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11014 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, | 
 | 11015 | 				       struct wireless_dev *wdev, bool aborted) | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11016 | { | 
 | 11017 | 	struct sk_buff *msg; | 
 | 11018 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11019 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11020 | 	if (!msg) | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11021 | 		return NULL; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11022 |  | 
| Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11023 | 	if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11024 | 				  aborted ? NL80211_CMD_SCAN_ABORTED : | 
 | 11025 | 					    NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11026 | 		nlmsg_free(msg); | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11027 | 		return NULL; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11028 | 	} | 
 | 11029 |  | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11030 | 	return msg; | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11031 | } | 
 | 11032 |  | 
| Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11033 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, | 
 | 11034 | 			      struct sk_buff *msg) | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11035 | { | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11036 | 	if (!msg) | 
 | 11037 | 		return; | 
 | 11038 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11039 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11040 | 				NL80211_MCGRP_SCAN, GFP_KERNEL); | 
| Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11041 | } | 
 | 11042 |  | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11043 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, | 
 | 11044 | 				     struct net_device *netdev) | 
 | 11045 | { | 
 | 11046 | 	struct sk_buff *msg; | 
 | 11047 |  | 
 | 11048 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 11049 | 	if (!msg) | 
 | 11050 | 		return; | 
 | 11051 |  | 
 | 11052 | 	if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | 
 | 11053 | 					NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | 
 | 11054 | 		nlmsg_free(msg); | 
 | 11055 | 		return; | 
 | 11056 | 	} | 
 | 11057 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11058 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11059 | 				NL80211_MCGRP_SCAN, GFP_KERNEL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11060 | } | 
 | 11061 |  | 
 | 11062 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | 
 | 11063 | 			     struct net_device *netdev, u32 cmd) | 
 | 11064 | { | 
 | 11065 | 	struct sk_buff *msg; | 
 | 11066 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11067 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11068 | 	if (!msg) | 
 | 11069 | 		return; | 
 | 11070 |  | 
 | 11071 | 	if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | 
 | 11072 | 		nlmsg_free(msg); | 
 | 11073 | 		return; | 
 | 11074 | 	} | 
 | 11075 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11076 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11077 | 				NL80211_MCGRP_SCAN, GFP_KERNEL); | 
| Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11078 | } | 
 | 11079 |  | 
| Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11080 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, | 
 | 11081 | 					  struct regulatory_request *request) | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11082 | { | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11083 | 	/* Userspace can always count this one always being set */ | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11084 | 	if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) | 
 | 11085 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11086 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11087 | 	if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | 
 | 11088 | 		if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
 | 11089 | 			       NL80211_REGDOM_TYPE_WORLD)) | 
 | 11090 | 			goto nla_put_failure; | 
 | 11091 | 	} else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | 
 | 11092 | 		if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
 | 11093 | 			       NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | 
 | 11094 | 			goto nla_put_failure; | 
 | 11095 | 	} else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | 
 | 11096 | 		   request->intersect) { | 
 | 11097 | 		if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
 | 11098 | 			       NL80211_REGDOM_TYPE_INTERSECTION)) | 
 | 11099 | 			goto nla_put_failure; | 
 | 11100 | 	} else { | 
 | 11101 | 		if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | 
 | 11102 | 			       NL80211_REGDOM_TYPE_COUNTRY) || | 
 | 11103 | 		    nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | 
 | 11104 | 				   request->alpha2)) | 
 | 11105 | 			goto nla_put_failure; | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11106 | 	} | 
 | 11107 |  | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11108 | 	if (request->wiphy_idx != WIPHY_IDX_INVALID) { | 
 | 11109 | 		struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | 
 | 11110 |  | 
 | 11111 | 		if (wiphy && | 
 | 11112 | 		    nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | 
 | 11113 | 			goto nla_put_failure; | 
| Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 11114 |  | 
 | 11115 | 		if (wiphy && | 
 | 11116 | 		    wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | 
 | 11117 | 		    nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | 
 | 11118 | 			goto nla_put_failure; | 
| Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11119 | 	} | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11120 |  | 
| Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11121 | 	return true; | 
 | 11122 |  | 
 | 11123 | nla_put_failure: | 
 | 11124 | 	return false; | 
 | 11125 | } | 
 | 11126 |  | 
 | 11127 | /* | 
 | 11128 |  * This can happen on global regulatory changes or device specific settings | 
 | 11129 |  * based on custom regulatory domains. | 
 | 11130 |  */ | 
 | 11131 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | 
 | 11132 | 				     struct regulatory_request *request) | 
 | 11133 | { | 
 | 11134 | 	struct sk_buff *msg; | 
 | 11135 | 	void *hdr; | 
 | 11136 |  | 
 | 11137 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 11138 | 	if (!msg) | 
 | 11139 | 		return; | 
 | 11140 |  | 
 | 11141 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | 
 | 11142 | 	if (!hdr) { | 
 | 11143 | 		nlmsg_free(msg); | 
 | 11144 | 		return; | 
 | 11145 | 	} | 
 | 11146 |  | 
 | 11147 | 	if (nl80211_reg_change_event_fill(msg, request) == false) | 
 | 11148 | 		goto nla_put_failure; | 
 | 11149 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11150 | 	genlmsg_end(msg, hdr); | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11151 |  | 
| Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11152 | 	rcu_read_lock(); | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11153 | 	genlmsg_multicast_allns(&nl80211_fam, msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11154 | 				NL80211_MCGRP_REGULATORY, GFP_ATOMIC); | 
| Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11155 | 	rcu_read_unlock(); | 
| Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11156 |  | 
 | 11157 | 	return; | 
 | 11158 |  | 
 | 11159 | nla_put_failure: | 
 | 11160 | 	genlmsg_cancel(msg, hdr); | 
 | 11161 | 	nlmsg_free(msg); | 
 | 11162 | } | 
 | 11163 |  | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11164 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, | 
 | 11165 | 				    struct net_device *netdev, | 
 | 11166 | 				    const u8 *buf, size_t len, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11167 | 				    enum nl80211_commands cmd, gfp_t gfp, | 
 | 11168 | 				    int uapsd_queues) | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11169 | { | 
 | 11170 | 	struct sk_buff *msg; | 
 | 11171 | 	void *hdr; | 
 | 11172 |  | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11173 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11174 | 	if (!msg) | 
 | 11175 | 		return; | 
 | 11176 |  | 
 | 11177 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
 | 11178 | 	if (!hdr) { | 
 | 11179 | 		nlmsg_free(msg); | 
 | 11180 | 		return; | 
 | 11181 | 	} | 
 | 11182 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11183 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11184 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11185 | 	    nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | 
 | 11186 | 		goto nla_put_failure; | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11187 |  | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11188 | 	if (uapsd_queues >= 0) { | 
 | 11189 | 		struct nlattr *nla_wmm = | 
 | 11190 | 			nla_nest_start(msg, NL80211_ATTR_STA_WME); | 
 | 11191 | 		if (!nla_wmm) | 
 | 11192 | 			goto nla_put_failure; | 
 | 11193 |  | 
 | 11194 | 		if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | 
 | 11195 | 			       uapsd_queues)) | 
 | 11196 | 			goto nla_put_failure; | 
 | 11197 |  | 
 | 11198 | 		nla_nest_end(msg, nla_wmm); | 
 | 11199 | 	} | 
 | 11200 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11201 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11202 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11203 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11204 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11205 | 	return; | 
 | 11206 |  | 
 | 11207 |  nla_put_failure: | 
 | 11208 | 	genlmsg_cancel(msg, hdr); | 
 | 11209 | 	nlmsg_free(msg); | 
 | 11210 | } | 
 | 11211 |  | 
 | 11212 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11213 | 			  struct net_device *netdev, const u8 *buf, | 
 | 11214 | 			  size_t len, gfp_t gfp) | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11215 | { | 
 | 11216 | 	nl80211_send_mlme_event(rdev, netdev, buf, len, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11217 | 				NL80211_CMD_AUTHENTICATE, gfp, -1); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11218 | } | 
 | 11219 |  | 
 | 11220 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | 
 | 11221 | 			   struct net_device *netdev, const u8 *buf, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11222 | 			   size_t len, gfp_t gfp, int uapsd_queues) | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11223 | { | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11224 | 	nl80211_send_mlme_event(rdev, netdev, buf, len, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11225 | 				NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11226 | } | 
 | 11227 |  | 
| Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11228 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11229 | 			 struct net_device *netdev, const u8 *buf, | 
 | 11230 | 			 size_t len, gfp_t gfp) | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11231 | { | 
 | 11232 | 	nl80211_send_mlme_event(rdev, netdev, buf, len, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11233 | 				NL80211_CMD_DEAUTHENTICATE, gfp, -1); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11234 | } | 
 | 11235 |  | 
| Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11236 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, | 
 | 11237 | 			   struct net_device *netdev, const u8 *buf, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11238 | 			   size_t len, gfp_t gfp) | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11239 | { | 
 | 11240 | 	nl80211_send_mlme_event(rdev, netdev, buf, len, | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11241 | 				NL80211_CMD_DISASSOCIATE, gfp, -1); | 
| Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11242 | } | 
 | 11243 |  | 
| Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11244 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, | 
 | 11245 | 				  size_t len) | 
| Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11246 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11247 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 11248 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11249 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11250 | 	const struct ieee80211_mgmt *mgmt = (void *)buf; | 
 | 11251 | 	u32 cmd; | 
| Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11252 |  | 
| Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11253 | 	if (WARN_ON(len < 2)) | 
 | 11254 | 		return; | 
 | 11255 |  | 
 | 11256 | 	if (ieee80211_is_deauth(mgmt->frame_control)) | 
 | 11257 | 		cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | 
 | 11258 | 	else | 
 | 11259 | 		cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | 
 | 11260 |  | 
 | 11261 | 	trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); | 
| Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11262 | 	nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); | 
| Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11263 | } | 
| Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11264 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); | 
| Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11265 |  | 
| Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11266 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, | 
 | 11267 | 				      struct net_device *netdev, int cmd, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11268 | 				      const u8 *addr, gfp_t gfp) | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11269 | { | 
 | 11270 | 	struct sk_buff *msg; | 
 | 11271 | 	void *hdr; | 
 | 11272 |  | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11273 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11274 | 	if (!msg) | 
 | 11275 | 		return; | 
 | 11276 |  | 
 | 11277 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
 | 11278 | 	if (!hdr) { | 
 | 11279 | 		nlmsg_free(msg); | 
 | 11280 | 		return; | 
 | 11281 | 	} | 
 | 11282 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11283 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11284 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11285 | 	    nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | 
 | 11286 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
 | 11287 | 		goto nla_put_failure; | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11288 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11289 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11290 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11291 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11292 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11293 | 	return; | 
 | 11294 |  | 
 | 11295 |  nla_put_failure: | 
 | 11296 | 	genlmsg_cancel(msg, hdr); | 
 | 11297 | 	nlmsg_free(msg); | 
 | 11298 | } | 
 | 11299 |  | 
 | 11300 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11301 | 			       struct net_device *netdev, const u8 *addr, | 
 | 11302 | 			       gfp_t gfp) | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11303 | { | 
 | 11304 | 	nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11305 | 				  addr, gfp); | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11306 | } | 
 | 11307 |  | 
 | 11308 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11309 | 				struct net_device *netdev, const u8 *addr, | 
 | 11310 | 				gfp_t gfp) | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11311 | { | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11312 | 	nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, | 
 | 11313 | 				  addr, gfp); | 
| Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11314 | } | 
 | 11315 |  | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11316 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, | 
 | 11317 | 				 struct net_device *netdev, const u8 *bssid, | 
 | 11318 | 				 const u8 *req_ie, size_t req_ie_len, | 
 | 11319 | 				 const u8 *resp_ie, size_t resp_ie_len, | 
 | 11320 | 				 u16 status, gfp_t gfp) | 
 | 11321 | { | 
 | 11322 | 	struct sk_buff *msg; | 
 | 11323 | 	void *hdr; | 
 | 11324 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11325 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11326 | 	if (!msg) | 
 | 11327 | 		return; | 
 | 11328 |  | 
 | 11329 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | 
 | 11330 | 	if (!hdr) { | 
 | 11331 | 		nlmsg_free(msg); | 
 | 11332 | 		return; | 
 | 11333 | 	} | 
 | 11334 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11335 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11336 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11337 | 	    (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | 
 | 11338 | 	    nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | 
 | 11339 | 	    (req_ie && | 
 | 11340 | 	     nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | 
 | 11341 | 	    (resp_ie && | 
 | 11342 | 	     nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | 
 | 11343 | 		goto nla_put_failure; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11344 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11345 | 	genlmsg_end(msg, hdr); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11346 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11347 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11348 | 				NL80211_MCGRP_MLME, gfp); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11349 | 	return; | 
 | 11350 |  | 
 | 11351 |  nla_put_failure: | 
 | 11352 | 	genlmsg_cancel(msg, hdr); | 
 | 11353 | 	nlmsg_free(msg); | 
 | 11354 |  | 
 | 11355 | } | 
 | 11356 |  | 
 | 11357 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | 
 | 11358 | 			 struct net_device *netdev, const u8 *bssid, | 
 | 11359 | 			 const u8 *req_ie, size_t req_ie_len, | 
 | 11360 | 			 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | 
 | 11361 | { | 
 | 11362 | 	struct sk_buff *msg; | 
 | 11363 | 	void *hdr; | 
 | 11364 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11365 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11366 | 	if (!msg) | 
 | 11367 | 		return; | 
 | 11368 |  | 
 | 11369 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | 
 | 11370 | 	if (!hdr) { | 
 | 11371 | 		nlmsg_free(msg); | 
 | 11372 | 		return; | 
 | 11373 | 	} | 
 | 11374 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11375 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11376 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11377 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | 
 | 11378 | 	    (req_ie && | 
 | 11379 | 	     nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | 
 | 11380 | 	    (resp_ie && | 
 | 11381 | 	     nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | 
 | 11382 | 		goto nla_put_failure; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11383 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11384 | 	genlmsg_end(msg, hdr); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11385 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11386 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11387 | 				NL80211_MCGRP_MLME, gfp); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11388 | 	return; | 
 | 11389 |  | 
 | 11390 |  nla_put_failure: | 
 | 11391 | 	genlmsg_cancel(msg, hdr); | 
 | 11392 | 	nlmsg_free(msg); | 
 | 11393 |  | 
 | 11394 | } | 
 | 11395 |  | 
 | 11396 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | 
 | 11397 | 			       struct net_device *netdev, u16 reason, | 
| Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11398 | 			       const u8 *ie, size_t ie_len, bool from_ap) | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11399 | { | 
 | 11400 | 	struct sk_buff *msg; | 
 | 11401 | 	void *hdr; | 
 | 11402 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11403 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11404 | 	if (!msg) | 
 | 11405 | 		return; | 
 | 11406 |  | 
 | 11407 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | 
 | 11408 | 	if (!hdr) { | 
 | 11409 | 		nlmsg_free(msg); | 
 | 11410 | 		return; | 
 | 11411 | 	} | 
 | 11412 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11413 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11414 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11415 | 	    (from_ap && reason && | 
 | 11416 | 	     nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | 
 | 11417 | 	    (from_ap && | 
 | 11418 | 	     nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | 
 | 11419 | 	    (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | 
 | 11420 | 		goto nla_put_failure; | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11421 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11422 | 	genlmsg_end(msg, hdr); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11423 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11424 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11425 | 				NL80211_MCGRP_MLME, GFP_KERNEL); | 
| Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11426 | 	return; | 
 | 11427 |  | 
 | 11428 |  nla_put_failure: | 
 | 11429 | 	genlmsg_cancel(msg, hdr); | 
 | 11430 | 	nlmsg_free(msg); | 
 | 11431 |  | 
 | 11432 | } | 
 | 11433 |  | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11434 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, | 
 | 11435 | 			     struct net_device *netdev, const u8 *bssid, | 
 | 11436 | 			     gfp_t gfp) | 
 | 11437 | { | 
 | 11438 | 	struct sk_buff *msg; | 
 | 11439 | 	void *hdr; | 
 | 11440 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11441 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11442 | 	if (!msg) | 
 | 11443 | 		return; | 
 | 11444 |  | 
 | 11445 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | 
 | 11446 | 	if (!hdr) { | 
 | 11447 | 		nlmsg_free(msg); | 
 | 11448 | 		return; | 
 | 11449 | 	} | 
 | 11450 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11451 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11452 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11453 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | 
 | 11454 | 		goto nla_put_failure; | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11455 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11456 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11457 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11458 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11459 | 				NL80211_MCGRP_MLME, gfp); | 
| Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11460 | 	return; | 
 | 11461 |  | 
 | 11462 |  nla_put_failure: | 
 | 11463 | 	genlmsg_cancel(msg, hdr); | 
 | 11464 | 	nlmsg_free(msg); | 
 | 11465 | } | 
 | 11466 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11467 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, | 
 | 11468 | 					const u8* ie, u8 ie_len, gfp_t gfp) | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11469 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11470 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11471 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11472 | 	struct sk_buff *msg; | 
 | 11473 | 	void *hdr; | 
 | 11474 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11475 | 	if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | 
 | 11476 | 		return; | 
 | 11477 |  | 
 | 11478 | 	trace_cfg80211_notify_new_peer_candidate(dev, addr); | 
 | 11479 |  | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11480 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 11481 | 	if (!msg) | 
 | 11482 | 		return; | 
 | 11483 |  | 
 | 11484 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | 
 | 11485 | 	if (!hdr) { | 
 | 11486 | 		nlmsg_free(msg); | 
 | 11487 | 		return; | 
 | 11488 | 	} | 
 | 11489 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11490 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11491 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 11492 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11493 | 	    (ie_len && ie && | 
 | 11494 | 	     nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | 
 | 11495 | 		goto nla_put_failure; | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11496 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11497 | 	genlmsg_end(msg, hdr); | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11498 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11499 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11500 | 				NL80211_MCGRP_MLME, gfp); | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11501 | 	return; | 
 | 11502 |  | 
 | 11503 |  nla_put_failure: | 
 | 11504 | 	genlmsg_cancel(msg, hdr); | 
 | 11505 | 	nlmsg_free(msg); | 
 | 11506 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11507 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); | 
| Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11508 |  | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11509 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, | 
 | 11510 | 				 struct net_device *netdev, const u8 *addr, | 
 | 11511 | 				 enum nl80211_key_type key_type, int key_id, | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11512 | 				 const u8 *tsc, gfp_t gfp) | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11513 | { | 
 | 11514 | 	struct sk_buff *msg; | 
 | 11515 | 	void *hdr; | 
 | 11516 |  | 
| Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11517 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11518 | 	if (!msg) | 
 | 11519 | 		return; | 
 | 11520 |  | 
 | 11521 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | 
 | 11522 | 	if (!hdr) { | 
 | 11523 | 		nlmsg_free(msg); | 
 | 11524 | 		return; | 
 | 11525 | 	} | 
 | 11526 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11527 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11528 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 11529 | 	    (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | 
 | 11530 | 	    nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | 
 | 11531 | 	    (key_id != -1 && | 
 | 11532 | 	     nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | 
 | 11533 | 	    (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | 
 | 11534 | 		goto nla_put_failure; | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11535 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11536 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11537 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11538 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11539 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11540 | 	return; | 
 | 11541 |  | 
 | 11542 |  nla_put_failure: | 
 | 11543 | 	genlmsg_cancel(msg, hdr); | 
 | 11544 | 	nlmsg_free(msg); | 
 | 11545 | } | 
 | 11546 |  | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11547 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, | 
 | 11548 | 				    struct ieee80211_channel *channel_before, | 
 | 11549 | 				    struct ieee80211_channel *channel_after) | 
 | 11550 | { | 
 | 11551 | 	struct sk_buff *msg; | 
 | 11552 | 	void *hdr; | 
 | 11553 | 	struct nlattr *nl_freq; | 
 | 11554 |  | 
| Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11555 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11556 | 	if (!msg) | 
 | 11557 | 		return; | 
 | 11558 |  | 
 | 11559 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | 
 | 11560 | 	if (!hdr) { | 
 | 11561 | 		nlmsg_free(msg); | 
 | 11562 | 		return; | 
 | 11563 | 	} | 
 | 11564 |  | 
 | 11565 | 	/* | 
 | 11566 | 	 * Since we are applying the beacon hint to a wiphy we know its | 
 | 11567 | 	 * wiphy_idx is valid | 
 | 11568 | 	 */ | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11569 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | 
 | 11570 | 		goto nla_put_failure; | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11571 |  | 
 | 11572 | 	/* Before */ | 
 | 11573 | 	nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | 
 | 11574 | 	if (!nl_freq) | 
 | 11575 | 		goto nla_put_failure; | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11576 | 	if (nl80211_msg_put_channel(msg, channel_before, false)) | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11577 | 		goto nla_put_failure; | 
 | 11578 | 	nla_nest_end(msg, nl_freq); | 
 | 11579 |  | 
 | 11580 | 	/* After */ | 
 | 11581 | 	nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | 
 | 11582 | 	if (!nl_freq) | 
 | 11583 | 		goto nla_put_failure; | 
| Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11584 | 	if (nl80211_msg_put_channel(msg, channel_after, false)) | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11585 | 		goto nla_put_failure; | 
 | 11586 | 	nla_nest_end(msg, nl_freq); | 
 | 11587 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11588 | 	genlmsg_end(msg, hdr); | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11589 |  | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11590 | 	rcu_read_lock(); | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11591 | 	genlmsg_multicast_allns(&nl80211_fam, msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11592 | 				NL80211_MCGRP_REGULATORY, GFP_ATOMIC); | 
| Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11593 | 	rcu_read_unlock(); | 
| Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11594 |  | 
 | 11595 | 	return; | 
 | 11596 |  | 
 | 11597 | nla_put_failure: | 
 | 11598 | 	genlmsg_cancel(msg, hdr); | 
 | 11599 | 	nlmsg_free(msg); | 
 | 11600 | } | 
 | 11601 |  | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11602 | static void nl80211_send_remain_on_chan_event( | 
 | 11603 | 	int cmd, struct cfg80211_registered_device *rdev, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11604 | 	struct wireless_dev *wdev, u64 cookie, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11605 | 	struct ieee80211_channel *chan, | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11606 | 	unsigned int duration, gfp_t gfp) | 
 | 11607 | { | 
 | 11608 | 	struct sk_buff *msg; | 
 | 11609 | 	void *hdr; | 
 | 11610 |  | 
 | 11611 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 11612 | 	if (!msg) | 
 | 11613 | 		return; | 
 | 11614 |  | 
 | 11615 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
 | 11616 | 	if (!hdr) { | 
 | 11617 | 		nlmsg_free(msg); | 
 | 11618 | 		return; | 
 | 11619 | 	} | 
 | 11620 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11621 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11622 | 	    (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
 | 11623 | 					 wdev->netdev->ifindex)) || | 
| Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11624 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11625 | 	    nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || | 
| Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11626 | 	    nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | 
 | 11627 | 			NL80211_CHAN_NO_HT) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11628 | 	    nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | 
 | 11629 | 		goto nla_put_failure; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11630 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11631 | 	if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && | 
 | 11632 | 	    nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | 
 | 11633 | 		goto nla_put_failure; | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11634 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11635 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11636 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11637 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11638 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11639 | 	return; | 
 | 11640 |  | 
 | 11641 |  nla_put_failure: | 
 | 11642 | 	genlmsg_cancel(msg, hdr); | 
 | 11643 | 	nlmsg_free(msg); | 
 | 11644 | } | 
 | 11645 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11646 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, | 
 | 11647 | 			       struct ieee80211_channel *chan, | 
 | 11648 | 			       unsigned int duration, gfp_t gfp) | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11649 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11650 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11651 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11652 |  | 
 | 11653 | 	trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11654 | 	nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11655 | 					  rdev, wdev, cookie, chan, | 
| Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11656 | 					  duration, gfp); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11657 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11658 | EXPORT_SYMBOL(cfg80211_ready_on_channel); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11659 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11660 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, | 
 | 11661 | 					struct ieee80211_channel *chan, | 
 | 11662 | 					gfp_t gfp) | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11663 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11664 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11665 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11666 |  | 
 | 11667 | 	trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11668 | 	nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | 
| Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11669 | 					  rdev, wdev, cookie, chan, 0, gfp); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11670 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11671 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); | 
| Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11672 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11673 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, | 
 | 11674 | 		      struct station_info *sinfo, gfp_t gfp) | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11675 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11676 | 	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11677 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11678 | 	struct sk_buff *msg; | 
 | 11679 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11680 | 	trace_cfg80211_new_sta(dev, mac_addr, sinfo); | 
 | 11681 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11682 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11683 | 	if (!msg) | 
 | 11684 | 		return; | 
 | 11685 |  | 
| John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11686 | 	if (nl80211_send_station(msg, 0, 0, 0, | 
 | 11687 | 				 rdev, dev, mac_addr, sinfo) < 0) { | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11688 | 		nlmsg_free(msg); | 
 | 11689 | 		return; | 
 | 11690 | 	} | 
 | 11691 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11692 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11693 | 				NL80211_MCGRP_MLME, gfp); | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11694 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11695 | EXPORT_SYMBOL(cfg80211_new_sta); | 
| Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11696 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11697 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11698 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11699 | 	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11700 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11701 | 	struct sk_buff *msg; | 
 | 11702 | 	void *hdr; | 
 | 11703 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11704 | 	trace_cfg80211_del_sta(dev, mac_addr); | 
 | 11705 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11706 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11707 | 	if (!msg) | 
 | 11708 | 		return; | 
 | 11709 |  | 
 | 11710 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | 
 | 11711 | 	if (!hdr) { | 
 | 11712 | 		nlmsg_free(msg); | 
 | 11713 | 		return; | 
 | 11714 | 	} | 
 | 11715 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11716 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 11717 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | 
 | 11718 | 		goto nla_put_failure; | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11719 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11720 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11721 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11722 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11723 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11724 | 	return; | 
 | 11725 |  | 
 | 11726 |  nla_put_failure: | 
 | 11727 | 	genlmsg_cancel(msg, hdr); | 
 | 11728 | 	nlmsg_free(msg); | 
 | 11729 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11730 | EXPORT_SYMBOL(cfg80211_del_sta); | 
| Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11731 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11732 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, | 
 | 11733 | 			  enum nl80211_connect_failed_reason reason, | 
 | 11734 | 			  gfp_t gfp) | 
| Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11735 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11736 | 	struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11737 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11738 | 	struct sk_buff *msg; | 
 | 11739 | 	void *hdr; | 
 | 11740 |  | 
 | 11741 | 	msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | 
 | 11742 | 	if (!msg) | 
 | 11743 | 		return; | 
 | 11744 |  | 
 | 11745 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | 
 | 11746 | 	if (!hdr) { | 
 | 11747 | 		nlmsg_free(msg); | 
 | 11748 | 		return; | 
 | 11749 | 	} | 
 | 11750 |  | 
 | 11751 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 11752 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | 
 | 11753 | 	    nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | 
 | 11754 | 		goto nla_put_failure; | 
 | 11755 |  | 
 | 11756 | 	genlmsg_end(msg, hdr); | 
 | 11757 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11758 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11759 | 				NL80211_MCGRP_MLME, gfp); | 
| Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11760 | 	return; | 
 | 11761 |  | 
 | 11762 |  nla_put_failure: | 
 | 11763 | 	genlmsg_cancel(msg, hdr); | 
 | 11764 | 	nlmsg_free(msg); | 
 | 11765 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11766 | EXPORT_SYMBOL(cfg80211_conn_failed); | 
| Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11767 |  | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11768 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, | 
 | 11769 | 				       const u8 *addr, gfp_t gfp) | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11770 | { | 
 | 11771 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11772 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11773 | 	struct sk_buff *msg; | 
 | 11774 | 	void *hdr; | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11775 | 	u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11776 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11777 | 	if (!nlportid) | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11778 | 		return false; | 
 | 11779 |  | 
 | 11780 | 	msg = nlmsg_new(100, gfp); | 
 | 11781 | 	if (!msg) | 
 | 11782 | 		return true; | 
 | 11783 |  | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11784 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11785 | 	if (!hdr) { | 
 | 11786 | 		nlmsg_free(msg); | 
 | 11787 | 		return true; | 
 | 11788 | 	} | 
 | 11789 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11790 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 11791 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 11792 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
 | 11793 | 		goto nla_put_failure; | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11794 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11795 | 	genlmsg_end(msg, hdr); | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11796 | 	genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
| Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11797 | 	return true; | 
 | 11798 |  | 
 | 11799 |  nla_put_failure: | 
 | 11800 | 	genlmsg_cancel(msg, hdr); | 
 | 11801 | 	nlmsg_free(msg); | 
 | 11802 | 	return true; | 
 | 11803 | } | 
 | 11804 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11805 | bool cfg80211_rx_spurious_frame(struct net_device *dev, | 
 | 11806 | 				const u8 *addr, gfp_t gfp) | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11807 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11808 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 11809 | 	bool ret; | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11810 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11811 | 	trace_cfg80211_rx_spurious_frame(dev, addr); | 
 | 11812 |  | 
 | 11813 | 	if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | 
 | 11814 | 		    wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | 
 | 11815 | 		trace_cfg80211_return_bool(false); | 
 | 11816 | 		return false; | 
 | 11817 | 	} | 
 | 11818 | 	ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | 
 | 11819 | 					 addr, gfp); | 
 | 11820 | 	trace_cfg80211_return_bool(ret); | 
 | 11821 | 	return ret; | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11822 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11823 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); | 
 | 11824 |  | 
 | 11825 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, | 
 | 11826 | 					const u8 *addr, gfp_t gfp) | 
 | 11827 | { | 
 | 11828 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 11829 | 	bool ret; | 
 | 11830 |  | 
 | 11831 | 	trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | 
 | 11832 |  | 
 | 11833 | 	if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | 
 | 11834 | 		    wdev->iftype != NL80211_IFTYPE_P2P_GO && | 
 | 11835 | 		    wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | 
 | 11836 | 		trace_cfg80211_return_bool(false); | 
 | 11837 | 		return false; | 
 | 11838 | 	} | 
 | 11839 | 	ret = __nl80211_unexpected_frame(dev, | 
 | 11840 | 					 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | 
 | 11841 | 					 addr, gfp); | 
 | 11842 | 	trace_cfg80211_return_bool(ret); | 
 | 11843 | 	return ret; | 
 | 11844 | } | 
 | 11845 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); | 
| Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11846 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11847 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11848 | 		      struct wireless_dev *wdev, u32 nlportid, | 
| Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11849 | 		      int freq, int sig_dbm, | 
| Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11850 | 		      const u8 *buf, size_t len, u32 flags, gfp_t gfp) | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11851 | { | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11852 | 	struct net_device *netdev = wdev->netdev; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11853 | 	struct sk_buff *msg; | 
 | 11854 | 	void *hdr; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11855 |  | 
 | 11856 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 11857 | 	if (!msg) | 
 | 11858 | 		return -ENOMEM; | 
 | 11859 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11860 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11861 | 	if (!hdr) { | 
 | 11862 | 		nlmsg_free(msg); | 
 | 11863 | 		return -ENOMEM; | 
 | 11864 | 	} | 
 | 11865 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11866 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11867 | 	    (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
 | 11868 | 					netdev->ifindex)) || | 
| Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11869 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11870 | 	    nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | 
 | 11871 | 	    (sig_dbm && | 
 | 11872 | 	     nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | 
| Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11873 | 	    nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | 
 | 11874 | 	    (flags && | 
 | 11875 | 	     nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11876 | 		goto nla_put_failure; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11877 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11878 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11879 |  | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11880 | 	return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11881 |  | 
 | 11882 |  nla_put_failure: | 
 | 11883 | 	genlmsg_cancel(msg, hdr); | 
 | 11884 | 	nlmsg_free(msg); | 
 | 11885 | 	return -ENOBUFS; | 
 | 11886 | } | 
 | 11887 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11888 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, | 
 | 11889 | 			     const u8 *buf, size_t len, bool ack, gfp_t gfp) | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11890 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11891 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11892 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11893 | 	struct net_device *netdev = wdev->netdev; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11894 | 	struct sk_buff *msg; | 
 | 11895 | 	void *hdr; | 
 | 11896 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11897 | 	trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); | 
 | 11898 |  | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11899 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 11900 | 	if (!msg) | 
 | 11901 | 		return; | 
 | 11902 |  | 
| Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11903 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11904 | 	if (!hdr) { | 
 | 11905 | 		nlmsg_free(msg); | 
 | 11906 | 		return; | 
 | 11907 | 	} | 
 | 11908 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11909 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11910 | 	    (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
 | 11911 | 				   netdev->ifindex)) || | 
| Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11912 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11913 | 	    nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | 
 | 11914 | 	    nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | 
 | 11915 | 	    (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | 
 | 11916 | 		goto nla_put_failure; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11917 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11918 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11919 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11920 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11921 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11922 | 	return; | 
 | 11923 |  | 
 | 11924 |  nla_put_failure: | 
 | 11925 | 	genlmsg_cancel(msg, hdr); | 
 | 11926 | 	nlmsg_free(msg); | 
 | 11927 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11928 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11929 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11930 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, | 
 | 11931 | 					    const char *mac, gfp_t gfp) | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11932 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11933 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11934 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
 | 11935 | 	struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 11936 | 	void **cb; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11937 |  | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11938 | 	if (!msg) | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11939 | 		return NULL; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11940 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11941 | 	cb = (void **)msg->cb; | 
 | 11942 |  | 
 | 11943 | 	cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | 
 | 11944 | 	if (!cb[0]) { | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11945 | 		nlmsg_free(msg); | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11946 | 		return NULL; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11947 | 	} | 
 | 11948 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11949 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11950 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11951 | 		goto nla_put_failure; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11952 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11953 | 	if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11954 | 		goto nla_put_failure; | 
 | 11955 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11956 | 	cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); | 
 | 11957 | 	if (!cb[1]) | 
 | 11958 | 		goto nla_put_failure; | 
 | 11959 |  | 
 | 11960 | 	cb[2] = rdev; | 
 | 11961 |  | 
 | 11962 | 	return msg; | 
 | 11963 |  nla_put_failure: | 
 | 11964 | 	nlmsg_free(msg); | 
 | 11965 | 	return NULL; | 
 | 11966 | } | 
 | 11967 |  | 
 | 11968 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | 
 | 11969 | { | 
 | 11970 | 	void **cb = (void **)msg->cb; | 
 | 11971 | 	struct cfg80211_registered_device *rdev = cb[2]; | 
 | 11972 |  | 
 | 11973 | 	nla_nest_end(msg, cb[1]); | 
 | 11974 | 	genlmsg_end(msg, cb[0]); | 
 | 11975 |  | 
 | 11976 | 	memset(msg->cb, 0, sizeof(msg->cb)); | 
 | 11977 |  | 
 | 11978 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
 | 11979 | 				NL80211_MCGRP_MLME, gfp); | 
 | 11980 | } | 
 | 11981 |  | 
 | 11982 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | 
 | 11983 | 			      enum nl80211_cqm_rssi_threshold_event rssi_event, | 
 | 11984 | 			      gfp_t gfp) | 
 | 11985 | { | 
 | 11986 | 	struct sk_buff *msg; | 
 | 11987 |  | 
 | 11988 | 	trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | 
 | 11989 |  | 
| Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 11990 | 	if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && | 
 | 11991 | 		    rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | 
 | 11992 | 		return; | 
 | 11993 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11994 | 	msg = cfg80211_prepare_cqm(dev, NULL, gfp); | 
 | 11995 | 	if (!msg) | 
 | 11996 | 		return; | 
 | 11997 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11998 | 	if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | 
 | 11999 | 			rssi_event)) | 
 | 12000 | 		goto nla_put_failure; | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12001 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12002 | 	cfg80211_send_cqm(msg, gfp); | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12003 |  | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12004 | 	return; | 
 | 12005 |  | 
 | 12006 |  nla_put_failure: | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12007 | 	nlmsg_free(msg); | 
 | 12008 | } | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12009 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); | 
| Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12010 |  | 
| Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12011 | void cfg80211_cqm_txe_notify(struct net_device *dev, | 
 | 12012 | 			     const u8 *peer, u32 num_packets, | 
 | 12013 | 			     u32 rate, u32 intvl, gfp_t gfp) | 
 | 12014 | { | 
 | 12015 | 	struct sk_buff *msg; | 
 | 12016 |  | 
 | 12017 | 	msg = cfg80211_prepare_cqm(dev, peer, gfp); | 
 | 12018 | 	if (!msg) | 
 | 12019 | 		return; | 
 | 12020 |  | 
 | 12021 | 	if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | 
 | 12022 | 		goto nla_put_failure; | 
 | 12023 |  | 
 | 12024 | 	if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | 
 | 12025 | 		goto nla_put_failure; | 
 | 12026 |  | 
 | 12027 | 	if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | 
 | 12028 | 		goto nla_put_failure; | 
 | 12029 |  | 
 | 12030 | 	cfg80211_send_cqm(msg, gfp); | 
 | 12031 | 	return; | 
 | 12032 |  | 
 | 12033 |  nla_put_failure: | 
 | 12034 | 	nlmsg_free(msg); | 
 | 12035 | } | 
 | 12036 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | 
 | 12037 |  | 
 | 12038 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | 
 | 12039 | 				 const u8 *peer, u32 num_packets, gfp_t gfp) | 
 | 12040 | { | 
 | 12041 | 	struct sk_buff *msg; | 
 | 12042 |  | 
 | 12043 | 	trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | 
 | 12044 |  | 
 | 12045 | 	msg = cfg80211_prepare_cqm(dev, peer, gfp); | 
 | 12046 | 	if (!msg) | 
 | 12047 | 		return; | 
 | 12048 |  | 
 | 12049 | 	if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | 
 | 12050 | 		goto nla_put_failure; | 
 | 12051 |  | 
 | 12052 | 	cfg80211_send_cqm(msg, gfp); | 
 | 12053 | 	return; | 
 | 12054 |  | 
 | 12055 |  nla_put_failure: | 
 | 12056 | 	nlmsg_free(msg); | 
 | 12057 | } | 
 | 12058 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | 
 | 12059 |  | 
| Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12060 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) | 
 | 12061 | { | 
 | 12062 | 	struct sk_buff *msg; | 
 | 12063 |  | 
 | 12064 | 	msg = cfg80211_prepare_cqm(dev, NULL, gfp); | 
 | 12065 | 	if (!msg) | 
 | 12066 | 		return; | 
 | 12067 |  | 
 | 12068 | 	if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | 
 | 12069 | 		goto nla_put_failure; | 
 | 12070 |  | 
 | 12071 | 	cfg80211_send_cqm(msg, gfp); | 
 | 12072 | 	return; | 
 | 12073 |  | 
 | 12074 |  nla_put_failure: | 
 | 12075 | 	nlmsg_free(msg); | 
 | 12076 | } | 
 | 12077 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | 
 | 12078 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12079 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, | 
 | 12080 | 				     struct net_device *netdev, const u8 *bssid, | 
 | 12081 | 				     const u8 *replay_ctr, gfp_t gfp) | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12082 | { | 
 | 12083 | 	struct sk_buff *msg; | 
 | 12084 | 	struct nlattr *rekey_attr; | 
 | 12085 | 	void *hdr; | 
 | 12086 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12087 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12088 | 	if (!msg) | 
 | 12089 | 		return; | 
 | 12090 |  | 
 | 12091 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | 
 | 12092 | 	if (!hdr) { | 
 | 12093 | 		nlmsg_free(msg); | 
 | 12094 | 		return; | 
 | 12095 | 	} | 
 | 12096 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12097 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12098 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 12099 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | 
 | 12100 | 		goto nla_put_failure; | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12101 |  | 
 | 12102 | 	rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | 
 | 12103 | 	if (!rekey_attr) | 
 | 12104 | 		goto nla_put_failure; | 
 | 12105 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12106 | 	if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, | 
 | 12107 | 		    NL80211_REPLAY_CTR_LEN, replay_ctr)) | 
 | 12108 | 		goto nla_put_failure; | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12109 |  | 
 | 12110 | 	nla_nest_end(msg, rekey_attr); | 
 | 12111 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12112 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12113 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12114 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12115 | 				NL80211_MCGRP_MLME, gfp); | 
| Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12116 | 	return; | 
 | 12117 |  | 
 | 12118 |  nla_put_failure: | 
 | 12119 | 	genlmsg_cancel(msg, hdr); | 
 | 12120 | 	nlmsg_free(msg); | 
 | 12121 | } | 
 | 12122 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12123 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, | 
 | 12124 | 			       const u8 *replay_ctr, gfp_t gfp) | 
 | 12125 | { | 
 | 12126 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 12127 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12128 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12129 |  | 
 | 12130 | 	trace_cfg80211_gtk_rekey_notify(dev, bssid); | 
 | 12131 | 	nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | 
 | 12132 | } | 
 | 12133 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | 
 | 12134 |  | 
 | 12135 | static void | 
 | 12136 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | 
 | 12137 | 			       struct net_device *netdev, int index, | 
 | 12138 | 			       const u8 *bssid, bool preauth, gfp_t gfp) | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12139 | { | 
 | 12140 | 	struct sk_buff *msg; | 
 | 12141 | 	struct nlattr *attr; | 
 | 12142 | 	void *hdr; | 
 | 12143 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12144 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12145 | 	if (!msg) | 
 | 12146 | 		return; | 
 | 12147 |  | 
 | 12148 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | 
 | 12149 | 	if (!hdr) { | 
 | 12150 | 		nlmsg_free(msg); | 
 | 12151 | 		return; | 
 | 12152 | 	} | 
 | 12153 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12154 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12155 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | 
 | 12156 | 		goto nla_put_failure; | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12157 |  | 
 | 12158 | 	attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | 
 | 12159 | 	if (!attr) | 
 | 12160 | 		goto nla_put_failure; | 
 | 12161 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12162 | 	if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || | 
 | 12163 | 	    nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | 
 | 12164 | 	    (preauth && | 
 | 12165 | 	     nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | 
 | 12166 | 		goto nla_put_failure; | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12167 |  | 
 | 12168 | 	nla_nest_end(msg, attr); | 
 | 12169 |  | 
| Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12170 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12171 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12172 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12173 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12174 | 	return; | 
 | 12175 |  | 
 | 12176 |  nla_put_failure: | 
 | 12177 | 	genlmsg_cancel(msg, hdr); | 
 | 12178 | 	nlmsg_free(msg); | 
 | 12179 | } | 
 | 12180 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12181 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, | 
 | 12182 | 				     const u8 *bssid, bool preauth, gfp_t gfp) | 
 | 12183 | { | 
 | 12184 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 12185 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12186 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12187 |  | 
 | 12188 | 	trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | 
 | 12189 | 	nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | 
 | 12190 | } | 
 | 12191 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | 
 | 12192 |  | 
 | 12193 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | 
 | 12194 | 				     struct net_device *netdev, | 
 | 12195 | 				     struct cfg80211_chan_def *chandef, | 
| Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12196 | 				     gfp_t gfp, | 
 | 12197 | 				     enum nl80211_commands notif, | 
 | 12198 | 				     u8 count) | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12199 | { | 
 | 12200 | 	struct sk_buff *msg; | 
 | 12201 | 	void *hdr; | 
 | 12202 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12203 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12204 | 	if (!msg) | 
 | 12205 | 		return; | 
 | 12206 |  | 
| Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12207 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, notif); | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12208 | 	if (!hdr) { | 
 | 12209 | 		nlmsg_free(msg); | 
 | 12210 | 		return; | 
 | 12211 | 	} | 
 | 12212 |  | 
| Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12213 | 	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | 
 | 12214 | 		goto nla_put_failure; | 
 | 12215 |  | 
 | 12216 | 	if (nl80211_send_chandef(msg, chandef)) | 
| John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12217 | 		goto nla_put_failure; | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12218 |  | 
| Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12219 | 	if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && | 
 | 12220 | 	    (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | 
 | 12221 | 			goto nla_put_failure; | 
 | 12222 |  | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12223 | 	genlmsg_end(msg, hdr); | 
 | 12224 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12225 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12226 | 				NL80211_MCGRP_MLME, gfp); | 
| Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12227 | 	return; | 
 | 12228 |  | 
 | 12229 |  nla_put_failure: | 
 | 12230 | 	genlmsg_cancel(msg, hdr); | 
 | 12231 | 	nlmsg_free(msg); | 
 | 12232 | } | 
 | 12233 |  | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12234 | void cfg80211_ch_switch_notify(struct net_device *dev, | 
 | 12235 | 			       struct cfg80211_chan_def *chandef) | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12236 | { | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12237 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 12238 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12239 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12240 |  | 
| Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12241 | 	ASSERT_WDEV_LOCK(wdev); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12242 |  | 
| Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12243 | 	trace_cfg80211_ch_switch_notify(dev, chandef); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12244 |  | 
| Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12245 | 	wdev->chandef = *chandef; | 
| Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12246 | 	wdev->preset_chandef = *chandef; | 
| Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12247 | 	nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | 
 | 12248 | 				 NL80211_CMD_CH_SWITCH_NOTIFY, 0); | 
| Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12249 | } | 
 | 12250 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | 
 | 12251 |  | 
| Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12252 | void cfg80211_ch_switch_started_notify(struct net_device *dev, | 
 | 12253 | 				       struct cfg80211_chan_def *chandef, | 
 | 12254 | 				       u8 count) | 
 | 12255 | { | 
 | 12256 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
 | 12257 | 	struct wiphy *wiphy = wdev->wiphy; | 
 | 12258 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
 | 12259 |  | 
 | 12260 | 	trace_cfg80211_ch_switch_started_notify(dev, chandef); | 
 | 12261 |  | 
 | 12262 | 	nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | 
 | 12263 | 				 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | 
 | 12264 | } | 
 | 12265 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | 
 | 12266 |  | 
| Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12267 | void | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12268 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | 
| Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12269 | 		     const struct cfg80211_chan_def *chandef, | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12270 | 		     enum nl80211_radar_event event, | 
 | 12271 | 		     struct net_device *netdev, gfp_t gfp) | 
 | 12272 | { | 
 | 12273 | 	struct sk_buff *msg; | 
 | 12274 | 	void *hdr; | 
 | 12275 |  | 
 | 12276 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 12277 | 	if (!msg) | 
 | 12278 | 		return; | 
 | 12279 |  | 
 | 12280 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | 
 | 12281 | 	if (!hdr) { | 
 | 12282 | 		nlmsg_free(msg); | 
 | 12283 | 		return; | 
 | 12284 | 	} | 
 | 12285 |  | 
 | 12286 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | 
 | 12287 | 		goto nla_put_failure; | 
 | 12288 |  | 
 | 12289 | 	/* NOP and radar events don't need a netdev parameter */ | 
 | 12290 | 	if (netdev) { | 
 | 12291 | 		struct wireless_dev *wdev = netdev->ieee80211_ptr; | 
 | 12292 |  | 
 | 12293 | 		if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 12294 | 		    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
 | 12295 | 			goto nla_put_failure; | 
 | 12296 | 	} | 
 | 12297 |  | 
 | 12298 | 	if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | 
 | 12299 | 		goto nla_put_failure; | 
 | 12300 |  | 
 | 12301 | 	if (nl80211_send_chandef(msg, chandef)) | 
 | 12302 | 		goto nla_put_failure; | 
 | 12303 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12304 | 	genlmsg_end(msg, hdr); | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12305 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12306 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12307 | 				NL80211_MCGRP_MLME, gfp); | 
| Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12308 | 	return; | 
 | 12309 |  | 
 | 12310 |  nla_put_failure: | 
 | 12311 | 	genlmsg_cancel(msg, hdr); | 
 | 12312 | 	nlmsg_free(msg); | 
 | 12313 | } | 
 | 12314 |  | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12315 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, | 
 | 12316 | 			   u64 cookie, bool acked, gfp_t gfp) | 
 | 12317 | { | 
 | 12318 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12319 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12320 | 	struct sk_buff *msg; | 
 | 12321 | 	void *hdr; | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12322 |  | 
| Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12323 | 	trace_cfg80211_probe_status(dev, addr, cookie, acked); | 
 | 12324 |  | 
| Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12325 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
| Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12326 |  | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12327 | 	if (!msg) | 
 | 12328 | 		return; | 
 | 12329 |  | 
 | 12330 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | 
 | 12331 | 	if (!hdr) { | 
 | 12332 | 		nlmsg_free(msg); | 
 | 12333 | 		return; | 
 | 12334 | 	} | 
 | 12335 |  | 
| David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12336 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12337 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 12338 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
 | 12339 | 	    nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | 
 | 12340 | 	    (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | 
 | 12341 | 		goto nla_put_failure; | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12342 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12343 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12344 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12345 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12346 | 				NL80211_MCGRP_MLME, gfp); | 
| Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12347 | 	return; | 
 | 12348 |  | 
 | 12349 |  nla_put_failure: | 
 | 12350 | 	genlmsg_cancel(msg, hdr); | 
 | 12351 | 	nlmsg_free(msg); | 
 | 12352 | } | 
 | 12353 | EXPORT_SYMBOL(cfg80211_probe_status); | 
 | 12354 |  | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12355 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, | 
 | 12356 | 				 const u8 *frame, size_t len, | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12357 | 				 int freq, int sig_dbm) | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12358 | { | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12359 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12360 | 	struct sk_buff *msg; | 
 | 12361 | 	void *hdr; | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12362 | 	struct cfg80211_beacon_registration *reg; | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12363 |  | 
| Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12364 | 	trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); | 
 | 12365 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12366 | 	spin_lock_bh(&rdev->beacon_registrations_lock); | 
 | 12367 | 	list_for_each_entry(reg, &rdev->beacon_registrations, list) { | 
 | 12368 | 		msg = nlmsg_new(len + 100, GFP_ATOMIC); | 
 | 12369 | 		if (!msg) { | 
 | 12370 | 			spin_unlock_bh(&rdev->beacon_registrations_lock); | 
 | 12371 | 			return; | 
 | 12372 | 		} | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12373 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12374 | 		hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | 
 | 12375 | 		if (!hdr) | 
 | 12376 | 			goto nla_put_failure; | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12377 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12378 | 		if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12379 | 		    (freq && | 
 | 12380 | 		     nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | 
 | 12381 | 		    (sig_dbm && | 
 | 12382 | 		     nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | 
 | 12383 | 		    nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | 
 | 12384 | 			goto nla_put_failure; | 
 | 12385 |  | 
 | 12386 | 		genlmsg_end(msg, hdr); | 
 | 12387 |  | 
 | 12388 | 		genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12389 | 	} | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12390 | 	spin_unlock_bh(&rdev->beacon_registrations_lock); | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12391 | 	return; | 
 | 12392 |  | 
 | 12393 |  nla_put_failure: | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12394 | 	spin_unlock_bh(&rdev->beacon_registrations_lock); | 
 | 12395 | 	if (hdr) | 
 | 12396 | 		genlmsg_cancel(msg, hdr); | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12397 | 	nlmsg_free(msg); | 
 | 12398 | } | 
 | 12399 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | 
 | 12400 |  | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12401 | #ifdef CONFIG_PM | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12402 | static int cfg80211_net_detect_results(struct sk_buff *msg, | 
 | 12403 | 				       struct cfg80211_wowlan_wakeup *wakeup) | 
 | 12404 | { | 
 | 12405 | 	struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | 
 | 12406 | 	struct nlattr *nl_results, *nl_match, *nl_freqs; | 
 | 12407 | 	int i, j; | 
 | 12408 |  | 
 | 12409 | 	nl_results = nla_nest_start( | 
 | 12410 | 		msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | 
 | 12411 | 	if (!nl_results) | 
 | 12412 | 		return -EMSGSIZE; | 
 | 12413 |  | 
 | 12414 | 	for (i = 0; i < nd->n_matches; i++) { | 
 | 12415 | 		struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | 
 | 12416 |  | 
 | 12417 | 		nl_match = nla_nest_start(msg, i); | 
 | 12418 | 		if (!nl_match) | 
 | 12419 | 			break; | 
 | 12420 |  | 
 | 12421 | 		/* The SSID attribute is optional in nl80211, but for | 
 | 12422 | 		 * simplicity reasons it's always present in the | 
 | 12423 | 		 * cfg80211 structure.  If a driver can't pass the | 
 | 12424 | 		 * SSID, that needs to be changed.  A zero length SSID | 
 | 12425 | 		 * is still a valid SSID (wildcard), so it cannot be | 
 | 12426 | 		 * used for this purpose. | 
 | 12427 | 		 */ | 
 | 12428 | 		if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | 
 | 12429 | 			    match->ssid.ssid)) { | 
 | 12430 | 			nla_nest_cancel(msg, nl_match); | 
 | 12431 | 			goto out; | 
 | 12432 | 		} | 
 | 12433 |  | 
 | 12434 | 		if (match->n_channels) { | 
 | 12435 | 			nl_freqs = nla_nest_start( | 
 | 12436 | 				msg, NL80211_ATTR_SCAN_FREQUENCIES); | 
 | 12437 | 			if (!nl_freqs) { | 
 | 12438 | 				nla_nest_cancel(msg, nl_match); | 
 | 12439 | 				goto out; | 
 | 12440 | 			} | 
 | 12441 |  | 
 | 12442 | 			for (j = 0; j < match->n_channels; j++) { | 
 | 12443 | 				if (nla_put_u32(msg, | 
 | 12444 | 						NL80211_ATTR_WIPHY_FREQ, | 
 | 12445 | 						match->channels[j])) { | 
 | 12446 | 					nla_nest_cancel(msg, nl_freqs); | 
 | 12447 | 					nla_nest_cancel(msg, nl_match); | 
 | 12448 | 					goto out; | 
 | 12449 | 				} | 
 | 12450 | 			} | 
 | 12451 |  | 
 | 12452 | 			nla_nest_end(msg, nl_freqs); | 
 | 12453 | 		} | 
 | 12454 |  | 
 | 12455 | 		nla_nest_end(msg, nl_match); | 
 | 12456 | 	} | 
 | 12457 |  | 
 | 12458 | out: | 
 | 12459 | 	nla_nest_end(msg, nl_results); | 
 | 12460 | 	return 0; | 
 | 12461 | } | 
 | 12462 |  | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12463 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | 
 | 12464 | 				   struct cfg80211_wowlan_wakeup *wakeup, | 
 | 12465 | 				   gfp_t gfp) | 
 | 12466 | { | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12467 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12468 | 	struct sk_buff *msg; | 
 | 12469 | 	void *hdr; | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12470 | 	int size = 200; | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12471 |  | 
 | 12472 | 	trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | 
 | 12473 |  | 
 | 12474 | 	if (wakeup) | 
 | 12475 | 		size += wakeup->packet_present_len; | 
 | 12476 |  | 
 | 12477 | 	msg = nlmsg_new(size, gfp); | 
 | 12478 | 	if (!msg) | 
 | 12479 | 		return; | 
 | 12480 |  | 
 | 12481 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | 
 | 12482 | 	if (!hdr) | 
 | 12483 | 		goto free_msg; | 
 | 12484 |  | 
 | 12485 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12486 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
 | 12487 | 		goto free_msg; | 
 | 12488 |  | 
 | 12489 | 	if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | 
 | 12490 | 					wdev->netdev->ifindex)) | 
 | 12491 | 		goto free_msg; | 
 | 12492 |  | 
 | 12493 | 	if (wakeup) { | 
 | 12494 | 		struct nlattr *reasons; | 
 | 12495 |  | 
 | 12496 | 		reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | 
| Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12497 | 		if (!reasons) | 
 | 12498 | 			goto free_msg; | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12499 |  | 
 | 12500 | 		if (wakeup->disconnect && | 
 | 12501 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | 
 | 12502 | 			goto free_msg; | 
 | 12503 | 		if (wakeup->magic_pkt && | 
 | 12504 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | 
 | 12505 | 			goto free_msg; | 
 | 12506 | 		if (wakeup->gtk_rekey_failure && | 
 | 12507 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | 
 | 12508 | 			goto free_msg; | 
 | 12509 | 		if (wakeup->eap_identity_req && | 
 | 12510 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | 
 | 12511 | 			goto free_msg; | 
 | 12512 | 		if (wakeup->four_way_handshake && | 
 | 12513 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | 
 | 12514 | 			goto free_msg; | 
 | 12515 | 		if (wakeup->rfkill_release && | 
 | 12516 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | 
 | 12517 | 			goto free_msg; | 
 | 12518 |  | 
 | 12519 | 		if (wakeup->pattern_idx >= 0 && | 
 | 12520 | 		    nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | 
 | 12521 | 				wakeup->pattern_idx)) | 
 | 12522 | 			goto free_msg; | 
 | 12523 |  | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12524 | 		if (wakeup->tcp_match && | 
 | 12525 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | 
 | 12526 | 			goto free_msg; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12527 |  | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12528 | 		if (wakeup->tcp_connlost && | 
 | 12529 | 		    nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | 
 | 12530 | 			goto free_msg; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12531 |  | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12532 | 		if (wakeup->tcp_nomoretokens && | 
 | 12533 | 		    nla_put_flag(msg, | 
 | 12534 | 				 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | 
 | 12535 | 			goto free_msg; | 
| Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12536 |  | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12537 | 		if (wakeup->packet) { | 
 | 12538 | 			u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | 
 | 12539 | 			u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | 
 | 12540 |  | 
 | 12541 | 			if (!wakeup->packet_80211) { | 
 | 12542 | 				pkt_attr = | 
 | 12543 | 					NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | 
 | 12544 | 				len_attr = | 
 | 12545 | 					NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | 
 | 12546 | 			} | 
 | 12547 |  | 
 | 12548 | 			if (wakeup->packet_len && | 
 | 12549 | 			    nla_put_u32(msg, len_attr, wakeup->packet_len)) | 
 | 12550 | 				goto free_msg; | 
 | 12551 |  | 
 | 12552 | 			if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | 
 | 12553 | 				    wakeup->packet)) | 
 | 12554 | 				goto free_msg; | 
 | 12555 | 		} | 
 | 12556 |  | 
| Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12557 | 		if (wakeup->net_detect && | 
 | 12558 | 		    cfg80211_net_detect_results(msg, wakeup)) | 
 | 12559 | 				goto free_msg; | 
 | 12560 |  | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12561 | 		nla_nest_end(msg, reasons); | 
 | 12562 | 	} | 
 | 12563 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12564 | 	genlmsg_end(msg, hdr); | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12565 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12566 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12567 | 				NL80211_MCGRP_MLME, gfp); | 
| Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12568 | 	return; | 
 | 12569 |  | 
 | 12570 |  free_msg: | 
 | 12571 | 	nlmsg_free(msg); | 
 | 12572 | } | 
 | 12573 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | 
 | 12574 | #endif | 
 | 12575 |  | 
| Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12576 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, | 
 | 12577 | 				enum nl80211_tdls_operation oper, | 
 | 12578 | 				u16 reason_code, gfp_t gfp) | 
 | 12579 | { | 
 | 12580 | 	struct wireless_dev *wdev = dev->ieee80211_ptr; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12581 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | 
| Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12582 | 	struct sk_buff *msg; | 
 | 12583 | 	void *hdr; | 
| Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12584 |  | 
 | 12585 | 	trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | 
 | 12586 | 					 reason_code); | 
 | 12587 |  | 
 | 12588 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 12589 | 	if (!msg) | 
 | 12590 | 		return; | 
 | 12591 |  | 
 | 12592 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | 
 | 12593 | 	if (!hdr) { | 
 | 12594 | 		nlmsg_free(msg); | 
 | 12595 | 		return; | 
 | 12596 | 	} | 
 | 12597 |  | 
 | 12598 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12599 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | 
 | 12600 | 	    nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | 
 | 12601 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | 
 | 12602 | 	    (reason_code > 0 && | 
 | 12603 | 	     nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | 
 | 12604 | 		goto nla_put_failure; | 
 | 12605 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12606 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12607 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12608 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12609 | 				NL80211_MCGRP_MLME, gfp); | 
| Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12610 | 	return; | 
 | 12611 |  | 
 | 12612 |  nla_put_failure: | 
 | 12613 | 	genlmsg_cancel(msg, hdr); | 
 | 12614 | 	nlmsg_free(msg); | 
 | 12615 | } | 
 | 12616 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | 
 | 12617 |  | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12618 | static int nl80211_netlink_notify(struct notifier_block * nb, | 
 | 12619 | 				  unsigned long state, | 
 | 12620 | 				  void *_notify) | 
 | 12621 | { | 
 | 12622 | 	struct netlink_notify *notify = _notify; | 
 | 12623 | 	struct cfg80211_registered_device *rdev; | 
 | 12624 | 	struct wireless_dev *wdev; | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12625 | 	struct cfg80211_beacon_registration *reg, *tmp; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12626 |  | 
 | 12627 | 	if (state != NETLINK_URELEASE) | 
 | 12628 | 		return NOTIFY_DONE; | 
 | 12629 |  | 
 | 12630 | 	rcu_read_lock(); | 
 | 12631 |  | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12632 | 	list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12633 | 		bool schedule_destroy_work = false; | 
| Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12634 | 		bool schedule_scan_stop = false; | 
 | 12635 | 		struct cfg80211_sched_scan_request *sched_scan_req = | 
 | 12636 | 			rcu_dereference(rdev->sched_scan_req); | 
 | 12637 |  | 
 | 12638 | 		if (sched_scan_req && notify->portid && | 
 | 12639 | 		    sched_scan_req->owner_nlportid == notify->portid) | 
 | 12640 | 			schedule_scan_stop = true; | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12641 |  | 
 | 12642 | 		list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | 
| Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12643 | 			cfg80211_mlme_unregister_socket(wdev, notify->portid); | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12644 |  | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12645 | 			if (wdev->owner_nlportid == notify->portid) | 
 | 12646 | 				schedule_destroy_work = true; | 
 | 12647 | 		} | 
 | 12648 |  | 
| Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12649 | 		spin_lock_bh(&rdev->beacon_registrations_lock); | 
 | 12650 | 		list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | 
 | 12651 | 					 list) { | 
 | 12652 | 			if (reg->nlportid == notify->portid) { | 
 | 12653 | 				list_del(®->list); | 
 | 12654 | 				kfree(reg); | 
 | 12655 | 				break; | 
 | 12656 | 			} | 
 | 12657 | 		} | 
 | 12658 | 		spin_unlock_bh(&rdev->beacon_registrations_lock); | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12659 |  | 
 | 12660 | 		if (schedule_destroy_work) { | 
 | 12661 | 			struct cfg80211_iface_destroy *destroy; | 
 | 12662 |  | 
 | 12663 | 			destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | 
 | 12664 | 			if (destroy) { | 
 | 12665 | 				destroy->nlportid = notify->portid; | 
 | 12666 | 				spin_lock(&rdev->destroy_list_lock); | 
 | 12667 | 				list_add(&destroy->list, &rdev->destroy_list); | 
 | 12668 | 				spin_unlock(&rdev->destroy_list_lock); | 
 | 12669 | 				schedule_work(&rdev->destroy_work); | 
 | 12670 | 			} | 
| Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 12671 | 		} else if (schedule_scan_stop) { | 
 | 12672 | 			sched_scan_req->owner_nlportid = 0; | 
 | 12673 |  | 
 | 12674 | 			if (rdev->ops->sched_scan_stop && | 
 | 12675 | 			    rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | 
 | 12676 | 				schedule_work(&rdev->sched_scan_stop_wk); | 
| Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12677 | 		} | 
| Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12678 | 	} | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12679 |  | 
 | 12680 | 	rcu_read_unlock(); | 
 | 12681 |  | 
| Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12682 | 	return NOTIFY_OK; | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12683 | } | 
 | 12684 |  | 
 | 12685 | static struct notifier_block nl80211_netlink_notifier = { | 
 | 12686 | 	.notifier_call = nl80211_netlink_notify, | 
 | 12687 | }; | 
 | 12688 |  | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12689 | void cfg80211_ft_event(struct net_device *netdev, | 
 | 12690 | 		       struct cfg80211_ft_event_params *ft_event) | 
 | 12691 | { | 
 | 12692 | 	struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12693 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12694 | 	struct sk_buff *msg; | 
 | 12695 | 	void *hdr; | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12696 |  | 
 | 12697 | 	trace_cfg80211_ft_event(wiphy, netdev, ft_event); | 
 | 12698 |  | 
 | 12699 | 	if (!ft_event->target_ap) | 
 | 12700 | 		return; | 
 | 12701 |  | 
 | 12702 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 12703 | 	if (!msg) | 
 | 12704 | 		return; | 
 | 12705 |  | 
 | 12706 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12707 | 	if (!hdr) | 
 | 12708 | 		goto out; | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12709 |  | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12710 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12711 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | 
 | 12712 | 	    nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | 
 | 12713 | 		goto out; | 
 | 12714 |  | 
 | 12715 | 	if (ft_event->ies && | 
 | 12716 | 	    nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | 
 | 12717 | 		goto out; | 
 | 12718 | 	if (ft_event->ric_ies && | 
 | 12719 | 	    nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | 
 | 12720 | 		    ft_event->ric_ies)) | 
 | 12721 | 		goto out; | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12722 |  | 
| Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12723 | 	genlmsg_end(msg, hdr); | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12724 |  | 
| Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12725 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12726 | 				NL80211_MCGRP_MLME, GFP_KERNEL); | 
| Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12727 | 	return; | 
 | 12728 |  out: | 
 | 12729 | 	nlmsg_free(msg); | 
| Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12730 | } | 
 | 12731 | EXPORT_SYMBOL(cfg80211_ft_event); | 
 | 12732 |  | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12733 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) | 
 | 12734 | { | 
 | 12735 | 	struct cfg80211_registered_device *rdev; | 
 | 12736 | 	struct sk_buff *msg; | 
 | 12737 | 	void *hdr; | 
 | 12738 | 	u32 nlportid; | 
 | 12739 |  | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12740 | 	rdev = wiphy_to_rdev(wdev->wiphy); | 
| Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12741 | 	if (!rdev->crit_proto_nlportid) | 
 | 12742 | 		return; | 
 | 12743 |  | 
 | 12744 | 	nlportid = rdev->crit_proto_nlportid; | 
 | 12745 | 	rdev->crit_proto_nlportid = 0; | 
 | 12746 |  | 
 | 12747 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | 
 | 12748 | 	if (!msg) | 
 | 12749 | 		return; | 
 | 12750 |  | 
 | 12751 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | 
 | 12752 | 	if (!hdr) | 
 | 12753 | 		goto nla_put_failure; | 
 | 12754 |  | 
 | 12755 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12756 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
 | 12757 | 		goto nla_put_failure; | 
 | 12758 |  | 
 | 12759 | 	genlmsg_end(msg, hdr); | 
 | 12760 |  | 
 | 12761 | 	genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | 
 | 12762 | 	return; | 
 | 12763 |  | 
 | 12764 |  nla_put_failure: | 
 | 12765 | 	if (hdr) | 
 | 12766 | 		genlmsg_cancel(msg, hdr); | 
 | 12767 | 	nlmsg_free(msg); | 
 | 12768 |  | 
 | 12769 | } | 
 | 12770 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | 
 | 12771 |  | 
| Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12772 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) | 
 | 12773 | { | 
 | 12774 | 	struct wiphy *wiphy = wdev->wiphy; | 
| Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12775 | 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | 
| Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12776 | 	struct sk_buff *msg; | 
 | 12777 | 	void *hdr; | 
 | 12778 |  | 
 | 12779 | 	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 
 | 12780 | 	if (!msg) | 
 | 12781 | 		return; | 
 | 12782 |  | 
 | 12783 | 	hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | 
 | 12784 | 	if (!hdr) | 
 | 12785 | 		goto out; | 
 | 12786 |  | 
 | 12787 | 	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | 
 | 12788 | 	    nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | 
 | 12789 | 	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | 
 | 12790 | 		goto out; | 
 | 12791 |  | 
 | 12792 | 	genlmsg_end(msg, hdr); | 
 | 12793 |  | 
 | 12794 | 	genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | 
 | 12795 | 				NL80211_MCGRP_MLME, GFP_KERNEL); | 
 | 12796 | 	return; | 
 | 12797 |  out: | 
 | 12798 | 	nlmsg_free(msg); | 
 | 12799 | } | 
 | 12800 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12801 | /* initialisation/exit functions */ | 
 | 12802 |  | 
 | 12803 | int nl80211_init(void) | 
 | 12804 | { | 
| Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12805 | 	int err; | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12806 |  | 
| Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12807 | 	err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, | 
 | 12808 | 						   nl80211_mcgrps); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12809 | 	if (err) | 
 | 12810 | 		return err; | 
 | 12811 |  | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12812 | 	err = netlink_register_notifier(&nl80211_netlink_notifier); | 
 | 12813 | 	if (err) | 
 | 12814 | 		goto err_out; | 
 | 12815 |  | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12816 | 	return 0; | 
 | 12817 |  err_out: | 
 | 12818 | 	genl_unregister_family(&nl80211_fam); | 
 | 12819 | 	return err; | 
 | 12820 | } | 
 | 12821 |  | 
 | 12822 | void nl80211_exit(void) | 
 | 12823 | { | 
| Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12824 | 	netlink_unregister_notifier(&nl80211_netlink_notifier); | 
| Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12825 | 	genl_unregister_family(&nl80211_fam); | 
 | 12826 | } |