blob: bf75afa186996f68ad7e7c2a5b2781a131470e1f [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg53873f12016-05-03 16:52:04 +0300106 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300152 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200404 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100405 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200406 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400407};
408
Johannes Berge31b8212010-10-05 19:39:30 +0200409/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000410static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200411 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200412 [NL80211_KEY_IDX] = { .type = NLA_U8 },
413 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200414 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200415 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200417 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100418 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
419};
420
421/* policy for the key default flags */
422static const struct nla_policy
423nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
424 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
425 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200426};
427
Johannes Bergff1b6e62011-05-04 15:37:28 +0200428/* policy for WoWLAN attributes */
429static const struct nla_policy
430nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
431 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200435 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
436 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
437 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100439 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300440 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100441};
442
443static const struct nla_policy
444nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
445 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
446 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
447 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
448 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
449 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
452 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
453 },
454 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
455 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
456 },
457 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
458 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
459 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200460};
461
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700462/* policy for coalesce rule attributes */
463static const struct nla_policy
464nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
465 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
466 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
467 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
468};
469
Johannes Berge5497d72011-07-05 16:35:40 +0200470/* policy for GTK rekey offload attributes */
471static const struct nla_policy
472nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
473 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
474 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
475 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
476};
477
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300478static const struct nla_policy
479nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200480 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300481 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700482 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300483};
484
Avraham Stern3b06d272015-10-12 09:51:34 +0300485static const struct nla_policy
486nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
487 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
488 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
489};
490
Arend van Spriel38de03d2016-03-02 20:37:18 +0100491static const struct nla_policy
492nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
493 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
494 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
495 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
496 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
497 },
498};
499
Johannes Berg97990a02013-04-19 01:02:55 +0200500static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
501 struct netlink_callback *cb,
502 struct cfg80211_registered_device **rdev,
503 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100504{
Johannes Berg67748892010-10-04 21:14:06 +0200505 int err;
506
Johannes Berg67748892010-10-04 21:14:06 +0200507 rtnl_lock();
508
Johannes Berg97990a02013-04-19 01:02:55 +0200509 if (!cb->args[0]) {
510 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
511 nl80211_fam.attrbuf, nl80211_fam.maxattr,
512 nl80211_policy);
513 if (err)
514 goto out_unlock;
515
516 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
517 nl80211_fam.attrbuf);
518 if (IS_ERR(*wdev)) {
519 err = PTR_ERR(*wdev);
520 goto out_unlock;
521 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800522 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200523 /* 0 is the first index - add 1 to parse only once */
524 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200525 cb->args[1] = (*wdev)->identifier;
526 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200527 /* subtract the 1 again here */
528 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200529 struct wireless_dev *tmp;
530
531 if (!wiphy) {
532 err = -ENODEV;
533 goto out_unlock;
534 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800535 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200536 *wdev = NULL;
537
Johannes Berg53873f12016-05-03 16:52:04 +0300538 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200539 if (tmp->identifier == cb->args[1]) {
540 *wdev = tmp;
541 break;
542 }
543 }
Johannes Berg97990a02013-04-19 01:02:55 +0200544
545 if (!*wdev) {
546 err = -ENODEV;
547 goto out_unlock;
548 }
Johannes Berg67748892010-10-04 21:14:06 +0200549 }
550
Johannes Berg67748892010-10-04 21:14:06 +0200551 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200552 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200553 rtnl_unlock();
554 return err;
555}
556
Johannes Berg97990a02013-04-19 01:02:55 +0200557static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200558{
Johannes Berg67748892010-10-04 21:14:06 +0200559 rtnl_unlock();
560}
561
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100562/* IE validation */
563static bool is_valid_ie_attr(const struct nlattr *attr)
564{
565 const u8 *pos;
566 int len;
567
568 if (!attr)
569 return true;
570
571 pos = nla_data(attr);
572 len = nla_len(attr);
573
574 while (len) {
575 u8 elemlen;
576
577 if (len < 2)
578 return false;
579 len -= 2;
580
581 elemlen = pos[1];
582 if (elemlen > len)
583 return false;
584
585 len -= elemlen;
586 pos += 2 + elemlen;
587 }
588
589 return true;
590}
591
Johannes Berg55682962007-09-20 13:09:35 -0400592/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000593static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400594 int flags, u8 cmd)
595{
596 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000597 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400598}
599
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400600static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100601 struct ieee80211_channel *chan,
602 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400603{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200604 /* Some channels must be completely excluded from the
605 * list to protect old user-space tools from breaking
606 */
607 if (!large && chan->flags &
608 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
609 return 0;
610
David S. Miller9360ffd2012-03-29 04:41:26 -0400611 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
612 chan->center_freq))
613 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400614
David S. Miller9360ffd2012-03-29 04:41:26 -0400615 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
617 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200618 if (chan->flags & IEEE80211_CHAN_NO_IR) {
619 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
620 goto nla_put_failure;
621 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
622 goto nla_put_failure;
623 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100624 if (chan->flags & IEEE80211_CHAN_RADAR) {
625 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
626 goto nla_put_failure;
627 if (large) {
628 u32 time;
629
630 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
631
632 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
633 chan->dfs_state))
634 goto nla_put_failure;
635 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
636 time))
637 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100638 if (nla_put_u32(msg,
639 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
640 chan->dfs_cac_ms))
641 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100642 }
643 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400644
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100645 if (large) {
646 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
647 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
648 goto nla_put_failure;
649 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
650 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
651 goto nla_put_failure;
652 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
654 goto nla_put_failure;
655 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
656 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
657 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200658 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
659 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
660 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300661 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
662 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200663 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200664 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
665 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
666 goto nla_put_failure;
667 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
668 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
669 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100670 }
671
David S. Miller9360ffd2012-03-29 04:41:26 -0400672 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
673 DBM_TO_MBM(chan->max_power)))
674 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400675
676 return 0;
677
678 nla_put_failure:
679 return -ENOBUFS;
680}
681
Johannes Berg55682962007-09-20 13:09:35 -0400682/* netlink command implementations */
683
Johannes Bergb9454e82009-07-08 13:29:08 +0200684struct key_parse {
685 struct key_params p;
686 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200687 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200688 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100689 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200690};
691
692static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
693{
694 struct nlattr *tb[NL80211_KEY_MAX + 1];
695 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
696 nl80211_key_policy);
697 if (err)
698 return err;
699
700 k->def = !!tb[NL80211_KEY_DEFAULT];
701 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
702
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (k->def) {
704 k->def_uni = true;
705 k->def_multi = true;
706 }
707 if (k->defmgmt)
708 k->def_multi = true;
709
Johannes Bergb9454e82009-07-08 13:29:08 +0200710 if (tb[NL80211_KEY_IDX])
711 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
712
713 if (tb[NL80211_KEY_DATA]) {
714 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
715 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
716 }
717
718 if (tb[NL80211_KEY_SEQ]) {
719 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
720 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
721 }
722
723 if (tb[NL80211_KEY_CIPHER])
724 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
725
Johannes Berge31b8212010-10-05 19:39:30 +0200726 if (tb[NL80211_KEY_TYPE]) {
727 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
728 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
729 return -EINVAL;
730 }
731
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100732 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
733 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100734 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
735 tb[NL80211_KEY_DEFAULT_TYPES],
736 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (err)
738 return err;
739
740 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
741 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
742 }
743
Johannes Bergb9454e82009-07-08 13:29:08 +0200744 return 0;
745}
746
747static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
748{
749 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
750 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
751 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
752 }
753
754 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
755 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
756 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
757 }
758
759 if (info->attrs[NL80211_ATTR_KEY_IDX])
760 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
761
762 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
763 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
764
765 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
766 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
767
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100768 if (k->def) {
769 k->def_uni = true;
770 k->def_multi = true;
771 }
772 if (k->defmgmt)
773 k->def_multi = true;
774
Johannes Berge31b8212010-10-05 19:39:30 +0200775 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
776 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
777 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
778 return -EINVAL;
779 }
780
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100781 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
782 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
783 int err = nla_parse_nested(
784 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
785 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
786 nl80211_key_default_policy);
787 if (err)
788 return err;
789
790 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
791 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
792 }
793
Johannes Bergb9454e82009-07-08 13:29:08 +0200794 return 0;
795}
796
797static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
798{
799 int err;
800
801 memset(k, 0, sizeof(*k));
802 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200803 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200804
805 if (info->attrs[NL80211_ATTR_KEY])
806 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
807 else
808 err = nl80211_parse_key_old(info, k);
809
810 if (err)
811 return err;
812
813 if (k->def && k->defmgmt)
814 return -EINVAL;
815
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100816 if (k->defmgmt) {
817 if (k->def_uni || !k->def_multi)
818 return -EINVAL;
819 }
820
Johannes Bergb9454e82009-07-08 13:29:08 +0200821 if (k->idx != -1) {
822 if (k->defmgmt) {
823 if (k->idx < 4 || k->idx > 5)
824 return -EINVAL;
825 } else if (k->def) {
826 if (k->idx < 0 || k->idx > 3)
827 return -EINVAL;
828 } else {
829 if (k->idx < 0 || k->idx > 5)
830 return -EINVAL;
831 }
832 }
833
834 return 0;
835}
836
Johannes Bergfffd0932009-07-08 14:22:54 +0200837static struct cfg80211_cached_keys *
838nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530839 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200840{
841 struct key_parse parse;
842 struct nlattr *key;
843 struct cfg80211_cached_keys *result;
844 int rem, err, def = 0;
845
846 result = kzalloc(sizeof(*result), GFP_KERNEL);
847 if (!result)
848 return ERR_PTR(-ENOMEM);
849
850 result->def = -1;
851 result->defmgmt = -1;
852
853 nla_for_each_nested(key, keys, rem) {
854 memset(&parse, 0, sizeof(parse));
855 parse.idx = -1;
856
857 err = nl80211_parse_key_new(key, &parse);
858 if (err)
859 goto error;
860 err = -EINVAL;
861 if (!parse.p.key)
862 goto error;
863 if (parse.idx < 0 || parse.idx > 4)
864 goto error;
865 if (parse.def) {
866 if (def)
867 goto error;
868 def = 1;
869 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100870 if (!parse.def_uni || !parse.def_multi)
871 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200872 } else if (parse.defmgmt)
873 goto error;
874 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200875 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 if (err)
877 goto error;
878 result->params[parse.idx].cipher = parse.p.cipher;
879 result->params[parse.idx].key_len = parse.p.key_len;
880 result->params[parse.idx].key = result->data[parse.idx];
881 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530882
883 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
884 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
885 if (no_ht)
886 *no_ht = true;
887 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 }
889
890 return result;
891 error:
892 kfree(result);
893 return ERR_PTR(err);
894}
895
896static int nl80211_key_allowed(struct wireless_dev *wdev)
897{
898 ASSERT_WDEV_LOCK(wdev);
899
Johannes Bergfffd0932009-07-08 14:22:54 +0200900 switch (wdev->iftype) {
901 case NL80211_IFTYPE_AP:
902 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200903 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700904 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200905 break;
906 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200908 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200909 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200910 return -ENOLINK;
911 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100912 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100913 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100914 case NL80211_IFTYPE_MONITOR:
915 case NL80211_IFTYPE_P2P_DEVICE:
916 case NL80211_IFTYPE_WDS:
917 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 return -EINVAL;
919 }
920
921 return 0;
922}
923
Jouni Malinen664834d2014-01-15 00:01:44 +0200924static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
925 struct nlattr *tb)
926{
927 struct ieee80211_channel *chan;
928
929 if (tb == NULL)
930 return NULL;
931 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
932 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
933 return NULL;
934 return chan;
935}
936
Johannes Berg7527a782011-05-13 10:58:57 +0200937static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
938{
939 struct nlattr *nl_modes = nla_nest_start(msg, attr);
940 int i;
941
942 if (!nl_modes)
943 goto nla_put_failure;
944
945 i = 0;
946 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400947 if ((ifmodes & 1) && nla_put_flag(msg, i))
948 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200949 ifmodes >>= 1;
950 i++;
951 }
952
953 nla_nest_end(msg, nl_modes);
954 return 0;
955
956nla_put_failure:
957 return -ENOBUFS;
958}
959
960static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100961 struct sk_buff *msg,
962 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200963{
964 struct nlattr *nl_combis;
965 int i, j;
966
967 nl_combis = nla_nest_start(msg,
968 NL80211_ATTR_INTERFACE_COMBINATIONS);
969 if (!nl_combis)
970 goto nla_put_failure;
971
972 for (i = 0; i < wiphy->n_iface_combinations; i++) {
973 const struct ieee80211_iface_combination *c;
974 struct nlattr *nl_combi, *nl_limits;
975
976 c = &wiphy->iface_combinations[i];
977
978 nl_combi = nla_nest_start(msg, i + 1);
979 if (!nl_combi)
980 goto nla_put_failure;
981
982 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
983 if (!nl_limits)
984 goto nla_put_failure;
985
986 for (j = 0; j < c->n_limits; j++) {
987 struct nlattr *nl_limit;
988
989 nl_limit = nla_nest_start(msg, j + 1);
990 if (!nl_limit)
991 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400992 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
993 c->limits[j].max))
994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
996 c->limits[j].types))
997 goto nla_put_failure;
998 nla_nest_end(msg, nl_limit);
999 }
1000
1001 nla_nest_end(msg, nl_limits);
1002
David S. Miller9360ffd2012-03-29 04:41:26 -04001003 if (c->beacon_int_infra_match &&
1004 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1005 goto nla_put_failure;
1006 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1007 c->num_different_channels) ||
1008 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1009 c->max_interfaces))
1010 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001011 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001012 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1013 c->radar_detect_widths) ||
1014 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1015 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001016 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001017
1018 nla_nest_end(msg, nl_combi);
1019 }
1020
1021 nla_nest_end(msg, nl_combis);
1022
1023 return 0;
1024nla_put_failure:
1025 return -ENOBUFS;
1026}
1027
Johannes Berg3713b4e2013-02-14 16:19:38 +01001028#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001029static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1030 struct sk_buff *msg)
1031{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001032 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001033 struct nlattr *nl_tcp;
1034
1035 if (!tcp)
1036 return 0;
1037
1038 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1039 if (!nl_tcp)
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1043 tcp->data_payload_max))
1044 return -ENOBUFS;
1045
1046 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1047 tcp->data_payload_max))
1048 return -ENOBUFS;
1049
1050 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1051 return -ENOBUFS;
1052
1053 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1054 sizeof(*tcp->tok), tcp->tok))
1055 return -ENOBUFS;
1056
1057 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1058 tcp->data_interval_max))
1059 return -ENOBUFS;
1060
1061 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1062 tcp->wake_payload_max))
1063 return -ENOBUFS;
1064
1065 nla_nest_end(msg, nl_tcp);
1066 return 0;
1067}
1068
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001071 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072{
1073 struct nlattr *nl_wowlan;
1074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 return 0;
1077
1078 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1079 if (!nl_wowlan)
1080 return -ENOBUFS;
1081
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001086 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1098 return -ENOBUFS;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001101 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1103 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1104 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1105 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001106 };
1107
1108 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1109 sizeof(pat), &pat))
1110 return -ENOBUFS;
1111 }
1112
Luciano Coelho75453cc2015-01-09 14:06:37 +02001113 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1114 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1115 rdev->wiphy.wowlan->max_nd_match_sets))
1116 return -ENOBUFS;
1117
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001119 return -ENOBUFS;
1120
Johannes Berg3713b4e2013-02-14 16:19:38 +01001121 nla_nest_end(msg, nl_wowlan);
1122
1123 return 0;
1124}
1125#endif
1126
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001127static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001128 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001129{
1130 struct nl80211_coalesce_rule_support rule;
1131
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001132 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001133 return 0;
1134
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001135 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1136 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1137 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1138 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1139 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1140 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001141
1142 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1143 return -ENOBUFS;
1144
1145 return 0;
1146}
1147
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1149 struct ieee80211_supported_band *sband)
1150{
1151 struct nlattr *nl_rates, *nl_rate;
1152 struct ieee80211_rate *rate;
1153 int i;
1154
1155 /* add HT info */
1156 if (sband->ht_cap.ht_supported &&
1157 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1158 sizeof(sband->ht_cap.mcs),
1159 &sband->ht_cap.mcs) ||
1160 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1161 sband->ht_cap.cap) ||
1162 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1163 sband->ht_cap.ampdu_factor) ||
1164 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1165 sband->ht_cap.ampdu_density)))
1166 return -ENOBUFS;
1167
1168 /* add VHT info */
1169 if (sband->vht_cap.vht_supported &&
1170 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1171 sizeof(sband->vht_cap.vht_mcs),
1172 &sband->vht_cap.vht_mcs) ||
1173 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1174 sband->vht_cap.cap)))
1175 return -ENOBUFS;
1176
1177 /* add bitrates */
1178 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1179 if (!nl_rates)
1180 return -ENOBUFS;
1181
1182 for (i = 0; i < sband->n_bitrates; i++) {
1183 nl_rate = nla_nest_start(msg, i);
1184 if (!nl_rate)
1185 return -ENOBUFS;
1186
1187 rate = &sband->bitrates[i];
1188 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1189 rate->bitrate))
1190 return -ENOBUFS;
1191 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1192 nla_put_flag(msg,
1193 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1194 return -ENOBUFS;
1195
1196 nla_nest_end(msg, nl_rate);
1197 }
1198
1199 nla_nest_end(msg, nl_rates);
1200
1201 return 0;
1202}
1203
1204static int
1205nl80211_send_mgmt_stypes(struct sk_buff *msg,
1206 const struct ieee80211_txrx_stypes *mgmt_stypes)
1207{
1208 u16 stypes;
1209 struct nlattr *nl_ftypes, *nl_ifs;
1210 enum nl80211_iftype ift;
1211 int i;
1212
1213 if (!mgmt_stypes)
1214 return 0;
1215
1216 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1217 if (!nl_ifs)
1218 return -ENOBUFS;
1219
1220 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1221 nl_ftypes = nla_nest_start(msg, ift);
1222 if (!nl_ftypes)
1223 return -ENOBUFS;
1224 i = 0;
1225 stypes = mgmt_stypes[ift].tx;
1226 while (stypes) {
1227 if ((stypes & 1) &&
1228 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1229 (i << 4) | IEEE80211_FTYPE_MGMT))
1230 return -ENOBUFS;
1231 stypes >>= 1;
1232 i++;
1233 }
1234 nla_nest_end(msg, nl_ftypes);
1235 }
1236
1237 nla_nest_end(msg, nl_ifs);
1238
1239 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1240 if (!nl_ifs)
1241 return -ENOBUFS;
1242
1243 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1244 nl_ftypes = nla_nest_start(msg, ift);
1245 if (!nl_ftypes)
1246 return -ENOBUFS;
1247 i = 0;
1248 stypes = mgmt_stypes[ift].rx;
1249 while (stypes) {
1250 if ((stypes & 1) &&
1251 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1252 (i << 4) | IEEE80211_FTYPE_MGMT))
1253 return -ENOBUFS;
1254 stypes >>= 1;
1255 i++;
1256 }
1257 nla_nest_end(msg, nl_ftypes);
1258 }
1259 nla_nest_end(msg, nl_ifs);
1260
1261 return 0;
1262}
1263
Johannes Berg86e8cf92013-06-19 10:57:22 +02001264struct nl80211_dump_wiphy_state {
1265 s64 filter_wiphy;
1266 long start;
1267 long split_start, band_start, chan_start;
1268 bool split;
1269};
1270
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001272 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001275{
1276 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001277 struct nlattr *nl_bands, *nl_band;
1278 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001279 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001280 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001281 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001282 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001283 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001285 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001286
Johannes Berg3bb20552014-05-26 13:52:25 +02001287 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001288 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 return -ENOBUFS;
1290
Johannes Berg86e8cf92013-06-19 10:57:22 +02001291 if (WARN_ON(!state))
1292 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001293
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001297 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001299 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001300
Johannes Berg3bb20552014-05-26 13:52:25 +02001301 if (cmd != NL80211_CMD_NEW_WIPHY)
1302 goto finish;
1303
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 case 0:
1306 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001325 rdev->wiphy.max_match_sets) ||
1326 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1327 rdev->wiphy.max_sched_scan_plans) ||
1328 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1329 rdev->wiphy.max_sched_scan_plan_interval) ||
1330 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1331 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001332 goto nla_put_failure;
1333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1336 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1339 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1342 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1345 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1348 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001351 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001352 state->split_start++;
1353 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 break;
1355 case 1:
1356 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1358 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001359 goto nla_put_failure;
1360
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001363 goto nla_put_failure;
1364
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1367 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001368
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001372 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001379
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001380 if ((rdev->wiphy.available_antennas_tx ||
1381 rdev->wiphy.available_antennas_rx) &&
1382 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 u32 tx_ant = 0, rx_ant = 0;
1384 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001385 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 if (!res) {
1387 if (nla_put_u32(msg,
1388 NL80211_ATTR_WIPHY_ANTENNA_TX,
1389 tx_ant) ||
1390 nla_put_u32(msg,
1391 NL80211_ATTR_WIPHY_ANTENNA_RX,
1392 rx_ant))
1393 goto nla_put_failure;
1394 }
Johannes Bergee688b002008-01-24 19:38:39 +01001395 }
1396
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->split_start++;
1398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 case 2:
1401 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->split_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 case 3:
1408 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1409 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001410 goto nla_put_failure;
1411
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001413 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 struct ieee80211_supported_band *sband;
1415
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417
1418 if (!sband)
1419 continue;
1420
1421 nl_band = nla_nest_start(msg, band);
1422 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001423 goto nla_put_failure;
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 case 0:
1427 if (nl80211_send_band_rateinfo(msg, sband))
1428 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->chan_start++;
1430 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 break;
1432 default:
1433 /* add frequencies */
1434 nl_freqs = nla_nest_start(
1435 msg, NL80211_BAND_ATTR_FREQS);
1436 if (!nl_freqs)
1437 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg86e8cf92013-06-19 10:57:22 +02001439 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 i < sband->n_channels;
1441 i++) {
1442 nl_freq = nla_nest_start(msg, i);
1443 if (!nl_freq)
1444 goto nla_put_failure;
1445
1446 chan = &sband->channels[i];
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (nl80211_msg_put_channel(
1449 msg, chan,
1450 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 goto nla_put_failure;
1452
1453 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001454 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 break;
1456 }
1457 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001458 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001460 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_nest_end(msg, nl_freqs);
1462 }
1463
1464 nla_nest_end(msg, nl_band);
1465
Johannes Berg86e8cf92013-06-19 10:57:22 +02001466 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 band--;
1470 break;
1471 }
Johannes Bergee688b002008-01-24 19:38:39 +01001472 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001474
Johannes Berg57fbcce2016-04-12 15:56:15 +02001475 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001476 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001478 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001479
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (state->band_start == 0 && state->chan_start == 0)
1482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485 case 4:
1486 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1487 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001488 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489
1490 i = 0;
1491#define CMD(op, n) \
1492 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 i++; \
1495 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1496 goto nla_put_failure; \
1497 } \
1498 } while (0)
1499
1500 CMD(add_virtual_intf, NEW_INTERFACE);
1501 CMD(change_virtual_intf, SET_INTERFACE);
1502 CMD(add_key, NEW_KEY);
1503 CMD(start_ap, START_AP);
1504 CMD(add_station, NEW_STATION);
1505 CMD(add_mpath, NEW_MPATH);
1506 CMD(update_mesh_config, SET_MESH_CONFIG);
1507 CMD(change_bss, SET_BSS);
1508 CMD(auth, AUTHENTICATE);
1509 CMD(assoc, ASSOCIATE);
1510 CMD(deauth, DEAUTHENTICATE);
1511 CMD(disassoc, DISASSOCIATE);
1512 CMD(join_ibss, JOIN_IBSS);
1513 CMD(join_mesh, JOIN_MESH);
1514 CMD(set_pmksa, SET_PMKSA);
1515 CMD(del_pmksa, DEL_PMKSA);
1516 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1519 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1520 CMD(mgmt_tx, FRAME);
1521 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 i++;
1524 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1525 goto nla_put_failure;
1526 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1528 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 i++;
1530 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1531 goto nla_put_failure;
1532 }
1533 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 CMD(tdls_mgmt, TDLS_MGMT);
1536 CMD(tdls_oper, TDLS_OPER);
1537 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 CMD(sched_scan_start, START_SCHED_SCAN);
1540 CMD(probe_client, PROBE_CLIENT);
1541 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 i++;
1544 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1545 goto nla_put_failure;
1546 }
1547 CMD(start_p2p_device, START_P2P_DEVICE);
1548 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001549#ifdef CONFIG_NL80211_TESTMODE
1550 CMD(testmode_cmd, TESTMODE);
1551#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001553 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1554 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001556 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001557 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001558 if (rdev->wiphy.features &
1559 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001560 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001561 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001562 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001563#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 i++;
1567 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001568 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001569 }
1570
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 i++;
1573 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1574 goto nla_put_failure;
1575 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001576
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->split_start++;
1579 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 break;
1581 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (rdev->ops->remain_on_channel &&
1583 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_put_u32(msg,
1585 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001587 goto nla_put_failure;
1588
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1591 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001592
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1594 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001595 state->split_start++;
1596 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 break;
1598 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001599#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001600 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start++;
1603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607#endif
1608 case 7:
1609 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001611 goto nla_put_failure;
1612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001614 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001616
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->split_start++;
1618 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 break;
1620 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
1625
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001627 /*
1628 * We can only add the per-channel limit information if the
1629 * dump is split, otherwise it makes it too big. Therefore
1630 * only advertise it in that case.
1631 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001633 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1634 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 goto nla_put_failure;
1636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1640 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 goto nla_put_failure;
1642
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1644 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647 goto nla_put_failure;
1648
1649 /*
1650 * Any information below this point is only available to
1651 * applications that can deal with it being split. This
1652 * helps ensure that newly added capabilities don't break
1653 * older tools by overrunning their buffers.
1654 *
1655 * We still increment split_start so that in the split
1656 * case we'll continue with more data in the next round,
1657 * but break unconditionally so unsplit data stops here.
1658 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001659 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001660 break;
1661 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001663 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 rdev->wiphy.extended_capabilities_len,
1665 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001666 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 rdev->wiphy.extended_capabilities_len,
1668 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001669 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001672 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1674 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001675 goto nla_put_failure;
1676
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001677 state->split_start++;
1678 break;
1679 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001681 goto nla_put_failure;
1682
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001683 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001684 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1685 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1686 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001689 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001691 goto nla_put_failure;
1692
Johannes Bergad7e7182013-11-13 13:37:47 +01001693 state->split_start++;
1694 break;
1695 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001697 const struct nl80211_vendor_cmd_info *info;
1698 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001699
Johannes Berg567ffc32013-12-18 14:43:31 +01001700 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1701 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001702 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001703
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001704 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1705 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001706 if (nla_put(msg, i + 1, sizeof(*info), info))
1707 goto nla_put_failure;
1708 }
1709 nla_nest_end(msg, nested);
1710 }
1711
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001712 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001713 const struct nl80211_vendor_cmd_info *info;
1714 struct nlattr *nested;
1715
1716 nested = nla_nest_start(msg,
1717 NL80211_ATTR_VENDOR_EVENTS);
1718 if (!nested)
1719 goto nla_put_failure;
1720
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001721 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1722 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001723 if (nla_put(msg, i + 1, sizeof(*info), info))
1724 goto nla_put_failure;
1725 }
1726 nla_nest_end(msg, nested);
1727 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001728 state->split_start++;
1729 break;
1730 case 12:
1731 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1732 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1733 rdev->wiphy.max_num_csa_counters))
1734 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001735
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001736 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1737 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1738 goto nla_put_failure;
1739
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001740 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1741 sizeof(rdev->wiphy.ext_features),
1742 rdev->wiphy.ext_features))
1743 goto nla_put_failure;
1744
Arend van Spriel38de03d2016-03-02 20:37:18 +01001745 if (rdev->wiphy.bss_select_support) {
1746 struct nlattr *nested;
1747 u32 bss_select_support = rdev->wiphy.bss_select_support;
1748
1749 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1750 if (!nested)
1751 goto nla_put_failure;
1752
1753 i = 0;
1754 while (bss_select_support) {
1755 if ((bss_select_support & 1) &&
1756 nla_put_flag(msg, i))
1757 goto nla_put_failure;
1758 i++;
1759 bss_select_support >>= 1;
1760 }
1761 nla_nest_end(msg, nested);
1762 }
1763
Johannes Berg3713b4e2013-02-14 16:19:38 +01001764 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001765 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001766 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001767 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001768 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001769 genlmsg_end(msg, hdr);
1770 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001771
1772 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001773 genlmsg_cancel(msg, hdr);
1774 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001775}
1776
Johannes Berg86e8cf92013-06-19 10:57:22 +02001777static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1778 struct netlink_callback *cb,
1779 struct nl80211_dump_wiphy_state *state)
1780{
1781 struct nlattr **tb = nl80211_fam.attrbuf;
1782 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1783 tb, nl80211_fam.maxattr, nl80211_policy);
1784 /* ignore parse errors for backward compatibility */
1785 if (ret)
1786 return 0;
1787
1788 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1789 if (tb[NL80211_ATTR_WIPHY])
1790 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1791 if (tb[NL80211_ATTR_WDEV])
1792 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1793 if (tb[NL80211_ATTR_IFINDEX]) {
1794 struct net_device *netdev;
1795 struct cfg80211_registered_device *rdev;
1796 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1797
Ying Xue7f2b8562014-01-15 10:23:45 +08001798 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001799 if (!netdev)
1800 return -ENODEV;
1801 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001802 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001803 netdev->ieee80211_ptr->wiphy);
1804 state->filter_wiphy = rdev->wiphy_idx;
1805 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 }
1807
1808 return 0;
1809}
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1812{
Johannes Berg645e77d2013-03-01 14:03:49 +01001813 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001815 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001816
Johannes Berg5fe231e2013-05-08 21:45:15 +02001817 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 if (!state) {
1819 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001820 if (!state) {
1821 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 state->filter_wiphy = -1;
1825 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1826 if (ret) {
1827 kfree(state);
1828 rtnl_unlock();
1829 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001830 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001831 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001832 }
1833
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001834 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1835 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001836 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001838 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001839 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001840 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001841 continue;
1842 /* attempt to fit multiple wiphy data chunks into the skb */
1843 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001844 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1845 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001846 NETLINK_CB(cb->skb).portid,
1847 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001848 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001849 if (ret < 0) {
1850 /*
1851 * If sending the wiphy data didn't fit (ENOBUFS
1852 * or EMSGSIZE returned), this SKB is still
1853 * empty (so it's not too big because another
1854 * wiphy dataset is already in the skb) and
1855 * we've not tried to adjust the dump allocation
1856 * yet ... then adjust the alloc size to be
1857 * bigger, and return 1 but with the empty skb.
1858 * This results in an empty message being RX'ed
1859 * in userspace, but that is ignored.
1860 *
1861 * We can then retry with the larger buffer.
1862 */
1863 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001864 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001865 cb->min_dump_alloc < 4096) {
1866 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001867 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001868 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001869 return 1;
1870 }
1871 idx--;
1872 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001873 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001874 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001875 break;
Johannes Berg55682962007-09-20 13:09:35 -04001876 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001877 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001878
Johannes Berg86e8cf92013-06-19 10:57:22 +02001879 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001880
1881 return skb->len;
1882}
1883
Johannes Berg86e8cf92013-06-19 10:57:22 +02001884static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1885{
1886 kfree((void *)cb->args[0]);
1887 return 0;
1888}
1889
Johannes Berg55682962007-09-20 13:09:35 -04001890static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1891{
1892 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001894 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001895
Johannes Berg645e77d2013-03-01 14:03:49 +01001896 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001897 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001898 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001899
Johannes Berg3bb20552014-05-26 13:52:25 +02001900 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1901 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001902 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001903 nlmsg_free(msg);
1904 return -ENOBUFS;
1905 }
Johannes Berg55682962007-09-20 13:09:35 -04001906
Johannes Berg134e6372009-07-10 09:51:34 +00001907 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001908}
1909
Jouni Malinen31888482008-10-30 16:59:24 +02001910static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1911 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1912 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1913 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1914 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1915 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1916};
1917
1918static int parse_txq_params(struct nlattr *tb[],
1919 struct ieee80211_txq_params *txq_params)
1920{
Johannes Berga3304b02012-03-28 11:04:24 +02001921 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001922 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1923 !tb[NL80211_TXQ_ATTR_AIFS])
1924 return -EINVAL;
1925
Johannes Berga3304b02012-03-28 11:04:24 +02001926 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001927 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1928 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1929 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1930 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1931
Johannes Berga3304b02012-03-28 11:04:24 +02001932 if (txq_params->ac >= NL80211_NUM_ACS)
1933 return -EINVAL;
1934
Jouni Malinen31888482008-10-30 16:59:24 +02001935 return 0;
1936}
1937
Johannes Bergf444de02010-05-05 15:25:02 +02001938static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1939{
1940 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001941 * You can only set the channel explicitly for WDS interfaces,
1942 * all others have their channel managed via their respective
1943 * "establish a connection" command (connect, join, ...)
1944 *
1945 * For AP/GO and mesh mode, the channel can be set with the
1946 * channel userspace API, but is only stored and passed to the
1947 * low-level driver when the AP starts or the mesh is joined.
1948 * This is for backward compatibility, userspace can also give
1949 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001950 *
1951 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001952 * whatever else is going on, so they have their own special
1953 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001954 */
1955 return !wdev ||
1956 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001957 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001958 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1959 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001960}
1961
Johannes Berg683b6d32012-11-08 21:25:48 +01001962static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1963 struct genl_info *info,
1964 struct cfg80211_chan_def *chandef)
1965{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301966 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001967
1968 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1969 return -EINVAL;
1970
1971 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1972
1973 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1975 chandef->center_freq1 = control_freq;
1976 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001977
1978 /* Primary channel not allowed */
1979 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1980 return -EINVAL;
1981
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001982 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1983 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001984
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001985 chantype = nla_get_u32(
1986 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1987
1988 switch (chantype) {
1989 case NL80211_CHAN_NO_HT:
1990 case NL80211_CHAN_HT20:
1991 case NL80211_CHAN_HT40PLUS:
1992 case NL80211_CHAN_HT40MINUS:
1993 cfg80211_chandef_create(chandef, chandef->chan,
1994 chantype);
1995 break;
1996 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001997 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001999 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2000 chandef->width =
2001 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2002 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2003 chandef->center_freq1 =
2004 nla_get_u32(
2005 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2006 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2007 chandef->center_freq2 =
2008 nla_get_u32(
2009 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2010 }
2011
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002012 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002013 return -EINVAL;
2014
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002015 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2016 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002017 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002018
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002019 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2020 chandef->width == NL80211_CHAN_WIDTH_10) &&
2021 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2022 return -EINVAL;
2023
Johannes Berg683b6d32012-11-08 21:25:48 +01002024 return 0;
2025}
2026
Johannes Bergf444de02010-05-05 15:25:02 +02002027static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002028 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002029 struct genl_info *info)
2030{
Johannes Berg683b6d32012-11-08 21:25:48 +01002031 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002032 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002033 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002034 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035
Jouni Malinene16821b2014-04-28 11:22:08 +03002036 if (dev)
2037 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002038 if (!nl80211_can_set_dev_channel(wdev))
2039 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002040 if (wdev)
2041 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002042
Johannes Berg683b6d32012-11-08 21:25:48 +01002043 result = nl80211_parse_chandef(rdev, info, &chandef);
2044 if (result)
2045 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002046
Johannes Berge8c9bd52012-06-06 08:18:22 +02002047 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002048 case NL80211_IFTYPE_AP:
2049 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002050 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2051 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002052 result = -EINVAL;
2053 break;
2054 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002055 if (wdev->beacon_interval) {
2056 if (!dev || !rdev->ops->set_ap_chanwidth ||
2057 !(rdev->wiphy.features &
2058 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2059 result = -EBUSY;
2060 break;
2061 }
2062
2063 /* Only allow dynamic channel width changes */
2064 if (chandef.chan != wdev->preset_chandef.chan) {
2065 result = -EBUSY;
2066 break;
2067 }
2068 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2069 if (result)
2070 break;
2071 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002072 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002073 result = 0;
2074 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002075 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002076 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002077 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002078 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002079 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002080 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002081 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002082 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002083 }
Johannes Bergf444de02010-05-05 15:25:02 +02002084
2085 return result;
2086}
2087
2088static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2089{
Johannes Berg4c476992010-10-04 21:36:35 +02002090 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2091 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002092
Jouni Malinene16821b2014-04-28 11:22:08 +03002093 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002094}
2095
Bill Jordane8347eb2010-10-01 13:54:28 -04002096static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2097{
Johannes Berg43b19952010-10-07 13:10:30 +02002098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2099 struct net_device *dev = info->user_ptr[1];
2100 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002101 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002102
2103 if (!info->attrs[NL80211_ATTR_MAC])
2104 return -EINVAL;
2105
Johannes Berg43b19952010-10-07 13:10:30 +02002106 if (netif_running(dev))
2107 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002108
Johannes Berg43b19952010-10-07 13:10:30 +02002109 if (!rdev->ops->set_wds_peer)
2110 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002111
Johannes Berg43b19952010-10-07 13:10:30 +02002112 if (wdev->iftype != NL80211_IFTYPE_WDS)
2113 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002114
2115 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002116 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002117}
2118
2119
Johannes Berg55682962007-09-20 13:09:35 -04002120static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2121{
2122 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002123 struct net_device *netdev = NULL;
2124 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002125 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002126 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002127 u32 changed;
2128 u8 retry_short = 0, retry_long = 0;
2129 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002130 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002131
Johannes Berg5fe231e2013-05-08 21:45:15 +02002132 ASSERT_RTNL();
2133
Johannes Bergf444de02010-05-05 15:25:02 +02002134 /*
2135 * Try to find the wiphy and netdev. Normally this
2136 * function shouldn't need the netdev, but this is
2137 * done for backward compatibility -- previously
2138 * setting the channel was done per wiphy, but now
2139 * it is per netdev. Previous userland like hostapd
2140 * also passed a netdev to set_wiphy, so that it is
2141 * possible to let that go to the right netdev!
2142 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002143
Johannes Bergf444de02010-05-05 15:25:02 +02002144 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2145 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2146
Ying Xue7f2b8562014-01-15 10:23:45 +08002147 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002148 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002149 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002150 else
Johannes Bergf444de02010-05-05 15:25:02 +02002151 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002152 }
2153
Johannes Bergf444de02010-05-05 15:25:02 +02002154 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002155 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2156 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002157 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002158 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002159 wdev = NULL;
2160 netdev = NULL;
2161 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002162 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002163 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002164
2165 /*
2166 * end workaround code, by now the rdev is available
2167 * and locked, and wdev may or may not be NULL.
2168 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002169
2170 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002171 result = cfg80211_dev_rename(
2172 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002173
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002176
Jouni Malinen31888482008-10-30 16:59:24 +02002177 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2178 struct ieee80211_txq_params txq_params;
2179 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2180
Ying Xue7f2b8562014-01-15 10:23:45 +08002181 if (!rdev->ops->set_txq_params)
2182 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002183
Ying Xue7f2b8562014-01-15 10:23:45 +08002184 if (!netdev)
2185 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002186
Johannes Berg133a3ff2011-11-03 14:50:13 +01002187 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2189 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002190
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 if (!netif_running(netdev))
2192 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002193
Jouni Malinen31888482008-10-30 16:59:24 +02002194 nla_for_each_nested(nl_txq_params,
2195 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2196 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002197 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2198 nla_data(nl_txq_params),
2199 nla_len(nl_txq_params),
2200 txq_params_policy);
2201 if (result)
2202 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002203 result = parse_txq_params(tb, &txq_params);
2204 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002205 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002206
Hila Gonene35e4d22012-06-27 17:19:42 +03002207 result = rdev_set_txq_params(rdev, netdev,
2208 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002209 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002211 }
2212 }
2213
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002214 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002215 result = __nl80211_set_channel(
2216 rdev,
2217 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2218 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002219 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002221 }
2222
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002223 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002224 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002225 enum nl80211_tx_power_setting type;
2226 int idx, mbm = 0;
2227
Johannes Bergc8442112012-10-24 10:17:18 +02002228 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2229 txp_wdev = NULL;
2230
Ying Xue7f2b8562014-01-15 10:23:45 +08002231 if (!rdev->ops->set_tx_power)
2232 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002233
2234 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2235 type = nla_get_u32(info->attrs[idx]);
2236
2237 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 (type != NL80211_TX_POWER_AUTOMATIC))
2239 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002240
2241 if (type != NL80211_TX_POWER_AUTOMATIC) {
2242 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2243 mbm = nla_get_u32(info->attrs[idx]);
2244 }
2245
Johannes Bergc8442112012-10-24 10:17:18 +02002246 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002247 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002248 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002249 }
2250
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002251 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2252 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2253 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002254 if ((!rdev->wiphy.available_antennas_tx &&
2255 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002256 !rdev->ops->set_antenna)
2257 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002258
2259 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2260 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2261
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002262 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002263 * available antenna masks, except for the "all" mask */
2264 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002265 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2266 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002267
Bruno Randolf7f531e02010-12-16 11:30:22 +09002268 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2269 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002270
Hila Gonene35e4d22012-06-27 17:19:42 +03002271 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002272 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002273 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002274 }
2275
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002276 changed = 0;
2277
2278 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2279 retry_short = nla_get_u8(
2280 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 if (retry_short == 0)
2282 return -EINVAL;
2283
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 changed |= WIPHY_PARAM_RETRY_SHORT;
2285 }
2286
2287 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2288 retry_long = nla_get_u8(
2289 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002290 if (retry_long == 0)
2291 return -EINVAL;
2292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002293 changed |= WIPHY_PARAM_RETRY_LONG;
2294 }
2295
2296 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2297 frag_threshold = nla_get_u32(
2298 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 if (frag_threshold < 256)
2300 return -EINVAL;
2301
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002302 if (frag_threshold != (u32) -1) {
2303 /*
2304 * Fragments (apart from the last one) are required to
2305 * have even length. Make the fragmentation code
2306 * simpler by stripping LSB should someone try to use
2307 * odd threshold value.
2308 */
2309 frag_threshold &= ~0x1;
2310 }
2311 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2312 }
2313
2314 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2315 rts_threshold = nla_get_u32(
2316 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2317 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2318 }
2319
Lukáš Turek81077e82009-12-21 22:50:47 +01002320 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002321 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2322 return -EINVAL;
2323
Lukáš Turek81077e82009-12-21 22:50:47 +01002324 coverage_class = nla_get_u8(
2325 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2326 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2327 }
2328
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002329 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2330 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2331 return -EOPNOTSUPP;
2332
2333 changed |= WIPHY_PARAM_DYN_ACK;
2334 }
2335
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002336 if (changed) {
2337 u8 old_retry_short, old_retry_long;
2338 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002339 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002340
Ying Xue7f2b8562014-01-15 10:23:45 +08002341 if (!rdev->ops->set_wiphy_params)
2342 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002343
2344 old_retry_short = rdev->wiphy.retry_short;
2345 old_retry_long = rdev->wiphy.retry_long;
2346 old_frag_threshold = rdev->wiphy.frag_threshold;
2347 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002348 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002349
2350 if (changed & WIPHY_PARAM_RETRY_SHORT)
2351 rdev->wiphy.retry_short = retry_short;
2352 if (changed & WIPHY_PARAM_RETRY_LONG)
2353 rdev->wiphy.retry_long = retry_long;
2354 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2355 rdev->wiphy.frag_threshold = frag_threshold;
2356 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2357 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002358 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2359 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002360
Hila Gonene35e4d22012-06-27 17:19:42 +03002361 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002362 if (result) {
2363 rdev->wiphy.retry_short = old_retry_short;
2364 rdev->wiphy.retry_long = old_retry_long;
2365 rdev->wiphy.frag_threshold = old_frag_threshold;
2366 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002367 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002368 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002369 }
2370 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002371 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002372}
2373
Johannes Berg71bbc992012-06-15 15:30:18 +02002374static inline u64 wdev_id(struct wireless_dev *wdev)
2375{
2376 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002377 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002378}
Johannes Berg55682962007-09-20 13:09:35 -04002379
Johannes Berg683b6d32012-11-08 21:25:48 +01002380static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002381 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002382{
Johannes Berg601555c2014-11-27 17:26:56 +01002383 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2384 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002385
Johannes Berg683b6d32012-11-08 21:25:48 +01002386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2387 chandef->chan->center_freq))
2388 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002389 switch (chandef->width) {
2390 case NL80211_CHAN_WIDTH_20_NOHT:
2391 case NL80211_CHAN_WIDTH_20:
2392 case NL80211_CHAN_WIDTH_40:
2393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2394 cfg80211_get_chandef_type(chandef)))
2395 return -ENOBUFS;
2396 break;
2397 default:
2398 break;
2399 }
2400 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2401 return -ENOBUFS;
2402 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2403 return -ENOBUFS;
2404 if (chandef->center_freq2 &&
2405 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002406 return -ENOBUFS;
2407 return 0;
2408}
2409
Eric W. Biederman15e47302012-09-07 20:12:54 +00002410static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002411 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002412 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002413{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002414 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002415 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002416 void *hdr;
2417
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002418 if (removal)
2419 cmd = NL80211_CMD_DEL_INTERFACE;
2420
2421 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002422 if (!hdr)
2423 return -1;
2424
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002425 if (dev &&
2426 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002427 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002428 goto nla_put_failure;
2429
2430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2431 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002432 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2433 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002434 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002435 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2436 rdev->devlist_generation ^
2437 (cfg80211_rdev_list_generation << 2)))
2438 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002439
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002440 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002441 int ret;
2442 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002443
Johannes Berg683b6d32012-11-08 21:25:48 +01002444 ret = rdev_get_channel(rdev, wdev, &chandef);
2445 if (ret == 0) {
2446 if (nl80211_send_chandef(msg, &chandef))
2447 goto nla_put_failure;
2448 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002449 }
2450
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002451 if (rdev->ops->get_tx_power) {
2452 int dbm, ret;
2453
2454 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2455 if (ret == 0 &&
2456 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2457 DBM_TO_MBM(dbm)))
2458 goto nla_put_failure;
2459 }
2460
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002461 if (wdev->ssid_len) {
2462 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2463 goto nla_put_failure;
2464 }
2465
Johannes Berg053c0952015-01-16 22:09:00 +01002466 genlmsg_end(msg, hdr);
2467 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002468
2469 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002470 genlmsg_cancel(msg, hdr);
2471 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002472}
2473
2474static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2475{
2476 int wp_idx = 0;
2477 int if_idx = 0;
2478 int wp_start = cb->args[0];
2479 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002480 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002481 struct wireless_dev *wdev;
2482
Johannes Berg5fe231e2013-05-08 21:45:15 +02002483 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002484 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2485 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002486 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002487 if (wp_idx < wp_start) {
2488 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002489 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002490 }
Johannes Berg55682962007-09-20 13:09:35 -04002491 if_idx = 0;
2492
Johannes Berg53873f12016-05-03 16:52:04 +03002493 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002494 if (if_idx < if_start) {
2495 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002496 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002497 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002498 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002499 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002500 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002501 goto out;
2502 }
2503 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002504 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002505
2506 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002507 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002508 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002509 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002510
2511 cb->args[0] = wp_idx;
2512 cb->args[1] = if_idx;
2513
2514 return skb->len;
2515}
2516
2517static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2518{
2519 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002521 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002522
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002524 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002525 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002526
Eric W. Biederman15e47302012-09-07 20:12:54 +00002527 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002528 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002529 nlmsg_free(msg);
2530 return -ENOBUFS;
2531 }
Johannes Berg55682962007-09-20 13:09:35 -04002532
Johannes Berg134e6372009-07-10 09:51:34 +00002533 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002534}
2535
Michael Wu66f7ac52008-01-31 19:48:22 +01002536static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2537 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2538 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2539 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2540 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2541 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002542 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002543};
2544
2545static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2546{
2547 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2548 int flag;
2549
2550 *mntrflags = 0;
2551
2552 if (!nla)
2553 return -EINVAL;
2554
2555 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2556 nla, mntr_flags_policy))
2557 return -EINVAL;
2558
2559 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2560 if (flags[flag])
2561 *mntrflags |= (1<<flag);
2562
2563 return 0;
2564}
2565
Johannes Berg9bc383d2009-11-19 11:55:19 +01002566static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002567 struct net_device *netdev, u8 use_4addr,
2568 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002569{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002570 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002571 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002572 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002573 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002574 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002575
2576 switch (iftype) {
2577 case NL80211_IFTYPE_AP_VLAN:
2578 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2579 return 0;
2580 break;
2581 case NL80211_IFTYPE_STATION:
2582 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2583 return 0;
2584 break;
2585 default:
2586 break;
2587 }
2588
2589 return -EOPNOTSUPP;
2590}
2591
Johannes Berg55682962007-09-20 13:09:35 -04002592static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2593{
Johannes Berg4c476992010-10-04 21:36:35 +02002594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002595 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002596 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002597 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002598 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002599 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002600 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002601
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002602 memset(&params, 0, sizeof(params));
2603
Johannes Berg04a773a2009-04-19 21:24:32 +02002604 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002605
Johannes Berg723b0382008-09-16 20:22:09 +02002606 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002607 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002608 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002609 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002610 if (ntype > NL80211_IFTYPE_MAX)
2611 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002612 }
2613
Johannes Berg92ffe052008-09-16 20:39:36 +02002614 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002615 struct wireless_dev *wdev = dev->ieee80211_ptr;
2616
Johannes Berg4c476992010-10-04 21:36:35 +02002617 if (ntype != NL80211_IFTYPE_MESH_POINT)
2618 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002619 if (netif_running(dev))
2620 return -EBUSY;
2621
2622 wdev_lock(wdev);
2623 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2624 IEEE80211_MAX_MESH_ID_LEN);
2625 wdev->mesh_id_up_len =
2626 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2627 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2628 wdev->mesh_id_up_len);
2629 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002630 }
2631
Felix Fietkau8b787642009-11-10 18:53:10 +01002632 if (info->attrs[NL80211_ATTR_4ADDR]) {
2633 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2634 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002635 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002636 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002637 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002638 } else {
2639 params.use_4addr = -1;
2640 }
2641
Johannes Berg92ffe052008-09-16 20:39:36 +02002642 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002643 if (ntype != NL80211_IFTYPE_MONITOR)
2644 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002645 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2646 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002647 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002648 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002649
2650 flags = &_flags;
2651 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002652 }
Johannes Berg3b858752009-03-12 09:55:09 +01002653
Luciano Coelho18003292013-08-29 13:26:57 +03002654 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002655 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2656 return -EOPNOTSUPP;
2657
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002658 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002659 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002660 else
2661 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002662
Johannes Berg9bc383d2009-11-19 11:55:19 +01002663 if (!err && params.use_4addr != -1)
2664 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2665
Johannes Berg55682962007-09-20 13:09:35 -04002666 return err;
2667}
2668
2669static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2670{
Johannes Berg4c476992010-10-04 21:36:35 +02002671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002672 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002673 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002674 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002675 int err;
2676 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002677 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002678
Johannes Berg78f22b62014-03-24 17:57:27 +01002679 /* to avoid failing a new interface creation due to pending removal */
2680 cfg80211_destroy_ifaces(rdev);
2681
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002682 memset(&params, 0, sizeof(params));
2683
Johannes Berg55682962007-09-20 13:09:35 -04002684 if (!info->attrs[NL80211_ATTR_IFNAME])
2685 return -EINVAL;
2686
2687 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2688 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2689 if (type > NL80211_IFTYPE_MAX)
2690 return -EINVAL;
2691 }
2692
Johannes Berg79c97e92009-07-07 03:56:12 +02002693 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002694 !(rdev->wiphy.interface_modes & (1 << type)))
2695 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002696
Ben Greeare8f479b2014-10-22 12:23:05 -07002697 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2698 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2699 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002700 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2701 ETH_ALEN);
2702 if (!is_valid_ether_addr(params.macaddr))
2703 return -EADDRNOTAVAIL;
2704 }
2705
Johannes Berg9bc383d2009-11-19 11:55:19 +01002706 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002707 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002708 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002709 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002710 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002711 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002712
Michael Wu66f7ac52008-01-31 19:48:22 +01002713 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2714 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2715 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002716
Luciano Coelho18003292013-08-29 13:26:57 +03002717 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002718 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2719 return -EOPNOTSUPP;
2720
Johannes Berga18c7192015-02-24 10:56:42 +01002721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2722 if (!msg)
2723 return -ENOMEM;
2724
Hila Gonene35e4d22012-06-27 17:19:42 +03002725 wdev = rdev_add_virtual_intf(rdev,
2726 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002727 NET_NAME_USER, type, err ? NULL : &flags,
2728 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002729 if (WARN_ON(!wdev)) {
2730 nlmsg_free(msg);
2731 return -EPROTO;
2732 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002733 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002734 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002735 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002736
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002737 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002738 wdev->owner_nlportid = info->snd_portid;
2739
Johannes Berg98104fde2012-06-16 00:19:54 +02002740 switch (type) {
2741 case NL80211_IFTYPE_MESH_POINT:
2742 if (!info->attrs[NL80211_ATTR_MESH_ID])
2743 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002744 wdev_lock(wdev);
2745 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2746 IEEE80211_MAX_MESH_ID_LEN);
2747 wdev->mesh_id_up_len =
2748 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2749 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2750 wdev->mesh_id_up_len);
2751 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002752 break;
2753 case NL80211_IFTYPE_P2P_DEVICE:
2754 /*
2755 * P2P Device doesn't have a netdev, so doesn't go
2756 * through the netdev notifier and must be added here
2757 */
2758 mutex_init(&wdev->mtx);
2759 INIT_LIST_HEAD(&wdev->event_list);
2760 spin_lock_init(&wdev->event_lock);
2761 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2762 spin_lock_init(&wdev->mgmt_registrations_lock);
2763
Johannes Berg98104fde2012-06-16 00:19:54 +02002764 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002765 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002766 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002767 break;
2768 default:
2769 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002770 }
2771
Eric W. Biederman15e47302012-09-07 20:12:54 +00002772 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002773 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002774 nlmsg_free(msg);
2775 return -ENOBUFS;
2776 }
2777
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002778 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2779 if (event) {
2780 if (nl80211_send_iface(event, 0, 0, 0,
2781 rdev, wdev, false) < 0) {
2782 nlmsg_free(event);
2783 goto out;
2784 }
2785
2786 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2787 event, 0, NL80211_MCGRP_CONFIG,
2788 GFP_KERNEL);
2789 }
2790
2791out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002792 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002793}
2794
2795static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2796{
Johannes Berg4c476992010-10-04 21:36:35 +02002797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002798 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002799 struct sk_buff *msg;
2800 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002801
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!rdev->ops->del_virtual_intf)
2803 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002804
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2806 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2807 nlmsg_free(msg);
2808 msg = NULL;
2809 }
2810
Johannes Berg84efbb82012-06-16 00:00:26 +02002811 /*
2812 * If we remove a wireless device without a netdev then clear
2813 * user_ptr[1] so that nl80211_post_doit won't dereference it
2814 * to check if it needs to do dev_put(). Otherwise it crashes
2815 * since the wdev has been freed, unlike with a netdev where
2816 * we need the dev_put() for the netdev to really be freed.
2817 */
2818 if (!wdev->netdev)
2819 info->user_ptr[1] = NULL;
2820
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002821 status = rdev_del_virtual_intf(rdev, wdev);
2822 if (status >= 0 && msg)
2823 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2824 msg, 0, NL80211_MCGRP_CONFIG,
2825 GFP_KERNEL);
2826 else
2827 nlmsg_free(msg);
2828
2829 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002830}
2831
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002832static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2833{
2834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2835 struct net_device *dev = info->user_ptr[1];
2836 u16 noack_map;
2837
2838 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2839 return -EINVAL;
2840
2841 if (!rdev->ops->set_noack_map)
2842 return -EOPNOTSUPP;
2843
2844 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2845
Hila Gonene35e4d22012-06-27 17:19:42 +03002846 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002847}
2848
Johannes Berg41ade002007-12-19 02:03:29 +01002849struct get_key_cookie {
2850 struct sk_buff *msg;
2851 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002852 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002853};
2854
2855static void get_key_callback(void *c, struct key_params *params)
2856{
Johannes Bergb9454e82009-07-08 13:29:08 +02002857 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002858 struct get_key_cookie *cookie = c;
2859
David S. Miller9360ffd2012-03-29 04:41:26 -04002860 if ((params->key &&
2861 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2862 params->key_len, params->key)) ||
2863 (params->seq &&
2864 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2865 params->seq_len, params->seq)) ||
2866 (params->cipher &&
2867 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2868 params->cipher)))
2869 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002870
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2872 if (!key)
2873 goto nla_put_failure;
2874
David S. Miller9360ffd2012-03-29 04:41:26 -04002875 if ((params->key &&
2876 nla_put(cookie->msg, NL80211_KEY_DATA,
2877 params->key_len, params->key)) ||
2878 (params->seq &&
2879 nla_put(cookie->msg, NL80211_KEY_SEQ,
2880 params->seq_len, params->seq)) ||
2881 (params->cipher &&
2882 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2883 params->cipher)))
2884 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002885
David S. Miller9360ffd2012-03-29 04:41:26 -04002886 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2887 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002888
2889 nla_nest_end(cookie->msg, key);
2890
Johannes Berg41ade002007-12-19 02:03:29 +01002891 return;
2892 nla_put_failure:
2893 cookie->error = 1;
2894}
2895
2896static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2897{
Johannes Berg4c476992010-10-04 21:36:35 +02002898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002899 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002900 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002901 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002902 const u8 *mac_addr = NULL;
2903 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002904 struct get_key_cookie cookie = {
2905 .error = 0,
2906 };
2907 void *hdr;
2908 struct sk_buff *msg;
2909
2910 if (info->attrs[NL80211_ATTR_KEY_IDX])
2911 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2912
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002913 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return -EINVAL;
2915
2916 if (info->attrs[NL80211_ATTR_MAC])
2917 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2918
Johannes Berge31b8212010-10-05 19:39:30 +02002919 pairwise = !!mac_addr;
2920 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2921 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2922 if (kt >= NUM_NL80211_KEYTYPES)
2923 return -EINVAL;
2924 if (kt != NL80211_KEYTYPE_GROUP &&
2925 kt != NL80211_KEYTYPE_PAIRWISE)
2926 return -EINVAL;
2927 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2928 }
2929
Johannes Berg4c476992010-10-04 21:36:35 +02002930 if (!rdev->ops->get_key)
2931 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002932
Johannes Berg0fa7b392015-01-23 11:10:12 +01002933 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2934 return -ENOENT;
2935
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002937 if (!msg)
2938 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002939
Eric W. Biederman15e47302012-09-07 20:12:54 +00002940 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002941 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002942 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002943 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002944
2945 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002946 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002947
David S. Miller9360ffd2012-03-29 04:41:26 -04002948 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2949 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2950 goto nla_put_failure;
2951 if (mac_addr &&
2952 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2953 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002954
Hila Gonene35e4d22012-06-27 17:19:42 +03002955 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2956 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002957
2958 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002959 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002960
2961 if (cookie.error)
2962 goto nla_put_failure;
2963
2964 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002965 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002966
2967 nla_put_failure:
2968 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002969 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002970 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002971 return err;
2972}
2973
2974static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2975{
Johannes Berg4c476992010-10-04 21:36:35 +02002976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002977 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002978 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002979 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002980
Johannes Bergb9454e82009-07-08 13:29:08 +02002981 err = nl80211_parse_key(info, &key);
2982 if (err)
2983 return err;
2984
2985 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002986 return -EINVAL;
2987
Johannes Bergb9454e82009-07-08 13:29:08 +02002988 /* only support setting default key */
2989 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002990 return -EINVAL;
2991
Johannes Bergfffd0932009-07-08 14:22:54 +02002992 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002993
2994 if (key.def) {
2995 if (!rdev->ops->set_default_key) {
2996 err = -EOPNOTSUPP;
2997 goto out;
2998 }
2999
3000 err = nl80211_key_allowed(dev->ieee80211_ptr);
3001 if (err)
3002 goto out;
3003
Hila Gonene35e4d22012-06-27 17:19:42 +03003004 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003005 key.def_uni, key.def_multi);
3006
3007 if (err)
3008 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003009
Johannes Berg3d23e342009-09-29 23:27:28 +02003010#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003011 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003012#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003013 } else {
3014 if (key.def_uni || !key.def_multi) {
3015 err = -EINVAL;
3016 goto out;
3017 }
3018
3019 if (!rdev->ops->set_default_mgmt_key) {
3020 err = -EOPNOTSUPP;
3021 goto out;
3022 }
3023
3024 err = nl80211_key_allowed(dev->ieee80211_ptr);
3025 if (err)
3026 goto out;
3027
Hila Gonene35e4d22012-06-27 17:19:42 +03003028 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003029 if (err)
3030 goto out;
3031
3032#ifdef CONFIG_CFG80211_WEXT
3033 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3034#endif
3035 }
3036
3037 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003038 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003039
Johannes Berg41ade002007-12-19 02:03:29 +01003040 return err;
3041}
3042
3043static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3044{
Johannes Berg4c476992010-10-04 21:36:35 +02003045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003046 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003047 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003048 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003049 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003050
Johannes Bergb9454e82009-07-08 13:29:08 +02003051 err = nl80211_parse_key(info, &key);
3052 if (err)
3053 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003054
Johannes Bergb9454e82009-07-08 13:29:08 +02003055 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003056 return -EINVAL;
3057
Johannes Berg41ade002007-12-19 02:03:29 +01003058 if (info->attrs[NL80211_ATTR_MAC])
3059 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3060
Johannes Berge31b8212010-10-05 19:39:30 +02003061 if (key.type == -1) {
3062 if (mac_addr)
3063 key.type = NL80211_KEYTYPE_PAIRWISE;
3064 else
3065 key.type = NL80211_KEYTYPE_GROUP;
3066 }
3067
3068 /* for now */
3069 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3070 key.type != NL80211_KEYTYPE_GROUP)
3071 return -EINVAL;
3072
Johannes Berg4c476992010-10-04 21:36:35 +02003073 if (!rdev->ops->add_key)
3074 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003075
Johannes Berge31b8212010-10-05 19:39:30 +02003076 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3077 key.type == NL80211_KEYTYPE_PAIRWISE,
3078 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003079 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003080
3081 wdev_lock(dev->ieee80211_ptr);
3082 err = nl80211_key_allowed(dev->ieee80211_ptr);
3083 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003084 err = rdev_add_key(rdev, dev, key.idx,
3085 key.type == NL80211_KEYTYPE_PAIRWISE,
3086 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003087 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003088
Johannes Berg41ade002007-12-19 02:03:29 +01003089 return err;
3090}
3091
3092static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3093{
Johannes Berg4c476992010-10-04 21:36:35 +02003094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003095 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003096 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003097 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003098 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Bergb9454e82009-07-08 13:29:08 +02003100 err = nl80211_parse_key(info, &key);
3101 if (err)
3102 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003103
3104 if (info->attrs[NL80211_ATTR_MAC])
3105 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3106
Johannes Berge31b8212010-10-05 19:39:30 +02003107 if (key.type == -1) {
3108 if (mac_addr)
3109 key.type = NL80211_KEYTYPE_PAIRWISE;
3110 else
3111 key.type = NL80211_KEYTYPE_GROUP;
3112 }
3113
3114 /* for now */
3115 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3116 key.type != NL80211_KEYTYPE_GROUP)
3117 return -EINVAL;
3118
Johannes Berg4c476992010-10-04 21:36:35 +02003119 if (!rdev->ops->del_key)
3120 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003121
Johannes Bergfffd0932009-07-08 14:22:54 +02003122 wdev_lock(dev->ieee80211_ptr);
3123 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003124
Johannes Berg0fa7b392015-01-23 11:10:12 +01003125 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003126 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3127 err = -ENOENT;
3128
Johannes Bergfffd0932009-07-08 14:22:54 +02003129 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003130 err = rdev_del_key(rdev, dev, key.idx,
3131 key.type == NL80211_KEYTYPE_PAIRWISE,
3132 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003133
Johannes Berg3d23e342009-09-29 23:27:28 +02003134#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003135 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003136 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003137 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003138 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003139 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3140 }
3141#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003142 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003143
Johannes Berg41ade002007-12-19 02:03:29 +01003144 return err;
3145}
3146
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303147/* This function returns an error or the number of nested attributes */
3148static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3149{
3150 struct nlattr *attr;
3151 int n_entries = 0, tmp;
3152
3153 nla_for_each_nested(attr, nl_attr, tmp) {
3154 if (nla_len(attr) != ETH_ALEN)
3155 return -EINVAL;
3156
3157 n_entries++;
3158 }
3159
3160 return n_entries;
3161}
3162
3163/*
3164 * This function parses ACL information and allocates memory for ACL data.
3165 * On successful return, the calling function is responsible to free the
3166 * ACL buffer returned by this function.
3167 */
3168static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3169 struct genl_info *info)
3170{
3171 enum nl80211_acl_policy acl_policy;
3172 struct nlattr *attr;
3173 struct cfg80211_acl_data *acl;
3174 int i = 0, n_entries, tmp;
3175
3176 if (!wiphy->max_acl_mac_addrs)
3177 return ERR_PTR(-EOPNOTSUPP);
3178
3179 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3180 return ERR_PTR(-EINVAL);
3181
3182 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3183 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3184 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3185 return ERR_PTR(-EINVAL);
3186
3187 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3188 return ERR_PTR(-EINVAL);
3189
3190 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3191 if (n_entries < 0)
3192 return ERR_PTR(n_entries);
3193
3194 if (n_entries > wiphy->max_acl_mac_addrs)
3195 return ERR_PTR(-ENOTSUPP);
3196
3197 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3198 GFP_KERNEL);
3199 if (!acl)
3200 return ERR_PTR(-ENOMEM);
3201
3202 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3203 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3204 i++;
3205 }
3206
3207 acl->n_acl_entries = n_entries;
3208 acl->acl_policy = acl_policy;
3209
3210 return acl;
3211}
3212
3213static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3214{
3215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3216 struct net_device *dev = info->user_ptr[1];
3217 struct cfg80211_acl_data *acl;
3218 int err;
3219
3220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3222 return -EOPNOTSUPP;
3223
3224 if (!dev->ieee80211_ptr->beacon_interval)
3225 return -EINVAL;
3226
3227 acl = parse_acl_data(&rdev->wiphy, info);
3228 if (IS_ERR(acl))
3229 return PTR_ERR(acl);
3230
3231 err = rdev_set_mac_acl(rdev, dev, acl);
3232
3233 kfree(acl);
3234
3235 return err;
3236}
3237
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003238static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003239 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003240{
Johannes Berg88600202012-02-13 15:17:18 +01003241 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003242
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3244 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3245 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3246 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003247 return -EINVAL;
3248
Johannes Berg88600202012-02-13 15:17:18 +01003249 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003250
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003251 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3252 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3253 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003254 if (!bcn->head_len)
3255 return -EINVAL;
3256 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003257 }
3258
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003259 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3260 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3261 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003262 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003263 }
3264
Johannes Berg4c476992010-10-04 21:36:35 +02003265 if (!haveinfo)
3266 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003267
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003268 if (attrs[NL80211_ATTR_IE]) {
3269 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3270 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003271 }
3272
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003273 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003274 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003275 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003276 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003277 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003278 }
3279
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003280 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003281 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003282 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003283 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003284 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003285 }
3286
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003287 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3288 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3289 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003290 }
3291
Johannes Berg88600202012-02-13 15:17:18 +01003292 return 0;
3293}
3294
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003295static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3296 struct cfg80211_ap_settings *params)
3297{
3298 struct wireless_dev *wdev;
3299 bool ret = false;
3300
Johannes Berg53873f12016-05-03 16:52:04 +03003301 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003302 if (wdev->iftype != NL80211_IFTYPE_AP &&
3303 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3304 continue;
3305
Johannes Berg683b6d32012-11-08 21:25:48 +01003306 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003307 continue;
3308
Johannes Berg683b6d32012-11-08 21:25:48 +01003309 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003310 ret = true;
3311 break;
3312 }
3313
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003314 return ret;
3315}
3316
Jouni Malinene39e5b52012-09-30 19:29:39 +03003317static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3318 enum nl80211_auth_type auth_type,
3319 enum nl80211_commands cmd)
3320{
3321 if (auth_type > NL80211_AUTHTYPE_MAX)
3322 return false;
3323
3324 switch (cmd) {
3325 case NL80211_CMD_AUTHENTICATE:
3326 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3327 auth_type == NL80211_AUTHTYPE_SAE)
3328 return false;
3329 return true;
3330 case NL80211_CMD_CONNECT:
3331 case NL80211_CMD_START_AP:
3332 /* SAE not supported yet */
3333 if (auth_type == NL80211_AUTHTYPE_SAE)
3334 return false;
3335 return true;
3336 default:
3337 return false;
3338 }
3339}
3340
Johannes Berg88600202012-02-13 15:17:18 +01003341static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3342{
3343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3344 struct net_device *dev = info->user_ptr[1];
3345 struct wireless_dev *wdev = dev->ieee80211_ptr;
3346 struct cfg80211_ap_settings params;
3347 int err;
3348
3349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3351 return -EOPNOTSUPP;
3352
3353 if (!rdev->ops->start_ap)
3354 return -EOPNOTSUPP;
3355
3356 if (wdev->beacon_interval)
3357 return -EALREADY;
3358
3359 memset(&params, 0, sizeof(params));
3360
3361 /* these are required for START_AP */
3362 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3363 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3364 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3365 return -EINVAL;
3366
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003367 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003368 if (err)
3369 return err;
3370
3371 params.beacon_interval =
3372 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3373 params.dtim_period =
3374 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3375
3376 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3377 if (err)
3378 return err;
3379
3380 /*
3381 * In theory, some of these attributes should be required here
3382 * but since they were not used when the command was originally
3383 * added, keep them optional for old user space programs to let
3384 * them continue to work with drivers that do not need the
3385 * additional information -- drivers must check!
3386 */
3387 if (info->attrs[NL80211_ATTR_SSID]) {
3388 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3389 params.ssid_len =
3390 nla_len(info->attrs[NL80211_ATTR_SSID]);
3391 if (params.ssid_len == 0 ||
3392 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3393 return -EINVAL;
3394 }
3395
3396 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3397 params.hidden_ssid = nla_get_u32(
3398 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3399 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3400 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3401 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3402 return -EINVAL;
3403 }
3404
3405 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3406
3407 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3408 params.auth_type = nla_get_u32(
3409 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003410 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3411 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003412 return -EINVAL;
3413 } else
3414 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3415
3416 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3417 NL80211_MAX_NR_CIPHER_SUITES);
3418 if (err)
3419 return err;
3420
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303421 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3422 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3423 return -EOPNOTSUPP;
3424 params.inactivity_timeout = nla_get_u16(
3425 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3426 }
3427
Johannes Berg53cabad2012-11-14 15:17:28 +01003428 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3429 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3430 return -EINVAL;
3431 params.p2p_ctwindow =
3432 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3433 if (params.p2p_ctwindow > 127)
3434 return -EINVAL;
3435 if (params.p2p_ctwindow != 0 &&
3436 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3437 return -EINVAL;
3438 }
3439
3440 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3441 u8 tmp;
3442
3443 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3444 return -EINVAL;
3445 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3446 if (tmp > 1)
3447 return -EINVAL;
3448 params.p2p_opp_ps = tmp;
3449 if (params.p2p_opp_ps != 0 &&
3450 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3451 return -EINVAL;
3452 }
3453
Johannes Bergaa430da2012-05-16 23:50:18 +02003454 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003455 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3456 if (err)
3457 return err;
3458 } else if (wdev->preset_chandef.chan) {
3459 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003460 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003461 return -EINVAL;
3462
Arik Nemtsov923b3522015-07-08 15:41:44 +03003463 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3464 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003465 return -EINVAL;
3466
Eliad Peller18998c32014-09-10 14:07:34 +03003467 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3468 params.smps_mode =
3469 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3470 switch (params.smps_mode) {
3471 case NL80211_SMPS_OFF:
3472 break;
3473 case NL80211_SMPS_STATIC:
3474 if (!(rdev->wiphy.features &
3475 NL80211_FEATURE_STATIC_SMPS))
3476 return -EINVAL;
3477 break;
3478 case NL80211_SMPS_DYNAMIC:
3479 if (!(rdev->wiphy.features &
3480 NL80211_FEATURE_DYNAMIC_SMPS))
3481 return -EINVAL;
3482 break;
3483 default:
3484 return -EINVAL;
3485 }
3486 } else {
3487 params.smps_mode = NL80211_SMPS_OFF;
3488 }
3489
Ola Olsson4baf6be2015-10-29 07:04:58 +01003490 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3491 params.acl = parse_acl_data(&rdev->wiphy, info);
3492 if (IS_ERR(params.acl))
3493 return PTR_ERR(params.acl);
3494 }
3495
Lior David34d50512016-01-28 10:58:25 +02003496 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02003497 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
Lior David34d50512016-01-28 10:58:25 +02003498 return -EOPNOTSUPP;
3499
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003500 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003501 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003502 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003503 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003504 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003505 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003506 wdev->ssid_len = params.ssid_len;
3507 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003508 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003509 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303510
3511 kfree(params.acl);
3512
Johannes Berg56d18932011-05-09 18:41:15 +02003513 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003514}
3515
Johannes Berg88600202012-02-13 15:17:18 +01003516static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3517{
3518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3519 struct net_device *dev = info->user_ptr[1];
3520 struct wireless_dev *wdev = dev->ieee80211_ptr;
3521 struct cfg80211_beacon_data params;
3522 int err;
3523
3524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3526 return -EOPNOTSUPP;
3527
3528 if (!rdev->ops->change_beacon)
3529 return -EOPNOTSUPP;
3530
3531 if (!wdev->beacon_interval)
3532 return -EINVAL;
3533
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003534 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003535 if (err)
3536 return err;
3537
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003538 wdev_lock(wdev);
3539 err = rdev_change_beacon(rdev, dev, &params);
3540 wdev_unlock(wdev);
3541
3542 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003543}
3544
3545static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003546{
Johannes Berg4c476992010-10-04 21:36:35 +02003547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3548 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003549
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003550 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003551}
3552
Johannes Berg5727ef12007-12-19 02:03:34 +01003553static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3554 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3555 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3556 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003557 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003558 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003559 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003560};
3561
Johannes Bergeccb8e82009-05-11 21:57:56 +03003562static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003563 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003564 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003565{
3566 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003567 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003568 int flag;
3569
Johannes Bergeccb8e82009-05-11 21:57:56 +03003570 /*
3571 * Try parsing the new attribute first so userspace
3572 * can specify both for older kernels.
3573 */
3574 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3575 if (nla) {
3576 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003577
Johannes Bergeccb8e82009-05-11 21:57:56 +03003578 sta_flags = nla_data(nla);
3579 params->sta_flags_mask = sta_flags->mask;
3580 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003581 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003582 if ((params->sta_flags_mask |
3583 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3584 return -EINVAL;
3585 return 0;
3586 }
3587
3588 /* if present, parse the old attribute */
3589
3590 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003591 if (!nla)
3592 return 0;
3593
3594 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3595 nla, sta_flags_policy))
3596 return -EINVAL;
3597
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003598 /*
3599 * Only allow certain flags for interface types so that
3600 * other attributes are silently ignored. Remember that
3601 * this is backward compatibility code with old userspace
3602 * and shouldn't be hit in other cases anyway.
3603 */
3604 switch (iftype) {
3605 case NL80211_IFTYPE_AP:
3606 case NL80211_IFTYPE_AP_VLAN:
3607 case NL80211_IFTYPE_P2P_GO:
3608 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3609 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3610 BIT(NL80211_STA_FLAG_WME) |
3611 BIT(NL80211_STA_FLAG_MFP);
3612 break;
3613 case NL80211_IFTYPE_P2P_CLIENT:
3614 case NL80211_IFTYPE_STATION:
3615 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3616 BIT(NL80211_STA_FLAG_TDLS_PEER);
3617 break;
3618 case NL80211_IFTYPE_MESH_POINT:
3619 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3620 BIT(NL80211_STA_FLAG_MFP) |
3621 BIT(NL80211_STA_FLAG_AUTHORIZED);
3622 default:
3623 return -EINVAL;
3624 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003625
Johannes Berg3383b5a2012-05-10 20:14:43 +02003626 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3627 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003628 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003629
Johannes Berg3383b5a2012-05-10 20:14:43 +02003630 /* no longer support new API additions in old API */
3631 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3632 return -EINVAL;
3633 }
3634 }
3635
Johannes Berg5727ef12007-12-19 02:03:34 +01003636 return 0;
3637}
3638
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003639static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3640 int attr)
3641{
3642 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003643 u32 bitrate;
3644 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003645 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003646
3647 rate = nla_nest_start(msg, attr);
3648 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003649 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003650
3651 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3652 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003653 /* report 16-bit bitrate only if we can */
3654 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003655 if (bitrate > 0 &&
3656 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3657 return false;
3658 if (bitrate_compat > 0 &&
3659 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3660 return false;
3661
Johannes Bergb51f3be2015-01-15 16:14:02 +01003662 switch (info->bw) {
3663 case RATE_INFO_BW_5:
3664 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3665 break;
3666 case RATE_INFO_BW_10:
3667 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3668 break;
3669 default:
3670 WARN_ON(1);
3671 /* fall through */
3672 case RATE_INFO_BW_20:
3673 rate_flg = 0;
3674 break;
3675 case RATE_INFO_BW_40:
3676 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3677 break;
3678 case RATE_INFO_BW_80:
3679 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3680 break;
3681 case RATE_INFO_BW_160:
3682 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3683 break;
3684 }
3685
3686 if (rate_flg && nla_put_flag(msg, rate_flg))
3687 return false;
3688
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003689 if (info->flags & RATE_INFO_FLAGS_MCS) {
3690 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3691 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003692 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3693 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3694 return false;
3695 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3696 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3697 return false;
3698 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3699 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003700 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3701 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3702 return false;
3703 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003704
3705 nla_nest_end(msg, rate);
3706 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003707}
3708
Felix Fietkau119363c2013-04-22 16:29:30 +02003709static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3710 int id)
3711{
3712 void *attr;
3713 int i = 0;
3714
3715 if (!mask)
3716 return true;
3717
3718 attr = nla_nest_start(msg, id);
3719 if (!attr)
3720 return false;
3721
3722 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3723 if (!(mask & BIT(i)))
3724 continue;
3725
3726 if (nla_put_u8(msg, i, signal[i]))
3727 return false;
3728 }
3729
3730 nla_nest_end(msg, attr);
3731
3732 return true;
3733}
3734
Johannes Bergcf5ead82014-11-14 17:14:00 +01003735static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3736 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003737 struct cfg80211_registered_device *rdev,
3738 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003739 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003740{
3741 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003742 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003743
Johannes Bergcf5ead82014-11-14 17:14:00 +01003744 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003745 if (!hdr)
3746 return -1;
3747
David S. Miller9360ffd2012-03-29 04:41:26 -04003748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3750 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3751 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003752
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003753 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3754 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003755 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003756
3757#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02003758 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05303759 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01003760 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3761 sinfo->memb)) \
3762 goto nla_put_failure; \
3763 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02003764#define PUT_SINFO_U64(attr, memb) do { \
3765 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3766 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3767 sinfo->memb, NL80211_STA_INFO_PAD)) \
3768 goto nla_put_failure; \
3769 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01003770
3771 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3772 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3773
3774 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3775 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003776 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003777 (u32)sinfo->rx_bytes))
3778 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003779
3780 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3781 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003782 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3783 (u32)sinfo->tx_bytes))
3784 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003785
Johannes Bergd686b922016-04-26 09:54:11 +02003786 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
3787 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01003788 PUT_SINFO(LLID, llid, u16);
3789 PUT_SINFO(PLID, plid, u16);
3790 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02003791 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01003792
John W. Linville66266b32012-03-15 13:25:41 -04003793 switch (rdev->wiphy.signal_type) {
3794 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003795 PUT_SINFO(SIGNAL, signal, u8);
3796 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003797 break;
3798 default:
3799 break;
3800 }
Johannes Berg319090b2014-11-17 14:08:11 +01003801 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003802 if (!nl80211_put_signal(msg, sinfo->chains,
3803 sinfo->chain_signal,
3804 NL80211_STA_INFO_CHAIN_SIGNAL))
3805 goto nla_put_failure;
3806 }
Johannes Berg319090b2014-11-17 14:08:11 +01003807 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003808 if (!nl80211_put_signal(msg, sinfo->chains,
3809 sinfo->chain_signal_avg,
3810 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3811 goto nla_put_failure;
3812 }
Johannes Berg319090b2014-11-17 14:08:11 +01003813 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003814 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3815 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003816 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003817 }
Johannes Berg319090b2014-11-17 14:08:11 +01003818 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003819 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3820 NL80211_STA_INFO_RX_BITRATE))
3821 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003822 }
Johannes Berg319090b2014-11-17 14:08:11 +01003823
3824 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3825 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3826 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3827 PUT_SINFO(TX_FAILED, tx_failed, u32);
3828 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3829 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3830 PUT_SINFO(LOCAL_PM, local_pm, u32);
3831 PUT_SINFO(PEER_PM, peer_pm, u32);
3832 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3833
3834 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003835 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3836 if (!bss_param)
3837 goto nla_put_failure;
3838
David S. Miller9360ffd2012-03-29 04:41:26 -04003839 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3840 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3841 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3842 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3843 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3844 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3845 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3846 sinfo->bss_param.dtim_period) ||
3847 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3848 sinfo->bss_param.beacon_interval))
3849 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003850
3851 nla_nest_end(msg, bss_param);
3852 }
Johannes Berg319090b2014-11-17 14:08:11 +01003853 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003854 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3855 sizeof(struct nl80211_sta_flag_update),
3856 &sinfo->sta_flags))
3857 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003858
Johannes Bergd686b922016-04-26 09:54:11 +02003859 PUT_SINFO_U64(T_OFFSET, t_offset);
3860 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
3861 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01003862 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003863
3864#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02003865#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003866
3867 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3868 struct nlattr *tidsattr;
3869 int tid;
3870
3871 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3872 if (!tidsattr)
3873 goto nla_put_failure;
3874
3875 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3876 struct cfg80211_tid_stats *tidstats;
3877 struct nlattr *tidattr;
3878
3879 tidstats = &sinfo->pertid[tid];
3880
3881 if (!tidstats->filled)
3882 continue;
3883
3884 tidattr = nla_nest_start(msg, tid + 1);
3885 if (!tidattr)
3886 goto nla_put_failure;
3887
Johannes Bergd686b922016-04-26 09:54:11 +02003888#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01003889 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02003890 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3891 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01003892 goto nla_put_failure; \
3893 } while (0)
3894
Johannes Bergd686b922016-04-26 09:54:11 +02003895 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
3896 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
3897 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
3898 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01003899
Johannes Bergd686b922016-04-26 09:54:11 +02003900#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01003901 nla_nest_end(msg, tidattr);
3902 }
3903
3904 nla_nest_end(msg, tidsattr);
3905 }
3906
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003907 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003908
Johannes Berg319090b2014-11-17 14:08:11 +01003909 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003910 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3911 sinfo->assoc_req_ies))
3912 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003913
Johannes Berg053c0952015-01-16 22:09:00 +01003914 genlmsg_end(msg, hdr);
3915 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003916
3917 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003918 genlmsg_cancel(msg, hdr);
3919 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003920}
3921
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003922static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003923 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003924{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003925 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003926 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003927 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003928 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003929 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003930 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003931
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003932 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003933 if (err)
3934 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003935
Johannes Berg97990a02013-04-19 01:02:55 +02003936 if (!wdev->netdev) {
3937 err = -EINVAL;
3938 goto out_err;
3939 }
3940
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003941 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003942 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003943 goto out_err;
3944 }
3945
Johannes Bergbba95fe2008-07-29 13:22:51 +02003946 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003947 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003948 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003949 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003950 if (err == -ENOENT)
3951 break;
3952 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003953 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003954
Johannes Bergcf5ead82014-11-14 17:14:00 +01003955 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003956 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003957 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003958 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003959 &sinfo) < 0)
3960 goto out;
3961
3962 sta_idx++;
3963 }
3964
3965
3966 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003967 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003968 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003969 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003970 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003971
3972 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003973}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003974
Johannes Berg5727ef12007-12-19 02:03:34 +01003975static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3976{
Johannes Berg4c476992010-10-04 21:36:35 +02003977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3978 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003979 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003980 struct sk_buff *msg;
3981 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003982 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003983
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003984 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003985
3986 if (!info->attrs[NL80211_ATTR_MAC])
3987 return -EINVAL;
3988
3989 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3990
Johannes Berg4c476992010-10-04 21:36:35 +02003991 if (!rdev->ops->get_station)
3992 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003993
Hila Gonene35e4d22012-06-27 17:19:42 +03003994 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003995 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003996 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003997
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003999 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004000 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004001
Johannes Bergcf5ead82014-11-14 17:14:00 +01004002 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4003 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004004 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004005 nlmsg_free(msg);
4006 return -ENOBUFS;
4007 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004008
Johannes Berg4c476992010-10-04 21:36:35 +02004009 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004010}
4011
Johannes Berg77ee7c82013-02-15 00:48:33 +01004012int cfg80211_check_station_change(struct wiphy *wiphy,
4013 struct station_parameters *params,
4014 enum cfg80211_station_type statype)
4015{
Ayala Bekere4208422015-10-23 11:20:06 +03004016 if (params->listen_interval != -1 &&
4017 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004018 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004019
Ayala Beker17b94242016-03-17 15:41:38 +02004020 if (params->support_p2p_ps != -1 &&
4021 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4022 return -EINVAL;
4023
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004024 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004025 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4026 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004027 return -EINVAL;
4028
4029 /* When you run into this, adjust the code below for the new flag */
4030 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4031
4032 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004033 case CFG80211_STA_MESH_PEER_KERNEL:
4034 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004035 /*
4036 * No ignoring the TDLS flag here -- the userspace mesh
4037 * code doesn't have the bug of including TDLS in the
4038 * mask everywhere.
4039 */
4040 if (params->sta_flags_mask &
4041 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4042 BIT(NL80211_STA_FLAG_MFP) |
4043 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4044 return -EINVAL;
4045 break;
4046 case CFG80211_STA_TDLS_PEER_SETUP:
4047 case CFG80211_STA_TDLS_PEER_ACTIVE:
4048 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4049 return -EINVAL;
4050 /* ignore since it can't change */
4051 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4052 break;
4053 default:
4054 /* disallow mesh-specific things */
4055 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4056 return -EINVAL;
4057 if (params->local_pm)
4058 return -EINVAL;
4059 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4060 return -EINVAL;
4061 }
4062
4063 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4064 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4065 /* TDLS can't be set, ... */
4066 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4067 return -EINVAL;
4068 /*
4069 * ... but don't bother the driver with it. This works around
4070 * a hostapd/wpa_supplicant issue -- it always includes the
4071 * TLDS_PEER flag in the mask even for AP mode.
4072 */
4073 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4074 }
4075
Ayala Beker47edb112015-09-21 15:49:53 +03004076 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4077 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004078 /* reject other things that can't change */
4079 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4080 return -EINVAL;
4081 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4082 return -EINVAL;
4083 if (params->supported_rates)
4084 return -EINVAL;
4085 if (params->ext_capab || params->ht_capa || params->vht_capa)
4086 return -EINVAL;
4087 }
4088
Ayala Beker47edb112015-09-21 15:49:53 +03004089 if (statype != CFG80211_STA_AP_CLIENT &&
4090 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004091 if (params->vlan)
4092 return -EINVAL;
4093 }
4094
4095 switch (statype) {
4096 case CFG80211_STA_AP_MLME_CLIENT:
4097 /* Use this only for authorizing/unauthorizing a station */
4098 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4099 return -EOPNOTSUPP;
4100 break;
4101 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004102 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004103 /* accept only the listed bits */
4104 if (params->sta_flags_mask &
4105 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4106 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4107 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4108 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4109 BIT(NL80211_STA_FLAG_WME) |
4110 BIT(NL80211_STA_FLAG_MFP)))
4111 return -EINVAL;
4112
4113 /* but authenticated/associated only if driver handles it */
4114 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4115 params->sta_flags_mask &
4116 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4117 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4118 return -EINVAL;
4119 break;
4120 case CFG80211_STA_IBSS:
4121 case CFG80211_STA_AP_STA:
4122 /* reject any changes other than AUTHORIZED */
4123 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4124 return -EINVAL;
4125 break;
4126 case CFG80211_STA_TDLS_PEER_SETUP:
4127 /* reject any changes other than AUTHORIZED or WME */
4128 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4129 BIT(NL80211_STA_FLAG_WME)))
4130 return -EINVAL;
4131 /* force (at least) rates when authorizing */
4132 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4133 !params->supported_rates)
4134 return -EINVAL;
4135 break;
4136 case CFG80211_STA_TDLS_PEER_ACTIVE:
4137 /* reject any changes */
4138 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004139 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004140 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4141 return -EINVAL;
4142 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004143 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004144 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4145 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004146 return -EINVAL;
4147 break;
4148 }
4149
4150 return 0;
4151}
4152EXPORT_SYMBOL(cfg80211_check_station_change);
4153
Johannes Berg5727ef12007-12-19 02:03:34 +01004154/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004155 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004156 */
Johannes Berg80b99892011-11-18 16:23:01 +01004157static struct net_device *get_vlan(struct genl_info *info,
4158 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004159{
Johannes Berg463d0182009-07-14 00:33:35 +02004160 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004161 struct net_device *v;
4162 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004163
Johannes Berg80b99892011-11-18 16:23:01 +01004164 if (!vlanattr)
4165 return NULL;
4166
4167 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4168 if (!v)
4169 return ERR_PTR(-ENODEV);
4170
4171 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4172 ret = -EINVAL;
4173 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004174 }
Johannes Berg80b99892011-11-18 16:23:01 +01004175
Johannes Berg77ee7c82013-02-15 00:48:33 +01004176 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4177 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4178 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4179 ret = -EINVAL;
4180 goto error;
4181 }
4182
Johannes Berg80b99892011-11-18 16:23:01 +01004183 if (!netif_running(v)) {
4184 ret = -ENETDOWN;
4185 goto error;
4186 }
4187
4188 return v;
4189 error:
4190 dev_put(v);
4191 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004192}
4193
Johannes Berg94e860f2014-01-20 23:58:15 +01004194static const struct nla_policy
4195nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004196 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4197 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4198};
4199
Johannes Bergff276692013-02-15 00:09:01 +01004200static int nl80211_parse_sta_wme(struct genl_info *info,
4201 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004202{
Jouni Malinendf881292013-02-14 21:10:54 +02004203 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4204 struct nlattr *nla;
4205 int err;
4206
Jouni Malinendf881292013-02-14 21:10:54 +02004207 /* parse WME attributes if present */
4208 if (!info->attrs[NL80211_ATTR_STA_WME])
4209 return 0;
4210
4211 nla = info->attrs[NL80211_ATTR_STA_WME];
4212 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4213 nl80211_sta_wme_policy);
4214 if (err)
4215 return err;
4216
4217 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4218 params->uapsd_queues = nla_get_u8(
4219 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4220 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4221 return -EINVAL;
4222
4223 if (tb[NL80211_STA_WME_MAX_SP])
4224 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4225
4226 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4227 return -EINVAL;
4228
4229 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4230
4231 return 0;
4232}
4233
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304234static int nl80211_parse_sta_channel_info(struct genl_info *info,
4235 struct station_parameters *params)
4236{
4237 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4238 params->supported_channels =
4239 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4240 params->supported_channels_len =
4241 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4242 /*
4243 * Need to include at least one (first channel, number of
4244 * channels) tuple for each subband, and must have proper
4245 * tuples for the rest of the data as well.
4246 */
4247 if (params->supported_channels_len < 2)
4248 return -EINVAL;
4249 if (params->supported_channels_len % 2)
4250 return -EINVAL;
4251 }
4252
4253 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4254 params->supported_oper_classes =
4255 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4256 params->supported_oper_classes_len =
4257 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4258 /*
4259 * The value of the Length field of the Supported Operating
4260 * Classes element is between 2 and 253.
4261 */
4262 if (params->supported_oper_classes_len < 2 ||
4263 params->supported_oper_classes_len > 253)
4264 return -EINVAL;
4265 }
4266 return 0;
4267}
4268
Johannes Bergff276692013-02-15 00:09:01 +01004269static int nl80211_set_station_tdls(struct genl_info *info,
4270 struct station_parameters *params)
4271{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304272 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004273 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004274 if (info->attrs[NL80211_ATTR_PEER_AID])
4275 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004276 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4277 params->ht_capa =
4278 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4279 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4280 params->vht_capa =
4281 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4282
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304283 err = nl80211_parse_sta_channel_info(info, params);
4284 if (err)
4285 return err;
4286
Johannes Bergff276692013-02-15 00:09:01 +01004287 return nl80211_parse_sta_wme(info, params);
4288}
4289
Johannes Berg5727ef12007-12-19 02:03:34 +01004290static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4291{
Johannes Berg4c476992010-10-04 21:36:35 +02004292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004293 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004294 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004295 u8 *mac_addr;
4296 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004297
4298 memset(&params, 0, sizeof(params));
4299
Johannes Berg77ee7c82013-02-15 00:48:33 +01004300 if (!rdev->ops->change_station)
4301 return -EOPNOTSUPP;
4302
Ayala Bekere4208422015-10-23 11:20:06 +03004303 /*
4304 * AID and listen_interval properties can be set only for unassociated
4305 * station. Include these parameters here and will check them in
4306 * cfg80211_check_station_change().
4307 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004308 if (info->attrs[NL80211_ATTR_STA_AID])
4309 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004310
4311 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4312 params.listen_interval =
4313 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4314 else
4315 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004316
Ayala Beker17b94242016-03-17 15:41:38 +02004317 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4318 u8 tmp;
4319
4320 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4321 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4322 return -EINVAL;
4323
4324 params.support_p2p_ps = tmp;
4325 } else {
4326 params.support_p2p_ps = -1;
4327 }
4328
Johannes Berg5727ef12007-12-19 02:03:34 +01004329 if (!info->attrs[NL80211_ATTR_MAC])
4330 return -EINVAL;
4331
4332 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4333
4334 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4335 params.supported_rates =
4336 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4337 params.supported_rates_len =
4338 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4339 }
4340
Jouni Malinen9d62a982013-02-14 21:10:13 +02004341 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4342 params.capability =
4343 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4344 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4345 }
4346
4347 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4348 params.ext_capab =
4349 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4350 params.ext_capab_len =
4351 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4352 }
4353
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004354 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004355 return -EINVAL;
4356
Johannes Bergf8bacc22013-02-14 23:27:01 +01004357 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004359 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4360 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4361 return -EINVAL;
4362 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004363
Johannes Bergf8bacc22013-02-14 23:27:01 +01004364 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004365 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004366 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4367 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4368 return -EINVAL;
4369 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4370 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004371
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004372 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4373 enum nl80211_mesh_power_mode pm = nla_get_u32(
4374 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4375
4376 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4377 pm > NL80211_MESH_POWER_MAX)
4378 return -EINVAL;
4379
4380 params.local_pm = pm;
4381 }
4382
Johannes Berg77ee7c82013-02-15 00:48:33 +01004383 /* Include parameters for TDLS peer (will check later) */
4384 err = nl80211_set_station_tdls(info, &params);
4385 if (err)
4386 return err;
4387
4388 params.vlan = get_vlan(info, rdev);
4389 if (IS_ERR(params.vlan))
4390 return PTR_ERR(params.vlan);
4391
Johannes Berga97f4422009-06-18 17:23:43 +02004392 switch (dev->ieee80211_ptr->iftype) {
4393 case NL80211_IFTYPE_AP:
4394 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004395 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004396 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004397 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004398 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004399 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004400 break;
4401 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004402 err = -EOPNOTSUPP;
4403 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004404 }
4405
Johannes Berg77ee7c82013-02-15 00:48:33 +01004406 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004407 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004408
Johannes Berg77ee7c82013-02-15 00:48:33 +01004409 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004410 if (params.vlan)
4411 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004412
Johannes Berg5727ef12007-12-19 02:03:34 +01004413 return err;
4414}
4415
4416static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4417{
Johannes Berg4c476992010-10-04 21:36:35 +02004418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004419 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004420 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004421 struct station_parameters params;
4422 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004423 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4424 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004425
4426 memset(&params, 0, sizeof(params));
4427
Johannes Berg984c3112013-02-14 23:43:25 +01004428 if (!rdev->ops->add_station)
4429 return -EOPNOTSUPP;
4430
Johannes Berg5727ef12007-12-19 02:03:34 +01004431 if (!info->attrs[NL80211_ATTR_MAC])
4432 return -EINVAL;
4433
Johannes Berg5727ef12007-12-19 02:03:34 +01004434 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4435 return -EINVAL;
4436
4437 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4438 return -EINVAL;
4439
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004440 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4441 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004442 return -EINVAL;
4443
Johannes Berg5727ef12007-12-19 02:03:34 +01004444 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4445 params.supported_rates =
4446 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4447 params.supported_rates_len =
4448 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4449 params.listen_interval =
4450 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004451
Ayala Beker17b94242016-03-17 15:41:38 +02004452 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4453 u8 tmp;
4454
4455 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4456 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4457 return -EINVAL;
4458
4459 params.support_p2p_ps = tmp;
4460 } else {
4461 /*
4462 * if not specified, assume it's supported for P2P GO interface,
4463 * and is NOT supported for AP interface
4464 */
4465 params.support_p2p_ps =
4466 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4467 }
4468
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004469 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004470 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004471 else
4472 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004473 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4474 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004475
Jouni Malinen9d62a982013-02-14 21:10:13 +02004476 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4477 params.capability =
4478 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4479 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4480 }
4481
4482 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4483 params.ext_capab =
4484 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4485 params.ext_capab_len =
4486 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4487 }
4488
Jouni Malinen36aedc902008-08-25 11:58:58 +03004489 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4490 params.ht_capa =
4491 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004492
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004493 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4494 params.vht_capa =
4495 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4496
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004497 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4498 params.opmode_notif_used = true;
4499 params.opmode_notif =
4500 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4501 }
4502
Johannes Bergf8bacc22013-02-14 23:27:01 +01004503 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004504 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004505 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4506 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4507 return -EINVAL;
4508 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004509
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304510 err = nl80211_parse_sta_channel_info(info, &params);
4511 if (err)
4512 return err;
4513
Johannes Bergff276692013-02-15 00:09:01 +01004514 err = nl80211_parse_sta_wme(info, &params);
4515 if (err)
4516 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004517
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004518 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004519 return -EINVAL;
4520
Johannes Berg496fcc22015-03-12 08:53:27 +02004521 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4522 * as userspace might just pass through the capabilities from the IEs
4523 * directly, rather than enforcing this restriction and returning an
4524 * error in this case.
4525 */
4526 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4527 params.ht_capa = NULL;
4528 params.vht_capa = NULL;
4529 }
4530
Johannes Berg77ee7c82013-02-15 00:48:33 +01004531 /* When you run into this, adjust the code below for the new flag */
4532 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4533
Johannes Bergbdd90d52011-12-14 12:20:27 +01004534 switch (dev->ieee80211_ptr->iftype) {
4535 case NL80211_IFTYPE_AP:
4536 case NL80211_IFTYPE_AP_VLAN:
4537 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004538 /* ignore WME attributes if iface/sta is not capable */
4539 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4540 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4541 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004542
Johannes Bergbdd90d52011-12-14 12:20:27 +01004543 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004544 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4545 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004546 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004547 /* but don't bother the driver with it */
4548 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004549
Johannes Bergd582cff2012-10-26 17:53:44 +02004550 /* allow authenticated/associated only if driver handles it */
4551 if (!(rdev->wiphy.features &
4552 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004553 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004554 return -EINVAL;
4555
Johannes Bergbda95eb2015-11-26 16:26:13 +01004556 /* Older userspace, or userspace wanting to be compatible with
4557 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4558 * and assoc flags in the mask, but assumes the station will be
4559 * added as associated anyway since this was the required driver
4560 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4561 * introduced.
4562 * In order to not bother drivers with this quirk in the API
4563 * set the flags in both the mask and set for new stations in
4564 * this case.
4565 */
4566 if (!(params.sta_flags_mask & auth_assoc)) {
4567 params.sta_flags_mask |= auth_assoc;
4568 params.sta_flags_set |= auth_assoc;
4569 }
4570
Johannes Bergbdd90d52011-12-14 12:20:27 +01004571 /* must be last in here for error handling */
4572 params.vlan = get_vlan(info, rdev);
4573 if (IS_ERR(params.vlan))
4574 return PTR_ERR(params.vlan);
4575 break;
4576 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004577 /* ignore uAPSD data */
4578 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4579
Johannes Bergd582cff2012-10-26 17:53:44 +02004580 /* associated is disallowed */
4581 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4582 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004583 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004584 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4585 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004586 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004587 break;
4588 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004589 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004590 /* ignore uAPSD data */
4591 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4592
Johannes Berg77ee7c82013-02-15 00:48:33 +01004593 /* these are disallowed */
4594 if (params.sta_flags_mask &
4595 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4596 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004597 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004598 /* Only TDLS peers can be added */
4599 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4600 return -EINVAL;
4601 /* Can only add if TDLS ... */
4602 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4603 return -EOPNOTSUPP;
4604 /* ... with external setup is supported */
4605 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4606 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004607 /*
4608 * Older wpa_supplicant versions always mark the TDLS peer
4609 * as authorized, but it shouldn't yet be.
4610 */
4611 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004612 break;
4613 default:
4614 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004615 }
4616
Johannes Bergbdd90d52011-12-14 12:20:27 +01004617 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004618
Hila Gonene35e4d22012-06-27 17:19:42 +03004619 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004620
Johannes Berg5727ef12007-12-19 02:03:34 +01004621 if (params.vlan)
4622 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004623 return err;
4624}
4625
4626static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4627{
Johannes Berg4c476992010-10-04 21:36:35 +02004628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4629 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004630 struct station_del_parameters params;
4631
4632 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004633
4634 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004635 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004636
Johannes Berge80cf852009-05-11 14:43:13 +02004637 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004638 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004639 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004640 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4641 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004642
Johannes Berg4c476992010-10-04 21:36:35 +02004643 if (!rdev->ops->del_station)
4644 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004645
Jouni Malinen98856862014-10-20 13:20:45 +03004646 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4647 params.subtype =
4648 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4649 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4650 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4651 return -EINVAL;
4652 } else {
4653 /* Default to Deauthentication frame */
4654 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4655 }
4656
4657 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4658 params.reason_code =
4659 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4660 if (params.reason_code == 0)
4661 return -EINVAL; /* 0 is reserved */
4662 } else {
4663 /* Default to reason code 2 */
4664 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4665 }
4666
Jouni Malinen89c771e2014-10-10 20:52:40 +03004667 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004668}
4669
Eric W. Biederman15e47302012-09-07 20:12:54 +00004670static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671 int flags, struct net_device *dev,
4672 u8 *dst, u8 *next_hop,
4673 struct mpath_info *pinfo)
4674{
4675 void *hdr;
4676 struct nlattr *pinfoattr;
4677
Henning Rogge1ef4c852014-11-04 16:14:58 +01004678 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004679 if (!hdr)
4680 return -1;
4681
David S. Miller9360ffd2012-03-29 04:41:26 -04004682 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4683 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4684 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4685 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4686 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004687
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004688 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4689 if (!pinfoattr)
4690 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004691 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4692 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4693 pinfo->frame_qlen))
4694 goto nla_put_failure;
4695 if (((pinfo->filled & MPATH_INFO_SN) &&
4696 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4697 ((pinfo->filled & MPATH_INFO_METRIC) &&
4698 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4699 pinfo->metric)) ||
4700 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4701 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4702 pinfo->exptime)) ||
4703 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4704 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4705 pinfo->flags)) ||
4706 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4707 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4708 pinfo->discovery_timeout)) ||
4709 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4710 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4711 pinfo->discovery_retries)))
4712 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004713
4714 nla_nest_end(msg, pinfoattr);
4715
Johannes Berg053c0952015-01-16 22:09:00 +01004716 genlmsg_end(msg, hdr);
4717 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004718
4719 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004720 genlmsg_cancel(msg, hdr);
4721 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004722}
4723
4724static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004725 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004727 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004728 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004729 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004730 u8 dst[ETH_ALEN];
4731 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004732 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004733 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004734
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004735 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004736 if (err)
4737 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004738
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004739 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004740 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004741 goto out_err;
4742 }
4743
Johannes Berg97990a02013-04-19 01:02:55 +02004744 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004745 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004746 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004747 }
4748
Johannes Bergbba95fe2008-07-29 13:22:51 +02004749 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004750 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004751 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004752 if (err == -ENOENT)
4753 break;
4754 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004755 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004756
Eric W. Biederman15e47302012-09-07 20:12:54 +00004757 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004758 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004759 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004760 &pinfo) < 0)
4761 goto out;
4762
4763 path_idx++;
4764 }
4765
4766
4767 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004768 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004769 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004770 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004771 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004772 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004773}
4774
4775static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4776{
Johannes Berg4c476992010-10-04 21:36:35 +02004777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004778 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004779 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004780 struct mpath_info pinfo;
4781 struct sk_buff *msg;
4782 u8 *dst = NULL;
4783 u8 next_hop[ETH_ALEN];
4784
4785 memset(&pinfo, 0, sizeof(pinfo));
4786
4787 if (!info->attrs[NL80211_ATTR_MAC])
4788 return -EINVAL;
4789
4790 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4791
Johannes Berg4c476992010-10-04 21:36:35 +02004792 if (!rdev->ops->get_mpath)
4793 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004794
Johannes Berg4c476992010-10-04 21:36:35 +02004795 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4796 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004797
Hila Gonene35e4d22012-06-27 17:19:42 +03004798 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004799 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004800 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004801
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004802 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004803 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004804 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004805
Eric W. Biederman15e47302012-09-07 20:12:54 +00004806 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004807 dev, dst, next_hop, &pinfo) < 0) {
4808 nlmsg_free(msg);
4809 return -ENOBUFS;
4810 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004811
Johannes Berg4c476992010-10-04 21:36:35 +02004812 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004813}
4814
4815static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4816{
Johannes Berg4c476992010-10-04 21:36:35 +02004817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4818 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004819 u8 *dst = NULL;
4820 u8 *next_hop = NULL;
4821
4822 if (!info->attrs[NL80211_ATTR_MAC])
4823 return -EINVAL;
4824
4825 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4826 return -EINVAL;
4827
4828 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4829 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4830
Johannes Berg4c476992010-10-04 21:36:35 +02004831 if (!rdev->ops->change_mpath)
4832 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004833
Johannes Berg4c476992010-10-04 21:36:35 +02004834 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4835 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004836
Hila Gonene35e4d22012-06-27 17:19:42 +03004837 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004838}
Johannes Berg4c476992010-10-04 21:36:35 +02004839
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004840static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4841{
Johannes Berg4c476992010-10-04 21:36:35 +02004842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4843 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004844 u8 *dst = NULL;
4845 u8 *next_hop = NULL;
4846
4847 if (!info->attrs[NL80211_ATTR_MAC])
4848 return -EINVAL;
4849
4850 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4851 return -EINVAL;
4852
4853 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4854 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4855
Johannes Berg4c476992010-10-04 21:36:35 +02004856 if (!rdev->ops->add_mpath)
4857 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004858
Johannes Berg4c476992010-10-04 21:36:35 +02004859 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4860 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004861
Hila Gonene35e4d22012-06-27 17:19:42 +03004862 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004863}
4864
4865static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4866{
Johannes Berg4c476992010-10-04 21:36:35 +02004867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4868 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004869 u8 *dst = NULL;
4870
4871 if (info->attrs[NL80211_ATTR_MAC])
4872 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4873
Johannes Berg4c476992010-10-04 21:36:35 +02004874 if (!rdev->ops->del_mpath)
4875 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004876
Hila Gonene35e4d22012-06-27 17:19:42 +03004877 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004878}
4879
Henning Rogge66be7d22014-09-12 08:58:49 +02004880static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4881{
4882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4883 int err;
4884 struct net_device *dev = info->user_ptr[1];
4885 struct mpath_info pinfo;
4886 struct sk_buff *msg;
4887 u8 *dst = NULL;
4888 u8 mpp[ETH_ALEN];
4889
4890 memset(&pinfo, 0, sizeof(pinfo));
4891
4892 if (!info->attrs[NL80211_ATTR_MAC])
4893 return -EINVAL;
4894
4895 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4896
4897 if (!rdev->ops->get_mpp)
4898 return -EOPNOTSUPP;
4899
4900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4901 return -EOPNOTSUPP;
4902
4903 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4904 if (err)
4905 return err;
4906
4907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4908 if (!msg)
4909 return -ENOMEM;
4910
4911 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4912 dev, dst, mpp, &pinfo) < 0) {
4913 nlmsg_free(msg);
4914 return -ENOBUFS;
4915 }
4916
4917 return genlmsg_reply(msg, info);
4918}
4919
4920static int nl80211_dump_mpp(struct sk_buff *skb,
4921 struct netlink_callback *cb)
4922{
4923 struct mpath_info pinfo;
4924 struct cfg80211_registered_device *rdev;
4925 struct wireless_dev *wdev;
4926 u8 dst[ETH_ALEN];
4927 u8 mpp[ETH_ALEN];
4928 int path_idx = cb->args[2];
4929 int err;
4930
4931 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4932 if (err)
4933 return err;
4934
4935 if (!rdev->ops->dump_mpp) {
4936 err = -EOPNOTSUPP;
4937 goto out_err;
4938 }
4939
4940 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4941 err = -EOPNOTSUPP;
4942 goto out_err;
4943 }
4944
4945 while (1) {
4946 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4947 mpp, &pinfo);
4948 if (err == -ENOENT)
4949 break;
4950 if (err)
4951 goto out_err;
4952
4953 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4954 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4955 wdev->netdev, dst, mpp,
4956 &pinfo) < 0)
4957 goto out;
4958
4959 path_idx++;
4960 }
4961
4962 out:
4963 cb->args[2] = path_idx;
4964 err = skb->len;
4965 out_err:
4966 nl80211_finish_wdev_dump(rdev);
4967 return err;
4968}
4969
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004970static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4971{
Johannes Berg4c476992010-10-04 21:36:35 +02004972 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4973 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004974 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004975 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004976 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004977
4978 memset(&params, 0, sizeof(params));
4979 /* default to not changing parameters */
4980 params.use_cts_prot = -1;
4981 params.use_short_preamble = -1;
4982 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004983 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004984 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004985 params.p2p_ctwindow = -1;
4986 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004987
4988 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4989 params.use_cts_prot =
4990 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4991 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4992 params.use_short_preamble =
4993 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4994 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4995 params.use_short_slot_time =
4996 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004997 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4998 params.basic_rates =
4999 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5000 params.basic_rates_len =
5001 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5002 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005003 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5004 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005005 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5006 params.ht_opmode =
5007 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005008
Johannes Berg53cabad2012-11-14 15:17:28 +01005009 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5010 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5011 return -EINVAL;
5012 params.p2p_ctwindow =
5013 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5014 if (params.p2p_ctwindow < 0)
5015 return -EINVAL;
5016 if (params.p2p_ctwindow != 0 &&
5017 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5018 return -EINVAL;
5019 }
5020
5021 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5022 u8 tmp;
5023
5024 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5025 return -EINVAL;
5026 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5027 if (tmp > 1)
5028 return -EINVAL;
5029 params.p2p_opp_ps = tmp;
5030 if (params.p2p_opp_ps &&
5031 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5032 return -EINVAL;
5033 }
5034
Johannes Berg4c476992010-10-04 21:36:35 +02005035 if (!rdev->ops->change_bss)
5036 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005037
Johannes Berg074ac8d2010-09-16 14:58:22 +02005038 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005039 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5040 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005041
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005042 wdev_lock(wdev);
5043 err = rdev_change_bss(rdev, dev, &params);
5044 wdev_unlock(wdev);
5045
5046 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005047}
5048
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5050{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005051 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005052 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005053 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005054 u32 owner_nlportid;
5055
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005056
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005057 /*
5058 * You should only get this when cfg80211 hasn't yet initialized
5059 * completely when built-in to the kernel right between the time
5060 * window between nl80211_init() and regulatory_init(), if that is
5061 * even possible.
5062 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005063 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005064 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005065
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005066 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5067 user_reg_hint_type =
5068 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5069 else
5070 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5071
5072 switch (user_reg_hint_type) {
5073 case NL80211_USER_REG_HINT_USER:
5074 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005075 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5076 return -EINVAL;
5077
5078 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5079 return regulatory_hint_user(data, user_reg_hint_type);
5080 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005081 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5082 owner_nlportid = info->snd_portid;
5083 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5084 } else {
5085 owner_nlportid = 0;
5086 is_indoor = true;
5087 }
5088
5089 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005090 default:
5091 return -EINVAL;
5092 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005093}
5094
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005095static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005096 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005097{
Johannes Berg4c476992010-10-04 21:36:35 +02005098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005099 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005100 struct wireless_dev *wdev = dev->ieee80211_ptr;
5101 struct mesh_config cur_params;
5102 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005103 void *hdr;
5104 struct nlattr *pinfoattr;
5105 struct sk_buff *msg;
5106
Johannes Berg29cbe682010-12-03 09:20:44 +01005107 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5108 return -EOPNOTSUPP;
5109
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005110 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005111 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005112
Johannes Berg29cbe682010-12-03 09:20:44 +01005113 wdev_lock(wdev);
5114 /* If not connected, get default parameters */
5115 if (!wdev->mesh_id_len)
5116 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5117 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005118 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005119 wdev_unlock(wdev);
5120
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005121 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005122 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123
5124 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005125 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005126 if (!msg)
5127 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005128 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005129 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005130 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005131 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005132 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005133 if (!pinfoattr)
5134 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005135 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5136 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5137 cur_params.dot11MeshRetryTimeout) ||
5138 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5139 cur_params.dot11MeshConfirmTimeout) ||
5140 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5141 cur_params.dot11MeshHoldingTimeout) ||
5142 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5143 cur_params.dot11MeshMaxPeerLinks) ||
5144 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5145 cur_params.dot11MeshMaxRetries) ||
5146 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5147 cur_params.dot11MeshTTL) ||
5148 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5149 cur_params.element_ttl) ||
5150 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5151 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005152 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5153 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005154 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5155 cur_params.dot11MeshHWMPmaxPREQretries) ||
5156 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5157 cur_params.path_refresh_time) ||
5158 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5159 cur_params.min_discovery_timeout) ||
5160 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5161 cur_params.dot11MeshHWMPactivePathTimeout) ||
5162 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5163 cur_params.dot11MeshHWMPpreqMinInterval) ||
5164 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5165 cur_params.dot11MeshHWMPperrMinInterval) ||
5166 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5167 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5168 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5169 cur_params.dot11MeshHWMPRootMode) ||
5170 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5171 cur_params.dot11MeshHWMPRannInterval) ||
5172 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5173 cur_params.dot11MeshGateAnnouncementProtocol) ||
5174 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5175 cur_params.dot11MeshForwarding) ||
5176 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005177 cur_params.rssi_threshold) ||
5178 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005179 cur_params.ht_opmode) ||
5180 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5181 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5182 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005183 cur_params.dot11MeshHWMProotInterval) ||
5184 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005185 cur_params.dot11MeshHWMPconfirmationInterval) ||
5186 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5187 cur_params.power_mode) ||
5188 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005189 cur_params.dot11MeshAwakeWindowDuration) ||
5190 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5191 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005192 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005193 nla_nest_end(msg, pinfoattr);
5194 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005195 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005196
Johannes Berg3b858752009-03-12 09:55:09 +01005197 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005198 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005199 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005200 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005201 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005202}
5203
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005204static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005205 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5206 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5207 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5208 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5209 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5210 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005211 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005212 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005213 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005214 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5215 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5216 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5217 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5218 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005219 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005220 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005221 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005222 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005223 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005224 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005225 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5226 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005227 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5228 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005229 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005230 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5231 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005232 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005233};
5234
Javier Cardonac80d5452010-12-16 17:37:49 -08005235static const struct nla_policy
5236 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005237 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005238 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5239 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005240 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005241 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005242 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005243 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005244 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005245 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005246};
5247
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005248static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005249 struct mesh_config *cfg,
5250 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005251{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005252 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005253 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005254
Marco Porschea54fba2013-01-07 16:04:48 +01005255#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5256do { \
5257 if (tb[attr]) { \
5258 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5259 return -EINVAL; \
5260 cfg->param = fn(tb[attr]); \
5261 mask |= (1 << (attr - 1)); \
5262 } \
5263} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005264
5265
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005266 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005267 return -EINVAL;
5268 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005269 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005270 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005271 return -EINVAL;
5272
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005273 /* This makes sure that there aren't more than 32 mesh config
5274 * parameters (otherwise our bitfield scheme would not work.) */
5275 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5276
5277 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005278 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005279 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5280 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005282 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5283 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005285 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5286 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005287 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005288 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5289 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005290 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005291 mask, NL80211_MESHCONF_MAX_RETRIES,
5292 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005293 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005294 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005295 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005296 mask, NL80211_MESHCONF_ELEMENT_TTL,
5297 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005298 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005299 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5300 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005301 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5302 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005303 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5304 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005306 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5307 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005309 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5310 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005311 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005312 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5313 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005314 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5315 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005316 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5317 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005318 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005319 1, 65535, mask,
5320 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005321 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005323 1, 65535, mask,
5324 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005325 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005326 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005327 dot11MeshHWMPnetDiameterTraversalTime,
5328 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005329 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5330 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005331 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5332 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5333 nla_get_u8);
5334 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5335 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005336 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005337 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005338 dot11MeshGateAnnouncementProtocol, 0, 1,
5339 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005340 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005341 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005342 mask, NL80211_MESHCONF_FORWARDING,
5343 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005344 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005345 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005346 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005348 mask, NL80211_MESHCONF_HT_OPMODE,
5349 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005350 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005351 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005352 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5353 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005354 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005355 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5356 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005358 dot11MeshHWMPconfirmationInterval,
5359 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005360 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5361 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005362 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5363 NL80211_MESH_POWER_ACTIVE,
5364 NL80211_MESH_POWER_MAX,
5365 mask, NL80211_MESHCONF_POWER_MODE,
5366 nla_get_u32);
5367 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5368 0, 65535, mask,
5369 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005370 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005371 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5372 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005373 if (mask_out)
5374 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005375
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005376 return 0;
5377
5378#undef FILL_IN_MESH_PARAM_IF_SET
5379}
5380
Javier Cardonac80d5452010-12-16 17:37:49 -08005381static int nl80211_parse_mesh_setup(struct genl_info *info,
5382 struct mesh_setup *setup)
5383{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005385 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5386
5387 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5388 return -EINVAL;
5389 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5390 info->attrs[NL80211_ATTR_MESH_SETUP],
5391 nl80211_mesh_setup_params_policy))
5392 return -EINVAL;
5393
Javier Cardonad299a1f2012-03-31 11:31:33 -07005394 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5395 setup->sync_method =
5396 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5397 IEEE80211_SYNC_METHOD_VENDOR :
5398 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5399
Javier Cardonac80d5452010-12-16 17:37:49 -08005400 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5401 setup->path_sel_proto =
5402 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5403 IEEE80211_PATH_PROTOCOL_VENDOR :
5404 IEEE80211_PATH_PROTOCOL_HWMP;
5405
5406 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5407 setup->path_metric =
5408 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5409 IEEE80211_PATH_METRIC_VENDOR :
5410 IEEE80211_PATH_METRIC_AIRTIME;
5411
Javier Cardona581a8b02011-04-07 15:08:27 -07005412
5413 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005414 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005415 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005416 if (!is_valid_ie_attr(ieattr))
5417 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005418 setup->ie = nla_data(ieattr);
5419 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005420 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005421 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5422 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5423 return -EINVAL;
5424 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005425 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5426 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005427 if (setup->is_secure)
5428 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005429
Colleen Twitty6e16d902013-05-08 11:45:59 -07005430 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5431 if (!setup->user_mpm)
5432 return -EINVAL;
5433 setup->auth_id =
5434 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5435 }
5436
Javier Cardonac80d5452010-12-16 17:37:49 -08005437 return 0;
5438}
5439
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005440static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005441 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005442{
5443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5444 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005445 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005446 struct mesh_config cfg;
5447 u32 mask;
5448 int err;
5449
Johannes Berg29cbe682010-12-03 09:20:44 +01005450 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5451 return -EOPNOTSUPP;
5452
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005453 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005454 return -EOPNOTSUPP;
5455
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005456 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005457 if (err)
5458 return err;
5459
Johannes Berg29cbe682010-12-03 09:20:44 +01005460 wdev_lock(wdev);
5461 if (!wdev->mesh_id_len)
5462 err = -ENOLINK;
5463
5464 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005465 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005466
5467 wdev_unlock(wdev);
5468
5469 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005470}
5471
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005472static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5473 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005474{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005475 struct nlattr *nl_reg_rules;
5476 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005477
Johannes Berg458f4f92012-12-06 15:47:38 +01005478 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5479 (regdom->dfs_region &&
5480 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005481 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005482
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005483 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5484 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005485 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005486
Johannes Berg458f4f92012-12-06 15:47:38 +01005487 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005488 struct nlattr *nl_reg_rule;
5489 const struct ieee80211_reg_rule *reg_rule;
5490 const struct ieee80211_freq_range *freq_range;
5491 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005492 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005493
Johannes Berg458f4f92012-12-06 15:47:38 +01005494 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005495 freq_range = &reg_rule->freq_range;
5496 power_rule = &reg_rule->power_rule;
5497
5498 nl_reg_rule = nla_nest_start(msg, i);
5499 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005500 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005501
Janusz Dziedzic97524822014-01-30 09:52:20 +01005502 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5503 if (!max_bandwidth_khz)
5504 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5505 reg_rule);
5506
David S. Miller9360ffd2012-03-29 04:41:26 -04005507 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5508 reg_rule->flags) ||
5509 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5510 freq_range->start_freq_khz) ||
5511 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5512 freq_range->end_freq_khz) ||
5513 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005514 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005515 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5516 power_rule->max_antenna_gain) ||
5517 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005518 power_rule->max_eirp) ||
5519 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5520 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005521 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005522
5523 nla_nest_end(msg, nl_reg_rule);
5524 }
5525
5526 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005527 return 0;
5528
5529nla_put_failure:
5530 return -EMSGSIZE;
5531}
5532
5533static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5534{
5535 const struct ieee80211_regdomain *regdom = NULL;
5536 struct cfg80211_registered_device *rdev;
5537 struct wiphy *wiphy = NULL;
5538 struct sk_buff *msg;
5539 void *hdr;
5540
5541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5542 if (!msg)
5543 return -ENOBUFS;
5544
5545 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5546 NL80211_CMD_GET_REG);
5547 if (!hdr)
5548 goto put_failure;
5549
5550 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005551 bool self_managed;
5552
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005553 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5554 if (IS_ERR(rdev)) {
5555 nlmsg_free(msg);
5556 return PTR_ERR(rdev);
5557 }
5558
5559 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005560 self_managed = wiphy->regulatory_flags &
5561 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005562 regdom = get_wiphy_regdom(wiphy);
5563
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005564 /* a self-managed-reg device must have a private regdom */
5565 if (WARN_ON(!regdom && self_managed)) {
5566 nlmsg_free(msg);
5567 return -EINVAL;
5568 }
5569
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005570 if (regdom &&
5571 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5572 goto nla_put_failure;
5573 }
5574
5575 if (!wiphy && reg_last_request_cell_base() &&
5576 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5577 NL80211_USER_REG_HINT_CELL_BASE))
5578 goto nla_put_failure;
5579
5580 rcu_read_lock();
5581
5582 if (!regdom)
5583 regdom = rcu_dereference(cfg80211_regdomain);
5584
5585 if (nl80211_put_regdom(regdom, msg))
5586 goto nla_put_failure_rcu;
5587
5588 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005589
5590 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005591 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005592
Johannes Berg458f4f92012-12-06 15:47:38 +01005593nla_put_failure_rcu:
5594 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005595nla_put_failure:
5596 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005597put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005598 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005599 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005600}
5601
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005602static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5603 u32 seq, int flags, struct wiphy *wiphy,
5604 const struct ieee80211_regdomain *regdom)
5605{
5606 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5607 NL80211_CMD_GET_REG);
5608
5609 if (!hdr)
5610 return -1;
5611
5612 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5613
5614 if (nl80211_put_regdom(regdom, msg))
5615 goto nla_put_failure;
5616
5617 if (!wiphy && reg_last_request_cell_base() &&
5618 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5619 NL80211_USER_REG_HINT_CELL_BASE))
5620 goto nla_put_failure;
5621
5622 if (wiphy &&
5623 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5624 goto nla_put_failure;
5625
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005626 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5627 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5628 goto nla_put_failure;
5629
Johannes Berg053c0952015-01-16 22:09:00 +01005630 genlmsg_end(msg, hdr);
5631 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005632
5633nla_put_failure:
5634 genlmsg_cancel(msg, hdr);
5635 return -EMSGSIZE;
5636}
5637
5638static int nl80211_get_reg_dump(struct sk_buff *skb,
5639 struct netlink_callback *cb)
5640{
5641 const struct ieee80211_regdomain *regdom = NULL;
5642 struct cfg80211_registered_device *rdev;
5643 int err, reg_idx, start = cb->args[2];
5644
5645 rtnl_lock();
5646
5647 if (cfg80211_regdomain && start == 0) {
5648 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5649 NLM_F_MULTI, NULL,
5650 rtnl_dereference(cfg80211_regdomain));
5651 if (err < 0)
5652 goto out_err;
5653 }
5654
5655 /* the global regdom is idx 0 */
5656 reg_idx = 1;
5657 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5658 regdom = get_wiphy_regdom(&rdev->wiphy);
5659 if (!regdom)
5660 continue;
5661
5662 if (++reg_idx <= start)
5663 continue;
5664
5665 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5666 NLM_F_MULTI, &rdev->wiphy, regdom);
5667 if (err < 0) {
5668 reg_idx--;
5669 break;
5670 }
5671 }
5672
5673 cb->args[2] = reg_idx;
5674 err = skb->len;
5675out_err:
5676 rtnl_unlock();
5677 return err;
5678}
5679
Johannes Bergb6863032015-10-15 09:25:18 +02005680#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5681static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5682 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5683 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5684 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5685 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5686 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5687 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5688 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5689};
5690
5691static int parse_reg_rule(struct nlattr *tb[],
5692 struct ieee80211_reg_rule *reg_rule)
5693{
5694 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5695 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5696
5697 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5698 return -EINVAL;
5699 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5700 return -EINVAL;
5701 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5702 return -EINVAL;
5703 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5704 return -EINVAL;
5705 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5706 return -EINVAL;
5707
5708 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5709
5710 freq_range->start_freq_khz =
5711 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5712 freq_range->end_freq_khz =
5713 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5714 freq_range->max_bandwidth_khz =
5715 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5716
5717 power_rule->max_eirp =
5718 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5719
5720 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5721 power_rule->max_antenna_gain =
5722 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5723
5724 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5725 reg_rule->dfs_cac_ms =
5726 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5727
5728 return 0;
5729}
5730
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005731static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5732{
5733 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5734 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005735 char *alpha2;
5736 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005737 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005738 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005739 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005740
5741 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5742 return -EINVAL;
5743
5744 if (!info->attrs[NL80211_ATTR_REG_RULES])
5745 return -EINVAL;
5746
5747 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5748
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005749 if (info->attrs[NL80211_ATTR_DFS_REGION])
5750 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5751
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005752 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005753 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005754 num_rules++;
5755 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005756 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005757 }
5758
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005759 if (!reg_is_valid_request(alpha2))
5760 return -EINVAL;
5761
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005762 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005763 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005764
5765 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005766 if (!rd)
5767 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005768
5769 rd->n_reg_rules = num_rules;
5770 rd->alpha2[0] = alpha2[0];
5771 rd->alpha2[1] = alpha2[1];
5772
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005773 /*
5774 * Disable DFS master mode if the DFS region was
5775 * not supported or known on this kernel.
5776 */
5777 if (reg_supported_dfs_region(dfs_region))
5778 rd->dfs_region = dfs_region;
5779
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005780 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005781 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005782 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5783 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5784 reg_rule_policy);
5785 if (r)
5786 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005787 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5788 if (r)
5789 goto bad_reg;
5790
5791 rule_idx++;
5792
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005793 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5794 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005795 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005796 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005797 }
5798
Ilan peerc37722b2015-03-30 15:15:49 +03005799 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005800 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005801 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005802
Johannes Bergd2372b32008-10-24 20:32:20 +02005803 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005804 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005805 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005806}
Johannes Bergb6863032015-10-15 09:25:18 +02005807#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005808
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005809static int validate_scan_freqs(struct nlattr *freqs)
5810{
5811 struct nlattr *attr1, *attr2;
5812 int n_channels = 0, tmp1, tmp2;
5813
5814 nla_for_each_nested(attr1, freqs, tmp1) {
5815 n_channels++;
5816 /*
5817 * Some hardware has a limited channel list for
5818 * scanning, and it is pretty much nonsensical
5819 * to scan for a channel twice, so disallow that
5820 * and don't require drivers to check that the
5821 * channel list they get isn't longer than what
5822 * they can scan, as long as they can scan all
5823 * the channels they registered at once.
5824 */
5825 nla_for_each_nested(attr2, freqs, tmp2)
5826 if (attr1 != attr2 &&
5827 nla_get_u32(attr1) == nla_get_u32(attr2))
5828 return 0;
5829 }
5830
5831 return n_channels;
5832}
5833
Johannes Berg57fbcce2016-04-12 15:56:15 +02005834static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01005835{
Johannes Berg57fbcce2016-04-12 15:56:15 +02005836 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01005837}
5838
5839static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
5840 struct cfg80211_bss_selection *bss_select)
5841{
5842 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
5843 struct nlattr *nest;
5844 int err;
5845 bool found = false;
5846 int i;
5847
5848 /* only process one nested attribute */
5849 nest = nla_data(nla);
5850 if (!nla_ok(nest, nla_len(nest)))
5851 return -EINVAL;
5852
5853 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
5854 nla_len(nest), nl80211_bss_select_policy);
5855 if (err)
5856 return err;
5857
5858 /* only one attribute may be given */
5859 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
5860 if (attr[i]) {
5861 if (found)
5862 return -EINVAL;
5863 found = true;
5864 }
5865 }
5866
5867 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
5868
5869 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
5870 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
5871
5872 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
5873 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
5874 bss_select->param.band_pref =
5875 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
5876 if (!is_band_valid(wiphy, bss_select->param.band_pref))
5877 return -EINVAL;
5878 }
5879
5880 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
5881 struct nl80211_bss_select_rssi_adjust *adj_param;
5882
5883 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
5884 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
5885 bss_select->param.adjust.band = adj_param->band;
5886 bss_select->param.adjust.delta = adj_param->delta;
5887 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
5888 return -EINVAL;
5889 }
5890
5891 /* user-space did not provide behaviour attribute */
5892 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
5893 return -EINVAL;
5894
5895 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
5896 return -EINVAL;
5897
5898 return 0;
5899}
5900
Johannes Bergad2b26a2014-06-12 21:39:05 +02005901static int nl80211_parse_random_mac(struct nlattr **attrs,
5902 u8 *mac_addr, u8 *mac_addr_mask)
5903{
5904 int i;
5905
5906 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005907 eth_zero_addr(mac_addr);
5908 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005909 mac_addr[0] = 0x2;
5910 mac_addr_mask[0] = 0x3;
5911
5912 return 0;
5913 }
5914
5915 /* need both or none */
5916 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5917 return -EINVAL;
5918
5919 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5920 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5921
5922 /* don't allow or configure an mcast address */
5923 if (!is_multicast_ether_addr(mac_addr_mask) ||
5924 is_multicast_ether_addr(mac_addr))
5925 return -EINVAL;
5926
5927 /*
5928 * allow users to pass a MAC address that has bits set outside
5929 * of the mask, but don't bother drivers with having to deal
5930 * with such bits
5931 */
5932 for (i = 0; i < ETH_ALEN; i++)
5933 mac_addr[i] &= mac_addr_mask[i];
5934
5935 return 0;
5936}
5937
Johannes Berg2a519312009-02-10 21:25:55 +01005938static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5939{
Johannes Berg4c476992010-10-04 21:36:35 +02005940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005941 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005942 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005943 struct nlattr *attr;
5944 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005945 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005946 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005947
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005948 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5949 return -EINVAL;
5950
Johannes Berg79c97e92009-07-07 03:56:12 +02005951 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005952
Johannes Berg4c476992010-10-04 21:36:35 +02005953 if (!rdev->ops->scan)
5954 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005955
Johannes Bergf9d15d12014-01-22 11:14:19 +02005956 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005957 err = -EBUSY;
5958 goto unlock;
5959 }
Johannes Berg2a519312009-02-10 21:25:55 +01005960
5961 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005962 n_channels = validate_scan_freqs(
5963 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005964 if (!n_channels) {
5965 err = -EINVAL;
5966 goto unlock;
5967 }
Johannes Berg2a519312009-02-10 21:25:55 +01005968 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005969 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005970 }
5971
5972 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5973 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5974 n_ssids++;
5975
Johannes Bergf9f47522013-03-19 15:04:07 +01005976 if (n_ssids > wiphy->max_scan_ssids) {
5977 err = -EINVAL;
5978 goto unlock;
5979 }
Johannes Berg2a519312009-02-10 21:25:55 +01005980
Jouni Malinen70692ad2009-02-16 19:39:13 +02005981 if (info->attrs[NL80211_ATTR_IE])
5982 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5983 else
5984 ie_len = 0;
5985
Johannes Bergf9f47522013-03-19 15:04:07 +01005986 if (ie_len > wiphy->max_scan_ie_len) {
5987 err = -EINVAL;
5988 goto unlock;
5989 }
Johannes Berg18a83652009-03-31 12:12:05 +02005990
Johannes Berg2a519312009-02-10 21:25:55 +01005991 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005992 + sizeof(*request->ssids) * n_ssids
5993 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005994 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005995 if (!request) {
5996 err = -ENOMEM;
5997 goto unlock;
5998 }
Johannes Berg2a519312009-02-10 21:25:55 +01005999
Johannes Berg2a519312009-02-10 21:25:55 +01006000 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006001 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006002 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006003 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006004 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006005 request->ie = (void *)(request->ssids + n_ssids);
6006 else
6007 request->ie = (void *)(request->channels + n_channels);
6008 }
Johannes Berg2a519312009-02-10 21:25:55 +01006009
Johannes Berg584991d2009-11-02 13:32:03 +01006010 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006011 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6012 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006013 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006014 struct ieee80211_channel *chan;
6015
6016 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6017
6018 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006019 err = -EINVAL;
6020 goto out_free;
6021 }
Johannes Berg584991d2009-11-02 13:32:03 +01006022
6023 /* ignore disabled channels */
6024 if (chan->flags & IEEE80211_CHAN_DISABLED)
6025 continue;
6026
6027 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006028 i++;
6029 }
6030 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006031 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006032
Johannes Berg2a519312009-02-10 21:25:55 +01006033 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006034 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006035 int j;
6036 if (!wiphy->bands[band])
6037 continue;
6038 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006039 struct ieee80211_channel *chan;
6040
6041 chan = &wiphy->bands[band]->channels[j];
6042
6043 if (chan->flags & IEEE80211_CHAN_DISABLED)
6044 continue;
6045
6046 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006047 i++;
6048 }
6049 }
6050 }
6051
Johannes Berg584991d2009-11-02 13:32:03 +01006052 if (!i) {
6053 err = -EINVAL;
6054 goto out_free;
6055 }
6056
6057 request->n_channels = i;
6058
Johannes Berg2a519312009-02-10 21:25:55 +01006059 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006060 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006061 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006062 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006063 err = -EINVAL;
6064 goto out_free;
6065 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006066 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006067 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006068 i++;
6069 }
6070 }
6071
Jouni Malinen70692ad2009-02-16 19:39:13 +02006072 if (info->attrs[NL80211_ATTR_IE]) {
6073 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006074 memcpy((void *)request->ie,
6075 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006076 request->ie_len);
6077 }
6078
Johannes Berg57fbcce2016-04-12 15:56:15 +02006079 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006080 if (wiphy->bands[i])
6081 request->rates[i] =
6082 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006083
6084 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6085 nla_for_each_nested(attr,
6086 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6087 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006088 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006089
Johannes Berg57fbcce2016-04-12 15:56:15 +02006090 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006091 err = -EINVAL;
6092 goto out_free;
6093 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006094
6095 if (!wiphy->bands[band])
6096 continue;
6097
Johannes Berg34850ab2011-07-18 18:08:35 +02006098 err = ieee80211_get_ratemask(wiphy->bands[band],
6099 nla_data(attr),
6100 nla_len(attr),
6101 &request->rates[band]);
6102 if (err)
6103 goto out_free;
6104 }
6105 }
6106
Sam Leffler46856bb2012-10-11 21:03:32 -07006107 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006108 request->flags = nla_get_u32(
6109 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006110 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6111 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006112 err = -EOPNOTSUPP;
6113 goto out_free;
6114 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006115
6116 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6117 if (!(wiphy->features &
6118 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6119 err = -EOPNOTSUPP;
6120 goto out_free;
6121 }
6122
6123 if (wdev->current_bss) {
6124 err = -EOPNOTSUPP;
6125 goto out_free;
6126 }
6127
6128 err = nl80211_parse_random_mac(info->attrs,
6129 request->mac_addr,
6130 request->mac_addr_mask);
6131 if (err)
6132 goto out_free;
6133 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006134 }
Sam Lefflered4737712012-10-11 21:03:31 -07006135
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306136 request->no_cck =
6137 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6138
Jouni Malinen818965d2016-02-26 22:12:47 +02006139 if (info->attrs[NL80211_ATTR_MAC])
6140 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6141 ETH_ALEN);
6142 else
6143 eth_broadcast_addr(request->bssid);
6144
Johannes Bergfd014282012-06-18 19:17:03 +02006145 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006146 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006147 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006148
Johannes Berg79c97e92009-07-07 03:56:12 +02006149 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006150 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006151
Johannes Berg463d0182009-07-14 00:33:35 +02006152 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006153 nl80211_send_scan_start(rdev, wdev);
6154 if (wdev->netdev)
6155 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006156 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006157 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006158 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006159 kfree(request);
6160 }
Johannes Berg3b858752009-03-12 09:55:09 +01006161
Johannes Bergf9f47522013-03-19 15:04:07 +01006162 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006163 return err;
6164}
6165
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306166static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6167{
6168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6169 struct wireless_dev *wdev = info->user_ptr[1];
6170
6171 if (!rdev->ops->abort_scan)
6172 return -EOPNOTSUPP;
6173
6174 if (rdev->scan_msg)
6175 return 0;
6176
6177 if (!rdev->scan_req)
6178 return -ENOENT;
6179
6180 rdev_abort_scan(rdev, wdev);
6181 return 0;
6182}
6183
Avraham Stern3b06d272015-10-12 09:51:34 +03006184static int
6185nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6186 struct cfg80211_sched_scan_request *request,
6187 struct nlattr **attrs)
6188{
6189 int tmp, err, i = 0;
6190 struct nlattr *attr;
6191
6192 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6193 u32 interval;
6194
6195 /*
6196 * If scan plans are not specified,
6197 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6198 * case one scan plan will be set with the specified scan
6199 * interval and infinite number of iterations.
6200 */
6201 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6202 return -EINVAL;
6203
6204 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6205 if (!interval)
6206 return -EINVAL;
6207
6208 request->scan_plans[0].interval =
6209 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6210 if (!request->scan_plans[0].interval)
6211 return -EINVAL;
6212
6213 if (request->scan_plans[0].interval >
6214 wiphy->max_sched_scan_plan_interval)
6215 request->scan_plans[0].interval =
6216 wiphy->max_sched_scan_plan_interval;
6217
6218 return 0;
6219 }
6220
6221 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6222 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6223
6224 if (WARN_ON(i >= n_plans))
6225 return -EINVAL;
6226
6227 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6228 nla_data(attr), nla_len(attr),
6229 nl80211_plan_policy);
6230 if (err)
6231 return err;
6232
6233 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6234 return -EINVAL;
6235
6236 request->scan_plans[i].interval =
6237 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6238 if (!request->scan_plans[i].interval ||
6239 request->scan_plans[i].interval >
6240 wiphy->max_sched_scan_plan_interval)
6241 return -EINVAL;
6242
6243 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6244 request->scan_plans[i].iterations =
6245 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6246 if (!request->scan_plans[i].iterations ||
6247 (request->scan_plans[i].iterations >
6248 wiphy->max_sched_scan_plan_iterations))
6249 return -EINVAL;
6250 } else if (i < n_plans - 1) {
6251 /*
6252 * All scan plans but the last one must specify
6253 * a finite number of iterations
6254 */
6255 return -EINVAL;
6256 }
6257
6258 i++;
6259 }
6260
6261 /*
6262 * The last scan plan must not specify the number of
6263 * iterations, it is supposed to run infinitely
6264 */
6265 if (request->scan_plans[n_plans - 1].iterations)
6266 return -EINVAL;
6267
6268 return 0;
6269}
6270
Luciano Coelho256da022014-11-10 16:13:46 +02006271static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006272nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006273 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006274{
6275 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006276 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006277 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006278 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006279 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006280 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006281 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006282
Luciano Coelho256da022014-11-10 16:13:46 +02006283 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6284 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006285
Luciano Coelho256da022014-11-10 16:13:46 +02006286 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006287 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006288 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006289 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006290 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006291 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006292 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006293 }
6294
Luciano Coelho256da022014-11-10 16:13:46 +02006295 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6296 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006297 tmp)
6298 n_ssids++;
6299
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006300 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006301 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006302
Johannes Bergea73cbc2014-01-24 10:53:53 +01006303 /*
6304 * First, count the number of 'real' matchsets. Due to an issue with
6305 * the old implementation, matchsets containing only the RSSI attribute
6306 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6307 * RSSI for all matchsets, rather than their own matchset for reporting
6308 * all APs with a strong RSSI. This is needed to be compatible with
6309 * older userspace that treated a matchset with only the RSSI as the
6310 * global RSSI for all other matchsets - if there are other matchsets.
6311 */
Luciano Coelho256da022014-11-10 16:13:46 +02006312 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006313 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006314 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006315 tmp) {
6316 struct nlattr *rssi;
6317
6318 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6319 nla_data(attr), nla_len(attr),
6320 nl80211_match_policy);
6321 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006322 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006323 /* add other standalone attributes here */
6324 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6325 n_match_sets++;
6326 continue;
6327 }
6328 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6329 if (rssi)
6330 default_match_rssi = nla_get_s32(rssi);
6331 }
6332 }
6333
6334 /* However, if there's no other matchset, add the RSSI one */
6335 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6336 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006337
6338 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006339 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006340
Luciano Coelho256da022014-11-10 16:13:46 +02006341 if (attrs[NL80211_ATTR_IE])
6342 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006343 else
6344 ie_len = 0;
6345
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006346 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006347 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006348
Avraham Stern3b06d272015-10-12 09:51:34 +03006349 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6350 /*
6351 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6352 * each scan plan already specifies its own interval
6353 */
6354 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6355 return ERR_PTR(-EINVAL);
6356
6357 nla_for_each_nested(attr,
6358 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6359 n_plans++;
6360 } else {
6361 /*
6362 * The scan interval attribute is kept for backward
6363 * compatibility. If no scan plans are specified and sched scan
6364 * interval is specified, one scan plan will be set with this
6365 * scan interval and infinite number of iterations.
6366 */
6367 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6368 return ERR_PTR(-EINVAL);
6369
6370 n_plans = 1;
6371 }
6372
6373 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6374 return ERR_PTR(-EINVAL);
6375
Luciano Coelho807f8a82011-05-11 17:09:35 +03006376 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006377 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006378 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006379 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006380 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006381 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006382 if (!request)
6383 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006384
6385 if (n_ssids)
6386 request->ssids = (void *)&request->channels[n_channels];
6387 request->n_ssids = n_ssids;
6388 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006389 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006390 request->ie = (void *)(request->ssids + n_ssids);
6391 else
6392 request->ie = (void *)(request->channels + n_channels);
6393 }
6394
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006395 if (n_match_sets) {
6396 if (request->ie)
6397 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006398 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006399 request->match_sets =
6400 (void *)(request->ssids + n_ssids);
6401 else
6402 request->match_sets =
6403 (void *)(request->channels + n_channels);
6404 }
6405 request->n_match_sets = n_match_sets;
6406
Avraham Stern3b06d272015-10-12 09:51:34 +03006407 if (n_match_sets)
6408 request->scan_plans = (void *)(request->match_sets +
6409 n_match_sets);
6410 else if (request->ie)
6411 request->scan_plans = (void *)(request->ie + ie_len);
6412 else if (n_ssids)
6413 request->scan_plans = (void *)(request->ssids + n_ssids);
6414 else
6415 request->scan_plans = (void *)(request->channels + n_channels);
6416
6417 request->n_scan_plans = n_plans;
6418
Luciano Coelho807f8a82011-05-11 17:09:35 +03006419 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006420 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006421 /* user specified, bail out if channel not found */
6422 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006423 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006424 tmp) {
6425 struct ieee80211_channel *chan;
6426
6427 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6428
6429 if (!chan) {
6430 err = -EINVAL;
6431 goto out_free;
6432 }
6433
6434 /* ignore disabled channels */
6435 if (chan->flags & IEEE80211_CHAN_DISABLED)
6436 continue;
6437
6438 request->channels[i] = chan;
6439 i++;
6440 }
6441 } else {
6442 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006443 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006444 int j;
6445 if (!wiphy->bands[band])
6446 continue;
6447 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6448 struct ieee80211_channel *chan;
6449
6450 chan = &wiphy->bands[band]->channels[j];
6451
6452 if (chan->flags & IEEE80211_CHAN_DISABLED)
6453 continue;
6454
6455 request->channels[i] = chan;
6456 i++;
6457 }
6458 }
6459 }
6460
6461 if (!i) {
6462 err = -EINVAL;
6463 goto out_free;
6464 }
6465
6466 request->n_channels = i;
6467
6468 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006469 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006470 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006471 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006472 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006473 err = -EINVAL;
6474 goto out_free;
6475 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006476 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006477 memcpy(request->ssids[i].ssid, nla_data(attr),
6478 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006479 i++;
6480 }
6481 }
6482
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006483 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006484 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006485 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006486 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006487 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006488 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006489
Johannes Bergae811e22014-01-24 10:17:47 +01006490 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6491 nla_data(attr), nla_len(attr),
6492 nl80211_match_policy);
6493 if (err)
6494 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006495 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006496 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006497 if (WARN_ON(i >= n_match_sets)) {
6498 /* this indicates a programming error,
6499 * the loop above should have verified
6500 * things properly
6501 */
6502 err = -EINVAL;
6503 goto out_free;
6504 }
6505
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006506 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6507 err = -EINVAL;
6508 goto out_free;
6509 }
6510 memcpy(request->match_sets[i].ssid.ssid,
6511 nla_data(ssid), nla_len(ssid));
6512 request->match_sets[i].ssid.ssid_len =
6513 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006514 /* special attribute - old implemenation w/a */
6515 request->match_sets[i].rssi_thold =
6516 default_match_rssi;
6517 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6518 if (rssi)
6519 request->match_sets[i].rssi_thold =
6520 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006521 }
6522 i++;
6523 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006524
6525 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006526 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006527 request->match_sets[0].rssi_thold = default_match_rssi;
6528
6529 request->min_rssi_thold = INT_MAX;
6530 for (i = 0; i < n_match_sets; i++)
6531 request->min_rssi_thold =
6532 min(request->match_sets[i].rssi_thold,
6533 request->min_rssi_thold);
6534 } else {
6535 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006536 }
6537
Johannes Berg9900e482014-02-04 21:01:25 +01006538 if (ie_len) {
6539 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006540 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006541 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006542 request->ie_len);
6543 }
6544
Luciano Coelho256da022014-11-10 16:13:46 +02006545 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006546 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006547 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006548 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6549 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006550 err = -EOPNOTSUPP;
6551 goto out_free;
6552 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006553
6554 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6555 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6556
6557 if (!wdev) /* must be net-detect */
6558 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6559
6560 if (!(wiphy->features & flg)) {
6561 err = -EOPNOTSUPP;
6562 goto out_free;
6563 }
6564
6565 if (wdev && wdev->current_bss) {
6566 err = -EOPNOTSUPP;
6567 goto out_free;
6568 }
6569
6570 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6571 request->mac_addr_mask);
6572 if (err)
6573 goto out_free;
6574 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006575 }
Sam Lefflered4737712012-10-11 21:03:31 -07006576
Luciano Coelho9c748932015-01-16 16:04:09 +02006577 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6578 request->delay =
6579 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6580
Avraham Stern3b06d272015-10-12 09:51:34 +03006581 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6582 if (err)
6583 goto out_free;
6584
Sam Leffler15d60302012-10-11 21:03:34 -07006585 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006586
Luciano Coelho256da022014-11-10 16:13:46 +02006587 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006588
6589out_free:
6590 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006591 return ERR_PTR(err);
6592}
6593
6594static int nl80211_start_sched_scan(struct sk_buff *skb,
6595 struct genl_info *info)
6596{
6597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6598 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006599 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006600 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006601 int err;
6602
6603 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6604 !rdev->ops->sched_scan_start)
6605 return -EOPNOTSUPP;
6606
6607 if (rdev->sched_scan_req)
6608 return -EINPROGRESS;
6609
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006610 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6611 info->attrs);
6612
6613 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006614 if (err)
6615 goto out_err;
6616
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006617 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006618 if (err)
6619 goto out_free;
6620
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006621 sched_scan_req->dev = dev;
6622 sched_scan_req->wiphy = &rdev->wiphy;
6623
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006624 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6625 sched_scan_req->owner_nlportid = info->snd_portid;
6626
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006627 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006628
6629 nl80211_send_sched_scan(rdev, dev,
6630 NL80211_CMD_START_SCHED_SCAN);
6631 return 0;
6632
6633out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006634 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006635out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006636 return err;
6637}
6638
6639static int nl80211_stop_sched_scan(struct sk_buff *skb,
6640 struct genl_info *info)
6641{
6642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6643
6644 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6645 !rdev->ops->sched_scan_stop)
6646 return -EOPNOTSUPP;
6647
Johannes Berg5fe231e2013-05-08 21:45:15 +02006648 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006649}
6650
Simon Wunderlich04f39042013-02-08 18:16:19 +01006651static int nl80211_start_radar_detection(struct sk_buff *skb,
6652 struct genl_info *info)
6653{
6654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6655 struct net_device *dev = info->user_ptr[1];
6656 struct wireless_dev *wdev = dev->ieee80211_ptr;
6657 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006658 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006659 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006660 int err;
6661
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006662 dfs_region = reg_get_dfs_region(wdev->wiphy);
6663 if (dfs_region == NL80211_DFS_UNSET)
6664 return -EINVAL;
6665
Simon Wunderlich04f39042013-02-08 18:16:19 +01006666 err = nl80211_parse_chandef(rdev, info, &chandef);
6667 if (err)
6668 return err;
6669
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006670 if (netif_carrier_ok(dev))
6671 return -EBUSY;
6672
Simon Wunderlich04f39042013-02-08 18:16:19 +01006673 if (wdev->cac_started)
6674 return -EBUSY;
6675
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006676 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006677 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006678 if (err < 0)
6679 return err;
6680
6681 if (err == 0)
6682 return -EINVAL;
6683
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006684 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006685 return -EINVAL;
6686
6687 if (!rdev->ops->start_radar_detection)
6688 return -EOPNOTSUPP;
6689
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006690 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6691 if (WARN_ON(!cac_time_ms))
6692 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6693
Ilan Peera1056b12015-10-22 22:27:46 +03006694 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006695 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006696 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006697 wdev->cac_started = true;
6698 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006699 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006700 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006701 return err;
6702}
6703
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006704static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6705{
6706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6707 struct net_device *dev = info->user_ptr[1];
6708 struct wireless_dev *wdev = dev->ieee80211_ptr;
6709 struct cfg80211_csa_settings params;
6710 /* csa_attrs is defined static to avoid waste of stack size - this
6711 * function is called under RTNL lock, so this should not be a problem.
6712 */
6713 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006714 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006715 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006716 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006717 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006718
6719 if (!rdev->ops->channel_switch ||
6720 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6721 return -EOPNOTSUPP;
6722
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006723 switch (dev->ieee80211_ptr->iftype) {
6724 case NL80211_IFTYPE_AP:
6725 case NL80211_IFTYPE_P2P_GO:
6726 need_new_beacon = true;
6727
6728 /* useless if AP is not running */
6729 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006730 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006731 break;
6732 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006733 if (!wdev->ssid_len)
6734 return -ENOTCONN;
6735 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006736 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006737 if (!wdev->mesh_id_len)
6738 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006739 break;
6740 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006741 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006742 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006743
6744 memset(&params, 0, sizeof(params));
6745
6746 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6747 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6748 return -EINVAL;
6749
6750 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006751 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006752 return -EINVAL;
6753
Luciano Coelho252e07c2014-10-08 09:48:34 +03006754 /* Even though the attribute is u32, the specification says
6755 * u8, so let's make sure we don't overflow.
6756 */
6757 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6758 if (cs_count > 255)
6759 return -EINVAL;
6760
6761 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006762
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006763 if (!need_new_beacon)
6764 goto skip_beacons;
6765
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006766 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6767 if (err)
6768 return err;
6769
6770 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6771 info->attrs[NL80211_ATTR_CSA_IES],
6772 nl80211_policy);
6773 if (err)
6774 return err;
6775
6776 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6777 if (err)
6778 return err;
6779
6780 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6781 return -EINVAL;
6782
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006783 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6784 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006785 return -EINVAL;
6786
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006787 params.n_counter_offsets_beacon = len / sizeof(u16);
6788 if (rdev->wiphy.max_num_csa_counters &&
6789 (params.n_counter_offsets_beacon >
6790 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006791 return -EINVAL;
6792
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006793 params.counter_offsets_beacon =
6794 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6795
6796 /* sanity checks - counters should fit and be the same */
6797 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6798 u16 offset = params.counter_offsets_beacon[i];
6799
6800 if (offset >= params.beacon_csa.tail_len)
6801 return -EINVAL;
6802
6803 if (params.beacon_csa.tail[offset] != params.count)
6804 return -EINVAL;
6805 }
6806
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006807 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006808 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6809 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006810 return -EINVAL;
6811
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006812 params.n_counter_offsets_presp = len / sizeof(u16);
6813 if (rdev->wiphy.max_num_csa_counters &&
6814 (params.n_counter_offsets_beacon >
6815 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006816 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006817
6818 params.counter_offsets_presp =
6819 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6820
6821 /* sanity checks - counters should fit and be the same */
6822 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6823 u16 offset = params.counter_offsets_presp[i];
6824
6825 if (offset >= params.beacon_csa.probe_resp_len)
6826 return -EINVAL;
6827
6828 if (params.beacon_csa.probe_resp[offset] !=
6829 params.count)
6830 return -EINVAL;
6831 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006832 }
6833
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006834skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006835 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6836 if (err)
6837 return err;
6838
Arik Nemtsov923b3522015-07-08 15:41:44 +03006839 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6840 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006841 return -EINVAL;
6842
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006843 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6844 &params.chandef,
6845 wdev->iftype);
6846 if (err < 0)
6847 return err;
6848
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006849 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006850 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006851
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006852 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6853 params.block_tx = true;
6854
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006855 wdev_lock(wdev);
6856 err = rdev_channel_switch(rdev, dev, &params);
6857 wdev_unlock(wdev);
6858
6859 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006860}
6861
Johannes Berg9720bb32011-06-21 09:45:33 +02006862static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6863 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006864 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006865 struct wireless_dev *wdev,
6866 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006867{
Johannes Berg48ab9052009-07-10 18:42:31 +02006868 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006869 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006870 void *hdr;
6871 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006872
6873 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006874
Eric W. Biederman15e47302012-09-07 20:12:54 +00006875 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006876 NL80211_CMD_NEW_SCAN_RESULTS);
6877 if (!hdr)
6878 return -1;
6879
Johannes Berg9720bb32011-06-21 09:45:33 +02006880 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6881
Johannes Berg97990a02013-04-19 01:02:55 +02006882 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6883 goto nla_put_failure;
6884 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006885 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6886 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006887 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
6888 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02006889 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006890
6891 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6892 if (!bss)
6893 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006894 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006895 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006896 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006897
6898 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006899 /* indicate whether we have probe response data or not */
6900 if (rcu_access_pointer(res->proberesp_ies) &&
6901 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6902 goto fail_unlock_rcu;
6903
6904 /* this pointer prefers to be pointed to probe response data
6905 * but is always valid
6906 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006907 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006908 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006909 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
6910 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006911 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006912 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6913 ies->len, ies->data))
6914 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006915 }
Johannes Berg0e227082014-08-12 20:34:30 +02006916
6917 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006918 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006919 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006920 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
6921 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006922 goto fail_unlock_rcu;
6923 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6924 ies->len, ies->data))
6925 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006926 }
6927 rcu_read_unlock();
6928
David S. Miller9360ffd2012-03-29 04:41:26 -04006929 if (res->beacon_interval &&
6930 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6931 goto nla_put_failure;
6932 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6933 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006934 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006935 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6936 jiffies_to_msecs(jiffies - intbss->ts)))
6937 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006938
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006939 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02006940 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6941 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006942 goto nla_put_failure;
6943
Johannes Berg77965c92009-02-18 18:45:06 +01006944 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006945 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006946 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6947 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006948 break;
6949 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006950 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6951 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006952 break;
6953 default:
6954 break;
6955 }
6956
Johannes Berg48ab9052009-07-10 18:42:31 +02006957 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006958 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006959 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006960 if (intbss == wdev->current_bss &&
6961 nla_put_u32(msg, NL80211_BSS_STATUS,
6962 NL80211_BSS_STATUS_ASSOCIATED))
6963 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006964 break;
6965 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006966 if (intbss == wdev->current_bss &&
6967 nla_put_u32(msg, NL80211_BSS_STATUS,
6968 NL80211_BSS_STATUS_IBSS_JOINED))
6969 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006970 break;
6971 default:
6972 break;
6973 }
6974
Johannes Berg2a519312009-02-10 21:25:55 +01006975 nla_nest_end(msg, bss);
6976
Johannes Berg053c0952015-01-16 22:09:00 +01006977 genlmsg_end(msg, hdr);
6978 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006979
Johannes Berg8cef2c92013-02-05 16:54:31 +01006980 fail_unlock_rcu:
6981 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006982 nla_put_failure:
6983 genlmsg_cancel(msg, hdr);
6984 return -EMSGSIZE;
6985}
6986
Johannes Berg97990a02013-04-19 01:02:55 +02006987static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006988{
Johannes Berg48ab9052009-07-10 18:42:31 +02006989 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006990 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006991 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006992 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006993 int err;
6994
Johannes Berg97990a02013-04-19 01:02:55 +02006995 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006996 if (err)
6997 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006998
Johannes Berg48ab9052009-07-10 18:42:31 +02006999 wdev_lock(wdev);
7000 spin_lock_bh(&rdev->bss_lock);
7001 cfg80211_bss_expire(rdev);
7002
Johannes Berg9720bb32011-06-21 09:45:33 +02007003 cb->seq = rdev->bss_generation;
7004
Johannes Berg48ab9052009-07-10 18:42:31 +02007005 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007006 if (++idx <= start)
7007 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007008 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007009 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007010 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007011 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007012 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007013 }
7014 }
7015
Johannes Berg48ab9052009-07-10 18:42:31 +02007016 spin_unlock_bh(&rdev->bss_lock);
7017 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007018
Johannes Berg97990a02013-04-19 01:02:55 +02007019 cb->args[2] = idx;
7020 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007021
Johannes Berg67748892010-10-04 21:14:06 +02007022 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007023}
7024
Eric W. Biederman15e47302012-09-07 20:12:54 +00007025static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007026 int flags, struct net_device *dev,
7027 bool allow_radio_stats,
7028 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007029{
7030 void *hdr;
7031 struct nlattr *infoattr;
7032
Johannes Berg11f78ac2014-11-14 16:43:50 +01007033 /* skip radio stats if userspace didn't request them */
7034 if (!survey->channel && !allow_radio_stats)
7035 return 0;
7036
Eric W. Biederman15e47302012-09-07 20:12:54 +00007037 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007038 NL80211_CMD_NEW_SURVEY_RESULTS);
7039 if (!hdr)
7040 return -ENOMEM;
7041
David S. Miller9360ffd2012-03-29 04:41:26 -04007042 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7043 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007044
7045 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7046 if (!infoattr)
7047 goto nla_put_failure;
7048
Johannes Berg11f78ac2014-11-14 16:43:50 +01007049 if (survey->channel &&
7050 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007051 survey->channel->center_freq))
7052 goto nla_put_failure;
7053
7054 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7055 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7056 goto nla_put_failure;
7057 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7058 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7059 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007060 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007061 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7062 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007063 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007064 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007065 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7066 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007067 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007068 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007069 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7070 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007071 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007072 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007073 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7074 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007075 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007076 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007077 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7078 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007079 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007080 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007081 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7082 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007083 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007084
7085 nla_nest_end(msg, infoattr);
7086
Johannes Berg053c0952015-01-16 22:09:00 +01007087 genlmsg_end(msg, hdr);
7088 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007089
7090 nla_put_failure:
7091 genlmsg_cancel(msg, hdr);
7092 return -EMSGSIZE;
7093}
7094
Johannes Berg11f78ac2014-11-14 16:43:50 +01007095static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007096{
7097 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007098 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007099 struct wireless_dev *wdev;
7100 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007101 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007102 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007103
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007104 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007105 if (res)
7106 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007107
Johannes Berg11f78ac2014-11-14 16:43:50 +01007108 /* prepare_wdev_dump parsed the attributes */
7109 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7110
Johannes Berg97990a02013-04-19 01:02:55 +02007111 if (!wdev->netdev) {
7112 res = -EINVAL;
7113 goto out_err;
7114 }
7115
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007116 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007117 res = -EOPNOTSUPP;
7118 goto out_err;
7119 }
7120
7121 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007122 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007123 if (res == -ENOENT)
7124 break;
7125 if (res)
7126 goto out_err;
7127
Johannes Berg11f78ac2014-11-14 16:43:50 +01007128 /* don't send disabled channels, but do send non-channel data */
7129 if (survey.channel &&
7130 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007131 survey_idx++;
7132 continue;
7133 }
7134
Holger Schurig61fa7132009-11-11 12:25:40 +01007135 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007136 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007137 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007138 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007139 goto out;
7140 survey_idx++;
7141 }
7142
7143 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007144 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007145 res = skb->len;
7146 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007147 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007148 return res;
7149}
7150
Samuel Ortizb23aa672009-07-01 21:26:54 +02007151static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7152{
7153 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7154 NL80211_WPA_VERSION_2));
7155}
7156
Jouni Malinen636a5d32009-03-19 13:39:22 +02007157static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7158{
Johannes Berg4c476992010-10-04 21:36:35 +02007159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7160 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007161 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007162 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7163 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007164 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007165 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007166 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007167
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007168 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7169 return -EINVAL;
7170
7171 if (!info->attrs[NL80211_ATTR_MAC])
7172 return -EINVAL;
7173
Jouni Malinen17780922009-03-27 20:52:47 +02007174 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7175 return -EINVAL;
7176
Johannes Berg19957bb2009-07-02 17:20:43 +02007177 if (!info->attrs[NL80211_ATTR_SSID])
7178 return -EINVAL;
7179
7180 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7181 return -EINVAL;
7182
Johannes Bergfffd0932009-07-08 14:22:54 +02007183 err = nl80211_parse_key(info, &key);
7184 if (err)
7185 return err;
7186
7187 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007188 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7189 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007190 if (!key.p.key || !key.p.key_len)
7191 return -EINVAL;
7192 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7193 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7194 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7195 key.p.key_len != WLAN_KEY_LEN_WEP104))
7196 return -EINVAL;
7197 if (key.idx > 4)
7198 return -EINVAL;
7199 } else {
7200 key.p.key_len = 0;
7201 key.p.key = NULL;
7202 }
7203
Johannes Bergafea0b72010-08-10 09:46:42 +02007204 if (key.idx >= 0) {
7205 int i;
7206 bool ok = false;
7207 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7208 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7209 ok = true;
7210 break;
7211 }
7212 }
Johannes Berg4c476992010-10-04 21:36:35 +02007213 if (!ok)
7214 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007215 }
7216
Johannes Berg4c476992010-10-04 21:36:35 +02007217 if (!rdev->ops->auth)
7218 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007219
Johannes Berg074ac8d2010-09-16 14:58:22 +02007220 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007221 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7222 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007223
Johannes Berg19957bb2009-07-02 17:20:43 +02007224 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007225 chan = nl80211_get_valid_chan(&rdev->wiphy,
7226 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7227 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007228 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007229
Johannes Berg19957bb2009-07-02 17:20:43 +02007230 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7231 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7232
7233 if (info->attrs[NL80211_ATTR_IE]) {
7234 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7235 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7236 }
7237
7238 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007239 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007240 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007241
Jouni Malinene39e5b52012-09-30 19:29:39 +03007242 if (auth_type == NL80211_AUTHTYPE_SAE &&
7243 !info->attrs[NL80211_ATTR_SAE_DATA])
7244 return -EINVAL;
7245
7246 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7247 if (auth_type != NL80211_AUTHTYPE_SAE)
7248 return -EINVAL;
7249 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7250 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7251 /* need to include at least Auth Transaction and Status Code */
7252 if (sae_data_len < 4)
7253 return -EINVAL;
7254 }
7255
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007256 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7257
Johannes Berg95de8172012-01-20 13:55:25 +01007258 /*
7259 * Since we no longer track auth state, ignore
7260 * requests to only change local state.
7261 */
7262 if (local_state_change)
7263 return 0;
7264
Johannes Berg91bf9b22013-05-15 17:44:01 +02007265 wdev_lock(dev->ieee80211_ptr);
7266 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7267 ssid, ssid_len, ie, ie_len,
7268 key.p.key, key.p.key_len, key.idx,
7269 sae_data, sae_data_len);
7270 wdev_unlock(dev->ieee80211_ptr);
7271 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007272}
7273
Johannes Bergc0692b82010-08-27 14:26:53 +03007274static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7275 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007276 struct cfg80211_crypto_settings *settings,
7277 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007278{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007279 memset(settings, 0, sizeof(*settings));
7280
Samuel Ortizb23aa672009-07-01 21:26:54 +02007281 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7282
Johannes Bergc0692b82010-08-27 14:26:53 +03007283 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7284 u16 proto;
7285 proto = nla_get_u16(
7286 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7287 settings->control_port_ethertype = cpu_to_be16(proto);
7288 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7289 proto != ETH_P_PAE)
7290 return -EINVAL;
7291 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7292 settings->control_port_no_encrypt = true;
7293 } else
7294 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7295
Samuel Ortizb23aa672009-07-01 21:26:54 +02007296 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7297 void *data;
7298 int len, i;
7299
7300 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7301 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7302 settings->n_ciphers_pairwise = len / sizeof(u32);
7303
7304 if (len % sizeof(u32))
7305 return -EINVAL;
7306
Johannes Berg3dc27d22009-07-02 21:36:37 +02007307 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007308 return -EINVAL;
7309
7310 memcpy(settings->ciphers_pairwise, data, len);
7311
7312 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007313 if (!cfg80211_supported_cipher_suite(
7314 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007315 settings->ciphers_pairwise[i]))
7316 return -EINVAL;
7317 }
7318
7319 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7320 settings->cipher_group =
7321 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007322 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7323 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007324 return -EINVAL;
7325 }
7326
7327 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7328 settings->wpa_versions =
7329 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7330 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7331 return -EINVAL;
7332 }
7333
7334 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7335 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007336 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007337
7338 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7339 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7340 settings->n_akm_suites = len / sizeof(u32);
7341
7342 if (len % sizeof(u32))
7343 return -EINVAL;
7344
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007345 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7346 return -EINVAL;
7347
Samuel Ortizb23aa672009-07-01 21:26:54 +02007348 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007349 }
7350
7351 return 0;
7352}
7353
Jouni Malinen636a5d32009-03-19 13:39:22 +02007354static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7355{
Johannes Berg4c476992010-10-04 21:36:35 +02007356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7357 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007358 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007359 struct cfg80211_assoc_request req = {};
7360 const u8 *bssid, *ssid;
7361 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007362
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007363 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7364 return -EINVAL;
7365
7366 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007367 !info->attrs[NL80211_ATTR_SSID] ||
7368 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007369 return -EINVAL;
7370
Johannes Berg4c476992010-10-04 21:36:35 +02007371 if (!rdev->ops->assoc)
7372 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007373
Johannes Berg074ac8d2010-09-16 14:58:22 +02007374 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007375 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7376 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007377
Johannes Berg19957bb2009-07-02 17:20:43 +02007378 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007379
Jouni Malinen664834d2014-01-15 00:01:44 +02007380 chan = nl80211_get_valid_chan(&rdev->wiphy,
7381 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7382 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007383 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007384
Johannes Berg19957bb2009-07-02 17:20:43 +02007385 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7386 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007387
7388 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007389 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7390 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007391 }
7392
Jouni Malinendc6382c2009-05-06 22:09:37 +03007393 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007394 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007395 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007396 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007397 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007398 else if (mfp != NL80211_MFP_NO)
7399 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007400 }
7401
Johannes Berg3e5d7642009-07-07 14:37:26 +02007402 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007403 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007404
Ben Greear7e7c8922011-11-18 11:31:59 -08007405 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007406 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007407
7408 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007409 memcpy(&req.ht_capa_mask,
7410 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7411 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007412
7413 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007414 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007415 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007416 memcpy(&req.ht_capa,
7417 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7418 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007419 }
7420
Johannes Bergee2aca32013-02-21 17:36:01 +01007421 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007422 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007423
7424 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007425 memcpy(&req.vht_capa_mask,
7426 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7427 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007428
7429 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007430 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007431 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007432 memcpy(&req.vht_capa,
7433 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7434 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007435 }
7436
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007437 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007438 if (!((rdev->wiphy.features &
7439 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7440 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7441 !wiphy_ext_feature_isset(&rdev->wiphy,
7442 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007443 return -EINVAL;
7444 req.flags |= ASSOC_REQ_USE_RRM;
7445 }
7446
Johannes Bergf62fab72013-02-21 20:09:09 +01007447 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007448 if (!err) {
7449 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007450 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7451 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007452 wdev_unlock(dev->ieee80211_ptr);
7453 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007454
Jouni Malinen636a5d32009-03-19 13:39:22 +02007455 return err;
7456}
7457
7458static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7459{
Johannes Berg4c476992010-10-04 21:36:35 +02007460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7461 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007462 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007463 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007464 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007465 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007466
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007467 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7468 return -EINVAL;
7469
7470 if (!info->attrs[NL80211_ATTR_MAC])
7471 return -EINVAL;
7472
7473 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7474 return -EINVAL;
7475
Johannes Berg4c476992010-10-04 21:36:35 +02007476 if (!rdev->ops->deauth)
7477 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007478
Johannes Berg074ac8d2010-09-16 14:58:22 +02007479 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007480 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7481 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007482
Johannes Berg19957bb2009-07-02 17:20:43 +02007483 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007484
Johannes Berg19957bb2009-07-02 17:20:43 +02007485 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7486 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007487 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007488 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007489 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007490
7491 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007492 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7493 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007494 }
7495
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007496 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7497
Johannes Berg91bf9b22013-05-15 17:44:01 +02007498 wdev_lock(dev->ieee80211_ptr);
7499 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7500 local_state_change);
7501 wdev_unlock(dev->ieee80211_ptr);
7502 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007503}
7504
7505static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7506{
Johannes Berg4c476992010-10-04 21:36:35 +02007507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7508 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007509 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007510 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007511 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007512 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007513
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007514 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7515 return -EINVAL;
7516
7517 if (!info->attrs[NL80211_ATTR_MAC])
7518 return -EINVAL;
7519
7520 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7521 return -EINVAL;
7522
Johannes Berg4c476992010-10-04 21:36:35 +02007523 if (!rdev->ops->disassoc)
7524 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007525
Johannes Berg074ac8d2010-09-16 14:58:22 +02007526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007527 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7528 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007529
Johannes Berg19957bb2009-07-02 17:20:43 +02007530 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007531
Johannes Berg19957bb2009-07-02 17:20:43 +02007532 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7533 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007534 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007535 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007536 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007537
7538 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007539 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7540 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007541 }
7542
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007543 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7544
Johannes Berg91bf9b22013-05-15 17:44:01 +02007545 wdev_lock(dev->ieee80211_ptr);
7546 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7547 local_state_change);
7548 wdev_unlock(dev->ieee80211_ptr);
7549 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007550}
7551
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007552static bool
7553nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02007554 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007555 int rateval)
7556{
7557 struct wiphy *wiphy = &rdev->wiphy;
7558 bool found = false;
7559 int band, i;
7560
Johannes Berg57fbcce2016-04-12 15:56:15 +02007561 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007562 struct ieee80211_supported_band *sband;
7563
7564 sband = wiphy->bands[band];
7565 if (!sband)
7566 continue;
7567
7568 for (i = 0; i < sband->n_bitrates; i++) {
7569 if (sband->bitrates[i].bitrate == rateval) {
7570 mcast_rate[band] = i + 1;
7571 found = true;
7572 break;
7573 }
7574 }
7575 }
7576
7577 return found;
7578}
7579
Johannes Berg04a773a2009-04-19 21:24:32 +02007580static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7581{
Johannes Berg4c476992010-10-04 21:36:35 +02007582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7583 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007584 struct cfg80211_ibss_params ibss;
7585 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007586 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007587 int err;
7588
Johannes Berg8e30bc52009-04-22 17:45:38 +02007589 memset(&ibss, 0, sizeof(ibss));
7590
Johannes Berg04a773a2009-04-19 21:24:32 +02007591 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7592 return -EINVAL;
7593
Johannes Berg683b6d32012-11-08 21:25:48 +01007594 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007595 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7596 return -EINVAL;
7597
Johannes Berg8e30bc52009-04-22 17:45:38 +02007598 ibss.beacon_interval = 100;
7599
7600 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7601 ibss.beacon_interval =
7602 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7603 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7604 return -EINVAL;
7605 }
7606
Johannes Berg4c476992010-10-04 21:36:35 +02007607 if (!rdev->ops->join_ibss)
7608 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007609
Johannes Berg4c476992010-10-04 21:36:35 +02007610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7611 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007612
Johannes Berg79c97e92009-07-07 03:56:12 +02007613 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007614
Johannes Berg39193492011-09-16 13:45:25 +02007615 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007616 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007617
7618 if (!is_valid_ether_addr(ibss.bssid))
7619 return -EINVAL;
7620 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007621 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7622 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7623
7624 if (info->attrs[NL80211_ATTR_IE]) {
7625 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7626 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7627 }
7628
Johannes Berg683b6d32012-11-08 21:25:48 +01007629 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7630 if (err)
7631 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007632
Ilan Peer174e0cd2014-02-23 09:13:01 +02007633 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7634 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007635 return -EINVAL;
7636
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007637 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007638 case NL80211_CHAN_WIDTH_5:
7639 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007640 case NL80211_CHAN_WIDTH_20_NOHT:
7641 break;
7642 case NL80211_CHAN_WIDTH_20:
7643 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007644 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7645 return -EINVAL;
7646 break;
7647 case NL80211_CHAN_WIDTH_80:
7648 case NL80211_CHAN_WIDTH_80P80:
7649 case NL80211_CHAN_WIDTH_160:
7650 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7651 return -EINVAL;
7652 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7653 NL80211_EXT_FEATURE_VHT_IBSS))
7654 return -EINVAL;
7655 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007656 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007657 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007658 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007659
Johannes Berg04a773a2009-04-19 21:24:32 +02007660 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007661 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007662
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007663 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7664 u8 *rates =
7665 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7666 int n_rates =
7667 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7668 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007669 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007670
Johannes Berg34850ab2011-07-18 18:08:35 +02007671 err = ieee80211_get_ratemask(sband, rates, n_rates,
7672 &ibss.basic_rates);
7673 if (err)
7674 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007675 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007676
Simon Wunderlich803768f2013-06-28 10:39:58 +02007677 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7678 memcpy(&ibss.ht_capa_mask,
7679 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7680 sizeof(ibss.ht_capa_mask));
7681
7682 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7683 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7684 return -EINVAL;
7685 memcpy(&ibss.ht_capa,
7686 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7687 sizeof(ibss.ht_capa));
7688 }
7689
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007690 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7691 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7692 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7693 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007694
Johannes Berg4c476992010-10-04 21:36:35 +02007695 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307696 bool no_ht = false;
7697
Johannes Berg4c476992010-10-04 21:36:35 +02007698 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307699 info->attrs[NL80211_ATTR_KEYS],
7700 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007701 if (IS_ERR(connkeys))
7702 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307703
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007704 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7705 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007706 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307707 return -EINVAL;
7708 }
Johannes Berg4c476992010-10-04 21:36:35 +02007709 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007710
Antonio Quartulli267335d2012-01-31 20:25:47 +01007711 ibss.control_port =
7712 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7713
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007714 ibss.userspace_handles_dfs =
7715 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7716
Johannes Berg4c476992010-10-04 21:36:35 +02007717 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007718 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007719 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007720 return err;
7721}
7722
7723static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7724{
Johannes Berg4c476992010-10-04 21:36:35 +02007725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7726 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007727
Johannes Berg4c476992010-10-04 21:36:35 +02007728 if (!rdev->ops->leave_ibss)
7729 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007730
Johannes Berg4c476992010-10-04 21:36:35 +02007731 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7732 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007733
Johannes Berg4c476992010-10-04 21:36:35 +02007734 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007735}
7736
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007737static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7738{
7739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7740 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02007741 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007742 u32 nla_rate;
7743 int err;
7744
7745 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007746 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7747 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007748 return -EOPNOTSUPP;
7749
7750 if (!rdev->ops->set_mcast_rate)
7751 return -EOPNOTSUPP;
7752
7753 memset(mcast_rate, 0, sizeof(mcast_rate));
7754
7755 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7756 return -EINVAL;
7757
7758 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7759 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7760 return -EINVAL;
7761
Ilan Peera1056b12015-10-22 22:27:46 +03007762 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007763
7764 return err;
7765}
7766
Johannes Bergad7e7182013-11-13 13:37:47 +01007767static struct sk_buff *
7768__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007769 struct wireless_dev *wdev, int approxlen,
7770 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007771 enum nl80211_attrs attr,
7772 const struct nl80211_vendor_cmd_info *info,
7773 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007774{
7775 struct sk_buff *skb;
7776 void *hdr;
7777 struct nlattr *data;
7778
7779 skb = nlmsg_new(approxlen + 100, gfp);
7780 if (!skb)
7781 return NULL;
7782
7783 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7784 if (!hdr) {
7785 kfree_skb(skb);
7786 return NULL;
7787 }
7788
7789 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7790 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007791
7792 if (info) {
7793 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7794 info->vendor_id))
7795 goto nla_put_failure;
7796 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7797 info->subcmd))
7798 goto nla_put_failure;
7799 }
7800
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007801 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007802 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
7803 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007804 goto nla_put_failure;
7805 if (wdev->netdev &&
7806 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7807 wdev->netdev->ifindex))
7808 goto nla_put_failure;
7809 }
7810
Johannes Bergad7e7182013-11-13 13:37:47 +01007811 data = nla_nest_start(skb, attr);
7812
7813 ((void **)skb->cb)[0] = rdev;
7814 ((void **)skb->cb)[1] = hdr;
7815 ((void **)skb->cb)[2] = data;
7816
7817 return skb;
7818
7819 nla_put_failure:
7820 kfree_skb(skb);
7821 return NULL;
7822}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007823
Johannes Berge03ad6e2014-01-01 17:22:30 +01007824struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007825 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007826 enum nl80211_commands cmd,
7827 enum nl80211_attrs attr,
7828 int vendor_event_idx,
7829 int approxlen, gfp_t gfp)
7830{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007831 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007832 const struct nl80211_vendor_cmd_info *info;
7833
7834 switch (cmd) {
7835 case NL80211_CMD_TESTMODE:
7836 if (WARN_ON(vendor_event_idx != -1))
7837 return NULL;
7838 info = NULL;
7839 break;
7840 case NL80211_CMD_VENDOR:
7841 if (WARN_ON(vendor_event_idx < 0 ||
7842 vendor_event_idx >= wiphy->n_vendor_events))
7843 return NULL;
7844 info = &wiphy->vendor_events[vendor_event_idx];
7845 break;
7846 default:
7847 WARN_ON(1);
7848 return NULL;
7849 }
7850
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007851 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007852 cmd, attr, info, gfp);
7853}
7854EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7855
7856void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7857{
7858 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7859 void *hdr = ((void **)skb->cb)[1];
7860 struct nlattr *data = ((void **)skb->cb)[2];
7861 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7862
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007863 /* clear CB data for netlink core to own from now on */
7864 memset(skb->cb, 0, sizeof(skb->cb));
7865
Johannes Berge03ad6e2014-01-01 17:22:30 +01007866 nla_nest_end(skb, data);
7867 genlmsg_end(skb, hdr);
7868
7869 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7870 mcgrp = NL80211_MCGRP_VENDOR;
7871
7872 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7873 mcgrp, gfp);
7874}
7875EXPORT_SYMBOL(__cfg80211_send_event_skb);
7876
Johannes Bergaff89a92009-07-01 21:26:51 +02007877#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007878static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7879{
Johannes Berg4c476992010-10-04 21:36:35 +02007880 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007881 struct wireless_dev *wdev =
7882 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007883 int err;
7884
David Spinadelfc73f112013-07-31 18:04:15 +03007885 if (!rdev->ops->testmode_cmd)
7886 return -EOPNOTSUPP;
7887
7888 if (IS_ERR(wdev)) {
7889 err = PTR_ERR(wdev);
7890 if (err != -EINVAL)
7891 return err;
7892 wdev = NULL;
7893 } else if (wdev->wiphy != &rdev->wiphy) {
7894 return -EINVAL;
7895 }
7896
Johannes Bergaff89a92009-07-01 21:26:51 +02007897 if (!info->attrs[NL80211_ATTR_TESTDATA])
7898 return -EINVAL;
7899
Johannes Bergad7e7182013-11-13 13:37:47 +01007900 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007901 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007902 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7903 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007904 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007905
Johannes Bergaff89a92009-07-01 21:26:51 +02007906 return err;
7907}
7908
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007909static int nl80211_testmode_dump(struct sk_buff *skb,
7910 struct netlink_callback *cb)
7911{
Johannes Berg00918d32011-12-13 17:22:05 +01007912 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007913 int err;
7914 long phy_idx;
7915 void *data = NULL;
7916 int data_len = 0;
7917
Johannes Berg5fe231e2013-05-08 21:45:15 +02007918 rtnl_lock();
7919
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007920 if (cb->args[0]) {
7921 /*
7922 * 0 is a valid index, but not valid for args[0],
7923 * so we need to offset by 1.
7924 */
7925 phy_idx = cb->args[0] - 1;
7926 } else {
7927 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7928 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7929 nl80211_policy);
7930 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007931 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007932
Johannes Berg2bd7e352012-06-15 14:23:16 +02007933 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7934 nl80211_fam.attrbuf);
7935 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007936 err = PTR_ERR(rdev);
7937 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007938 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007939 phy_idx = rdev->wiphy_idx;
7940 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007941
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007942 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7943 cb->args[1] =
7944 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7945 }
7946
7947 if (cb->args[1]) {
7948 data = nla_data((void *)cb->args[1]);
7949 data_len = nla_len((void *)cb->args[1]);
7950 }
7951
Johannes Berg00918d32011-12-13 17:22:05 +01007952 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7953 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007954 err = -ENOENT;
7955 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007956 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007957
Johannes Berg00918d32011-12-13 17:22:05 +01007958 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007959 err = -EOPNOTSUPP;
7960 goto out_err;
7961 }
7962
7963 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007964 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007965 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7966 NL80211_CMD_TESTMODE);
7967 struct nlattr *tmdata;
7968
Dan Carpentercb35fba2013-08-14 14:50:01 +03007969 if (!hdr)
7970 break;
7971
David S. Miller9360ffd2012-03-29 04:41:26 -04007972 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007973 genlmsg_cancel(skb, hdr);
7974 break;
7975 }
7976
7977 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7978 if (!tmdata) {
7979 genlmsg_cancel(skb, hdr);
7980 break;
7981 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007982 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007983 nla_nest_end(skb, tmdata);
7984
7985 if (err == -ENOBUFS || err == -ENOENT) {
7986 genlmsg_cancel(skb, hdr);
7987 break;
7988 } else if (err) {
7989 genlmsg_cancel(skb, hdr);
7990 goto out_err;
7991 }
7992
7993 genlmsg_end(skb, hdr);
7994 }
7995
7996 err = skb->len;
7997 /* see above */
7998 cb->args[0] = phy_idx + 1;
7999 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008000 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008001 return err;
8002}
Johannes Bergaff89a92009-07-01 21:26:51 +02008003#endif
8004
Samuel Ortizb23aa672009-07-01 21:26:54 +02008005static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8006{
Johannes Berg4c476992010-10-04 21:36:35 +02008007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8008 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008009 struct cfg80211_connect_params connect;
8010 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008011 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008012 int err;
8013
8014 memset(&connect, 0, sizeof(connect));
8015
8016 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8017 return -EINVAL;
8018
8019 if (!info->attrs[NL80211_ATTR_SSID] ||
8020 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8021 return -EINVAL;
8022
8023 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8024 connect.auth_type =
8025 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008026 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8027 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008028 return -EINVAL;
8029 } else
8030 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8031
8032 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8033
Johannes Bergc0692b82010-08-27 14:26:53 +03008034 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008035 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008036 if (err)
8037 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008038
Johannes Berg074ac8d2010-09-16 14:58:22 +02008039 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008040 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8041 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008042
Johannes Berg79c97e92009-07-07 03:56:12 +02008043 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008044
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308045 connect.bg_scan_period = -1;
8046 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8047 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8048 connect.bg_scan_period =
8049 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8050 }
8051
Samuel Ortizb23aa672009-07-01 21:26:54 +02008052 if (info->attrs[NL80211_ATTR_MAC])
8053 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008054 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8055 connect.bssid_hint =
8056 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008057 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8058 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8059
8060 if (info->attrs[NL80211_ATTR_IE]) {
8061 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8062 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8063 }
8064
Jouni Malinencee00a92013-01-15 17:15:57 +02008065 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8066 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8067 if (connect.mfp != NL80211_MFP_REQUIRED &&
8068 connect.mfp != NL80211_MFP_NO)
8069 return -EINVAL;
8070 } else {
8071 connect.mfp = NL80211_MFP_NO;
8072 }
8073
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008074 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8075 connect.prev_bssid =
8076 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8077
Samuel Ortizb23aa672009-07-01 21:26:54 +02008078 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008079 connect.channel = nl80211_get_valid_chan(
8080 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8081 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008082 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008083 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008084 connect.channel_hint = nl80211_get_valid_chan(
8085 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8086 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008087 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008088 }
8089
Johannes Bergfffd0932009-07-08 14:22:54 +02008090 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8091 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308092 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008093 if (IS_ERR(connkeys))
8094 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008095 }
8096
Ben Greear7e7c8922011-11-18 11:31:59 -08008097 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8098 connect.flags |= ASSOC_REQ_DISABLE_HT;
8099
8100 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8101 memcpy(&connect.ht_capa_mask,
8102 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8103 sizeof(connect.ht_capa_mask));
8104
8105 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008106 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008107 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008108 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008109 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008110 memcpy(&connect.ht_capa,
8111 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8112 sizeof(connect.ht_capa));
8113 }
8114
Johannes Bergee2aca32013-02-21 17:36:01 +01008115 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8116 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8117
8118 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8119 memcpy(&connect.vht_capa_mask,
8120 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8121 sizeof(connect.vht_capa_mask));
8122
8123 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8124 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008125 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008126 return -EINVAL;
8127 }
8128 memcpy(&connect.vht_capa,
8129 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8130 sizeof(connect.vht_capa));
8131 }
8132
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008133 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008134 if (!((rdev->wiphy.features &
8135 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8136 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8137 !wiphy_ext_feature_isset(&rdev->wiphy,
8138 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008139 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008140 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008141 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008142 connect.flags |= ASSOC_REQ_USE_RRM;
8143 }
8144
Lior David34d50512016-01-28 10:58:25 +02008145 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008146 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008147 kzfree(connkeys);
8148 return -EOPNOTSUPP;
8149 }
8150
Arend van Spriel38de03d2016-03-02 20:37:18 +01008151 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8152 /* bss selection makes no sense if bssid is set */
8153 if (connect.bssid) {
8154 kzfree(connkeys);
8155 return -EINVAL;
8156 }
8157
8158 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8159 wiphy, &connect.bss_select);
8160 if (err) {
8161 kzfree(connkeys);
8162 return err;
8163 }
8164 }
8165
Johannes Berg83739b02013-05-15 17:44:01 +02008166 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008167 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8168 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008169 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008170 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008171 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008172 return err;
8173}
8174
8175static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8176{
Johannes Berg4c476992010-10-04 21:36:35 +02008177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8178 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008179 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008180 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008181
8182 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8183 reason = WLAN_REASON_DEAUTH_LEAVING;
8184 else
8185 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8186
8187 if (reason == 0)
8188 return -EINVAL;
8189
Johannes Berg074ac8d2010-09-16 14:58:22 +02008190 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008191 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8192 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008193
Johannes Berg83739b02013-05-15 17:44:01 +02008194 wdev_lock(dev->ieee80211_ptr);
8195 ret = cfg80211_disconnect(rdev, dev, reason, true);
8196 wdev_unlock(dev->ieee80211_ptr);
8197 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008198}
8199
Johannes Berg463d0182009-07-14 00:33:35 +02008200static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8201{
Johannes Berg4c476992010-10-04 21:36:35 +02008202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008203 struct net *net;
8204 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008205
Vadim Kochan4b681c82015-01-12 16:34:05 +02008206 if (info->attrs[NL80211_ATTR_PID]) {
8207 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8208
8209 net = get_net_ns_by_pid(pid);
8210 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8211 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8212
8213 net = get_net_ns_by_fd(fd);
8214 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008215 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008216 }
Johannes Berg463d0182009-07-14 00:33:35 +02008217
Johannes Berg4c476992010-10-04 21:36:35 +02008218 if (IS_ERR(net))
8219 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008220
8221 err = 0;
8222
8223 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008224 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8225 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008226
Johannes Berg463d0182009-07-14 00:33:35 +02008227 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008228 return err;
8229}
8230
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008231static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8232{
Johannes Berg4c476992010-10-04 21:36:35 +02008233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008234 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8235 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008236 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008237 struct cfg80211_pmksa pmksa;
8238
8239 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8240
8241 if (!info->attrs[NL80211_ATTR_MAC])
8242 return -EINVAL;
8243
8244 if (!info->attrs[NL80211_ATTR_PMKID])
8245 return -EINVAL;
8246
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008247 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8248 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8249
Johannes Berg074ac8d2010-09-16 14:58:22 +02008250 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008251 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8252 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008253
8254 switch (info->genlhdr->cmd) {
8255 case NL80211_CMD_SET_PMKSA:
8256 rdev_ops = rdev->ops->set_pmksa;
8257 break;
8258 case NL80211_CMD_DEL_PMKSA:
8259 rdev_ops = rdev->ops->del_pmksa;
8260 break;
8261 default:
8262 WARN_ON(1);
8263 break;
8264 }
8265
Johannes Berg4c476992010-10-04 21:36:35 +02008266 if (!rdev_ops)
8267 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008268
Johannes Berg4c476992010-10-04 21:36:35 +02008269 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008270}
8271
8272static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8273{
Johannes Berg4c476992010-10-04 21:36:35 +02008274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8275 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008276
Johannes Berg074ac8d2010-09-16 14:58:22 +02008277 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008278 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8279 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008280
Johannes Berg4c476992010-10-04 21:36:35 +02008281 if (!rdev->ops->flush_pmksa)
8282 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008283
Hila Gonene35e4d22012-06-27 17:19:42 +03008284 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008285}
8286
Arik Nemtsov109086c2011-09-28 14:12:50 +03008287static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8288{
8289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8290 struct net_device *dev = info->user_ptr[1];
8291 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308292 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008293 u16 status_code;
8294 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008295 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008296
8297 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8298 !rdev->ops->tdls_mgmt)
8299 return -EOPNOTSUPP;
8300
8301 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8302 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8303 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8304 !info->attrs[NL80211_ATTR_IE] ||
8305 !info->attrs[NL80211_ATTR_MAC])
8306 return -EINVAL;
8307
8308 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8309 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8310 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8311 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008312 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308313 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8314 peer_capability =
8315 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008316
Hila Gonene35e4d22012-06-27 17:19:42 +03008317 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308318 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008319 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008320 nla_data(info->attrs[NL80211_ATTR_IE]),
8321 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008322}
8323
8324static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8325{
8326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8327 struct net_device *dev = info->user_ptr[1];
8328 enum nl80211_tdls_operation operation;
8329 u8 *peer;
8330
8331 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8332 !rdev->ops->tdls_oper)
8333 return -EOPNOTSUPP;
8334
8335 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8336 !info->attrs[NL80211_ATTR_MAC])
8337 return -EINVAL;
8338
8339 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8340 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8341
Hila Gonene35e4d22012-06-27 17:19:42 +03008342 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008343}
8344
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008345static int nl80211_remain_on_channel(struct sk_buff *skb,
8346 struct genl_info *info)
8347{
Johannes Berg4c476992010-10-04 21:36:35 +02008348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008349 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008350 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008351 struct sk_buff *msg;
8352 void *hdr;
8353 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008354 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008355 int err;
8356
8357 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8358 !info->attrs[NL80211_ATTR_DURATION])
8359 return -EINVAL;
8360
8361 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8362
Johannes Berg7c4ef712011-11-18 15:33:48 +01008363 if (!rdev->ops->remain_on_channel ||
8364 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008365 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008366
Johannes Bergebf348f2012-06-01 12:50:54 +02008367 /*
8368 * We should be on that channel for at least a minimum amount of
8369 * time (10ms) but no longer than the driver supports.
8370 */
8371 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8372 duration > rdev->wiphy.max_remain_on_channel_duration)
8373 return -EINVAL;
8374
Johannes Berg683b6d32012-11-08 21:25:48 +01008375 err = nl80211_parse_chandef(rdev, info, &chandef);
8376 if (err)
8377 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008378
8379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008380 if (!msg)
8381 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008382
Eric W. Biederman15e47302012-09-07 20:12:54 +00008383 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008384 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008385 if (!hdr) {
8386 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008387 goto free_msg;
8388 }
8389
Johannes Berg683b6d32012-11-08 21:25:48 +01008390 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8391 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008392
8393 if (err)
8394 goto free_msg;
8395
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008396 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8397 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008398 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008399
8400 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008401
8402 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008403
8404 nla_put_failure:
8405 err = -ENOBUFS;
8406 free_msg:
8407 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008408 return err;
8409}
8410
8411static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8412 struct genl_info *info)
8413{
Johannes Berg4c476992010-10-04 21:36:35 +02008414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008415 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008416 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008417
8418 if (!info->attrs[NL80211_ATTR_COOKIE])
8419 return -EINVAL;
8420
Johannes Berg4c476992010-10-04 21:36:35 +02008421 if (!rdev->ops->cancel_remain_on_channel)
8422 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008423
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008424 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8425
Hila Gonene35e4d22012-06-27 17:19:42 +03008426 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008427}
8428
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008429static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8430 u8 *rates, u8 rates_len)
8431{
8432 u8 i;
8433 u32 mask = 0;
8434
8435 for (i = 0; i < rates_len; i++) {
8436 int rate = (rates[i] & 0x7f) * 5;
8437 int ridx;
8438 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8439 struct ieee80211_rate *srate =
8440 &sband->bitrates[ridx];
8441 if (rate == srate->bitrate) {
8442 mask |= 1 << ridx;
8443 break;
8444 }
8445 }
8446 if (ridx == sband->n_bitrates)
8447 return 0; /* rate not found */
8448 }
8449
8450 return mask;
8451}
8452
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008453static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8454 u8 *rates, u8 rates_len,
8455 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8456{
8457 u8 i;
8458
8459 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8460
8461 for (i = 0; i < rates_len; i++) {
8462 int ridx, rbit;
8463
8464 ridx = rates[i] / 8;
8465 rbit = BIT(rates[i] % 8);
8466
8467 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008468 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008469 return false;
8470
8471 /* check availability */
8472 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8473 mcs[ridx] |= rbit;
8474 else
8475 return false;
8476 }
8477
8478 return true;
8479}
8480
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008481static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8482{
8483 u16 mcs_mask = 0;
8484
8485 switch (vht_mcs_map) {
8486 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8487 break;
8488 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8489 mcs_mask = 0x00FF;
8490 break;
8491 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8492 mcs_mask = 0x01FF;
8493 break;
8494 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8495 mcs_mask = 0x03FF;
8496 break;
8497 default:
8498 break;
8499 }
8500
8501 return mcs_mask;
8502}
8503
8504static void vht_build_mcs_mask(u16 vht_mcs_map,
8505 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8506{
8507 u8 nss;
8508
8509 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8510 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8511 vht_mcs_map >>= 2;
8512 }
8513}
8514
8515static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8516 struct nl80211_txrate_vht *txrate,
8517 u16 mcs[NL80211_VHT_NSS_MAX])
8518{
8519 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8520 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8521 u8 i;
8522
8523 if (!sband->vht_cap.vht_supported)
8524 return false;
8525
8526 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8527
8528 /* Build vht_mcs_mask from VHT capabilities */
8529 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8530
8531 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8532 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8533 mcs[i] = txrate->mcs[i];
8534 else
8535 return false;
8536 }
8537
8538 return true;
8539}
8540
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008541static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008542 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8543 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008544 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8545 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008546 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008547 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008548};
8549
8550static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8551 struct genl_info *info)
8552{
8553 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008555 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008556 int rem, i;
8557 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008558 struct nlattr *tx_rates;
8559 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008560 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008561
Johannes Berg4c476992010-10-04 21:36:35 +02008562 if (!rdev->ops->set_bitrate_mask)
8563 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008564
8565 memset(&mask, 0, sizeof(mask));
8566 /* Default to all rates enabled */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008567 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008568 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008569
8570 if (!sband)
8571 continue;
8572
8573 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008574 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008575 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008576 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008577
8578 if (!sband->vht_cap.vht_supported)
8579 continue;
8580
8581 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8582 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008583 }
8584
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008585 /* if no rates are given set it back to the defaults */
8586 if (!info->attrs[NL80211_ATTR_TX_RATES])
8587 goto out;
8588
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008589 /*
8590 * The nested attribute uses enum nl80211_band as the index. This maps
Johannes Berg57fbcce2016-04-12 15:56:15 +02008591 * directly to the enum nl80211_band values used in cfg80211.
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008592 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008593 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008594 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008595 enum nl80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008596 int err;
8597
Johannes Berg57fbcce2016-04-12 15:56:15 +02008598 if (band < 0 || band >= NUM_NL80211_BANDS)
Johannes Berg4c476992010-10-04 21:36:35 +02008599 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008600 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008601 if (sband == NULL)
8602 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008603 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8604 nla_len(tx_rates), nl80211_txattr_policy);
8605 if (err)
8606 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008607 if (tb[NL80211_TXRATE_LEGACY]) {
8608 mask.control[band].legacy = rateset_to_mask(
8609 sband,
8610 nla_data(tb[NL80211_TXRATE_LEGACY]),
8611 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308612 if ((mask.control[band].legacy == 0) &&
8613 nla_len(tb[NL80211_TXRATE_LEGACY]))
8614 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008615 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008616 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008617 if (!ht_rateset_to_mask(
8618 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008619 nla_data(tb[NL80211_TXRATE_HT]),
8620 nla_len(tb[NL80211_TXRATE_HT]),
8621 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008622 return -EINVAL;
8623 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008624 if (tb[NL80211_TXRATE_VHT]) {
8625 if (!vht_set_mcs_mask(
8626 sband,
8627 nla_data(tb[NL80211_TXRATE_VHT]),
8628 mask.control[band].vht_mcs))
8629 return -EINVAL;
8630 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008631 if (tb[NL80211_TXRATE_GI]) {
8632 mask.control[band].gi =
8633 nla_get_u8(tb[NL80211_TXRATE_GI]);
8634 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8635 return -EINVAL;
8636 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008637
8638 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008639 /* don't allow empty legacy rates if HT or VHT
8640 * are not even supported.
8641 */
8642 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8643 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008644 return -EINVAL;
8645
8646 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008647 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008648 goto out;
8649
8650 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8651 if (mask.control[band].vht_mcs[i])
8652 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008653
8654 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008655 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008656 }
8657 }
8658
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008659out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008660 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008661}
8662
Johannes Berg2e161f72010-08-12 15:38:38 +02008663static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008664{
Johannes Berg4c476992010-10-04 21:36:35 +02008665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008666 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008667 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008668
8669 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8670 return -EINVAL;
8671
Johannes Berg2e161f72010-08-12 15:38:38 +02008672 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8673 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008674
Johannes Berg71bbc992012-06-15 15:30:18 +02008675 switch (wdev->iftype) {
8676 case NL80211_IFTYPE_STATION:
8677 case NL80211_IFTYPE_ADHOC:
8678 case NL80211_IFTYPE_P2P_CLIENT:
8679 case NL80211_IFTYPE_AP:
8680 case NL80211_IFTYPE_AP_VLAN:
8681 case NL80211_IFTYPE_MESH_POINT:
8682 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008683 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008684 break;
8685 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008686 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008687 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008688
8689 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008690 if (!rdev->ops->mgmt_tx)
8691 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008692
Eric W. Biederman15e47302012-09-07 20:12:54 +00008693 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008694 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8695 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008696}
8697
Johannes Berg2e161f72010-08-12 15:38:38 +02008698static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008699{
Johannes Berg4c476992010-10-04 21:36:35 +02008700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008701 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008702 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008703 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008704 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008705 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008706 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008707 struct cfg80211_mgmt_tx_params params = {
8708 .dont_wait_for_ack =
8709 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8710 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008711
Johannes Berg683b6d32012-11-08 21:25:48 +01008712 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008713 return -EINVAL;
8714
Johannes Berg4c476992010-10-04 21:36:35 +02008715 if (!rdev->ops->mgmt_tx)
8716 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008717
Johannes Berg71bbc992012-06-15 15:30:18 +02008718 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008719 case NL80211_IFTYPE_P2P_DEVICE:
8720 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8721 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008722 case NL80211_IFTYPE_STATION:
8723 case NL80211_IFTYPE_ADHOC:
8724 case NL80211_IFTYPE_P2P_CLIENT:
8725 case NL80211_IFTYPE_AP:
8726 case NL80211_IFTYPE_AP_VLAN:
8727 case NL80211_IFTYPE_MESH_POINT:
8728 case NL80211_IFTYPE_P2P_GO:
8729 break;
8730 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008731 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008732 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008733
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008734 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008735 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008736 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008737 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008738
8739 /*
8740 * We should wait on the channel for at least a minimum amount
8741 * of time (10ms) but no longer than the driver supports.
8742 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008743 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8744 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008745 return -EINVAL;
8746
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008747 }
8748
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008749 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008750
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008751 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008752 return -EINVAL;
8753
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008754 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308755
Antonio Quartulliea141b752013-06-11 14:20:03 +02008756 /* get the channel if any has been specified, otherwise pass NULL to
8757 * the driver. The latter will use the current one
8758 */
8759 chandef.chan = NULL;
8760 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8761 err = nl80211_parse_chandef(rdev, info, &chandef);
8762 if (err)
8763 return err;
8764 }
8765
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008766 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008767 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008768
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008769 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8770 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8771
8772 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8773 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8774 int i;
8775
8776 if (len % sizeof(u16))
8777 return -EINVAL;
8778
8779 params.n_csa_offsets = len / sizeof(u16);
8780 params.csa_offsets =
8781 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8782
8783 /* check that all the offsets fit the frame */
8784 for (i = 0; i < params.n_csa_offsets; i++) {
8785 if (params.csa_offsets[i] >= params.len)
8786 return -EINVAL;
8787 }
8788 }
8789
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008790 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8792 if (!msg)
8793 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008794
Eric W. Biederman15e47302012-09-07 20:12:54 +00008795 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008796 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008797 if (!hdr) {
8798 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008799 goto free_msg;
8800 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008801 }
Johannes Berge247bd902011-11-04 11:18:21 +01008802
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008803 params.chan = chandef.chan;
8804 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008805 if (err)
8806 goto free_msg;
8807
Johannes Berge247bd902011-11-04 11:18:21 +01008808 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008809 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8810 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008811 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008812
Johannes Berge247bd902011-11-04 11:18:21 +01008813 genlmsg_end(msg, hdr);
8814 return genlmsg_reply(msg, info);
8815 }
8816
8817 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008818
8819 nla_put_failure:
8820 err = -ENOBUFS;
8821 free_msg:
8822 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008823 return err;
8824}
8825
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008826static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8827{
8828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008829 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008830 u64 cookie;
8831
8832 if (!info->attrs[NL80211_ATTR_COOKIE])
8833 return -EINVAL;
8834
8835 if (!rdev->ops->mgmt_tx_cancel_wait)
8836 return -EOPNOTSUPP;
8837
Johannes Berg71bbc992012-06-15 15:30:18 +02008838 switch (wdev->iftype) {
8839 case NL80211_IFTYPE_STATION:
8840 case NL80211_IFTYPE_ADHOC:
8841 case NL80211_IFTYPE_P2P_CLIENT:
8842 case NL80211_IFTYPE_AP:
8843 case NL80211_IFTYPE_AP_VLAN:
8844 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008845 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008846 break;
8847 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008848 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008849 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008850
8851 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8852
Hila Gonene35e4d22012-06-27 17:19:42 +03008853 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008854}
8855
Kalle Valoffb9eb32010-02-17 17:58:10 +02008856static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8857{
Johannes Berg4c476992010-10-04 21:36:35 +02008858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008859 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008860 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008861 u8 ps_state;
8862 bool state;
8863 int err;
8864
Johannes Berg4c476992010-10-04 21:36:35 +02008865 if (!info->attrs[NL80211_ATTR_PS_STATE])
8866 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008867
8868 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8869
Johannes Berg4c476992010-10-04 21:36:35 +02008870 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8871 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008872
8873 wdev = dev->ieee80211_ptr;
8874
Johannes Berg4c476992010-10-04 21:36:35 +02008875 if (!rdev->ops->set_power_mgmt)
8876 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008877
8878 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8879
8880 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008881 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008882
Hila Gonene35e4d22012-06-27 17:19:42 +03008883 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008884 if (!err)
8885 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008886 return err;
8887}
8888
8889static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8890{
Johannes Berg4c476992010-10-04 21:36:35 +02008891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008892 enum nl80211_ps_state ps_state;
8893 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008894 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008895 struct sk_buff *msg;
8896 void *hdr;
8897 int err;
8898
Kalle Valoffb9eb32010-02-17 17:58:10 +02008899 wdev = dev->ieee80211_ptr;
8900
Johannes Berg4c476992010-10-04 21:36:35 +02008901 if (!rdev->ops->set_power_mgmt)
8902 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008903
8904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008905 if (!msg)
8906 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008907
Eric W. Biederman15e47302012-09-07 20:12:54 +00008908 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008909 NL80211_CMD_GET_POWER_SAVE);
8910 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008911 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008912 goto free_msg;
8913 }
8914
8915 if (wdev->ps)
8916 ps_state = NL80211_PS_ENABLED;
8917 else
8918 ps_state = NL80211_PS_DISABLED;
8919
David S. Miller9360ffd2012-03-29 04:41:26 -04008920 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8921 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008922
8923 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008924 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008925
Johannes Berg4c476992010-10-04 21:36:35 +02008926 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008927 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008928 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008929 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008930 return err;
8931}
8932
Johannes Berg94e860f2014-01-20 23:58:15 +01008933static const struct nla_policy
8934nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008935 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8936 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8937 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008938 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8939 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8940 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008941};
8942
Thomas Pedersen84f10702012-07-12 16:17:33 -07008943static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008944 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008945{
8946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008947 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008948 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008949
Johannes Bergd9d8b012012-11-26 12:51:52 +01008950 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008951 return -EINVAL;
8952
Thomas Pedersen84f10702012-07-12 16:17:33 -07008953 if (!rdev->ops->set_cqm_txe_config)
8954 return -EOPNOTSUPP;
8955
8956 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8957 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8958 return -EOPNOTSUPP;
8959
Hila Gonene35e4d22012-06-27 17:19:42 +03008960 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008961}
8962
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008963static int nl80211_set_cqm_rssi(struct genl_info *info,
8964 s32 threshold, u32 hysteresis)
8965{
Johannes Berg4c476992010-10-04 21:36:35 +02008966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008967 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008968 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008969
8970 if (threshold > 0)
8971 return -EINVAL;
8972
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008973 /* disabling - hysteresis should also be zero then */
8974 if (threshold == 0)
8975 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008976
Johannes Berg4c476992010-10-04 21:36:35 +02008977 if (!rdev->ops->set_cqm_rssi_config)
8978 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008979
Johannes Berg074ac8d2010-09-16 14:58:22 +02008980 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008981 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8982 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008983
Hila Gonene35e4d22012-06-27 17:19:42 +03008984 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008985}
8986
8987static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8988{
8989 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8990 struct nlattr *cqm;
8991 int err;
8992
8993 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008994 if (!cqm)
8995 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008996
8997 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8998 nl80211_attr_cqm_policy);
8999 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009000 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009001
9002 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9003 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009004 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9005 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009006
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009007 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9008 }
9009
9010 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9011 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9012 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9013 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9014 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9015 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9016
9017 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9018 }
9019
9020 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009021}
9022
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009023static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9024{
9025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9026 struct net_device *dev = info->user_ptr[1];
9027 struct ocb_setup setup = {};
9028 int err;
9029
9030 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9031 if (err)
9032 return err;
9033
9034 return cfg80211_join_ocb(rdev, dev, &setup);
9035}
9036
9037static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9038{
9039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9040 struct net_device *dev = info->user_ptr[1];
9041
9042 return cfg80211_leave_ocb(rdev, dev);
9043}
9044
Johannes Berg29cbe682010-12-03 09:20:44 +01009045static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9046{
9047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9048 struct net_device *dev = info->user_ptr[1];
9049 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009050 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009051 int err;
9052
9053 /* start with default */
9054 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009055 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009056
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009057 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009058 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009059 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009060 if (err)
9061 return err;
9062 }
9063
9064 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9065 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9066 return -EINVAL;
9067
Javier Cardonac80d5452010-12-16 17:37:49 -08009068 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9069 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9070
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009071 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9072 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9073 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9074 return -EINVAL;
9075
Marco Porsch9bdbf042013-01-07 16:04:51 +01009076 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9077 setup.beacon_interval =
9078 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
9079 if (setup.beacon_interval < 10 ||
9080 setup.beacon_interval > 10000)
9081 return -EINVAL;
9082 }
9083
9084 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9085 setup.dtim_period =
9086 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9087 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9088 return -EINVAL;
9089 }
9090
Javier Cardonac80d5452010-12-16 17:37:49 -08009091 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9092 /* parse additional setup parameters if given */
9093 err = nl80211_parse_mesh_setup(info, &setup);
9094 if (err)
9095 return err;
9096 }
9097
Thomas Pedersend37bb182013-03-04 13:06:13 -08009098 if (setup.user_mpm)
9099 cfg.auto_open_plinks = false;
9100
Johannes Bergcc1d2802012-05-16 23:50:20 +02009101 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009102 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9103 if (err)
9104 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009105 } else {
9106 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009107 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009108 }
9109
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009110 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9111 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9112 int n_rates =
9113 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9114 struct ieee80211_supported_band *sband;
9115
9116 if (!setup.chandef.chan)
9117 return -EINVAL;
9118
9119 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9120
9121 err = ieee80211_get_ratemask(sband, rates, n_rates,
9122 &setup.basic_rates);
9123 if (err)
9124 return err;
9125 }
9126
Javier Cardonac80d5452010-12-16 17:37:49 -08009127 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009128}
9129
9130static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9131{
9132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9133 struct net_device *dev = info->user_ptr[1];
9134
9135 return cfg80211_leave_mesh(rdev, dev);
9136}
9137
Johannes Bergdfb89c52012-06-27 09:23:48 +02009138#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009139static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9140 struct cfg80211_registered_device *rdev)
9141{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009142 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009143 struct nlattr *nl_pats, *nl_pat;
9144 int i, pat_len;
9145
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009146 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009147 return 0;
9148
9149 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9150 if (!nl_pats)
9151 return -ENOBUFS;
9152
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009153 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009154 nl_pat = nla_nest_start(msg, i + 1);
9155 if (!nl_pat)
9156 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009157 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009158 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009159 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009160 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9161 wowlan->patterns[i].pattern) ||
9162 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009163 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009164 return -ENOBUFS;
9165 nla_nest_end(msg, nl_pat);
9166 }
9167 nla_nest_end(msg, nl_pats);
9168
9169 return 0;
9170}
9171
Johannes Berg2a0e0472013-01-23 22:57:40 +01009172static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9173 struct cfg80211_wowlan_tcp *tcp)
9174{
9175 struct nlattr *nl_tcp;
9176
9177 if (!tcp)
9178 return 0;
9179
9180 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9181 if (!nl_tcp)
9182 return -ENOBUFS;
9183
Jiri Benc930345e2015-03-29 16:59:25 +02009184 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9185 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009186 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9187 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9188 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9189 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9190 tcp->payload_len, tcp->payload) ||
9191 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9192 tcp->data_interval) ||
9193 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9194 tcp->wake_len, tcp->wake_data) ||
9195 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9196 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9197 return -ENOBUFS;
9198
9199 if (tcp->payload_seq.len &&
9200 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9201 sizeof(tcp->payload_seq), &tcp->payload_seq))
9202 return -ENOBUFS;
9203
9204 if (tcp->payload_tok.len &&
9205 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9206 sizeof(tcp->payload_tok) + tcp->tokens_size,
9207 &tcp->payload_tok))
9208 return -ENOBUFS;
9209
Johannes Berge248ad32013-05-16 10:24:28 +02009210 nla_nest_end(msg, nl_tcp);
9211
Johannes Berg2a0e0472013-01-23 22:57:40 +01009212 return 0;
9213}
9214
Luciano Coelho75453cc2015-01-09 14:06:37 +02009215static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9216 struct cfg80211_sched_scan_request *req)
9217{
Avraham Stern3b06d272015-10-12 09:51:34 +03009218 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009219 int i;
9220
9221 if (!req)
9222 return 0;
9223
9224 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9225 if (!nd)
9226 return -ENOBUFS;
9227
Avraham Stern3b06d272015-10-12 09:51:34 +03009228 if (req->n_scan_plans == 1 &&
9229 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9230 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009231 return -ENOBUFS;
9232
Luciano Coelho21fea562015-03-17 16:36:01 +02009233 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9234 return -ENOBUFS;
9235
Luciano Coelho75453cc2015-01-09 14:06:37 +02009236 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9237 if (!freqs)
9238 return -ENOBUFS;
9239
9240 for (i = 0; i < req->n_channels; i++)
9241 nla_put_u32(msg, i, req->channels[i]->center_freq);
9242
9243 nla_nest_end(msg, freqs);
9244
9245 if (req->n_match_sets) {
9246 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9247 for (i = 0; i < req->n_match_sets; i++) {
9248 match = nla_nest_start(msg, i);
9249 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9250 req->match_sets[i].ssid.ssid_len,
9251 req->match_sets[i].ssid.ssid);
9252 nla_nest_end(msg, match);
9253 }
9254 nla_nest_end(msg, matches);
9255 }
9256
Avraham Stern3b06d272015-10-12 09:51:34 +03009257 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9258 if (!scan_plans)
9259 return -ENOBUFS;
9260
9261 for (i = 0; i < req->n_scan_plans; i++) {
9262 scan_plan = nla_nest_start(msg, i + 1);
9263 if (!scan_plan ||
9264 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9265 req->scan_plans[i].interval) ||
9266 (req->scan_plans[i].iterations &&
9267 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9268 req->scan_plans[i].iterations)))
9269 return -ENOBUFS;
9270 nla_nest_end(msg, scan_plan);
9271 }
9272 nla_nest_end(msg, scan_plans);
9273
Luciano Coelho75453cc2015-01-09 14:06:37 +02009274 nla_nest_end(msg, nd);
9275
9276 return 0;
9277}
9278
Johannes Bergff1b6e62011-05-04 15:37:28 +02009279static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9280{
9281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9282 struct sk_buff *msg;
9283 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009284 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009285
Johannes Berg964dc9e2013-06-03 17:25:34 +02009286 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009287 return -EOPNOTSUPP;
9288
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009289 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009290 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009291 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9292 rdev->wiphy.wowlan_config->tcp->payload_len +
9293 rdev->wiphy.wowlan_config->tcp->wake_len +
9294 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009295 }
9296
9297 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009298 if (!msg)
9299 return -ENOMEM;
9300
Eric W. Biederman15e47302012-09-07 20:12:54 +00009301 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009302 NL80211_CMD_GET_WOWLAN);
9303 if (!hdr)
9304 goto nla_put_failure;
9305
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009306 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009307 struct nlattr *nl_wowlan;
9308
9309 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9310 if (!nl_wowlan)
9311 goto nla_put_failure;
9312
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009313 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009314 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009315 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009316 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009317 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009318 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009319 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009320 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009321 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009322 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009323 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009324 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009325 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009326 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9327 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009328
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009329 if (nl80211_send_wowlan_patterns(msg, rdev))
9330 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009331
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009332 if (nl80211_send_wowlan_tcp(msg,
9333 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009334 goto nla_put_failure;
9335
Luciano Coelho75453cc2015-01-09 14:06:37 +02009336 if (nl80211_send_wowlan_nd(
9337 msg,
9338 rdev->wiphy.wowlan_config->nd_config))
9339 goto nla_put_failure;
9340
Johannes Bergff1b6e62011-05-04 15:37:28 +02009341 nla_nest_end(msg, nl_wowlan);
9342 }
9343
9344 genlmsg_end(msg, hdr);
9345 return genlmsg_reply(msg, info);
9346
9347nla_put_failure:
9348 nlmsg_free(msg);
9349 return -ENOBUFS;
9350}
9351
Johannes Berg2a0e0472013-01-23 22:57:40 +01009352static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9353 struct nlattr *attr,
9354 struct cfg80211_wowlan *trig)
9355{
9356 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9357 struct cfg80211_wowlan_tcp *cfg;
9358 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9359 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9360 u32 size;
9361 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9362 int err, port;
9363
Johannes Berg964dc9e2013-06-03 17:25:34 +02009364 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009365 return -EINVAL;
9366
9367 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9368 nla_data(attr), nla_len(attr),
9369 nl80211_wowlan_tcp_policy);
9370 if (err)
9371 return err;
9372
9373 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9374 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9375 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9376 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9377 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9378 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9379 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9380 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9381 return -EINVAL;
9382
9383 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009384 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009385 return -EINVAL;
9386
9387 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009388 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009389 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009390 return -EINVAL;
9391
9392 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009393 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009394 return -EINVAL;
9395
9396 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9397 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9398 return -EINVAL;
9399
9400 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9401 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9402
9403 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9404 tokens_size = tokln - sizeof(*tok);
9405
9406 if (!tok->len || tokens_size % tok->len)
9407 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009408 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009409 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009410 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009411 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009412 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009413 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009414 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009415 return -EINVAL;
9416 if (tok->offset + tok->len > data_size)
9417 return -EINVAL;
9418 }
9419
9420 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9421 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009422 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009423 return -EINVAL;
9424 if (seq->len == 0 || seq->len > 4)
9425 return -EINVAL;
9426 if (seq->len + seq->offset > data_size)
9427 return -EINVAL;
9428 }
9429
9430 size = sizeof(*cfg);
9431 size += data_size;
9432 size += wake_size + wake_mask_size;
9433 size += tokens_size;
9434
9435 cfg = kzalloc(size, GFP_KERNEL);
9436 if (!cfg)
9437 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009438 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9439 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009440 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9441 ETH_ALEN);
9442 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9443 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9444 else
9445 port = 0;
9446#ifdef CONFIG_INET
9447 /* allocate a socket and port for it and use it */
9448 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9449 IPPROTO_TCP, &cfg->sock, 1);
9450 if (err) {
9451 kfree(cfg);
9452 return err;
9453 }
9454 if (inet_csk_get_port(cfg->sock->sk, port)) {
9455 sock_release(cfg->sock);
9456 kfree(cfg);
9457 return -EADDRINUSE;
9458 }
9459 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9460#else
9461 if (!port) {
9462 kfree(cfg);
9463 return -EINVAL;
9464 }
9465 cfg->src_port = port;
9466#endif
9467
9468 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9469 cfg->payload_len = data_size;
9470 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9471 memcpy((void *)cfg->payload,
9472 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9473 data_size);
9474 if (seq)
9475 cfg->payload_seq = *seq;
9476 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9477 cfg->wake_len = wake_size;
9478 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9479 memcpy((void *)cfg->wake_data,
9480 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9481 wake_size);
9482 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9483 data_size + wake_size;
9484 memcpy((void *)cfg->wake_mask,
9485 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9486 wake_mask_size);
9487 if (tok) {
9488 cfg->tokens_size = tokens_size;
9489 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9490 }
9491
9492 trig->tcp = cfg;
9493
9494 return 0;
9495}
9496
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009497static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9498 const struct wiphy_wowlan_support *wowlan,
9499 struct nlattr *attr,
9500 struct cfg80211_wowlan *trig)
9501{
9502 struct nlattr **tb;
9503 int err;
9504
9505 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9506 if (!tb)
9507 return -ENOMEM;
9508
9509 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9510 err = -EOPNOTSUPP;
9511 goto out;
9512 }
9513
9514 err = nla_parse(tb, NL80211_ATTR_MAX,
9515 nla_data(attr), nla_len(attr),
9516 nl80211_policy);
9517 if (err)
9518 goto out;
9519
Johannes Bergad2b26a2014-06-12 21:39:05 +02009520 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009521 err = PTR_ERR_OR_ZERO(trig->nd_config);
9522 if (err)
9523 trig->nd_config = NULL;
9524
9525out:
9526 kfree(tb);
9527 return err;
9528}
9529
Johannes Bergff1b6e62011-05-04 15:37:28 +02009530static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9531{
9532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9533 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009534 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009535 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009536 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009537 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009538 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009539 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009540
Johannes Berg964dc9e2013-06-03 17:25:34 +02009541 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009542 return -EOPNOTSUPP;
9543
Johannes Bergae33bd82012-07-12 16:25:02 +02009544 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9545 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009546 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009547 goto set_wakeup;
9548 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009549
9550 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9551 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9552 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9553 nl80211_wowlan_policy);
9554 if (err)
9555 return err;
9556
9557 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9558 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9559 return -EINVAL;
9560 new_triggers.any = true;
9561 }
9562
9563 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9564 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9565 return -EINVAL;
9566 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009567 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009568 }
9569
9570 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9571 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9572 return -EINVAL;
9573 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009574 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009575 }
9576
Johannes Berg77dbbb12011-07-13 10:48:55 +02009577 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9578 return -EINVAL;
9579
9580 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9581 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9582 return -EINVAL;
9583 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009584 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009585 }
9586
9587 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9588 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9589 return -EINVAL;
9590 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009591 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009592 }
9593
9594 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9595 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9596 return -EINVAL;
9597 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009598 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009599 }
9600
9601 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9602 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9603 return -EINVAL;
9604 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009605 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009606 }
9607
Johannes Bergff1b6e62011-05-04 15:37:28 +02009608 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9609 struct nlattr *pat;
9610 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009611 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009612 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009613
Johannes Berg98fc4382015-03-01 09:10:13 +02009614 regular = true;
9615
Johannes Bergff1b6e62011-05-04 15:37:28 +02009616 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9617 rem)
9618 n_patterns++;
9619 if (n_patterns > wowlan->n_patterns)
9620 return -EINVAL;
9621
9622 new_triggers.patterns = kcalloc(n_patterns,
9623 sizeof(new_triggers.patterns[0]),
9624 GFP_KERNEL);
9625 if (!new_triggers.patterns)
9626 return -ENOMEM;
9627
9628 new_triggers.n_patterns = n_patterns;
9629 i = 0;
9630
9631 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9632 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009633 u8 *mask_pat;
9634
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009635 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9636 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009637 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009638 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9639 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009640 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009641 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009642 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009643 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009644 goto error;
9645 if (pat_len > wowlan->pattern_max_len ||
9646 pat_len < wowlan->pattern_min_len)
9647 goto error;
9648
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009649 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009650 pkt_offset = 0;
9651 else
9652 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009653 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009654 if (pkt_offset > wowlan->max_pkt_offset)
9655 goto error;
9656 new_triggers.patterns[i].pkt_offset = pkt_offset;
9657
Johannes Berg922bd802014-05-19 17:59:50 +02009658 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9659 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009660 err = -ENOMEM;
9661 goto error;
9662 }
Johannes Berg922bd802014-05-19 17:59:50 +02009663 new_triggers.patterns[i].mask = mask_pat;
9664 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009665 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009666 mask_pat += mask_len;
9667 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009668 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009669 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009670 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009671 pat_len);
9672 i++;
9673 }
9674 }
9675
Johannes Berg2a0e0472013-01-23 22:57:40 +01009676 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009677 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009678 err = nl80211_parse_wowlan_tcp(
9679 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9680 &new_triggers);
9681 if (err)
9682 goto error;
9683 }
9684
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009685 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009686 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009687 err = nl80211_parse_wowlan_nd(
9688 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9689 &new_triggers);
9690 if (err)
9691 goto error;
9692 }
9693
Johannes Berg98fc4382015-03-01 09:10:13 +02009694 /* The 'any' trigger means the device continues operating more or less
9695 * as in its normal operation mode and wakes up the host on most of the
9696 * normal interrupts (like packet RX, ...)
9697 * It therefore makes little sense to combine with the more constrained
9698 * wakeup trigger modes.
9699 */
9700 if (new_triggers.any && regular) {
9701 err = -EINVAL;
9702 goto error;
9703 }
9704
Johannes Bergae33bd82012-07-12 16:25:02 +02009705 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9706 if (!ntrig) {
9707 err = -ENOMEM;
9708 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009709 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009710 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009711 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009712
Johannes Bergae33bd82012-07-12 16:25:02 +02009713 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009714 if (rdev->ops->set_wakeup &&
9715 prev_enabled != !!rdev->wiphy.wowlan_config)
9716 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009717
Johannes Bergff1b6e62011-05-04 15:37:28 +02009718 return 0;
9719 error:
9720 for (i = 0; i < new_triggers.n_patterns; i++)
9721 kfree(new_triggers.patterns[i].mask);
9722 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009723 if (new_triggers.tcp && new_triggers.tcp->sock)
9724 sock_release(new_triggers.tcp->sock);
9725 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009726 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009727 return err;
9728}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009729#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009730
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009731static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9732 struct cfg80211_registered_device *rdev)
9733{
9734 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9735 int i, j, pat_len;
9736 struct cfg80211_coalesce_rules *rule;
9737
9738 if (!rdev->coalesce->n_rules)
9739 return 0;
9740
9741 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9742 if (!nl_rules)
9743 return -ENOBUFS;
9744
9745 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9746 nl_rule = nla_nest_start(msg, i + 1);
9747 if (!nl_rule)
9748 return -ENOBUFS;
9749
9750 rule = &rdev->coalesce->rules[i];
9751 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9752 rule->delay))
9753 return -ENOBUFS;
9754
9755 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9756 rule->condition))
9757 return -ENOBUFS;
9758
9759 nl_pats = nla_nest_start(msg,
9760 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9761 if (!nl_pats)
9762 return -ENOBUFS;
9763
9764 for (j = 0; j < rule->n_patterns; j++) {
9765 nl_pat = nla_nest_start(msg, j + 1);
9766 if (!nl_pat)
9767 return -ENOBUFS;
9768 pat_len = rule->patterns[j].pattern_len;
9769 if (nla_put(msg, NL80211_PKTPAT_MASK,
9770 DIV_ROUND_UP(pat_len, 8),
9771 rule->patterns[j].mask) ||
9772 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9773 rule->patterns[j].pattern) ||
9774 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9775 rule->patterns[j].pkt_offset))
9776 return -ENOBUFS;
9777 nla_nest_end(msg, nl_pat);
9778 }
9779 nla_nest_end(msg, nl_pats);
9780 nla_nest_end(msg, nl_rule);
9781 }
9782 nla_nest_end(msg, nl_rules);
9783
9784 return 0;
9785}
9786
9787static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9788{
9789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9790 struct sk_buff *msg;
9791 void *hdr;
9792
9793 if (!rdev->wiphy.coalesce)
9794 return -EOPNOTSUPP;
9795
9796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9797 if (!msg)
9798 return -ENOMEM;
9799
9800 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9801 NL80211_CMD_GET_COALESCE);
9802 if (!hdr)
9803 goto nla_put_failure;
9804
9805 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9806 goto nla_put_failure;
9807
9808 genlmsg_end(msg, hdr);
9809 return genlmsg_reply(msg, info);
9810
9811nla_put_failure:
9812 nlmsg_free(msg);
9813 return -ENOBUFS;
9814}
9815
9816void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9817{
9818 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9819 int i, j;
9820 struct cfg80211_coalesce_rules *rule;
9821
9822 if (!coalesce)
9823 return;
9824
9825 for (i = 0; i < coalesce->n_rules; i++) {
9826 rule = &coalesce->rules[i];
9827 for (j = 0; j < rule->n_patterns; j++)
9828 kfree(rule->patterns[j].mask);
9829 kfree(rule->patterns);
9830 }
9831 kfree(coalesce->rules);
9832 kfree(coalesce);
9833 rdev->coalesce = NULL;
9834}
9835
9836static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9837 struct nlattr *rule,
9838 struct cfg80211_coalesce_rules *new_rule)
9839{
9840 int err, i;
9841 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9842 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9843 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9844 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9845
9846 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9847 nla_len(rule), nl80211_coalesce_policy);
9848 if (err)
9849 return err;
9850
9851 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9852 new_rule->delay =
9853 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9854 if (new_rule->delay > coalesce->max_delay)
9855 return -EINVAL;
9856
9857 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9858 new_rule->condition =
9859 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9860 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9861 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9862 return -EINVAL;
9863
9864 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9865 return -EINVAL;
9866
9867 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9868 rem)
9869 n_patterns++;
9870 if (n_patterns > coalesce->n_patterns)
9871 return -EINVAL;
9872
9873 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9874 GFP_KERNEL);
9875 if (!new_rule->patterns)
9876 return -ENOMEM;
9877
9878 new_rule->n_patterns = n_patterns;
9879 i = 0;
9880
9881 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9882 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009883 u8 *mask_pat;
9884
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009885 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9886 nla_len(pat), NULL);
9887 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9888 !pat_tb[NL80211_PKTPAT_PATTERN])
9889 return -EINVAL;
9890 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9891 mask_len = DIV_ROUND_UP(pat_len, 8);
9892 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9893 return -EINVAL;
9894 if (pat_len > coalesce->pattern_max_len ||
9895 pat_len < coalesce->pattern_min_len)
9896 return -EINVAL;
9897
9898 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9899 pkt_offset = 0;
9900 else
9901 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9902 if (pkt_offset > coalesce->max_pkt_offset)
9903 return -EINVAL;
9904 new_rule->patterns[i].pkt_offset = pkt_offset;
9905
Johannes Berg922bd802014-05-19 17:59:50 +02009906 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9907 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009908 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009909
9910 new_rule->patterns[i].mask = mask_pat;
9911 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9912 mask_len);
9913
9914 mask_pat += mask_len;
9915 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009916 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009917 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9918 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009919 i++;
9920 }
9921
9922 return 0;
9923}
9924
9925static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9926{
9927 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9928 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9929 struct cfg80211_coalesce new_coalesce = {};
9930 struct cfg80211_coalesce *n_coalesce;
9931 int err, rem_rule, n_rules = 0, i, j;
9932 struct nlattr *rule;
9933 struct cfg80211_coalesce_rules *tmp_rule;
9934
9935 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9936 return -EOPNOTSUPP;
9937
9938 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9939 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009940 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009941 return 0;
9942 }
9943
9944 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9945 rem_rule)
9946 n_rules++;
9947 if (n_rules > coalesce->n_rules)
9948 return -EINVAL;
9949
9950 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9951 GFP_KERNEL);
9952 if (!new_coalesce.rules)
9953 return -ENOMEM;
9954
9955 new_coalesce.n_rules = n_rules;
9956 i = 0;
9957
9958 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9959 rem_rule) {
9960 err = nl80211_parse_coalesce_rule(rdev, rule,
9961 &new_coalesce.rules[i]);
9962 if (err)
9963 goto error;
9964
9965 i++;
9966 }
9967
Ilan Peera1056b12015-10-22 22:27:46 +03009968 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009969 if (err)
9970 goto error;
9971
9972 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9973 if (!n_coalesce) {
9974 err = -ENOMEM;
9975 goto error;
9976 }
9977 cfg80211_rdev_free_coalesce(rdev);
9978 rdev->coalesce = n_coalesce;
9979
9980 return 0;
9981error:
9982 for (i = 0; i < new_coalesce.n_rules; i++) {
9983 tmp_rule = &new_coalesce.rules[i];
9984 for (j = 0; j < tmp_rule->n_patterns; j++)
9985 kfree(tmp_rule->patterns[j].mask);
9986 kfree(tmp_rule->patterns);
9987 }
9988 kfree(new_coalesce.rules);
9989
9990 return err;
9991}
9992
Johannes Berge5497d72011-07-05 16:35:40 +02009993static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9994{
9995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9996 struct net_device *dev = info->user_ptr[1];
9997 struct wireless_dev *wdev = dev->ieee80211_ptr;
9998 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9999 struct cfg80211_gtk_rekey_data rekey_data;
10000 int err;
10001
10002 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10003 return -EINVAL;
10004
10005 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10006 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10007 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10008 nl80211_rekey_policy);
10009 if (err)
10010 return err;
10011
10012 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10013 return -ERANGE;
10014 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10015 return -ERANGE;
10016 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10017 return -ERANGE;
10018
Johannes Berg78f686c2014-09-10 22:28:06 +030010019 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10020 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10021 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010022
10023 wdev_lock(wdev);
10024 if (!wdev->current_bss) {
10025 err = -ENOTCONN;
10026 goto out;
10027 }
10028
10029 if (!rdev->ops->set_rekey_data) {
10030 err = -EOPNOTSUPP;
10031 goto out;
10032 }
10033
Hila Gonene35e4d22012-06-27 17:19:42 +030010034 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010035 out:
10036 wdev_unlock(wdev);
10037 return err;
10038}
10039
Johannes Berg28946da2011-11-04 11:18:12 +010010040static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10041 struct genl_info *info)
10042{
10043 struct net_device *dev = info->user_ptr[1];
10044 struct wireless_dev *wdev = dev->ieee80211_ptr;
10045
10046 if (wdev->iftype != NL80211_IFTYPE_AP &&
10047 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10048 return -EINVAL;
10049
Eric W. Biederman15e47302012-09-07 20:12:54 +000010050 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010051 return -EBUSY;
10052
Eric W. Biederman15e47302012-09-07 20:12:54 +000010053 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010054 return 0;
10055}
10056
Johannes Berg7f6cf312011-11-04 11:18:15 +010010057static int nl80211_probe_client(struct sk_buff *skb,
10058 struct genl_info *info)
10059{
10060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10061 struct net_device *dev = info->user_ptr[1];
10062 struct wireless_dev *wdev = dev->ieee80211_ptr;
10063 struct sk_buff *msg;
10064 void *hdr;
10065 const u8 *addr;
10066 u64 cookie;
10067 int err;
10068
10069 if (wdev->iftype != NL80211_IFTYPE_AP &&
10070 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10071 return -EOPNOTSUPP;
10072
10073 if (!info->attrs[NL80211_ATTR_MAC])
10074 return -EINVAL;
10075
10076 if (!rdev->ops->probe_client)
10077 return -EOPNOTSUPP;
10078
10079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10080 if (!msg)
10081 return -ENOMEM;
10082
Eric W. Biederman15e47302012-09-07 20:12:54 +000010083 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010084 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010085 if (!hdr) {
10086 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010087 goto free_msg;
10088 }
10089
10090 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10091
Hila Gonene35e4d22012-06-27 17:19:42 +030010092 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010093 if (err)
10094 goto free_msg;
10095
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010096 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10097 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010098 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010099
10100 genlmsg_end(msg, hdr);
10101
10102 return genlmsg_reply(msg, info);
10103
10104 nla_put_failure:
10105 err = -ENOBUFS;
10106 free_msg:
10107 nlmsg_free(msg);
10108 return err;
10109}
10110
Johannes Berg5e7602302011-11-04 11:18:17 +010010111static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10112{
10113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010114 struct cfg80211_beacon_registration *reg, *nreg;
10115 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010116
10117 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10118 return -EOPNOTSUPP;
10119
Ben Greear37c73b52012-10-26 14:49:25 -070010120 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10121 if (!nreg)
10122 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010123
Ben Greear37c73b52012-10-26 14:49:25 -070010124 /* First, check if already registered. */
10125 spin_lock_bh(&rdev->beacon_registrations_lock);
10126 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10127 if (reg->nlportid == info->snd_portid) {
10128 rv = -EALREADY;
10129 goto out_err;
10130 }
10131 }
10132 /* Add it to the list */
10133 nreg->nlportid = info->snd_portid;
10134 list_add(&nreg->list, &rdev->beacon_registrations);
10135
10136 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010137
10138 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010139out_err:
10140 spin_unlock_bh(&rdev->beacon_registrations_lock);
10141 kfree(nreg);
10142 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010143}
10144
Johannes Berg98104fde2012-06-16 00:19:54 +020010145static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10146{
10147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10148 struct wireless_dev *wdev = info->user_ptr[1];
10149 int err;
10150
10151 if (!rdev->ops->start_p2p_device)
10152 return -EOPNOTSUPP;
10153
10154 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10155 return -EOPNOTSUPP;
10156
10157 if (wdev->p2p_started)
10158 return 0;
10159
Luciano Coelhob6a55012014-02-27 11:07:21 +020010160 if (rfkill_blocked(rdev->rfkill))
10161 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010162
Johannes Bergeeb126e2012-10-23 15:16:50 +020010163 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010164 if (err)
10165 return err;
10166
10167 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010168 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010169
10170 return 0;
10171}
10172
10173static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10174{
10175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10176 struct wireless_dev *wdev = info->user_ptr[1];
10177
10178 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10179 return -EOPNOTSUPP;
10180
10181 if (!rdev->ops->stop_p2p_device)
10182 return -EOPNOTSUPP;
10183
Johannes Bergf9f47522013-03-19 15:04:07 +010010184 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010185
10186 return 0;
10187}
10188
Johannes Berg3713b4e2013-02-14 16:19:38 +010010189static int nl80211_get_protocol_features(struct sk_buff *skb,
10190 struct genl_info *info)
10191{
10192 void *hdr;
10193 struct sk_buff *msg;
10194
10195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10196 if (!msg)
10197 return -ENOMEM;
10198
10199 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10200 NL80211_CMD_GET_PROTOCOL_FEATURES);
10201 if (!hdr)
10202 goto nla_put_failure;
10203
10204 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10205 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10206 goto nla_put_failure;
10207
10208 genlmsg_end(msg, hdr);
10209 return genlmsg_reply(msg, info);
10210
10211 nla_put_failure:
10212 kfree_skb(msg);
10213 return -ENOBUFS;
10214}
10215
Jouni Malinen355199e2013-02-27 17:14:27 +020010216static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10217{
10218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10219 struct cfg80211_update_ft_ies_params ft_params;
10220 struct net_device *dev = info->user_ptr[1];
10221
10222 if (!rdev->ops->update_ft_ies)
10223 return -EOPNOTSUPP;
10224
10225 if (!info->attrs[NL80211_ATTR_MDID] ||
10226 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10227 return -EINVAL;
10228
10229 memset(&ft_params, 0, sizeof(ft_params));
10230 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10231 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10232 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10233
10234 return rdev_update_ft_ies(rdev, dev, &ft_params);
10235}
10236
Arend van Spriel5de17982013-04-18 15:49:00 +020010237static int nl80211_crit_protocol_start(struct sk_buff *skb,
10238 struct genl_info *info)
10239{
10240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10241 struct wireless_dev *wdev = info->user_ptr[1];
10242 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10243 u16 duration;
10244 int ret;
10245
10246 if (!rdev->ops->crit_proto_start)
10247 return -EOPNOTSUPP;
10248
10249 if (WARN_ON(!rdev->ops->crit_proto_stop))
10250 return -EINVAL;
10251
10252 if (rdev->crit_proto_nlportid)
10253 return -EBUSY;
10254
10255 /* determine protocol if provided */
10256 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10257 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10258
10259 if (proto >= NUM_NL80211_CRIT_PROTO)
10260 return -EINVAL;
10261
10262 /* timeout must be provided */
10263 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10264 return -EINVAL;
10265
10266 duration =
10267 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10268
10269 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10270 return -ERANGE;
10271
10272 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10273 if (!ret)
10274 rdev->crit_proto_nlportid = info->snd_portid;
10275
10276 return ret;
10277}
10278
10279static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10280 struct genl_info *info)
10281{
10282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10283 struct wireless_dev *wdev = info->user_ptr[1];
10284
10285 if (!rdev->ops->crit_proto_stop)
10286 return -EOPNOTSUPP;
10287
10288 if (rdev->crit_proto_nlportid) {
10289 rdev->crit_proto_nlportid = 0;
10290 rdev_crit_proto_stop(rdev, wdev);
10291 }
10292 return 0;
10293}
10294
Johannes Bergad7e7182013-11-13 13:37:47 +010010295static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10296{
10297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10298 struct wireless_dev *wdev =
10299 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10300 int i, err;
10301 u32 vid, subcmd;
10302
10303 if (!rdev->wiphy.vendor_commands)
10304 return -EOPNOTSUPP;
10305
10306 if (IS_ERR(wdev)) {
10307 err = PTR_ERR(wdev);
10308 if (err != -EINVAL)
10309 return err;
10310 wdev = NULL;
10311 } else if (wdev->wiphy != &rdev->wiphy) {
10312 return -EINVAL;
10313 }
10314
10315 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10316 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10317 return -EINVAL;
10318
10319 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10320 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10321 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10322 const struct wiphy_vendor_command *vcmd;
10323 void *data = NULL;
10324 int len = 0;
10325
10326 vcmd = &rdev->wiphy.vendor_commands[i];
10327
10328 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10329 continue;
10330
10331 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10332 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10333 if (!wdev)
10334 return -EINVAL;
10335 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10336 !wdev->netdev)
10337 return -EINVAL;
10338
10339 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10340 if (wdev->netdev &&
10341 !netif_running(wdev->netdev))
10342 return -ENETDOWN;
10343 if (!wdev->netdev && !wdev->p2p_started)
10344 return -ENETDOWN;
10345 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010346
10347 if (!vcmd->doit)
10348 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010349 } else {
10350 wdev = NULL;
10351 }
10352
10353 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10354 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10355 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10356 }
10357
10358 rdev->cur_cmd_info = info;
10359 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10360 data, len);
10361 rdev->cur_cmd_info = NULL;
10362 return err;
10363 }
10364
10365 return -EOPNOTSUPP;
10366}
10367
Johannes Berg7bdbe402015-08-15 22:39:49 +030010368static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10369 struct netlink_callback *cb,
10370 struct cfg80211_registered_device **rdev,
10371 struct wireless_dev **wdev)
10372{
10373 u32 vid, subcmd;
10374 unsigned int i;
10375 int vcmd_idx = -1;
10376 int err;
10377 void *data = NULL;
10378 unsigned int data_len = 0;
10379
10380 rtnl_lock();
10381
10382 if (cb->args[0]) {
10383 /* subtract the 1 again here */
10384 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10385 struct wireless_dev *tmp;
10386
10387 if (!wiphy) {
10388 err = -ENODEV;
10389 goto out_unlock;
10390 }
10391 *rdev = wiphy_to_rdev(wiphy);
10392 *wdev = NULL;
10393
10394 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030010395 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010396 if (tmp->identifier == cb->args[1] - 1) {
10397 *wdev = tmp;
10398 break;
10399 }
10400 }
10401 }
10402
10403 /* keep rtnl locked in successful case */
10404 return 0;
10405 }
10406
10407 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10408 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10409 nl80211_policy);
10410 if (err)
10411 goto out_unlock;
10412
10413 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10414 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10415 err = -EINVAL;
10416 goto out_unlock;
10417 }
10418
10419 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10420 nl80211_fam.attrbuf);
10421 if (IS_ERR(*wdev))
10422 *wdev = NULL;
10423
10424 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10425 nl80211_fam.attrbuf);
10426 if (IS_ERR(*rdev)) {
10427 err = PTR_ERR(*rdev);
10428 goto out_unlock;
10429 }
10430
10431 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10432 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10433
10434 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10435 const struct wiphy_vendor_command *vcmd;
10436
10437 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10438
10439 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10440 continue;
10441
10442 if (!vcmd->dumpit) {
10443 err = -EOPNOTSUPP;
10444 goto out_unlock;
10445 }
10446
10447 vcmd_idx = i;
10448 break;
10449 }
10450
10451 if (vcmd_idx < 0) {
10452 err = -EOPNOTSUPP;
10453 goto out_unlock;
10454 }
10455
10456 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10457 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10458 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10459 }
10460
10461 /* 0 is the first index - add 1 to parse only once */
10462 cb->args[0] = (*rdev)->wiphy_idx + 1;
10463 /* add 1 to know if it was NULL */
10464 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10465 cb->args[2] = vcmd_idx;
10466 cb->args[3] = (unsigned long)data;
10467 cb->args[4] = data_len;
10468
10469 /* keep rtnl locked in successful case */
10470 return 0;
10471 out_unlock:
10472 rtnl_unlock();
10473 return err;
10474}
10475
10476static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10477 struct netlink_callback *cb)
10478{
10479 struct cfg80211_registered_device *rdev;
10480 struct wireless_dev *wdev;
10481 unsigned int vcmd_idx;
10482 const struct wiphy_vendor_command *vcmd;
10483 void *data;
10484 int data_len;
10485 int err;
10486 struct nlattr *vendor_data;
10487
10488 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10489 if (err)
10490 return err;
10491
10492 vcmd_idx = cb->args[2];
10493 data = (void *)cb->args[3];
10494 data_len = cb->args[4];
10495 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10496
10497 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10498 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10499 if (!wdev)
10500 return -EINVAL;
10501 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10502 !wdev->netdev)
10503 return -EINVAL;
10504
10505 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10506 if (wdev->netdev &&
10507 !netif_running(wdev->netdev))
10508 return -ENETDOWN;
10509 if (!wdev->netdev && !wdev->p2p_started)
10510 return -ENETDOWN;
10511 }
10512 }
10513
10514 while (1) {
10515 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10516 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10517 NL80211_CMD_VENDOR);
10518 if (!hdr)
10519 break;
10520
10521 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010522 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10523 wdev_id(wdev),
10524 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030010525 genlmsg_cancel(skb, hdr);
10526 break;
10527 }
10528
10529 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10530 if (!vendor_data) {
10531 genlmsg_cancel(skb, hdr);
10532 break;
10533 }
10534
10535 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10536 (unsigned long *)&cb->args[5]);
10537 nla_nest_end(skb, vendor_data);
10538
10539 if (err == -ENOBUFS || err == -ENOENT) {
10540 genlmsg_cancel(skb, hdr);
10541 break;
10542 } else if (err) {
10543 genlmsg_cancel(skb, hdr);
10544 goto out;
10545 }
10546
10547 genlmsg_end(skb, hdr);
10548 }
10549
10550 err = skb->len;
10551 out:
10552 rtnl_unlock();
10553 return err;
10554}
10555
Johannes Bergad7e7182013-11-13 13:37:47 +010010556struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10557 enum nl80211_commands cmd,
10558 enum nl80211_attrs attr,
10559 int approxlen)
10560{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010561 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010562
10563 if (WARN_ON(!rdev->cur_cmd_info))
10564 return NULL;
10565
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010566 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010567 rdev->cur_cmd_info->snd_portid,
10568 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010569 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010570}
10571EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10572
10573int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10574{
10575 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10576 void *hdr = ((void **)skb->cb)[1];
10577 struct nlattr *data = ((void **)skb->cb)[2];
10578
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010579 /* clear CB data for netlink core to own from now on */
10580 memset(skb->cb, 0, sizeof(skb->cb));
10581
Johannes Bergad7e7182013-11-13 13:37:47 +010010582 if (WARN_ON(!rdev->cur_cmd_info)) {
10583 kfree_skb(skb);
10584 return -EINVAL;
10585 }
10586
10587 nla_nest_end(skb, data);
10588 genlmsg_end(skb, hdr);
10589 return genlmsg_reply(skb, rdev->cur_cmd_info);
10590}
10591EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10592
10593
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010594static int nl80211_set_qos_map(struct sk_buff *skb,
10595 struct genl_info *info)
10596{
10597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10598 struct cfg80211_qos_map *qos_map = NULL;
10599 struct net_device *dev = info->user_ptr[1];
10600 u8 *pos, len, num_des, des_len, des;
10601 int ret;
10602
10603 if (!rdev->ops->set_qos_map)
10604 return -EOPNOTSUPP;
10605
10606 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10607 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10608 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10609
10610 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10611 len > IEEE80211_QOS_MAP_LEN_MAX)
10612 return -EINVAL;
10613
10614 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10615 if (!qos_map)
10616 return -ENOMEM;
10617
10618 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10619 if (num_des) {
10620 des_len = num_des *
10621 sizeof(struct cfg80211_dscp_exception);
10622 memcpy(qos_map->dscp_exception, pos, des_len);
10623 qos_map->num_des = num_des;
10624 for (des = 0; des < num_des; des++) {
10625 if (qos_map->dscp_exception[des].up > 7) {
10626 kfree(qos_map);
10627 return -EINVAL;
10628 }
10629 }
10630 pos += des_len;
10631 }
10632 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10633 }
10634
10635 wdev_lock(dev->ieee80211_ptr);
10636 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10637 if (!ret)
10638 ret = rdev_set_qos_map(rdev, dev, qos_map);
10639 wdev_unlock(dev->ieee80211_ptr);
10640
10641 kfree(qos_map);
10642 return ret;
10643}
10644
Johannes Berg960d01a2014-09-09 22:55:35 +030010645static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10646{
10647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10648 struct net_device *dev = info->user_ptr[1];
10649 struct wireless_dev *wdev = dev->ieee80211_ptr;
10650 const u8 *peer;
10651 u8 tsid, up;
10652 u16 admitted_time = 0;
10653 int err;
10654
Johannes Berg723e73a2014-10-22 09:25:06 +020010655 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010656 return -EOPNOTSUPP;
10657
10658 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10659 !info->attrs[NL80211_ATTR_USER_PRIO])
10660 return -EINVAL;
10661
10662 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10663 if (tsid >= IEEE80211_NUM_TIDS)
10664 return -EINVAL;
10665
10666 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10667 if (up >= IEEE80211_NUM_UPS)
10668 return -EINVAL;
10669
10670 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010671 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010672 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010673 * need more attributes for that (e.g. BA session requirement);
10674 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010675 */
10676 return -EINVAL;
10677 }
10678
10679 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10680
10681 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10682 admitted_time =
10683 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10684 if (!admitted_time)
10685 return -EINVAL;
10686 }
10687
10688 wdev_lock(wdev);
10689 switch (wdev->iftype) {
10690 case NL80211_IFTYPE_STATION:
10691 case NL80211_IFTYPE_P2P_CLIENT:
10692 if (wdev->current_bss)
10693 break;
10694 err = -ENOTCONN;
10695 goto out;
10696 default:
10697 err = -EOPNOTSUPP;
10698 goto out;
10699 }
10700
10701 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10702
10703 out:
10704 wdev_unlock(wdev);
10705 return err;
10706}
10707
10708static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10709{
10710 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10711 struct net_device *dev = info->user_ptr[1];
10712 struct wireless_dev *wdev = dev->ieee80211_ptr;
10713 const u8 *peer;
10714 u8 tsid;
10715 int err;
10716
10717 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10718 return -EINVAL;
10719
10720 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10721 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10722
10723 wdev_lock(wdev);
10724 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10725 wdev_unlock(wdev);
10726
10727 return err;
10728}
10729
Arik Nemtsov1057d352014-11-19 12:54:26 +020010730static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10731 struct genl_info *info)
10732{
10733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10734 struct net_device *dev = info->user_ptr[1];
10735 struct wireless_dev *wdev = dev->ieee80211_ptr;
10736 struct cfg80211_chan_def chandef = {};
10737 const u8 *addr;
10738 u8 oper_class;
10739 int err;
10740
10741 if (!rdev->ops->tdls_channel_switch ||
10742 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10743 return -EOPNOTSUPP;
10744
10745 switch (dev->ieee80211_ptr->iftype) {
10746 case NL80211_IFTYPE_STATION:
10747 case NL80211_IFTYPE_P2P_CLIENT:
10748 break;
10749 default:
10750 return -EOPNOTSUPP;
10751 }
10752
10753 if (!info->attrs[NL80211_ATTR_MAC] ||
10754 !info->attrs[NL80211_ATTR_OPER_CLASS])
10755 return -EINVAL;
10756
10757 err = nl80211_parse_chandef(rdev, info, &chandef);
10758 if (err)
10759 return err;
10760
10761 /*
10762 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10763 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10764 * specification is not defined for them.
10765 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020010766 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020010767 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10768 chandef.width != NL80211_CHAN_WIDTH_20)
10769 return -EINVAL;
10770
10771 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010772 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10773 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010774 return -EINVAL;
10775
10776 /* don't allow switching to DFS channels */
10777 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10778 return -EINVAL;
10779
10780 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10781 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10782
10783 wdev_lock(wdev);
10784 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10785 wdev_unlock(wdev);
10786
10787 return err;
10788}
10789
10790static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10791 struct genl_info *info)
10792{
10793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10794 struct net_device *dev = info->user_ptr[1];
10795 struct wireless_dev *wdev = dev->ieee80211_ptr;
10796 const u8 *addr;
10797
10798 if (!rdev->ops->tdls_channel_switch ||
10799 !rdev->ops->tdls_cancel_channel_switch ||
10800 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10801 return -EOPNOTSUPP;
10802
10803 switch (dev->ieee80211_ptr->iftype) {
10804 case NL80211_IFTYPE_STATION:
10805 case NL80211_IFTYPE_P2P_CLIENT:
10806 break;
10807 default:
10808 return -EOPNOTSUPP;
10809 }
10810
10811 if (!info->attrs[NL80211_ATTR_MAC])
10812 return -EINVAL;
10813
10814 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10815
10816 wdev_lock(wdev);
10817 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10818 wdev_unlock(wdev);
10819
10820 return 0;
10821}
10822
Johannes Berg4c476992010-10-04 21:36:35 +020010823#define NL80211_FLAG_NEED_WIPHY 0x01
10824#define NL80211_FLAG_NEED_NETDEV 0x02
10825#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010826#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10827#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10828 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010829#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010830/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010831#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10832 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010833#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010834
Johannes Bergf84f7712013-11-14 17:14:45 +010010835static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010836 struct genl_info *info)
10837{
10838 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010839 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010840 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010841 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10842
10843 if (rtnl)
10844 rtnl_lock();
10845
10846 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010847 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010848 if (IS_ERR(rdev)) {
10849 if (rtnl)
10850 rtnl_unlock();
10851 return PTR_ERR(rdev);
10852 }
10853 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010854 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10855 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010856 ASSERT_RTNL();
10857
Johannes Berg89a54e42012-06-15 14:33:17 +020010858 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10859 info->attrs);
10860 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010861 if (rtnl)
10862 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010863 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010864 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010865
Johannes Berg89a54e42012-06-15 14:33:17 +020010866 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010867 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010868
Johannes Berg1bf614e2012-06-15 15:23:36 +020010869 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10870 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010871 if (rtnl)
10872 rtnl_unlock();
10873 return -EINVAL;
10874 }
10875
10876 info->user_ptr[1] = dev;
10877 } else {
10878 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010879 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010880
Johannes Berg1bf614e2012-06-15 15:23:36 +020010881 if (dev) {
10882 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10883 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010884 if (rtnl)
10885 rtnl_unlock();
10886 return -ENETDOWN;
10887 }
10888
10889 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010890 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10891 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010892 if (rtnl)
10893 rtnl_unlock();
10894 return -ENETDOWN;
10895 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010896 }
10897
Johannes Berg4c476992010-10-04 21:36:35 +020010898 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010899 }
10900
10901 return 0;
10902}
10903
Johannes Bergf84f7712013-11-14 17:14:45 +010010904static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010905 struct genl_info *info)
10906{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010907 if (info->user_ptr[1]) {
10908 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10909 struct wireless_dev *wdev = info->user_ptr[1];
10910
10911 if (wdev->netdev)
10912 dev_put(wdev->netdev);
10913 } else {
10914 dev_put(info->user_ptr[1]);
10915 }
10916 }
Johannes Berg5393b912014-09-10 15:00:16 +030010917
Johannes Berg4c476992010-10-04 21:36:35 +020010918 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10919 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010920
10921 /* If needed, clear the netlink message payload from the SKB
10922 * as it might contain key data that shouldn't stick around on
10923 * the heap after the SKB is freed. The netlink message header
10924 * is still needed for further processing, so leave it intact.
10925 */
10926 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10927 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10928
10929 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10930 }
Johannes Berg4c476992010-10-04 21:36:35 +020010931}
10932
Johannes Berg4534de82013-11-14 17:14:46 +010010933static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010934 {
10935 .cmd = NL80211_CMD_GET_WIPHY,
10936 .doit = nl80211_get_wiphy,
10937 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010938 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010939 .policy = nl80211_policy,
10940 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010941 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10942 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010943 },
10944 {
10945 .cmd = NL80211_CMD_SET_WIPHY,
10946 .doit = nl80211_set_wiphy,
10947 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010948 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010949 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010950 },
10951 {
10952 .cmd = NL80211_CMD_GET_INTERFACE,
10953 .doit = nl80211_get_interface,
10954 .dumpit = nl80211_dump_interface,
10955 .policy = nl80211_policy,
10956 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010957 .internal_flags = NL80211_FLAG_NEED_WDEV |
10958 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010959 },
10960 {
10961 .cmd = NL80211_CMD_SET_INTERFACE,
10962 .doit = nl80211_set_interface,
10963 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010964 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010965 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10966 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010967 },
10968 {
10969 .cmd = NL80211_CMD_NEW_INTERFACE,
10970 .doit = nl80211_new_interface,
10971 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010972 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010973 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10974 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010975 },
10976 {
10977 .cmd = NL80211_CMD_DEL_INTERFACE,
10978 .doit = nl80211_del_interface,
10979 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010980 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010981 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010982 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010983 },
Johannes Berg41ade002007-12-19 02:03:29 +010010984 {
10985 .cmd = NL80211_CMD_GET_KEY,
10986 .doit = nl80211_get_key,
10987 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010988 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010990 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010991 },
10992 {
10993 .cmd = NL80211_CMD_SET_KEY,
10994 .doit = nl80211_set_key,
10995 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020010996 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010998 NL80211_FLAG_NEED_RTNL |
10999 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011000 },
11001 {
11002 .cmd = NL80211_CMD_NEW_KEY,
11003 .doit = nl80211_new_key,
11004 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011005 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011007 NL80211_FLAG_NEED_RTNL |
11008 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011009 },
11010 {
11011 .cmd = NL80211_CMD_DEL_KEY,
11012 .doit = nl80211_del_key,
11013 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011014 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011016 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011017 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011018 {
11019 .cmd = NL80211_CMD_SET_BEACON,
11020 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011021 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011022 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011024 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011025 },
11026 {
Johannes Berg88600202012-02-13 15:17:18 +010011027 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011028 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011029 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011030 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011032 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011033 },
11034 {
Johannes Berg88600202012-02-13 15:17:18 +010011035 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011036 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011037 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011038 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011040 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011041 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011042 {
11043 .cmd = NL80211_CMD_GET_STATION,
11044 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011045 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011046 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011047 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11048 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011049 },
11050 {
11051 .cmd = NL80211_CMD_SET_STATION,
11052 .doit = nl80211_set_station,
11053 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011054 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011056 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011057 },
11058 {
11059 .cmd = NL80211_CMD_NEW_STATION,
11060 .doit = nl80211_new_station,
11061 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011062 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011064 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011065 },
11066 {
11067 .cmd = NL80211_CMD_DEL_STATION,
11068 .doit = nl80211_del_station,
11069 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011070 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011071 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011072 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011073 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011074 {
11075 .cmd = NL80211_CMD_GET_MPATH,
11076 .doit = nl80211_get_mpath,
11077 .dumpit = nl80211_dump_mpath,
11078 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011079 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011081 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011082 },
11083 {
Henning Rogge66be7d22014-09-12 08:58:49 +020011084 .cmd = NL80211_CMD_GET_MPP,
11085 .doit = nl80211_get_mpp,
11086 .dumpit = nl80211_dump_mpp,
11087 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011088 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020011089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11090 NL80211_FLAG_NEED_RTNL,
11091 },
11092 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011093 .cmd = NL80211_CMD_SET_MPATH,
11094 .doit = nl80211_set_mpath,
11095 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011096 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011098 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011099 },
11100 {
11101 .cmd = NL80211_CMD_NEW_MPATH,
11102 .doit = nl80211_new_mpath,
11103 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011104 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011105 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011106 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011107 },
11108 {
11109 .cmd = NL80211_CMD_DEL_MPATH,
11110 .doit = nl80211_del_mpath,
11111 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011112 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011114 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011115 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011116 {
11117 .cmd = NL80211_CMD_SET_BSS,
11118 .doit = nl80211_set_bss,
11119 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011120 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011122 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030011123 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011124 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011125 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011126 .doit = nl80211_get_reg_do,
11127 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011128 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011129 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011130 /* can be retrieved by unprivileged users */
11131 },
Johannes Bergb6863032015-10-15 09:25:18 +020011132#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080011133 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011134 .cmd = NL80211_CMD_SET_REG,
11135 .doit = nl80211_set_reg,
11136 .policy = nl80211_policy,
11137 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020011138 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011139 },
Johannes Bergb6863032015-10-15 09:25:18 +020011140#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070011141 {
11142 .cmd = NL80211_CMD_REQ_SET_REG,
11143 .doit = nl80211_req_set_reg,
11144 .policy = nl80211_policy,
11145 .flags = GENL_ADMIN_PERM,
11146 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011147 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011148 .cmd = NL80211_CMD_GET_MESH_CONFIG,
11149 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011150 .policy = nl80211_policy,
11151 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011152 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011153 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011154 },
11155 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011156 .cmd = NL80211_CMD_SET_MESH_CONFIG,
11157 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011158 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011159 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011161 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070011162 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020011163 {
Johannes Berg2a519312009-02-10 21:25:55 +010011164 .cmd = NL80211_CMD_TRIGGER_SCAN,
11165 .doit = nl80211_trigger_scan,
11166 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011167 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020011168 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011169 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010011170 },
11171 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011172 .cmd = NL80211_CMD_ABORT_SCAN,
11173 .doit = nl80211_abort_scan,
11174 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011175 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053011176 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11177 NL80211_FLAG_NEED_RTNL,
11178 },
11179 {
Johannes Berg2a519312009-02-10 21:25:55 +010011180 .cmd = NL80211_CMD_GET_SCAN,
11181 .policy = nl80211_policy,
11182 .dumpit = nl80211_dump_scan,
11183 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011184 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011185 .cmd = NL80211_CMD_START_SCHED_SCAN,
11186 .doit = nl80211_start_sched_scan,
11187 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011188 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011189 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11190 NL80211_FLAG_NEED_RTNL,
11191 },
11192 {
11193 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11194 .doit = nl80211_stop_sched_scan,
11195 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011196 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030011197 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11198 NL80211_FLAG_NEED_RTNL,
11199 },
11200 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011201 .cmd = NL80211_CMD_AUTHENTICATE,
11202 .doit = nl80211_authenticate,
11203 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011204 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011205 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011206 NL80211_FLAG_NEED_RTNL |
11207 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011208 },
11209 {
11210 .cmd = NL80211_CMD_ASSOCIATE,
11211 .doit = nl80211_associate,
11212 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011213 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011214 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011215 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011216 },
11217 {
11218 .cmd = NL80211_CMD_DEAUTHENTICATE,
11219 .doit = nl80211_deauthenticate,
11220 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011221 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011222 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011223 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011224 },
11225 {
11226 .cmd = NL80211_CMD_DISASSOCIATE,
11227 .doit = nl80211_disassociate,
11228 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011229 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011231 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011232 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011233 {
11234 .cmd = NL80211_CMD_JOIN_IBSS,
11235 .doit = nl80211_join_ibss,
11236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011237 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011239 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011240 },
11241 {
11242 .cmd = NL80211_CMD_LEAVE_IBSS,
11243 .doit = nl80211_leave_ibss,
11244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011245 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011247 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011248 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011249#ifdef CONFIG_NL80211_TESTMODE
11250 {
11251 .cmd = NL80211_CMD_TESTMODE,
11252 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011253 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011254 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011255 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011256 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11257 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011258 },
11259#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011260 {
11261 .cmd = NL80211_CMD_CONNECT,
11262 .doit = nl80211_connect,
11263 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011264 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011266 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011267 },
11268 {
11269 .cmd = NL80211_CMD_DISCONNECT,
11270 .doit = nl80211_disconnect,
11271 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011272 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011273 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011274 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011275 },
Johannes Berg463d0182009-07-14 00:33:35 +020011276 {
11277 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11278 .doit = nl80211_wiphy_netns,
11279 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011280 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011281 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11282 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011283 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011284 {
11285 .cmd = NL80211_CMD_GET_SURVEY,
11286 .policy = nl80211_policy,
11287 .dumpit = nl80211_dump_survey,
11288 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011289 {
11290 .cmd = NL80211_CMD_SET_PMKSA,
11291 .doit = nl80211_setdel_pmksa,
11292 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011293 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011295 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011296 },
11297 {
11298 .cmd = NL80211_CMD_DEL_PMKSA,
11299 .doit = nl80211_setdel_pmksa,
11300 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011301 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011302 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011303 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011304 },
11305 {
11306 .cmd = NL80211_CMD_FLUSH_PMKSA,
11307 .doit = nl80211_flush_pmksa,
11308 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011309 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011310 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011311 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011312 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011313 {
11314 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11315 .doit = nl80211_remain_on_channel,
11316 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011317 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011318 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011319 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011320 },
11321 {
11322 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11323 .doit = nl80211_cancel_remain_on_channel,
11324 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011325 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011326 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011327 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011328 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011329 {
11330 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11331 .doit = nl80211_set_tx_bitrate_mask,
11332 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011333 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011334 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11335 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011336 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011337 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011338 .cmd = NL80211_CMD_REGISTER_FRAME,
11339 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011340 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011341 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011342 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011343 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011344 },
11345 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011346 .cmd = NL80211_CMD_FRAME,
11347 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011348 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011349 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011350 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011351 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011352 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011353 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011354 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11355 .doit = nl80211_tx_mgmt_cancel_wait,
11356 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011357 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011358 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011359 NL80211_FLAG_NEED_RTNL,
11360 },
11361 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011362 .cmd = NL80211_CMD_SET_POWER_SAVE,
11363 .doit = nl80211_set_power_save,
11364 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011365 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011366 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11367 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011368 },
11369 {
11370 .cmd = NL80211_CMD_GET_POWER_SAVE,
11371 .doit = nl80211_get_power_save,
11372 .policy = nl80211_policy,
11373 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011374 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11375 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011376 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011377 {
11378 .cmd = NL80211_CMD_SET_CQM,
11379 .doit = nl80211_set_cqm,
11380 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011381 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011382 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11383 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011384 },
Johannes Bergf444de02010-05-05 15:25:02 +020011385 {
11386 .cmd = NL80211_CMD_SET_CHANNEL,
11387 .doit = nl80211_set_channel,
11388 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011389 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011390 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11391 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011392 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011393 {
11394 .cmd = NL80211_CMD_SET_WDS_PEER,
11395 .doit = nl80211_set_wds_peer,
11396 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011397 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011398 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11399 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011400 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011401 {
11402 .cmd = NL80211_CMD_JOIN_MESH,
11403 .doit = nl80211_join_mesh,
11404 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011405 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11407 NL80211_FLAG_NEED_RTNL,
11408 },
11409 {
11410 .cmd = NL80211_CMD_LEAVE_MESH,
11411 .doit = nl80211_leave_mesh,
11412 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011413 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010011414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11415 NL80211_FLAG_NEED_RTNL,
11416 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011417 {
11418 .cmd = NL80211_CMD_JOIN_OCB,
11419 .doit = nl80211_join_ocb,
11420 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011421 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11423 NL80211_FLAG_NEED_RTNL,
11424 },
11425 {
11426 .cmd = NL80211_CMD_LEAVE_OCB,
11427 .doit = nl80211_leave_ocb,
11428 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011429 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011430 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11431 NL80211_FLAG_NEED_RTNL,
11432 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011433#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011434 {
11435 .cmd = NL80211_CMD_GET_WOWLAN,
11436 .doit = nl80211_get_wowlan,
11437 .policy = nl80211_policy,
11438 /* can be retrieved by unprivileged users */
11439 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11440 NL80211_FLAG_NEED_RTNL,
11441 },
11442 {
11443 .cmd = NL80211_CMD_SET_WOWLAN,
11444 .doit = nl80211_set_wowlan,
11445 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011446 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011447 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11448 NL80211_FLAG_NEED_RTNL,
11449 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011450#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011451 {
11452 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11453 .doit = nl80211_set_rekey_data,
11454 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011455 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020011456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011457 NL80211_FLAG_NEED_RTNL |
11458 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011459 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011460 {
11461 .cmd = NL80211_CMD_TDLS_MGMT,
11462 .doit = nl80211_tdls_mgmt,
11463 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011464 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11466 NL80211_FLAG_NEED_RTNL,
11467 },
11468 {
11469 .cmd = NL80211_CMD_TDLS_OPER,
11470 .doit = nl80211_tdls_oper,
11471 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011472 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030011473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11474 NL80211_FLAG_NEED_RTNL,
11475 },
Johannes Berg28946da2011-11-04 11:18:12 +010011476 {
11477 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11478 .doit = nl80211_register_unexpected_frame,
11479 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011480 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010011481 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11482 NL80211_FLAG_NEED_RTNL,
11483 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011484 {
11485 .cmd = NL80211_CMD_PROBE_CLIENT,
11486 .doit = nl80211_probe_client,
11487 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011488 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011489 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011490 NL80211_FLAG_NEED_RTNL,
11491 },
Johannes Berg5e7602302011-11-04 11:18:17 +010011492 {
11493 .cmd = NL80211_CMD_REGISTER_BEACONS,
11494 .doit = nl80211_register_beacons,
11495 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011496 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010011497 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11498 NL80211_FLAG_NEED_RTNL,
11499 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011500 {
11501 .cmd = NL80211_CMD_SET_NOACK_MAP,
11502 .doit = nl80211_set_noack_map,
11503 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011504 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011505 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11506 NL80211_FLAG_NEED_RTNL,
11507 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011508 {
11509 .cmd = NL80211_CMD_START_P2P_DEVICE,
11510 .doit = nl80211_start_p2p_device,
11511 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011512 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011513 .internal_flags = NL80211_FLAG_NEED_WDEV |
11514 NL80211_FLAG_NEED_RTNL,
11515 },
11516 {
11517 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11518 .doit = nl80211_stop_p2p_device,
11519 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011520 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020011521 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11522 NL80211_FLAG_NEED_RTNL,
11523 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011524 {
11525 .cmd = NL80211_CMD_SET_MCAST_RATE,
11526 .doit = nl80211_set_mcast_rate,
11527 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011528 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011529 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11530 NL80211_FLAG_NEED_RTNL,
11531 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011532 {
11533 .cmd = NL80211_CMD_SET_MAC_ACL,
11534 .doit = nl80211_set_mac_acl,
11535 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011536 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011537 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11538 NL80211_FLAG_NEED_RTNL,
11539 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011540 {
11541 .cmd = NL80211_CMD_RADAR_DETECT,
11542 .doit = nl80211_start_radar_detection,
11543 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011544 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11546 NL80211_FLAG_NEED_RTNL,
11547 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011548 {
11549 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11550 .doit = nl80211_get_protocol_features,
11551 .policy = nl80211_policy,
11552 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011553 {
11554 .cmd = NL80211_CMD_UPDATE_FT_IES,
11555 .doit = nl80211_update_ft_ies,
11556 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011557 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020011558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11559 NL80211_FLAG_NEED_RTNL,
11560 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011561 {
11562 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11563 .doit = nl80211_crit_protocol_start,
11564 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011565 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011566 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11567 NL80211_FLAG_NEED_RTNL,
11568 },
11569 {
11570 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11571 .doit = nl80211_crit_protocol_stop,
11572 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011573 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020011574 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11575 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011576 },
11577 {
11578 .cmd = NL80211_CMD_GET_COALESCE,
11579 .doit = nl80211_get_coalesce,
11580 .policy = nl80211_policy,
11581 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11582 NL80211_FLAG_NEED_RTNL,
11583 },
11584 {
11585 .cmd = NL80211_CMD_SET_COALESCE,
11586 .doit = nl80211_set_coalesce,
11587 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011588 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011589 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11590 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011591 },
11592 {
11593 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11594 .doit = nl80211_channel_switch,
11595 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011596 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11598 NL80211_FLAG_NEED_RTNL,
11599 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011600 {
11601 .cmd = NL80211_CMD_VENDOR,
11602 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011603 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011604 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011605 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010011606 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11607 NL80211_FLAG_NEED_RTNL,
11608 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011609 {
11610 .cmd = NL80211_CMD_SET_QOS_MAP,
11611 .doit = nl80211_set_qos_map,
11612 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011613 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11615 NL80211_FLAG_NEED_RTNL,
11616 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011617 {
11618 .cmd = NL80211_CMD_ADD_TX_TS,
11619 .doit = nl80211_add_tx_ts,
11620 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011621 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11623 NL80211_FLAG_NEED_RTNL,
11624 },
11625 {
11626 .cmd = NL80211_CMD_DEL_TX_TS,
11627 .doit = nl80211_del_tx_ts,
11628 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011629 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030011630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11631 NL80211_FLAG_NEED_RTNL,
11632 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011633 {
11634 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11635 .doit = nl80211_tdls_channel_switch,
11636 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011637 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11639 NL80211_FLAG_NEED_RTNL,
11640 },
11641 {
11642 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11643 .doit = nl80211_tdls_cancel_channel_switch,
11644 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011645 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020011646 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11647 NL80211_FLAG_NEED_RTNL,
11648 },
Johannes Berg55682962007-09-20 13:09:35 -040011649};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011650
Johannes Berg55682962007-09-20 13:09:35 -040011651/* notification functions */
11652
Johannes Berg3bb20552014-05-26 13:52:25 +020011653void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11654 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011655{
11656 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011657 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011658
Johannes Berg3bb20552014-05-26 13:52:25 +020011659 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11660 cmd != NL80211_CMD_DEL_WIPHY);
11661
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011663 if (!msg)
11664 return;
11665
Johannes Berg3bb20552014-05-26 13:52:25 +020011666 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011667 nlmsg_free(msg);
11668 return;
11669 }
11670
Johannes Berg68eb5502013-11-19 15:19:38 +010011671 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011672 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011673}
11674
Johannes Berg362a4152009-05-24 16:43:15 +020011675static int nl80211_add_scan_req(struct sk_buff *msg,
11676 struct cfg80211_registered_device *rdev)
11677{
11678 struct cfg80211_scan_request *req = rdev->scan_req;
11679 struct nlattr *nest;
11680 int i;
11681
11682 if (WARN_ON(!req))
11683 return 0;
11684
11685 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11686 if (!nest)
11687 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011688 for (i = 0; i < req->n_ssids; i++) {
11689 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11690 goto nla_put_failure;
11691 }
Johannes Berg362a4152009-05-24 16:43:15 +020011692 nla_nest_end(msg, nest);
11693
11694 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11695 if (!nest)
11696 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011697 for (i = 0; i < req->n_channels; i++) {
11698 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11699 goto nla_put_failure;
11700 }
Johannes Berg362a4152009-05-24 16:43:15 +020011701 nla_nest_end(msg, nest);
11702
David S. Miller9360ffd2012-03-29 04:41:26 -040011703 if (req->ie &&
11704 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11705 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011706
Johannes Bergae917c92013-10-25 11:05:22 +020011707 if (req->flags &&
11708 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11709 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011710
Johannes Berg362a4152009-05-24 16:43:15 +020011711 return 0;
11712 nla_put_failure:
11713 return -ENOBUFS;
11714}
11715
Johannes Berga538e2d2009-06-16 19:56:42 +020011716static int nl80211_send_scan_msg(struct sk_buff *msg,
11717 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011718 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011719 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011720 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011721{
11722 void *hdr;
11723
Eric W. Biederman15e47302012-09-07 20:12:54 +000011724 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011725 if (!hdr)
11726 return -1;
11727
David S. Miller9360ffd2012-03-29 04:41:26 -040011728 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011729 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11730 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011731 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11732 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011733 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011734
Johannes Berg362a4152009-05-24 16:43:15 +020011735 /* ignore errors and send incomplete event anyway */
11736 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011737
Johannes Berg053c0952015-01-16 22:09:00 +010011738 genlmsg_end(msg, hdr);
11739 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011740
11741 nla_put_failure:
11742 genlmsg_cancel(msg, hdr);
11743 return -EMSGSIZE;
11744}
11745
Luciano Coelho807f8a82011-05-11 17:09:35 +030011746static int
11747nl80211_send_sched_scan_msg(struct sk_buff *msg,
11748 struct cfg80211_registered_device *rdev,
11749 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011750 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011751{
11752 void *hdr;
11753
Eric W. Biederman15e47302012-09-07 20:12:54 +000011754 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011755 if (!hdr)
11756 return -1;
11757
David S. Miller9360ffd2012-03-29 04:41:26 -040011758 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11759 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11760 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011761
Johannes Berg053c0952015-01-16 22:09:00 +010011762 genlmsg_end(msg, hdr);
11763 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011764
11765 nla_put_failure:
11766 genlmsg_cancel(msg, hdr);
11767 return -EMSGSIZE;
11768}
11769
Johannes Berga538e2d2009-06-16 19:56:42 +020011770void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011771 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011772{
11773 struct sk_buff *msg;
11774
Thomas Graf58050fc2012-06-28 03:57:45 +000011775 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011776 if (!msg)
11777 return;
11778
Johannes Bergfd014282012-06-18 19:17:03 +020011779 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011780 NL80211_CMD_TRIGGER_SCAN) < 0) {
11781 nlmsg_free(msg);
11782 return;
11783 }
11784
Johannes Berg68eb5502013-11-19 15:19:38 +010011785 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011786 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011787}
11788
Johannes Bergf9d15d12014-01-22 11:14:19 +020011789struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11790 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011791{
11792 struct sk_buff *msg;
11793
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011795 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011796 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011797
Johannes Bergfd014282012-06-18 19:17:03 +020011798 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011799 aborted ? NL80211_CMD_SCAN_ABORTED :
11800 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011801 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011802 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011803 }
11804
Johannes Bergf9d15d12014-01-22 11:14:19 +020011805 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011806}
11807
Johannes Bergf9d15d12014-01-22 11:14:19 +020011808void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11809 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011810{
Johannes Berg2a519312009-02-10 21:25:55 +010011811 if (!msg)
11812 return;
11813
Johannes Berg68eb5502013-11-19 15:19:38 +010011814 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011815 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011816}
11817
Luciano Coelho807f8a82011-05-11 17:09:35 +030011818void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11819 struct net_device *netdev)
11820{
11821 struct sk_buff *msg;
11822
11823 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11824 if (!msg)
11825 return;
11826
11827 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11828 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11829 nlmsg_free(msg);
11830 return;
11831 }
11832
Johannes Berg68eb5502013-11-19 15:19:38 +010011833 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011834 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011835}
11836
11837void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11838 struct net_device *netdev, u32 cmd)
11839{
11840 struct sk_buff *msg;
11841
Thomas Graf58050fc2012-06-28 03:57:45 +000011842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011843 if (!msg)
11844 return;
11845
11846 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11847 nlmsg_free(msg);
11848 return;
11849 }
11850
Johannes Berg68eb5502013-11-19 15:19:38 +010011851 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011852 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011853}
11854
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011855static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11856 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011857{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011858 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011859 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11860 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011861
David S. Miller9360ffd2012-03-29 04:41:26 -040011862 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11863 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11864 NL80211_REGDOM_TYPE_WORLD))
11865 goto nla_put_failure;
11866 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11867 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11868 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11869 goto nla_put_failure;
11870 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11871 request->intersect) {
11872 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11873 NL80211_REGDOM_TYPE_INTERSECTION))
11874 goto nla_put_failure;
11875 } else {
11876 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11877 NL80211_REGDOM_TYPE_COUNTRY) ||
11878 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11879 request->alpha2))
11880 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011881 }
11882
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011883 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11884 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11885
11886 if (wiphy &&
11887 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11888 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011889
11890 if (wiphy &&
11891 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11892 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11893 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011894 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011895
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011896 return true;
11897
11898nla_put_failure:
11899 return false;
11900}
11901
11902/*
11903 * This can happen on global regulatory changes or device specific settings
11904 * based on custom regulatory domains.
11905 */
11906void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11907 struct regulatory_request *request)
11908{
11909 struct sk_buff *msg;
11910 void *hdr;
11911
11912 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11913 if (!msg)
11914 return;
11915
11916 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11917 if (!hdr) {
11918 nlmsg_free(msg);
11919 return;
11920 }
11921
11922 if (nl80211_reg_change_event_fill(msg, request) == false)
11923 goto nla_put_failure;
11924
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011925 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011926
Johannes Bergbc43b282009-07-25 10:54:13 +020011927 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011928 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011929 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011930 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011931
11932 return;
11933
11934nla_put_failure:
11935 genlmsg_cancel(msg, hdr);
11936 nlmsg_free(msg);
11937}
11938
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011939static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11940 struct net_device *netdev,
11941 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011942 enum nl80211_commands cmd, gfp_t gfp,
11943 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011944{
11945 struct sk_buff *msg;
11946 void *hdr;
11947
Johannes Berge6d6e342009-07-01 21:26:47 +020011948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011949 if (!msg)
11950 return;
11951
11952 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11953 if (!hdr) {
11954 nlmsg_free(msg);
11955 return;
11956 }
11957
David S. Miller9360ffd2012-03-29 04:41:26 -040011958 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11960 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11961 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011962
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011963 if (uapsd_queues >= 0) {
11964 struct nlattr *nla_wmm =
11965 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11966 if (!nla_wmm)
11967 goto nla_put_failure;
11968
11969 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11970 uapsd_queues))
11971 goto nla_put_failure;
11972
11973 nla_nest_end(msg, nla_wmm);
11974 }
11975
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011976 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011977
Johannes Berg68eb5502013-11-19 15:19:38 +010011978 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011979 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011980 return;
11981
11982 nla_put_failure:
11983 genlmsg_cancel(msg, hdr);
11984 nlmsg_free(msg);
11985}
11986
11987void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011988 struct net_device *netdev, const u8 *buf,
11989 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011990{
11991 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011992 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011993}
11994
11995void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11996 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011997 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011998{
Johannes Berge6d6e342009-07-01 21:26:47 +020011999 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012000 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012001}
12002
Jouni Malinen53b46b82009-03-27 20:53:56 +020012003void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012004 struct net_device *netdev, const u8 *buf,
12005 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012006{
12007 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012008 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012009}
12010
Jouni Malinen53b46b82009-03-27 20:53:56 +020012011void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
12012 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020012013 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012014{
12015 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012016 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012017}
12018
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012019void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
12020 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020012021{
Johannes Berg947add32013-02-22 22:05:20 +010012022 struct wireless_dev *wdev = dev->ieee80211_ptr;
12023 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012024 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012025 const struct ieee80211_mgmt *mgmt = (void *)buf;
12026 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020012027
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012028 if (WARN_ON(len < 2))
12029 return;
12030
12031 if (ieee80211_is_deauth(mgmt->frame_control))
12032 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
12033 else
12034 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
12035
12036 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012037 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012038}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020012039EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020012040
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040012041static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
12042 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020012043 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012044{
12045 struct sk_buff *msg;
12046 void *hdr;
12047
Johannes Berge6d6e342009-07-01 21:26:47 +020012048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012049 if (!msg)
12050 return;
12051
12052 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12053 if (!hdr) {
12054 nlmsg_free(msg);
12055 return;
12056 }
12057
David S. Miller9360ffd2012-03-29 04:41:26 -040012058 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12059 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12060 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
12061 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12062 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030012063
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012064 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030012065
Johannes Berg68eb5502013-11-19 15:19:38 +010012066 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012067 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012068 return;
12069
12070 nla_put_failure:
12071 genlmsg_cancel(msg, hdr);
12072 nlmsg_free(msg);
12073}
12074
12075void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012076 struct net_device *netdev, const u8 *addr,
12077 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012078{
12079 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020012080 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012081}
12082
12083void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012084 struct net_device *netdev, const u8 *addr,
12085 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030012086{
Johannes Berge6d6e342009-07-01 21:26:47 +020012087 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
12088 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030012089}
12090
Samuel Ortizb23aa672009-07-01 21:26:54 +020012091void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
12092 struct net_device *netdev, const u8 *bssid,
12093 const u8 *req_ie, size_t req_ie_len,
12094 const u8 *resp_ie, size_t resp_ie_len,
12095 u16 status, gfp_t gfp)
12096{
12097 struct sk_buff *msg;
12098 void *hdr;
12099
Thomas Graf58050fc2012-06-28 03:57:45 +000012100 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012101 if (!msg)
12102 return;
12103
12104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
12105 if (!hdr) {
12106 nlmsg_free(msg);
12107 return;
12108 }
12109
David S. Miller9360ffd2012-03-29 04:41:26 -040012110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12111 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12112 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
12113 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
12114 (req_ie &&
12115 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12116 (resp_ie &&
12117 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12118 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012119
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012120 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012121
Johannes Berg68eb5502013-11-19 15:19:38 +010012122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012123 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012124 return;
12125
12126 nla_put_failure:
12127 genlmsg_cancel(msg, hdr);
12128 nlmsg_free(msg);
12129
12130}
12131
12132void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
12133 struct net_device *netdev, const u8 *bssid,
12134 const u8 *req_ie, size_t req_ie_len,
12135 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
12136{
12137 struct sk_buff *msg;
12138 void *hdr;
12139
Thomas Graf58050fc2012-06-28 03:57:45 +000012140 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012141 if (!msg)
12142 return;
12143
12144 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
12145 if (!hdr) {
12146 nlmsg_free(msg);
12147 return;
12148 }
12149
David S. Miller9360ffd2012-03-29 04:41:26 -040012150 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12151 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12152 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
12153 (req_ie &&
12154 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
12155 (resp_ie &&
12156 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
12157 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012158
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012159 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012160
Johannes Berg68eb5502013-11-19 15:19:38 +010012161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012162 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012163 return;
12164
12165 nla_put_failure:
12166 genlmsg_cancel(msg, hdr);
12167 nlmsg_free(msg);
12168
12169}
12170
12171void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
12172 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020012173 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012174{
12175 struct sk_buff *msg;
12176 void *hdr;
12177
Thomas Graf58050fc2012-06-28 03:57:45 +000012178 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012179 if (!msg)
12180 return;
12181
12182 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12183 if (!hdr) {
12184 nlmsg_free(msg);
12185 return;
12186 }
12187
David S. Miller9360ffd2012-03-29 04:41:26 -040012188 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12189 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12190 (from_ap && reason &&
12191 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12192 (from_ap &&
12193 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12194 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12195 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012196
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012197 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012198
Johannes Berg68eb5502013-11-19 15:19:38 +010012199 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012200 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012201 return;
12202
12203 nla_put_failure:
12204 genlmsg_cancel(msg, hdr);
12205 nlmsg_free(msg);
12206
12207}
12208
Johannes Berg04a773a2009-04-19 21:24:32 +020012209void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12210 struct net_device *netdev, const u8 *bssid,
12211 gfp_t gfp)
12212{
12213 struct sk_buff *msg;
12214 void *hdr;
12215
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012217 if (!msg)
12218 return;
12219
12220 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12221 if (!hdr) {
12222 nlmsg_free(msg);
12223 return;
12224 }
12225
David S. Miller9360ffd2012-03-29 04:41:26 -040012226 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12227 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12228 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12229 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012230
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012231 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012232
Johannes Berg68eb5502013-11-19 15:19:38 +010012233 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012234 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012235 return;
12236
12237 nla_put_failure:
12238 genlmsg_cancel(msg, hdr);
12239 nlmsg_free(msg);
12240}
12241
Johannes Berg947add32013-02-22 22:05:20 +010012242void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12243 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012244{
Johannes Berg947add32013-02-22 22:05:20 +010012245 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012246 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012247 struct sk_buff *msg;
12248 void *hdr;
12249
Johannes Berg947add32013-02-22 22:05:20 +010012250 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12251 return;
12252
12253 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12254
Javier Cardonac93b5e72011-04-07 15:08:34 -070012255 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12256 if (!msg)
12257 return;
12258
12259 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12260 if (!hdr) {
12261 nlmsg_free(msg);
12262 return;
12263 }
12264
David S. Miller9360ffd2012-03-29 04:41:26 -040012265 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012266 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12267 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012268 (ie_len && ie &&
12269 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12270 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012271
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012272 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012273
Johannes Berg68eb5502013-11-19 15:19:38 +010012274 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012275 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012276 return;
12277
12278 nla_put_failure:
12279 genlmsg_cancel(msg, hdr);
12280 nlmsg_free(msg);
12281}
Johannes Berg947add32013-02-22 22:05:20 +010012282EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012283
Jouni Malinena3b8b052009-03-27 21:59:49 +020012284void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12285 struct net_device *netdev, const u8 *addr,
12286 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012287 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012288{
12289 struct sk_buff *msg;
12290 void *hdr;
12291
Johannes Berge6d6e342009-07-01 21:26:47 +020012292 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012293 if (!msg)
12294 return;
12295
12296 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12297 if (!hdr) {
12298 nlmsg_free(msg);
12299 return;
12300 }
12301
David S. Miller9360ffd2012-03-29 04:41:26 -040012302 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12303 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12304 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12305 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12306 (key_id != -1 &&
12307 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12308 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12309 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012310
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012311 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012312
Johannes Berg68eb5502013-11-19 15:19:38 +010012313 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012314 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012315 return;
12316
12317 nla_put_failure:
12318 genlmsg_cancel(msg, hdr);
12319 nlmsg_free(msg);
12320}
12321
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012322void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12323 struct ieee80211_channel *channel_before,
12324 struct ieee80211_channel *channel_after)
12325{
12326 struct sk_buff *msg;
12327 void *hdr;
12328 struct nlattr *nl_freq;
12329
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012331 if (!msg)
12332 return;
12333
12334 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12335 if (!hdr) {
12336 nlmsg_free(msg);
12337 return;
12338 }
12339
12340 /*
12341 * Since we are applying the beacon hint to a wiphy we know its
12342 * wiphy_idx is valid
12343 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12345 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012346
12347 /* Before */
12348 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12349 if (!nl_freq)
12350 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012351 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012352 goto nla_put_failure;
12353 nla_nest_end(msg, nl_freq);
12354
12355 /* After */
12356 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12357 if (!nl_freq)
12358 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012359 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012360 goto nla_put_failure;
12361 nla_nest_end(msg, nl_freq);
12362
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012363 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012364
Johannes Berg463d0182009-07-14 00:33:35 +020012365 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012366 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012367 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012368 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012369
12370 return;
12371
12372nla_put_failure:
12373 genlmsg_cancel(msg, hdr);
12374 nlmsg_free(msg);
12375}
12376
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012377static void nl80211_send_remain_on_chan_event(
12378 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012379 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012380 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012381 unsigned int duration, gfp_t gfp)
12382{
12383 struct sk_buff *msg;
12384 void *hdr;
12385
12386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12387 if (!msg)
12388 return;
12389
12390 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12391 if (!hdr) {
12392 nlmsg_free(msg);
12393 return;
12394 }
12395
David S. Miller9360ffd2012-03-29 04:41:26 -040012396 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012397 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12398 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012399 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12400 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012401 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012402 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12403 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012404 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12405 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012406 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012407
David S. Miller9360ffd2012-03-29 04:41:26 -040012408 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12409 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12410 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012411
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012412 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012413
Johannes Berg68eb5502013-11-19 15:19:38 +010012414 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012415 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012416 return;
12417
12418 nla_put_failure:
12419 genlmsg_cancel(msg, hdr);
12420 nlmsg_free(msg);
12421}
12422
Johannes Berg947add32013-02-22 22:05:20 +010012423void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12424 struct ieee80211_channel *chan,
12425 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012426{
Johannes Berg947add32013-02-22 22:05:20 +010012427 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012428 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012429
12430 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012431 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012432 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012433 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012434}
Johannes Berg947add32013-02-22 22:05:20 +010012435EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012436
Johannes Berg947add32013-02-22 22:05:20 +010012437void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12438 struct ieee80211_channel *chan,
12439 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012440{
Johannes Berg947add32013-02-22 22:05:20 +010012441 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012442 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012443
12444 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012445 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012446 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012447}
Johannes Berg947add32013-02-22 22:05:20 +010012448EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012449
Johannes Berg947add32013-02-22 22:05:20 +010012450void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12451 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012452{
Johannes Berg947add32013-02-22 22:05:20 +010012453 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012454 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012455 struct sk_buff *msg;
12456
Johannes Berg947add32013-02-22 22:05:20 +010012457 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12458
Thomas Graf58050fc2012-06-28 03:57:45 +000012459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012460 if (!msg)
12461 return;
12462
Johannes Bergcf5ead82014-11-14 17:14:00 +010012463 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012464 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012465 nlmsg_free(msg);
12466 return;
12467 }
12468
Johannes Berg68eb5502013-11-19 15:19:38 +010012469 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012470 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012471}
Johannes Berg947add32013-02-22 22:05:20 +010012472EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012473
Johannes Bergcf5ead82014-11-14 17:14:00 +010012474void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12475 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012476{
Johannes Berg947add32013-02-22 22:05:20 +010012477 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012478 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012479 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012480 struct station_info empty_sinfo = {};
12481
12482 if (!sinfo)
12483 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012484
Johannes Berg947add32013-02-22 22:05:20 +010012485 trace_cfg80211_del_sta(dev, mac_addr);
12486
Thomas Graf58050fc2012-06-28 03:57:45 +000012487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012488 if (!msg)
12489 return;
12490
Johannes Bergcf5ead82014-11-14 17:14:00 +010012491 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012492 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012493 nlmsg_free(msg);
12494 return;
12495 }
12496
Johannes Berg68eb5502013-11-19 15:19:38 +010012497 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012498 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012499}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012500EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012501
Johannes Berg947add32013-02-22 22:05:20 +010012502void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12503 enum nl80211_connect_failed_reason reason,
12504 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012505{
Johannes Berg947add32013-02-22 22:05:20 +010012506 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012507 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012508 struct sk_buff *msg;
12509 void *hdr;
12510
12511 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12512 if (!msg)
12513 return;
12514
12515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12516 if (!hdr) {
12517 nlmsg_free(msg);
12518 return;
12519 }
12520
12521 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12522 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12523 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12524 goto nla_put_failure;
12525
12526 genlmsg_end(msg, hdr);
12527
Johannes Berg68eb5502013-11-19 15:19:38 +010012528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012529 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012530 return;
12531
12532 nla_put_failure:
12533 genlmsg_cancel(msg, hdr);
12534 nlmsg_free(msg);
12535}
Johannes Berg947add32013-02-22 22:05:20 +010012536EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012537
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012538static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12539 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012540{
12541 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012542 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012543 struct sk_buff *msg;
12544 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012545 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012546
Eric W. Biederman15e47302012-09-07 20:12:54 +000012547 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012548 return false;
12549
12550 msg = nlmsg_new(100, gfp);
12551 if (!msg)
12552 return true;
12553
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012554 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012555 if (!hdr) {
12556 nlmsg_free(msg);
12557 return true;
12558 }
12559
David S. Miller9360ffd2012-03-29 04:41:26 -040012560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12562 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12563 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012564
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012565 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012566 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012567 return true;
12568
12569 nla_put_failure:
12570 genlmsg_cancel(msg, hdr);
12571 nlmsg_free(msg);
12572 return true;
12573}
12574
Johannes Berg947add32013-02-22 22:05:20 +010012575bool cfg80211_rx_spurious_frame(struct net_device *dev,
12576 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012577{
Johannes Berg947add32013-02-22 22:05:20 +010012578 struct wireless_dev *wdev = dev->ieee80211_ptr;
12579 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012580
Johannes Berg947add32013-02-22 22:05:20 +010012581 trace_cfg80211_rx_spurious_frame(dev, addr);
12582
12583 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12584 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12585 trace_cfg80211_return_bool(false);
12586 return false;
12587 }
12588 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12589 addr, gfp);
12590 trace_cfg80211_return_bool(ret);
12591 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012592}
Johannes Berg947add32013-02-22 22:05:20 +010012593EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12594
12595bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12596 const u8 *addr, gfp_t gfp)
12597{
12598 struct wireless_dev *wdev = dev->ieee80211_ptr;
12599 bool ret;
12600
12601 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12602
12603 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12604 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12605 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12606 trace_cfg80211_return_bool(false);
12607 return false;
12608 }
12609 ret = __nl80211_unexpected_frame(dev,
12610 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12611 addr, gfp);
12612 trace_cfg80211_return_bool(ret);
12613 return ret;
12614}
12615EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012616
Johannes Berg2e161f72010-08-12 15:38:38 +020012617int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012618 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012619 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012620 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012621{
Johannes Berg71bbc992012-06-15 15:30:18 +020012622 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012623 struct sk_buff *msg;
12624 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012625
12626 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12627 if (!msg)
12628 return -ENOMEM;
12629
Johannes Berg2e161f72010-08-12 15:38:38 +020012630 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012631 if (!hdr) {
12632 nlmsg_free(msg);
12633 return -ENOMEM;
12634 }
12635
David S. Miller9360ffd2012-03-29 04:41:26 -040012636 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012637 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12638 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012639 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12640 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012641 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12642 (sig_dbm &&
12643 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012644 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12645 (flags &&
12646 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012647 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012648
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012649 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012650
Eric W. Biederman15e47302012-09-07 20:12:54 +000012651 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012652
12653 nla_put_failure:
12654 genlmsg_cancel(msg, hdr);
12655 nlmsg_free(msg);
12656 return -ENOBUFS;
12657}
12658
Johannes Berg947add32013-02-22 22:05:20 +010012659void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12660 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012661{
Johannes Berg947add32013-02-22 22:05:20 +010012662 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012663 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012664 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012665 struct sk_buff *msg;
12666 void *hdr;
12667
Johannes Berg947add32013-02-22 22:05:20 +010012668 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12669
Jouni Malinen026331c2010-02-15 12:53:10 +020012670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12671 if (!msg)
12672 return;
12673
Johannes Berg2e161f72010-08-12 15:38:38 +020012674 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012675 if (!hdr) {
12676 nlmsg_free(msg);
12677 return;
12678 }
12679
David S. Miller9360ffd2012-03-29 04:41:26 -040012680 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012681 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12682 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012683 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12684 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012685 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012686 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12687 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012688 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12689 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012690
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012691 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012692
Johannes Berg68eb5502013-11-19 15:19:38 +010012693 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012694 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012695 return;
12696
12697 nla_put_failure:
12698 genlmsg_cancel(msg, hdr);
12699 nlmsg_free(msg);
12700}
Johannes Berg947add32013-02-22 22:05:20 +010012701EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012702
Johannes Berg5b97f492014-11-26 12:37:43 +010012703static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12704 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012705{
Johannes Berg947add32013-02-22 22:05:20 +010012706 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012707 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12708 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12709 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012710
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012711 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012712 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012713
Johannes Berg5b97f492014-11-26 12:37:43 +010012714 cb = (void **)msg->cb;
12715
12716 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12717 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012718 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012719 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012720 }
12721
David S. Miller9360ffd2012-03-29 04:41:26 -040012722 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012723 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012724 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012725
Johannes Berg5b97f492014-11-26 12:37:43 +010012726 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012727 goto nla_put_failure;
12728
Johannes Berg5b97f492014-11-26 12:37:43 +010012729 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12730 if (!cb[1])
12731 goto nla_put_failure;
12732
12733 cb[2] = rdev;
12734
12735 return msg;
12736 nla_put_failure:
12737 nlmsg_free(msg);
12738 return NULL;
12739}
12740
12741static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12742{
12743 void **cb = (void **)msg->cb;
12744 struct cfg80211_registered_device *rdev = cb[2];
12745
12746 nla_nest_end(msg, cb[1]);
12747 genlmsg_end(msg, cb[0]);
12748
12749 memset(msg->cb, 0, sizeof(msg->cb));
12750
12751 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12752 NL80211_MCGRP_MLME, gfp);
12753}
12754
12755void cfg80211_cqm_rssi_notify(struct net_device *dev,
12756 enum nl80211_cqm_rssi_threshold_event rssi_event,
12757 gfp_t gfp)
12758{
12759 struct sk_buff *msg;
12760
12761 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12762
Johannes Berg98f03342014-11-26 12:42:02 +010012763 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12764 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12765 return;
12766
Johannes Berg5b97f492014-11-26 12:37:43 +010012767 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12768 if (!msg)
12769 return;
12770
David S. Miller9360ffd2012-03-29 04:41:26 -040012771 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12772 rssi_event))
12773 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012774
Johannes Berg5b97f492014-11-26 12:37:43 +010012775 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012776
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012777 return;
12778
12779 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012780 nlmsg_free(msg);
12781}
Johannes Berg947add32013-02-22 22:05:20 +010012782EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012783
Johannes Berg5b97f492014-11-26 12:37:43 +010012784void cfg80211_cqm_txe_notify(struct net_device *dev,
12785 const u8 *peer, u32 num_packets,
12786 u32 rate, u32 intvl, gfp_t gfp)
12787{
12788 struct sk_buff *msg;
12789
12790 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12791 if (!msg)
12792 return;
12793
12794 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12795 goto nla_put_failure;
12796
12797 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12798 goto nla_put_failure;
12799
12800 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12801 goto nla_put_failure;
12802
12803 cfg80211_send_cqm(msg, gfp);
12804 return;
12805
12806 nla_put_failure:
12807 nlmsg_free(msg);
12808}
12809EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12810
12811void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12812 const u8 *peer, u32 num_packets, gfp_t gfp)
12813{
12814 struct sk_buff *msg;
12815
12816 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12817
12818 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12819 if (!msg)
12820 return;
12821
12822 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12823 goto nla_put_failure;
12824
12825 cfg80211_send_cqm(msg, gfp);
12826 return;
12827
12828 nla_put_failure:
12829 nlmsg_free(msg);
12830}
12831EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12832
Johannes Berg98f03342014-11-26 12:42:02 +010012833void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12834{
12835 struct sk_buff *msg;
12836
12837 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12838 if (!msg)
12839 return;
12840
12841 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12842 goto nla_put_failure;
12843
12844 cfg80211_send_cqm(msg, gfp);
12845 return;
12846
12847 nla_put_failure:
12848 nlmsg_free(msg);
12849}
12850EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12851
Johannes Berg947add32013-02-22 22:05:20 +010012852static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12853 struct net_device *netdev, const u8 *bssid,
12854 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012855{
12856 struct sk_buff *msg;
12857 struct nlattr *rekey_attr;
12858 void *hdr;
12859
Thomas Graf58050fc2012-06-28 03:57:45 +000012860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012861 if (!msg)
12862 return;
12863
12864 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12865 if (!hdr) {
12866 nlmsg_free(msg);
12867 return;
12868 }
12869
David S. Miller9360ffd2012-03-29 04:41:26 -040012870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12871 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12872 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12873 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012874
12875 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12876 if (!rekey_attr)
12877 goto nla_put_failure;
12878
David S. Miller9360ffd2012-03-29 04:41:26 -040012879 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12880 NL80211_REPLAY_CTR_LEN, replay_ctr))
12881 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012882
12883 nla_nest_end(msg, rekey_attr);
12884
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012885 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012886
Johannes Berg68eb5502013-11-19 15:19:38 +010012887 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012888 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012889 return;
12890
12891 nla_put_failure:
12892 genlmsg_cancel(msg, hdr);
12893 nlmsg_free(msg);
12894}
12895
Johannes Berg947add32013-02-22 22:05:20 +010012896void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12897 const u8 *replay_ctr, gfp_t gfp)
12898{
12899 struct wireless_dev *wdev = dev->ieee80211_ptr;
12900 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012901 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012902
12903 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12904 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12905}
12906EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12907
12908static void
12909nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12910 struct net_device *netdev, int index,
12911 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012912{
12913 struct sk_buff *msg;
12914 struct nlattr *attr;
12915 void *hdr;
12916
Thomas Graf58050fc2012-06-28 03:57:45 +000012917 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012918 if (!msg)
12919 return;
12920
12921 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12922 if (!hdr) {
12923 nlmsg_free(msg);
12924 return;
12925 }
12926
David S. Miller9360ffd2012-03-29 04:41:26 -040012927 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12928 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12929 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012930
12931 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12932 if (!attr)
12933 goto nla_put_failure;
12934
David S. Miller9360ffd2012-03-29 04:41:26 -040012935 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12936 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12937 (preauth &&
12938 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12939 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012940
12941 nla_nest_end(msg, attr);
12942
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012943 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012944
Johannes Berg68eb5502013-11-19 15:19:38 +010012945 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012946 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012947 return;
12948
12949 nla_put_failure:
12950 genlmsg_cancel(msg, hdr);
12951 nlmsg_free(msg);
12952}
12953
Johannes Berg947add32013-02-22 22:05:20 +010012954void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12955 const u8 *bssid, bool preauth, gfp_t gfp)
12956{
12957 struct wireless_dev *wdev = dev->ieee80211_ptr;
12958 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012959 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012960
12961 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12962 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12963}
12964EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12965
12966static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12967 struct net_device *netdev,
12968 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012969 gfp_t gfp,
12970 enum nl80211_commands notif,
12971 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012972{
12973 struct sk_buff *msg;
12974 void *hdr;
12975
Thomas Graf58050fc2012-06-28 03:57:45 +000012976 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012977 if (!msg)
12978 return;
12979
Luciano Coelhof8d75522014-11-07 14:31:35 +020012980 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012981 if (!hdr) {
12982 nlmsg_free(msg);
12983 return;
12984 }
12985
Johannes Berg683b6d32012-11-08 21:25:48 +010012986 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12987 goto nla_put_failure;
12988
12989 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012990 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012991
Luciano Coelhof8d75522014-11-07 14:31:35 +020012992 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12993 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12994 goto nla_put_failure;
12995
Thomas Pedersen53145262012-04-06 13:35:47 -070012996 genlmsg_end(msg, hdr);
12997
Johannes Berg68eb5502013-11-19 15:19:38 +010012998 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012999 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013000 return;
13001
13002 nla_put_failure:
13003 genlmsg_cancel(msg, hdr);
13004 nlmsg_free(msg);
13005}
13006
Johannes Berg947add32013-02-22 22:05:20 +010013007void cfg80211_ch_switch_notify(struct net_device *dev,
13008 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070013009{
Johannes Berg947add32013-02-22 22:05:20 +010013010 struct wireless_dev *wdev = dev->ieee80211_ptr;
13011 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013012 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013013
Simon Wunderliche487eae2013-11-21 18:19:51 +010013014 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010013015
Simon Wunderliche487eae2013-11-21 18:19:51 +010013016 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010013017
Michal Kazior9e0e2962014-01-29 14:22:27 +010013018 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010013019 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020013020 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13021 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010013022}
13023EXPORT_SYMBOL(cfg80211_ch_switch_notify);
13024
Luciano Coelhof8d75522014-11-07 14:31:35 +020013025void cfg80211_ch_switch_started_notify(struct net_device *dev,
13026 struct cfg80211_chan_def *chandef,
13027 u8 count)
13028{
13029 struct wireless_dev *wdev = dev->ieee80211_ptr;
13030 struct wiphy *wiphy = wdev->wiphy;
13031 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13032
13033 trace_cfg80211_ch_switch_started_notify(dev, chandef);
13034
13035 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
13036 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
13037}
13038EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
13039
Thomas Pedersen84f10702012-07-12 16:17:33 -070013040void
Simon Wunderlich04f39042013-02-08 18:16:19 +010013041nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010013042 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010013043 enum nl80211_radar_event event,
13044 struct net_device *netdev, gfp_t gfp)
13045{
13046 struct sk_buff *msg;
13047 void *hdr;
13048
13049 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13050 if (!msg)
13051 return;
13052
13053 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
13054 if (!hdr) {
13055 nlmsg_free(msg);
13056 return;
13057 }
13058
13059 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
13060 goto nla_put_failure;
13061
13062 /* NOP and radar events don't need a netdev parameter */
13063 if (netdev) {
13064 struct wireless_dev *wdev = netdev->ieee80211_ptr;
13065
13066 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013067 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13068 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010013069 goto nla_put_failure;
13070 }
13071
13072 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
13073 goto nla_put_failure;
13074
13075 if (nl80211_send_chandef(msg, chandef))
13076 goto nla_put_failure;
13077
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013078 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013079
Johannes Berg68eb5502013-11-19 15:19:38 +010013080 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013081 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010013082 return;
13083
13084 nla_put_failure:
13085 genlmsg_cancel(msg, hdr);
13086 nlmsg_free(msg);
13087}
13088
Johannes Berg7f6cf312011-11-04 11:18:15 +010013089void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
13090 u64 cookie, bool acked, gfp_t gfp)
13091{
13092 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013093 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013094 struct sk_buff *msg;
13095 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013096
Beni Lev4ee3e062012-08-27 12:49:39 +030013097 trace_cfg80211_probe_status(dev, addr, cookie, acked);
13098
Thomas Graf58050fc2012-06-28 03:57:45 +000013099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030013100
Johannes Berg7f6cf312011-11-04 11:18:15 +010013101 if (!msg)
13102 return;
13103
13104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
13105 if (!hdr) {
13106 nlmsg_free(msg);
13107 return;
13108 }
13109
David S. Miller9360ffd2012-03-29 04:41:26 -040013110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13111 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13112 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013113 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13114 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013115 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
13116 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010013117
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013118 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013119
Johannes Berg68eb5502013-11-19 15:19:38 +010013120 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013121 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010013122 return;
13123
13124 nla_put_failure:
13125 genlmsg_cancel(msg, hdr);
13126 nlmsg_free(msg);
13127}
13128EXPORT_SYMBOL(cfg80211_probe_status);
13129
Johannes Berg5e7602302011-11-04 11:18:17 +010013130void cfg80211_report_obss_beacon(struct wiphy *wiphy,
13131 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070013132 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010013133{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013134 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010013135 struct sk_buff *msg;
13136 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070013137 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010013138
Beni Lev4ee3e062012-08-27 12:49:39 +030013139 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
13140
Ben Greear37c73b52012-10-26 14:49:25 -070013141 spin_lock_bh(&rdev->beacon_registrations_lock);
13142 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
13143 msg = nlmsg_new(len + 100, GFP_ATOMIC);
13144 if (!msg) {
13145 spin_unlock_bh(&rdev->beacon_registrations_lock);
13146 return;
13147 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013148
Ben Greear37c73b52012-10-26 14:49:25 -070013149 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
13150 if (!hdr)
13151 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010013152
Ben Greear37c73b52012-10-26 14:49:25 -070013153 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13154 (freq &&
13155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
13156 (sig_dbm &&
13157 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
13158 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
13159 goto nla_put_failure;
13160
13161 genlmsg_end(msg, hdr);
13162
13163 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010013164 }
Ben Greear37c73b52012-10-26 14:49:25 -070013165 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010013166 return;
13167
13168 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070013169 spin_unlock_bh(&rdev->beacon_registrations_lock);
13170 if (hdr)
13171 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010013172 nlmsg_free(msg);
13173}
13174EXPORT_SYMBOL(cfg80211_report_obss_beacon);
13175
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013176#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013177static int cfg80211_net_detect_results(struct sk_buff *msg,
13178 struct cfg80211_wowlan_wakeup *wakeup)
13179{
13180 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13181 struct nlattr *nl_results, *nl_match, *nl_freqs;
13182 int i, j;
13183
13184 nl_results = nla_nest_start(
13185 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13186 if (!nl_results)
13187 return -EMSGSIZE;
13188
13189 for (i = 0; i < nd->n_matches; i++) {
13190 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13191
13192 nl_match = nla_nest_start(msg, i);
13193 if (!nl_match)
13194 break;
13195
13196 /* The SSID attribute is optional in nl80211, but for
13197 * simplicity reasons it's always present in the
13198 * cfg80211 structure. If a driver can't pass the
13199 * SSID, that needs to be changed. A zero length SSID
13200 * is still a valid SSID (wildcard), so it cannot be
13201 * used for this purpose.
13202 */
13203 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13204 match->ssid.ssid)) {
13205 nla_nest_cancel(msg, nl_match);
13206 goto out;
13207 }
13208
13209 if (match->n_channels) {
13210 nl_freqs = nla_nest_start(
13211 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13212 if (!nl_freqs) {
13213 nla_nest_cancel(msg, nl_match);
13214 goto out;
13215 }
13216
13217 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013218 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013219 nla_nest_cancel(msg, nl_freqs);
13220 nla_nest_cancel(msg, nl_match);
13221 goto out;
13222 }
13223 }
13224
13225 nla_nest_end(msg, nl_freqs);
13226 }
13227
13228 nla_nest_end(msg, nl_match);
13229 }
13230
13231out:
13232 nla_nest_end(msg, nl_results);
13233 return 0;
13234}
13235
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013236void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13237 struct cfg80211_wowlan_wakeup *wakeup,
13238 gfp_t gfp)
13239{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013240 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013241 struct sk_buff *msg;
13242 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013243 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013244
13245 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13246
13247 if (wakeup)
13248 size += wakeup->packet_present_len;
13249
13250 msg = nlmsg_new(size, gfp);
13251 if (!msg)
13252 return;
13253
13254 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13255 if (!hdr)
13256 goto free_msg;
13257
13258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013259 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13260 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013261 goto free_msg;
13262
13263 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13264 wdev->netdev->ifindex))
13265 goto free_msg;
13266
13267 if (wakeup) {
13268 struct nlattr *reasons;
13269
13270 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013271 if (!reasons)
13272 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013273
13274 if (wakeup->disconnect &&
13275 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13276 goto free_msg;
13277 if (wakeup->magic_pkt &&
13278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13279 goto free_msg;
13280 if (wakeup->gtk_rekey_failure &&
13281 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13282 goto free_msg;
13283 if (wakeup->eap_identity_req &&
13284 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13285 goto free_msg;
13286 if (wakeup->four_way_handshake &&
13287 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13288 goto free_msg;
13289 if (wakeup->rfkill_release &&
13290 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13291 goto free_msg;
13292
13293 if (wakeup->pattern_idx >= 0 &&
13294 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13295 wakeup->pattern_idx))
13296 goto free_msg;
13297
Johannes Bergae917c92013-10-25 11:05:22 +020013298 if (wakeup->tcp_match &&
13299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13300 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013301
Johannes Bergae917c92013-10-25 11:05:22 +020013302 if (wakeup->tcp_connlost &&
13303 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13304 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013305
Johannes Bergae917c92013-10-25 11:05:22 +020013306 if (wakeup->tcp_nomoretokens &&
13307 nla_put_flag(msg,
13308 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13309 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013310
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013311 if (wakeup->packet) {
13312 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13313 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13314
13315 if (!wakeup->packet_80211) {
13316 pkt_attr =
13317 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13318 len_attr =
13319 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13320 }
13321
13322 if (wakeup->packet_len &&
13323 nla_put_u32(msg, len_attr, wakeup->packet_len))
13324 goto free_msg;
13325
13326 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13327 wakeup->packet))
13328 goto free_msg;
13329 }
13330
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013331 if (wakeup->net_detect &&
13332 cfg80211_net_detect_results(msg, wakeup))
13333 goto free_msg;
13334
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013335 nla_nest_end(msg, reasons);
13336 }
13337
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013338 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013339
Johannes Berg68eb5502013-11-19 15:19:38 +010013340 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013341 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013342 return;
13343
13344 free_msg:
13345 nlmsg_free(msg);
13346}
13347EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13348#endif
13349
Jouni Malinen3475b092012-11-16 22:49:57 +020013350void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13351 enum nl80211_tdls_operation oper,
13352 u16 reason_code, gfp_t gfp)
13353{
13354 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013355 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013356 struct sk_buff *msg;
13357 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013358
13359 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13360 reason_code);
13361
13362 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13363 if (!msg)
13364 return;
13365
13366 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13367 if (!hdr) {
13368 nlmsg_free(msg);
13369 return;
13370 }
13371
13372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13373 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13374 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13375 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13376 (reason_code > 0 &&
13377 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13378 goto nla_put_failure;
13379
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013380 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013381
Johannes Berg68eb5502013-11-19 15:19:38 +010013382 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013383 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013384 return;
13385
13386 nla_put_failure:
13387 genlmsg_cancel(msg, hdr);
13388 nlmsg_free(msg);
13389}
13390EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13391
Jouni Malinen026331c2010-02-15 12:53:10 +020013392static int nl80211_netlink_notify(struct notifier_block * nb,
13393 unsigned long state,
13394 void *_notify)
13395{
13396 struct netlink_notify *notify = _notify;
13397 struct cfg80211_registered_device *rdev;
13398 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013399 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013400
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030013401 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020013402 return NOTIFY_DONE;
13403
13404 rcu_read_lock();
13405
Johannes Berg5e7602302011-11-04 11:18:17 +010013406 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013407 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013408 bool schedule_scan_stop = false;
13409 struct cfg80211_sched_scan_request *sched_scan_req =
13410 rcu_dereference(rdev->sched_scan_req);
13411
13412 if (sched_scan_req && notify->portid &&
13413 sched_scan_req->owner_nlportid == notify->portid)
13414 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013415
Johannes Berg53873f12016-05-03 16:52:04 +030013416 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013417 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013418
Johannes Berg78f22b62014-03-24 17:57:27 +010013419 if (wdev->owner_nlportid == notify->portid)
13420 schedule_destroy_work = true;
13421 }
13422
Ben Greear37c73b52012-10-26 14:49:25 -070013423 spin_lock_bh(&rdev->beacon_registrations_lock);
13424 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13425 list) {
13426 if (reg->nlportid == notify->portid) {
13427 list_del(&reg->list);
13428 kfree(reg);
13429 break;
13430 }
13431 }
13432 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013433
13434 if (schedule_destroy_work) {
13435 struct cfg80211_iface_destroy *destroy;
13436
13437 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13438 if (destroy) {
13439 destroy->nlportid = notify->portid;
13440 spin_lock(&rdev->destroy_list_lock);
13441 list_add(&destroy->list, &rdev->destroy_list);
13442 spin_unlock(&rdev->destroy_list_lock);
13443 schedule_work(&rdev->destroy_work);
13444 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013445 } else if (schedule_scan_stop) {
13446 sched_scan_req->owner_nlportid = 0;
13447
13448 if (rdev->ops->sched_scan_stop &&
13449 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13450 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013451 }
Johannes Berg5e7602302011-11-04 11:18:17 +010013452 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013453
13454 rcu_read_unlock();
13455
Ilan peer05050752015-03-04 00:32:06 -050013456 /*
13457 * It is possible that the user space process that is controlling the
13458 * indoor setting disappeared, so notify the regulatory core.
13459 */
13460 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013461 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013462}
13463
13464static struct notifier_block nl80211_netlink_notifier = {
13465 .notifier_call = nl80211_netlink_notify,
13466};
13467
Jouni Malinen355199e2013-02-27 17:14:27 +020013468void cfg80211_ft_event(struct net_device *netdev,
13469 struct cfg80211_ft_event_params *ft_event)
13470{
13471 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013472 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013473 struct sk_buff *msg;
13474 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013475
13476 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13477
13478 if (!ft_event->target_ap)
13479 return;
13480
13481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13482 if (!msg)
13483 return;
13484
13485 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013486 if (!hdr)
13487 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013488
Johannes Bergae917c92013-10-25 11:05:22 +020013489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13490 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13491 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13492 goto out;
13493
13494 if (ft_event->ies &&
13495 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13496 goto out;
13497 if (ft_event->ric_ies &&
13498 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13499 ft_event->ric_ies))
13500 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013501
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013502 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013503
Johannes Berg68eb5502013-11-19 15:19:38 +010013504 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013505 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013506 return;
13507 out:
13508 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013509}
13510EXPORT_SYMBOL(cfg80211_ft_event);
13511
Arend van Spriel5de17982013-04-18 15:49:00 +020013512void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13513{
13514 struct cfg80211_registered_device *rdev;
13515 struct sk_buff *msg;
13516 void *hdr;
13517 u32 nlportid;
13518
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013519 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013520 if (!rdev->crit_proto_nlportid)
13521 return;
13522
13523 nlportid = rdev->crit_proto_nlportid;
13524 rdev->crit_proto_nlportid = 0;
13525
13526 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13527 if (!msg)
13528 return;
13529
13530 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13531 if (!hdr)
13532 goto nla_put_failure;
13533
13534 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013535 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13536 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020013537 goto nla_put_failure;
13538
13539 genlmsg_end(msg, hdr);
13540
13541 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13542 return;
13543
13544 nla_put_failure:
13545 if (hdr)
13546 genlmsg_cancel(msg, hdr);
13547 nlmsg_free(msg);
13548
13549}
13550EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13551
Johannes Berg348baf02014-01-24 14:06:29 +010013552void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13553{
13554 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013555 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013556 struct sk_buff *msg;
13557 void *hdr;
13558
13559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13560 if (!msg)
13561 return;
13562
13563 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13564 if (!hdr)
13565 goto out;
13566
13567 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13568 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013569 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13570 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010013571 goto out;
13572
13573 genlmsg_end(msg, hdr);
13574
13575 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13576 NL80211_MCGRP_MLME, GFP_KERNEL);
13577 return;
13578 out:
13579 nlmsg_free(msg);
13580}
13581
Johannes Berg55682962007-09-20 13:09:35 -040013582/* initialisation/exit functions */
13583
13584int nl80211_init(void)
13585{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013586 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013587
Johannes Berg2a94fe42013-11-19 15:19:39 +010013588 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13589 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013590 if (err)
13591 return err;
13592
Jouni Malinen026331c2010-02-15 12:53:10 +020013593 err = netlink_register_notifier(&nl80211_netlink_notifier);
13594 if (err)
13595 goto err_out;
13596
Johannes Berg55682962007-09-20 13:09:35 -040013597 return 0;
13598 err_out:
13599 genl_unregister_family(&nl80211_fam);
13600 return err;
13601}
13602
13603void nl80211_exit(void)
13604{
Jouni Malinen026331c2010-02-15 12:53:10 +020013605 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013606 genl_unregister_family(&nl80211_fam);
13607}