blob: e0869504e817070e64cf6c9db7537524c7a5c788 [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>
Dan Williams0781a502018-01-29 17:03:15 -080019#include <linux/nospec.h>
Johannes Berg2a519312009-02-10 21:25:55 +010020#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040022#include <net/genetlink.h>
23#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020024#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010025#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040026#include "core.h"
27#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070028#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030029#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040030
Jouni Malinen5fb628e2011-08-10 23:54:35 +030031static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
32 struct genl_info *info,
33 struct cfg80211_crypto_settings *settings,
34 int cipher_limit);
35
Johannes Bergf84f7712013-11-14 17:14:45 +010036static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010038static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020039 struct genl_info *info);
40
Johannes Berg55682962007-09-20 13:09:35 -040041/* the netlink family */
42static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070043 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
44 .name = NL80211_GENL_NAME, /* have users key off the name instead */
45 .hdrsize = 0, /* no private header */
46 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040047 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020048 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020049 .pre_doit = nl80211_pre_doit,
50 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040051};
52
Johannes Berg2a94fe42013-11-19 15:19:39 +010053/* multicast groups */
54enum nl80211_multicast_groups {
55 NL80211_MCGRP_CONFIG,
56 NL80211_MCGRP_SCAN,
57 NL80211_MCGRP_REGULATORY,
58 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010059 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030060 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010061 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
62};
63
64static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010065 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
66 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
67 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
68 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
69 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030070 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010071#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010072 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010073#endif
74};
75
Johannes Berg89a54e42012-06-15 14:33:17 +020076/* returns ERR_PTR values */
77static struct wireless_dev *
78__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040079{
Johannes Berg89a54e42012-06-15 14:33:17 +020080 struct cfg80211_registered_device *rdev;
81 struct wireless_dev *result = NULL;
82 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
83 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
84 u64 wdev_id;
85 int wiphy_idx = -1;
86 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg5fe231e2013-05-08 21:45:15 +020088 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (!have_ifidx && !have_wdev_id)
91 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040092
Johannes Berg89a54e42012-06-15 14:33:17 +020093 if (have_ifidx)
94 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
95 if (have_wdev_id) {
96 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
97 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040098 }
99
Johannes Berg89a54e42012-06-15 14:33:17 +0200100 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
101 struct wireless_dev *wdev;
102
103 if (wiphy_net(&rdev->wiphy) != netns)
104 continue;
105
106 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
107 continue;
108
Johannes Berg53873f12016-05-03 16:52:04 +0300109 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200110 if (have_ifidx && wdev->netdev &&
111 wdev->netdev->ifindex == ifidx) {
112 result = wdev;
113 break;
114 }
115 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
116 result = wdev;
117 break;
118 }
119 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200120
121 if (result)
122 break;
123 }
124
125 if (result)
126 return result;
127 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400128}
129
Johannes Berga9455402012-06-15 13:32:49 +0200130static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200131__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200132{
Johannes Berg7fee4772012-06-15 14:09:58 +0200133 struct cfg80211_registered_device *rdev = NULL, *tmp;
134 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200135
Johannes Berg5fe231e2013-05-08 21:45:15 +0200136 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200139 !attrs[NL80211_ATTR_IFINDEX] &&
140 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 return ERR_PTR(-EINVAL);
142
Johannes Berg878d9ec2012-06-15 14:18:32 +0200143 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200144 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200146
Johannes Berg89a54e42012-06-15 14:33:17 +0200147 if (attrs[NL80211_ATTR_WDEV]) {
148 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
149 struct wireless_dev *wdev;
150 bool found = false;
151
152 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
153 if (tmp) {
154 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300155 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200156 if (wdev->identifier != (u32)wdev_id)
157 continue;
158 found = true;
159 break;
160 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200161
162 if (!found)
163 tmp = NULL;
164
165 if (rdev && tmp != rdev)
166 return ERR_PTR(-EINVAL);
167 rdev = tmp;
168 }
169 }
170
Johannes Berg878d9ec2012-06-15 14:18:32 +0200171 if (attrs[NL80211_ATTR_IFINDEX]) {
172 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700173
Ying Xue7f2b8562014-01-15 10:23:45 +0800174 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 if (netdev) {
176 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800177 tmp = wiphy_to_rdev(
178 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200179 else
180 tmp = NULL;
181
Johannes Berg7fee4772012-06-15 14:09:58 +0200182 /* not wireless device -- return error */
183 if (!tmp)
184 return ERR_PTR(-EINVAL);
185
186 /* mismatch -- return error */
187 if (rdev && tmp != rdev)
188 return ERR_PTR(-EINVAL);
189
190 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200191 }
Johannes Berga9455402012-06-15 13:32:49 +0200192 }
193
Johannes Berg4f7eff12012-06-15 14:14:22 +0200194 if (!rdev)
195 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200196
Johannes Berg4f7eff12012-06-15 14:14:22 +0200197 if (netns != wiphy_net(&rdev->wiphy))
198 return ERR_PTR(-ENODEV);
199
200 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200201}
202
203/*
204 * This function returns a pointer to the driver
205 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200206 *
207 * The result of this can be a PTR_ERR and hence must
208 * be checked with IS_ERR() for errors.
209 */
210static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200211cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200212{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200213 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200214}
215
Johannes Berg55682962007-09-20 13:09:35 -0400216/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300217static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400218 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
219 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700220 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200221 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100222
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200223 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530224 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100225 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
226 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
227 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
228
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200229 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
230 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
231 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
232 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100233 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200234 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400235
236 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
237 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
238 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100239
Eliad Pellere007b852011-11-24 18:13:56 +0200240 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
241 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100242
Johannes Bergb9454e82009-07-08 13:29:08 +0200243 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100244 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
245 .len = WLAN_MAX_KEY_LEN },
246 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
247 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
248 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200249 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200250 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100251
252 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
253 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
254 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
255 .len = IEEE80211_MAX_DATA_LEN },
256 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
257 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100258 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
259 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
260 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
261 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100264 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200265 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100266 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800267 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100268 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700270 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
271 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
272
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300273 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
274 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
275 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200276 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
277 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100278 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300279
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800280 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700281 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700282
Johannes Berg6c739412011-11-03 09:27:01 +0100283 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200284
285 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
286 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100288 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
289 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200290
291 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
292 .len = IEEE80211_MAX_SSID_LEN },
293 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
294 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200295 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300296 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300297 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300298 [NL80211_ATTR_STA_FLAGS2] = {
299 .len = sizeof(struct nl80211_sta_flag_update),
300 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300301 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300302 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
303 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200304 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
305 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
306 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200307 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100308 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Srinivas Dasari7e9e9632017-07-07 01:43:39 +0300309 [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100310 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
311 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200312 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200313 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
314 .len = IEEE80211_MAX_DATA_LEN },
315 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200316 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200317 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300318 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200319 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300320 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200322 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900323 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
324 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100325 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100326 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100327 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200328 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700329 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300330 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200331 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200332 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300333 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300334 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
336 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
337 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530338 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530340 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300341 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
343 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
344 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300346 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100347 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200348 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
349 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700350 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800351 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
352 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
353 .len = NL80211_HT_CAPABILITY_LEN
354 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100355 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530356 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530357 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200358 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700359 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen3255b4a2016-10-27 00:41:58 +0300360 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000361 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700362 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100363 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
364 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Srinivas Dasarib68aa7d2017-07-07 01:43:41 +0300365 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530366 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
367 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200368 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
369 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100370 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100371 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
372 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
373 .len = NL80211_VHT_CAPABILITY_LEN,
374 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200375 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
376 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
377 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300378 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200379 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
380 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
381 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300382 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
383 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530384 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
385 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200386 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100387 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100388 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
389 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
390 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800391 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
392 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200393 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
394 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530395 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200396 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300397 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300398 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300399 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
400 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
401 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300402 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200403 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200404 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200405 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200406 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500407 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200408 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100409 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200410 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300411 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
412 .len = VHT_MUMIMO_GROUPS_DATA_LEN
413 },
414 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300415 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
416 [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
Ayala Bekera442b762016-09-20 17:31:15 +0300417 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinenc9a63622016-10-27 00:42:03 +0300418 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
419 .len = FILS_MAX_KEK_LEN },
420 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braund757efc2016-10-10 19:12:22 +0200421 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna45816392016-12-02 23:59:08 +0200422 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
vamsi krishnaf4f1a542017-01-13 01:12:20 +0200423 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
424 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
425 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
426 },
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200427 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +0300428 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
429 .len = FILS_ERP_MAX_USERNAME_LEN },
430 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
431 .len = FILS_ERP_MAX_REALM_LEN },
432 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
433 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
434 .len = FILS_ERP_MAX_RRK_LEN },
435 [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
436 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Srinivas Dasarid041a1a2018-02-07 18:32:17 +0530437 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400438};
439
Johannes Berge31b8212010-10-05 19:39:30 +0200440/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000441static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200442 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200443 [NL80211_KEY_IDX] = { .type = NLA_U8 },
444 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200445 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200446 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
447 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200448 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100449 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
450};
451
452/* policy for the key default flags */
453static const struct nla_policy
454nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
455 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
456 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200457};
458
Johannes Bergff1b6e62011-05-04 15:37:28 +0200459/* policy for WoWLAN attributes */
460static const struct nla_policy
461nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
462 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
463 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
464 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
465 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200466 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
467 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
468 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
469 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100470 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300471 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100472};
473
474static const struct nla_policy
475nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
476 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
477 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
478 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
479 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
480 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
481 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
482 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
483 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
484 },
485 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
486 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
487 },
488 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
489 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
490 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200491};
492
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700493/* policy for coalesce rule attributes */
494static const struct nla_policy
495nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
496 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
497 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
498 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
499};
500
Johannes Berge5497d72011-07-05 16:35:40 +0200501/* policy for GTK rekey offload attributes */
502static const struct nla_policy
503nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +0530504 [NL80211_REKEY_DATA_KEK] = { .type = NLA_BINARY,
505 .len = FILS_MAX_KEK_LEN },
Johannes Berge5497d72011-07-05 16:35:40 +0200506 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
507 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
508};
509
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300510static const struct nla_policy
511nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200512 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300513 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700514 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300515};
516
Avraham Stern3b06d272015-10-12 09:51:34 +0300517static const struct nla_policy
518nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
519 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
520 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
521};
522
Arend van Spriel38de03d2016-03-02 20:37:18 +0100523static const struct nla_policy
524nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
525 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
526 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
527 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
528 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
529 },
530};
531
Ayala Bekera442b762016-09-20 17:31:15 +0300532/* policy for NAN function attributes */
533static const struct nla_policy
534nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
535 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari6a90f812017-07-07 01:43:40 +0300536 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300537 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
538 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
539 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
540 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
541 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
542 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
543 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
544 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
545 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
546 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
547 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
548 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
549 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
550 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
551 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
552 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
553};
554
555/* policy for Service Response Filter attributes */
556static const struct nla_policy
557nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
558 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
559 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
560 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
561 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
562 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
563};
564
Peng Xu4ec90fd2017-10-10 13:56:53 -0700565/* policy for packet pattern attributes */
566static const struct nla_policy
567nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
568 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
569 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
570 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
571};
572
Johannes Berg97990a02013-04-19 01:02:55 +0200573static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
574 struct netlink_callback *cb,
575 struct cfg80211_registered_device **rdev,
576 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100577{
Johannes Berg67748892010-10-04 21:14:06 +0200578 int err;
579
Johannes Berg97990a02013-04-19 01:02:55 +0200580 if (!cb->args[0]) {
581 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
582 nl80211_fam.attrbuf, nl80211_fam.maxattr,
583 nl80211_policy);
584 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +0100585 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200586
587 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
588 nl80211_fam.attrbuf);
Johannes Berg56769e72017-03-15 14:26:04 +0100589 if (IS_ERR(*wdev))
590 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800591 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200592 /* 0 is the first index - add 1 to parse only once */
593 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200594 cb->args[1] = (*wdev)->identifier;
595 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200596 /* subtract the 1 again here */
597 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200598 struct wireless_dev *tmp;
599
Johannes Berg56769e72017-03-15 14:26:04 +0100600 if (!wiphy)
601 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800602 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200603 *wdev = NULL;
604
Johannes Berg53873f12016-05-03 16:52:04 +0300605 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200606 if (tmp->identifier == cb->args[1]) {
607 *wdev = tmp;
608 break;
609 }
610 }
Johannes Berg97990a02013-04-19 01:02:55 +0200611
Johannes Berg56769e72017-03-15 14:26:04 +0100612 if (!*wdev)
613 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200614 }
615
Johannes Berg67748892010-10-04 21:14:06 +0200616 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200617}
618
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100619/* IE validation */
620static bool is_valid_ie_attr(const struct nlattr *attr)
621{
622 const u8 *pos;
623 int len;
624
625 if (!attr)
626 return true;
627
628 pos = nla_data(attr);
629 len = nla_len(attr);
630
631 while (len) {
632 u8 elemlen;
633
634 if (len < 2)
635 return false;
636 len -= 2;
637
638 elemlen = pos[1];
639 if (elemlen > len)
640 return false;
641
642 len -= elemlen;
643 pos += 2 + elemlen;
644 }
645
646 return true;
647}
648
Johannes Berg55682962007-09-20 13:09:35 -0400649/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000650static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400651 int flags, u8 cmd)
652{
653 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000654 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400655}
656
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400657static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100658 struct ieee80211_channel *chan,
659 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400660{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200661 /* Some channels must be completely excluded from the
662 * list to protect old user-space tools from breaking
663 */
664 if (!large && chan->flags &
665 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
666 return 0;
667
David S. Miller9360ffd2012-03-29 04:41:26 -0400668 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
669 chan->center_freq))
670 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400671
David S. Miller9360ffd2012-03-29 04:41:26 -0400672 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
673 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
674 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200675 if (chan->flags & IEEE80211_CHAN_NO_IR) {
676 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
677 goto nla_put_failure;
678 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
679 goto nla_put_failure;
680 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100681 if (chan->flags & IEEE80211_CHAN_RADAR) {
682 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
683 goto nla_put_failure;
684 if (large) {
685 u32 time;
686
687 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
688
689 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
690 chan->dfs_state))
691 goto nla_put_failure;
692 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
693 time))
694 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100695 if (nla_put_u32(msg,
696 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
697 chan->dfs_cac_ms))
698 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100699 }
700 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400701
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100702 if (large) {
703 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
704 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
705 goto nla_put_failure;
706 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
708 goto nla_put_failure;
709 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
710 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
711 goto nla_put_failure;
712 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
713 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
714 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200715 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
716 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
717 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300718 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
719 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200720 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200721 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
722 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
723 goto nla_put_failure;
724 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
725 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
726 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100727 }
728
David S. Miller9360ffd2012-03-29 04:41:26 -0400729 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
730 DBM_TO_MBM(chan->max_power)))
731 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400732
733 return 0;
734
735 nla_put_failure:
736 return -ENOBUFS;
737}
738
Johannes Berg55682962007-09-20 13:09:35 -0400739/* netlink command implementations */
740
Johannes Bergb9454e82009-07-08 13:29:08 +0200741struct key_parse {
742 struct key_params p;
743 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200744 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200745 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100746 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200747};
748
749static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
750{
751 struct nlattr *tb[NL80211_KEY_MAX + 1];
752 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
753 nl80211_key_policy);
754 if (err)
755 return err;
756
757 k->def = !!tb[NL80211_KEY_DEFAULT];
758 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
759
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100760 if (k->def) {
761 k->def_uni = true;
762 k->def_multi = true;
763 }
764 if (k->defmgmt)
765 k->def_multi = true;
766
Johannes Bergb9454e82009-07-08 13:29:08 +0200767 if (tb[NL80211_KEY_IDX])
768 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
769
770 if (tb[NL80211_KEY_DATA]) {
771 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
772 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
773 }
774
775 if (tb[NL80211_KEY_SEQ]) {
776 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
777 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
778 }
779
780 if (tb[NL80211_KEY_CIPHER])
781 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
782
Johannes Berge31b8212010-10-05 19:39:30 +0200783 if (tb[NL80211_KEY_TYPE]) {
784 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
785 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
786 return -EINVAL;
787 }
788
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100789 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
790 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700791
Johannes Berg2da8f412012-01-20 13:52:37 +0100792 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
793 tb[NL80211_KEY_DEFAULT_TYPES],
794 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100795 if (err)
796 return err;
797
798 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
799 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
800 }
801
Johannes Bergb9454e82009-07-08 13:29:08 +0200802 return 0;
803}
804
805static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
806{
807 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
808 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
809 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
810 }
811
812 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
813 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
814 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
815 }
816
817 if (info->attrs[NL80211_ATTR_KEY_IDX])
818 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
819
820 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
821 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
822
823 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
824 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
825
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100826 if (k->def) {
827 k->def_uni = true;
828 k->def_multi = true;
829 }
830 if (k->defmgmt)
831 k->def_multi = true;
832
Johannes Berge31b8212010-10-05 19:39:30 +0200833 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
834 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
835 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
836 return -EINVAL;
837 }
838
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100839 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
840 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
841 int err = nla_parse_nested(
842 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
843 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
844 nl80211_key_default_policy);
845 if (err)
846 return err;
847
848 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
849 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
850 }
851
Johannes Bergb9454e82009-07-08 13:29:08 +0200852 return 0;
853}
854
855static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
856{
857 int err;
858
859 memset(k, 0, sizeof(*k));
860 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200861 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200862
863 if (info->attrs[NL80211_ATTR_KEY])
864 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
865 else
866 err = nl80211_parse_key_old(info, k);
867
868 if (err)
869 return err;
870
871 if (k->def && k->defmgmt)
872 return -EINVAL;
873
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100874 if (k->defmgmt) {
875 if (k->def_uni || !k->def_multi)
876 return -EINVAL;
877 }
878
Johannes Bergb9454e82009-07-08 13:29:08 +0200879 if (k->idx != -1) {
880 if (k->defmgmt) {
881 if (k->idx < 4 || k->idx > 5)
882 return -EINVAL;
883 } else if (k->def) {
884 if (k->idx < 0 || k->idx > 3)
885 return -EINVAL;
886 } else {
887 if (k->idx < 0 || k->idx > 5)
888 return -EINVAL;
889 }
890 }
891
892 return 0;
893}
894
Johannes Bergfffd0932009-07-08 14:22:54 +0200895static struct cfg80211_cached_keys *
896nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530897 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200898{
899 struct key_parse parse;
900 struct nlattr *key;
901 struct cfg80211_cached_keys *result;
902 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200903 bool have_key = false;
904
905 nla_for_each_nested(key, keys, rem) {
906 have_key = true;
907 break;
908 }
909
910 if (!have_key)
911 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200912
913 result = kzalloc(sizeof(*result), GFP_KERNEL);
914 if (!result)
915 return ERR_PTR(-ENOMEM);
916
917 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200918
919 nla_for_each_nested(key, keys, rem) {
920 memset(&parse, 0, sizeof(parse));
921 parse.idx = -1;
922
923 err = nl80211_parse_key_new(key, &parse);
924 if (err)
925 goto error;
926 err = -EINVAL;
927 if (!parse.p.key)
928 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200929 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200930 goto error;
931 if (parse.def) {
932 if (def)
933 goto error;
934 def = 1;
935 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100936 if (!parse.def_uni || !parse.def_multi)
937 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200938 } else if (parse.defmgmt)
939 goto error;
940 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200941 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200942 if (err)
943 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200944 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
945 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
946 err = -EINVAL;
947 goto error;
948 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200949 result->params[parse.idx].cipher = parse.p.cipher;
950 result->params[parse.idx].key_len = parse.p.key_len;
951 result->params[parse.idx].key = result->data[parse.idx];
952 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530953
Johannes Berg386b1f22016-09-13 16:10:02 +0200954 /* must be WEP key if we got here */
955 if (no_ht)
956 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200957 }
958
Johannes Bergf1c1f172016-09-13 17:08:23 +0200959 if (result->def < 0) {
960 err = -EINVAL;
961 goto error;
962 }
963
Johannes Bergfffd0932009-07-08 14:22:54 +0200964 return result;
965 error:
966 kfree(result);
967 return ERR_PTR(err);
968}
969
970static int nl80211_key_allowed(struct wireless_dev *wdev)
971{
972 ASSERT_WDEV_LOCK(wdev);
973
Johannes Bergfffd0932009-07-08 14:22:54 +0200974 switch (wdev->iftype) {
975 case NL80211_IFTYPE_AP:
976 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200977 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700978 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200979 break;
980 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200981 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200982 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200983 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200984 return -ENOLINK;
985 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100986 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100987 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100988 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300989 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100990 case NL80211_IFTYPE_P2P_DEVICE:
991 case NL80211_IFTYPE_WDS:
992 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200993 return -EINVAL;
994 }
995
996 return 0;
997}
998
Jouni Malinen664834d2014-01-15 00:01:44 +0200999static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1000 struct nlattr *tb)
1001{
1002 struct ieee80211_channel *chan;
1003
1004 if (tb == NULL)
1005 return NULL;
1006 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1007 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1008 return NULL;
1009 return chan;
1010}
1011
Johannes Berg7527a782011-05-13 10:58:57 +02001012static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1013{
1014 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1015 int i;
1016
1017 if (!nl_modes)
1018 goto nla_put_failure;
1019
1020 i = 0;
1021 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001022 if ((ifmodes & 1) && nla_put_flag(msg, i))
1023 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001024 ifmodes >>= 1;
1025 i++;
1026 }
1027
1028 nla_nest_end(msg, nl_modes);
1029 return 0;
1030
1031nla_put_failure:
1032 return -ENOBUFS;
1033}
1034
1035static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001036 struct sk_buff *msg,
1037 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001038{
1039 struct nlattr *nl_combis;
1040 int i, j;
1041
1042 nl_combis = nla_nest_start(msg,
1043 NL80211_ATTR_INTERFACE_COMBINATIONS);
1044 if (!nl_combis)
1045 goto nla_put_failure;
1046
1047 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1048 const struct ieee80211_iface_combination *c;
1049 struct nlattr *nl_combi, *nl_limits;
1050
1051 c = &wiphy->iface_combinations[i];
1052
1053 nl_combi = nla_nest_start(msg, i + 1);
1054 if (!nl_combi)
1055 goto nla_put_failure;
1056
1057 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1058 if (!nl_limits)
1059 goto nla_put_failure;
1060
1061 for (j = 0; j < c->n_limits; j++) {
1062 struct nlattr *nl_limit;
1063
1064 nl_limit = nla_nest_start(msg, j + 1);
1065 if (!nl_limit)
1066 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001067 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1068 c->limits[j].max))
1069 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001070 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1071 c->limits[j].types))
1072 goto nla_put_failure;
1073 nla_nest_end(msg, nl_limit);
1074 }
1075
1076 nla_nest_end(msg, nl_limits);
1077
David S. Miller9360ffd2012-03-29 04:41:26 -04001078 if (c->beacon_int_infra_match &&
1079 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1080 goto nla_put_failure;
1081 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1082 c->num_different_channels) ||
1083 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1084 c->max_interfaces))
1085 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001086 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001087 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1088 c->radar_detect_widths) ||
1089 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1090 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001091 goto nla_put_failure;
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05301092 if (c->beacon_int_min_gcd &&
1093 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1094 c->beacon_int_min_gcd))
1095 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001096
1097 nla_nest_end(msg, nl_combi);
1098 }
1099
1100 nla_nest_end(msg, nl_combis);
1101
1102 return 0;
1103nla_put_failure:
1104 return -ENOBUFS;
1105}
1106
Johannes Berg3713b4e2013-02-14 16:19:38 +01001107#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001108static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1109 struct sk_buff *msg)
1110{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001111 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001112 struct nlattr *nl_tcp;
1113
1114 if (!tcp)
1115 return 0;
1116
1117 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1118 if (!nl_tcp)
1119 return -ENOBUFS;
1120
1121 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1122 tcp->data_payload_max))
1123 return -ENOBUFS;
1124
1125 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1126 tcp->data_payload_max))
1127 return -ENOBUFS;
1128
1129 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1130 return -ENOBUFS;
1131
1132 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1133 sizeof(*tcp->tok), tcp->tok))
1134 return -ENOBUFS;
1135
1136 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1137 tcp->data_interval_max))
1138 return -ENOBUFS;
1139
1140 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1141 tcp->wake_payload_max))
1142 return -ENOBUFS;
1143
1144 nla_nest_end(msg, nl_tcp);
1145 return 0;
1146}
1147
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001149 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001150 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151{
1152 struct nlattr *nl_wowlan;
1153
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001154 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001155 return 0;
1156
1157 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1158 if (!nl_wowlan)
1159 return -ENOBUFS;
1160
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001161 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001162 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001163 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001164 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001165 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001166 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001167 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001168 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001169 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001170 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001171 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001172 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001173 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001174 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001175 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1177 return -ENOBUFS;
1178
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001179 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001180 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001181 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1182 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1183 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1184 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001185 };
1186
1187 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1188 sizeof(pat), &pat))
1189 return -ENOBUFS;
1190 }
1191
Luciano Coelho75453cc2015-01-09 14:06:37 +02001192 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1193 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1194 rdev->wiphy.wowlan->max_nd_match_sets))
1195 return -ENOBUFS;
1196
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001197 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001198 return -ENOBUFS;
1199
Johannes Berg3713b4e2013-02-14 16:19:38 +01001200 nla_nest_end(msg, nl_wowlan);
1201
1202 return 0;
1203}
1204#endif
1205
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001206static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001207 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001208{
1209 struct nl80211_coalesce_rule_support rule;
1210
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001211 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001212 return 0;
1213
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001214 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1215 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1216 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1217 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1218 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1219 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001220
1221 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1222 return -ENOBUFS;
1223
1224 return 0;
1225}
1226
Johannes Berg3713b4e2013-02-14 16:19:38 +01001227static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1228 struct ieee80211_supported_band *sband)
1229{
1230 struct nlattr *nl_rates, *nl_rate;
1231 struct ieee80211_rate *rate;
1232 int i;
1233
1234 /* add HT info */
1235 if (sband->ht_cap.ht_supported &&
1236 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1237 sizeof(sband->ht_cap.mcs),
1238 &sband->ht_cap.mcs) ||
1239 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1240 sband->ht_cap.cap) ||
1241 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1242 sband->ht_cap.ampdu_factor) ||
1243 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1244 sband->ht_cap.ampdu_density)))
1245 return -ENOBUFS;
1246
1247 /* add VHT info */
1248 if (sband->vht_cap.vht_supported &&
1249 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1250 sizeof(sband->vht_cap.vht_mcs),
1251 &sband->vht_cap.vht_mcs) ||
1252 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1253 sband->vht_cap.cap)))
1254 return -ENOBUFS;
1255
1256 /* add bitrates */
1257 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1258 if (!nl_rates)
1259 return -ENOBUFS;
1260
1261 for (i = 0; i < sband->n_bitrates; i++) {
1262 nl_rate = nla_nest_start(msg, i);
1263 if (!nl_rate)
1264 return -ENOBUFS;
1265
1266 rate = &sband->bitrates[i];
1267 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1268 rate->bitrate))
1269 return -ENOBUFS;
1270 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1271 nla_put_flag(msg,
1272 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1273 return -ENOBUFS;
1274
1275 nla_nest_end(msg, nl_rate);
1276 }
1277
1278 nla_nest_end(msg, nl_rates);
1279
1280 return 0;
1281}
1282
1283static int
1284nl80211_send_mgmt_stypes(struct sk_buff *msg,
1285 const struct ieee80211_txrx_stypes *mgmt_stypes)
1286{
1287 u16 stypes;
1288 struct nlattr *nl_ftypes, *nl_ifs;
1289 enum nl80211_iftype ift;
1290 int i;
1291
1292 if (!mgmt_stypes)
1293 return 0;
1294
1295 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1296 if (!nl_ifs)
1297 return -ENOBUFS;
1298
1299 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1300 nl_ftypes = nla_nest_start(msg, ift);
1301 if (!nl_ftypes)
1302 return -ENOBUFS;
1303 i = 0;
1304 stypes = mgmt_stypes[ift].tx;
1305 while (stypes) {
1306 if ((stypes & 1) &&
1307 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1308 (i << 4) | IEEE80211_FTYPE_MGMT))
1309 return -ENOBUFS;
1310 stypes >>= 1;
1311 i++;
1312 }
1313 nla_nest_end(msg, nl_ftypes);
1314 }
1315
1316 nla_nest_end(msg, nl_ifs);
1317
1318 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1319 if (!nl_ifs)
1320 return -ENOBUFS;
1321
1322 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1323 nl_ftypes = nla_nest_start(msg, ift);
1324 if (!nl_ftypes)
1325 return -ENOBUFS;
1326 i = 0;
1327 stypes = mgmt_stypes[ift].rx;
1328 while (stypes) {
1329 if ((stypes & 1) &&
1330 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1331 (i << 4) | IEEE80211_FTYPE_MGMT))
1332 return -ENOBUFS;
1333 stypes >>= 1;
1334 i++;
1335 }
1336 nla_nest_end(msg, nl_ftypes);
1337 }
1338 nla_nest_end(msg, nl_ifs);
1339
1340 return 0;
1341}
1342
Johannes Berg86e8cf92013-06-19 10:57:22 +02001343struct nl80211_dump_wiphy_state {
1344 s64 filter_wiphy;
1345 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301346 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001347 bool split;
1348};
1349
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001350static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001351 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001353 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001354{
1355 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001356 struct nlattr *nl_bands, *nl_band;
1357 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001358 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001359 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001360 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001361 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001362 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001364 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001365
Johannes Berg3bb20552014-05-26 13:52:25 +02001366 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001367 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 return -ENOBUFS;
1369
Johannes Berg86e8cf92013-06-19 10:57:22 +02001370 if (WARN_ON(!state))
1371 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001372
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001373 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001376 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001378 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001379
Johannes Berg3bb20552014-05-26 13:52:25 +02001380 if (cmd != NL80211_CMD_NEW_WIPHY)
1381 goto finish;
1382
Johannes Berg86e8cf92013-06-19 10:57:22 +02001383 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 case 0:
1385 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001386 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001387 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001388 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001390 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001394 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001396 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001397 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001398 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001400 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001402 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001404 rdev->wiphy.max_match_sets) ||
1405 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1406 rdev->wiphy.max_sched_scan_plans) ||
1407 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1408 rdev->wiphy.max_sched_scan_plan_interval) ||
1409 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1410 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001411 goto nla_put_failure;
1412
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001413 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1415 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001416 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1418 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001419 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1421 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001422 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1424 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001425 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1427 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001428 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001430 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 state->split_start++;
1432 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 break;
1434 case 1:
1435 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001436 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1437 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001438 goto nla_put_failure;
1439
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001441 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001442 goto nla_put_failure;
1443
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001444 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1446 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001449 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001451 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001453
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001454 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001456 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001458
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001459 if ((rdev->wiphy.available_antennas_tx ||
1460 rdev->wiphy.available_antennas_rx) &&
1461 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 u32 tx_ant = 0, rx_ant = 0;
1463 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001464
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001465 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 if (!res) {
1467 if (nla_put_u32(msg,
1468 NL80211_ATTR_WIPHY_ANTENNA_TX,
1469 tx_ant) ||
1470 nla_put_u32(msg,
1471 NL80211_ATTR_WIPHY_ANTENNA_RX,
1472 rx_ant))
1473 goto nla_put_failure;
1474 }
Johannes Bergee688b002008-01-24 19:38:39 +01001475 }
1476
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 state->split_start++;
1478 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 break;
1480 case 2:
1481 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001484 state->split_start++;
1485 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 break;
1487 case 3:
1488 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1489 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001490 goto nla_put_failure;
1491
Johannes Berg86e8cf92013-06-19 10:57:22 +02001492 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001493 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 struct ieee80211_supported_band *sband;
1495
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497
1498 if (!sband)
1499 continue;
1500
1501 nl_band = nla_nest_start(msg, band);
1502 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001503 goto nla_put_failure;
1504
Johannes Berg86e8cf92013-06-19 10:57:22 +02001505 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 case 0:
1507 if (nl80211_send_band_rateinfo(msg, sband))
1508 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 state->chan_start++;
1510 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 break;
1512 default:
1513 /* add frequencies */
1514 nl_freqs = nla_nest_start(
1515 msg, NL80211_BAND_ATTR_FREQS);
1516 if (!nl_freqs)
1517 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001518
Johannes Berg86e8cf92013-06-19 10:57:22 +02001519 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 i < sband->n_channels;
1521 i++) {
1522 nl_freq = nla_nest_start(msg, i);
1523 if (!nl_freq)
1524 goto nla_put_failure;
1525
1526 chan = &sband->channels[i];
1527
Johannes Berg86e8cf92013-06-19 10:57:22 +02001528 if (nl80211_msg_put_channel(
1529 msg, chan,
1530 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 goto nla_put_failure;
1532
1533 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001534 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 break;
1536 }
1537 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001538 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001540 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 nla_nest_end(msg, nl_freqs);
1542 }
1543
1544 nla_nest_end(msg, nl_band);
1545
Johannes Berg86e8cf92013-06-19 10:57:22 +02001546 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001548 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 band--;
1550 break;
1551 }
Johannes Bergee688b002008-01-24 19:38:39 +01001552 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001554
Johannes Berg57fbcce2016-04-12 15:56:15 +02001555 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001556 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001558 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001559
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 if (state->band_start == 0 && state->chan_start == 0)
1562 state->split_start++;
1563 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 4:
1566 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1567 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001568 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569
1570 i = 0;
1571#define CMD(op, n) \
1572 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001573 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 i++; \
1575 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1576 goto nla_put_failure; \
1577 } \
1578 } while (0)
1579
1580 CMD(add_virtual_intf, NEW_INTERFACE);
1581 CMD(change_virtual_intf, SET_INTERFACE);
1582 CMD(add_key, NEW_KEY);
1583 CMD(start_ap, START_AP);
1584 CMD(add_station, NEW_STATION);
1585 CMD(add_mpath, NEW_MPATH);
1586 CMD(update_mesh_config, SET_MESH_CONFIG);
1587 CMD(change_bss, SET_BSS);
1588 CMD(auth, AUTHENTICATE);
1589 CMD(assoc, ASSOCIATE);
1590 CMD(deauth, DEAUTHENTICATE);
1591 CMD(disassoc, DISASSOCIATE);
1592 CMD(join_ibss, JOIN_IBSS);
1593 CMD(join_mesh, JOIN_MESH);
1594 CMD(set_pmksa, SET_PMKSA);
1595 CMD(del_pmksa, DEL_PMKSA);
1596 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001597 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1599 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1600 CMD(mgmt_tx, FRAME);
1601 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 i++;
1604 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1605 goto nla_put_failure;
1606 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1608 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 i++;
1610 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1611 goto nla_put_failure;
1612 }
1613 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 CMD(tdls_mgmt, TDLS_MGMT);
1616 CMD(tdls_oper, TDLS_OPER);
1617 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 CMD(sched_scan_start, START_SCHED_SCAN);
1620 CMD(probe_client, PROBE_CLIENT);
1621 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 i++;
1624 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1625 goto nla_put_failure;
1626 }
1627 CMD(start_p2p_device, START_P2P_DEVICE);
1628 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001629#ifdef CONFIG_NL80211_TESTMODE
1630 CMD(testmode_cmd, TESTMODE);
1631#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001633 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1634 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001636 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001637 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001638 if (rdev->wiphy.features &
1639 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001640 CMD(add_tx_ts, ADD_TX_TS);
Michael Braund757efc2016-10-10 19:12:22 +02001641 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna30da4e82016-10-27 16:51:11 +03001642 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001643 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001644 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001645#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001646
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 i++;
1649 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001650 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001651 }
1652
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001654 i++;
1655 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1656 goto nla_put_failure;
1657 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001658
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001660 state->split_start++;
1661 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001662 break;
1663 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (rdev->ops->remain_on_channel &&
1665 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001666 nla_put_u32(msg,
1667 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001668 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001669 goto nla_put_failure;
1670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1673 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001674
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1676 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001677 state->split_start++;
1678 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001679 break;
1680 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001681#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001682 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001684 state->split_start++;
1685 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686 break;
1687#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001688 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689#endif
1690 case 7:
1691 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001692 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001693 goto nla_put_failure;
1694
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001695 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001697 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001698
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699 state->split_start++;
1700 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001701 break;
1702 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001703 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001705 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 goto nla_put_failure;
1707
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001708 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001709 /*
1710 * We can only add the per-channel limit information if the
1711 * dump is split, otherwise it makes it too big. Therefore
1712 * only advertise it in that case.
1713 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001714 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001715 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1716 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001717 goto nla_put_failure;
1718
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001719 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001721 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1722 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 goto nla_put_failure;
1724
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001725 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1726 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001727 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001728 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 goto nla_put_failure;
1730
1731 /*
1732 * Any information below this point is only available to
1733 * applications that can deal with it being split. This
1734 * helps ensure that newly added capabilities don't break
1735 * older tools by overrunning their buffers.
1736 *
1737 * We still increment split_start so that in the split
1738 * case we'll continue with more data in the next round,
1739 * but break unconditionally so unsplit data stops here.
1740 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001741 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001742 break;
1743 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001744 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001745 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001746 rdev->wiphy.extended_capabilities_len,
1747 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001748 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001749 rdev->wiphy.extended_capabilities_len,
1750 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001751 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001753 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001754 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1756 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001757 goto nla_put_failure;
1758
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001759 state->split_start++;
1760 break;
1761 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001762 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001763 goto nla_put_failure;
1764
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001765 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001766 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1767 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1768 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001769
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001770 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001771 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001773 goto nla_put_failure;
1774
Johannes Bergad7e7182013-11-13 13:37:47 +01001775 state->split_start++;
1776 break;
1777 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001779 const struct nl80211_vendor_cmd_info *info;
1780 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001781
Johannes Berg567ffc32013-12-18 14:43:31 +01001782 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1783 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001784 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001785
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001786 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1787 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001788 if (nla_put(msg, i + 1, sizeof(*info), info))
1789 goto nla_put_failure;
1790 }
1791 nla_nest_end(msg, nested);
1792 }
1793
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001794 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001795 const struct nl80211_vendor_cmd_info *info;
1796 struct nlattr *nested;
1797
1798 nested = nla_nest_start(msg,
1799 NL80211_ATTR_VENDOR_EVENTS);
1800 if (!nested)
1801 goto nla_put_failure;
1802
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001803 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1804 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001805 if (nla_put(msg, i + 1, sizeof(*info), info))
1806 goto nla_put_failure;
1807 }
1808 nla_nest_end(msg, nested);
1809 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001810 state->split_start++;
1811 break;
1812 case 12:
1813 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1814 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1815 rdev->wiphy.max_num_csa_counters))
1816 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001817
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001818 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1819 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1820 goto nla_put_failure;
1821
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001822 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1823 sizeof(rdev->wiphy.ext_features),
1824 rdev->wiphy.ext_features))
1825 goto nla_put_failure;
1826
Arend van Spriel38de03d2016-03-02 20:37:18 +01001827 if (rdev->wiphy.bss_select_support) {
1828 struct nlattr *nested;
1829 u32 bss_select_support = rdev->wiphy.bss_select_support;
1830
1831 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1832 if (!nested)
1833 goto nla_put_failure;
1834
1835 i = 0;
1836 while (bss_select_support) {
1837 if ((bss_select_support & 1) &&
1838 nla_put_flag(msg, i))
1839 goto nla_put_failure;
1840 i++;
1841 bss_select_support >>= 1;
1842 }
1843 nla_nest_end(msg, nested);
1844 }
1845
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301846 state->split_start++;
1847 break;
1848 case 13:
1849 if (rdev->wiphy.num_iftype_ext_capab &&
1850 rdev->wiphy.iftype_ext_capab) {
1851 struct nlattr *nested_ext_capab, *nested;
1852
1853 nested = nla_nest_start(msg,
1854 NL80211_ATTR_IFTYPE_EXT_CAPA);
1855 if (!nested)
1856 goto nla_put_failure;
1857
1858 for (i = state->capa_start;
1859 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1860 const struct wiphy_iftype_ext_capab *capab;
1861
1862 capab = &rdev->wiphy.iftype_ext_capab[i];
1863
1864 nested_ext_capab = nla_nest_start(msg, i);
1865 if (!nested_ext_capab ||
1866 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1867 capab->iftype) ||
1868 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1869 capab->extended_capabilities_len,
1870 capab->extended_capabilities) ||
1871 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1872 capab->extended_capabilities_len,
1873 capab->extended_capabilities_mask))
1874 goto nla_put_failure;
1875
1876 nla_nest_end(msg, nested_ext_capab);
1877 if (state->split)
1878 break;
1879 }
1880 nla_nest_end(msg, nested);
1881 if (i < rdev->wiphy.num_iftype_ext_capab) {
1882 state->capa_start = i + 1;
1883 break;
1884 }
1885 }
1886
Johannes Berg3713b4e2013-02-14 16:19:38 +01001887 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001888 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001889 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001890 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001891 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001892 genlmsg_end(msg, hdr);
1893 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001894
1895 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001896 genlmsg_cancel(msg, hdr);
1897 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001898}
1899
Johannes Berg86e8cf92013-06-19 10:57:22 +02001900static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1901 struct netlink_callback *cb,
1902 struct nl80211_dump_wiphy_state *state)
1903{
1904 struct nlattr **tb = nl80211_fam.attrbuf;
1905 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1906 tb, nl80211_fam.maxattr, nl80211_policy);
1907 /* ignore parse errors for backward compatibility */
1908 if (ret)
1909 return 0;
1910
1911 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1912 if (tb[NL80211_ATTR_WIPHY])
1913 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1914 if (tb[NL80211_ATTR_WDEV])
1915 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1916 if (tb[NL80211_ATTR_IFINDEX]) {
1917 struct net_device *netdev;
1918 struct cfg80211_registered_device *rdev;
1919 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1920
Ying Xue7f2b8562014-01-15 10:23:45 +08001921 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001922 if (!netdev)
1923 return -ENODEV;
1924 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001925 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001926 netdev->ieee80211_ptr->wiphy);
1927 state->filter_wiphy = rdev->wiphy_idx;
1928 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 }
1930
1931 return 0;
1932}
1933
Johannes Berg55682962007-09-20 13:09:35 -04001934static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1935{
Johannes Berg645e77d2013-03-01 14:03:49 +01001936 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001937 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001938 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001939
Johannes Berg5fe231e2013-05-08 21:45:15 +02001940 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001941 if (!state) {
1942 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001943 if (!state) {
1944 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001945 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001946 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001947 state->filter_wiphy = -1;
1948 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1949 if (ret) {
1950 kfree(state);
1951 rtnl_unlock();
1952 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001953 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001954 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001955 }
1956
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001957 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1958 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001959 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001960 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001961 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001962 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001963 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001964 continue;
1965 /* attempt to fit multiple wiphy data chunks into the skb */
1966 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001967 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1968 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001969 NETLINK_CB(cb->skb).portid,
1970 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001971 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001972 if (ret < 0) {
1973 /*
1974 * If sending the wiphy data didn't fit (ENOBUFS
1975 * or EMSGSIZE returned), this SKB is still
1976 * empty (so it's not too big because another
1977 * wiphy dataset is already in the skb) and
1978 * we've not tried to adjust the dump allocation
1979 * yet ... then adjust the alloc size to be
1980 * bigger, and return 1 but with the empty skb.
1981 * This results in an empty message being RX'ed
1982 * in userspace, but that is ignored.
1983 *
1984 * We can then retry with the larger buffer.
1985 */
1986 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001987 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001988 cb->min_dump_alloc < 4096) {
1989 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001990 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001991 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001992 return 1;
1993 }
1994 idx--;
1995 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001996 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001997 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001998 break;
Johannes Berg55682962007-09-20 13:09:35 -04001999 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002000 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002001
Johannes Berg86e8cf92013-06-19 10:57:22 +02002002 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002003
2004 return skb->len;
2005}
2006
Johannes Berg86e8cf92013-06-19 10:57:22 +02002007static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2008{
2009 kfree((void *)cb->args[0]);
2010 return 0;
2011}
2012
Johannes Berg55682962007-09-20 13:09:35 -04002013static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2014{
2015 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002017 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002018
Johannes Berg645e77d2013-03-01 14:03:49 +01002019 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002020 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002021 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002022
Johannes Berg3bb20552014-05-26 13:52:25 +02002023 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2024 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002025 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002026 nlmsg_free(msg);
2027 return -ENOBUFS;
2028 }
Johannes Berg55682962007-09-20 13:09:35 -04002029
Johannes Berg134e6372009-07-10 09:51:34 +00002030 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002031}
2032
Jouni Malinen31888482008-10-30 16:59:24 +02002033static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2034 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2035 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2036 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2037 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2038 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2039};
2040
2041static int parse_txq_params(struct nlattr *tb[],
2042 struct ieee80211_txq_params *txq_params)
2043{
Dan Williams0781a502018-01-29 17:03:15 -08002044 u8 ac;
2045
Johannes Berga3304b02012-03-28 11:04:24 +02002046 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002047 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2048 !tb[NL80211_TXQ_ATTR_AIFS])
2049 return -EINVAL;
2050
Dan Williams0781a502018-01-29 17:03:15 -08002051 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002052 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2053 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2054 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2055 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2056
Dan Williams0781a502018-01-29 17:03:15 -08002057 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002058 return -EINVAL;
Dan Williams0781a502018-01-29 17:03:15 -08002059 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002060 return 0;
2061}
2062
Johannes Bergf444de02010-05-05 15:25:02 +02002063static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2064{
2065 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002066 * You can only set the channel explicitly for WDS interfaces,
2067 * all others have their channel managed via their respective
2068 * "establish a connection" command (connect, join, ...)
2069 *
2070 * For AP/GO and mesh mode, the channel can be set with the
2071 * channel userspace API, but is only stored and passed to the
2072 * low-level driver when the AP starts or the mesh is joined.
2073 * This is for backward compatibility, userspace can also give
2074 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002075 *
2076 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002077 * whatever else is going on, so they have their own special
2078 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002079 */
2080 return !wdev ||
2081 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002082 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002083 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2084 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002085}
2086
Johannes Berg683b6d32012-11-08 21:25:48 +01002087static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2088 struct genl_info *info,
2089 struct cfg80211_chan_def *chandef)
2090{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302091 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002092
2093 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2094 return -EINVAL;
2095
2096 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2097
2098 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002099 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2100 chandef->center_freq1 = control_freq;
2101 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002102
2103 /* Primary channel not allowed */
2104 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2105 return -EINVAL;
2106
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002107 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2108 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002109
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002110 chantype = nla_get_u32(
2111 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2112
2113 switch (chantype) {
2114 case NL80211_CHAN_NO_HT:
2115 case NL80211_CHAN_HT20:
2116 case NL80211_CHAN_HT40PLUS:
2117 case NL80211_CHAN_HT40MINUS:
2118 cfg80211_chandef_create(chandef, chandef->chan,
2119 chantype);
2120 break;
2121 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002122 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002123 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002124 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2125 chandef->width =
2126 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2127 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2128 chandef->center_freq1 =
2129 nla_get_u32(
2130 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2131 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2132 chandef->center_freq2 =
2133 nla_get_u32(
2134 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2135 }
2136
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002137 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002138 return -EINVAL;
2139
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002140 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2141 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002142 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002143
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002144 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2145 chandef->width == NL80211_CHAN_WIDTH_10) &&
2146 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2147 return -EINVAL;
2148
Johannes Berg683b6d32012-11-08 21:25:48 +01002149 return 0;
2150}
2151
Johannes Bergf444de02010-05-05 15:25:02 +02002152static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002153 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002154 struct genl_info *info)
2155{
Johannes Berg683b6d32012-11-08 21:25:48 +01002156 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002157 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002158 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002159 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002160
Jouni Malinene16821b2014-04-28 11:22:08 +03002161 if (dev)
2162 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002163 if (!nl80211_can_set_dev_channel(wdev))
2164 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002165 if (wdev)
2166 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002167
Johannes Berg683b6d32012-11-08 21:25:48 +01002168 result = nl80211_parse_chandef(rdev, info, &chandef);
2169 if (result)
2170 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002171
Johannes Berge8c9bd52012-06-06 08:18:22 +02002172 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002173 case NL80211_IFTYPE_AP:
2174 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002175 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2176 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002177 result = -EINVAL;
2178 break;
2179 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002180 if (wdev->beacon_interval) {
2181 if (!dev || !rdev->ops->set_ap_chanwidth ||
2182 !(rdev->wiphy.features &
2183 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2184 result = -EBUSY;
2185 break;
2186 }
2187
2188 /* Only allow dynamic channel width changes */
2189 if (chandef.chan != wdev->preset_chandef.chan) {
2190 result = -EBUSY;
2191 break;
2192 }
2193 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2194 if (result)
2195 break;
2196 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002197 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002198 result = 0;
2199 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002200 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002201 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002202 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002203 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002204 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002205 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002206 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002207 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002208 }
Johannes Bergf444de02010-05-05 15:25:02 +02002209
2210 return result;
2211}
2212
2213static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2214{
Johannes Berg4c476992010-10-04 21:36:35 +02002215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2216 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002217
Jouni Malinene16821b2014-04-28 11:22:08 +03002218 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002219}
2220
Bill Jordane8347eb2010-10-01 13:54:28 -04002221static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2222{
Johannes Berg43b19952010-10-07 13:10:30 +02002223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2224 struct net_device *dev = info->user_ptr[1];
2225 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002226 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002227
2228 if (!info->attrs[NL80211_ATTR_MAC])
2229 return -EINVAL;
2230
Johannes Berg43b19952010-10-07 13:10:30 +02002231 if (netif_running(dev))
2232 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002233
Johannes Berg43b19952010-10-07 13:10:30 +02002234 if (!rdev->ops->set_wds_peer)
2235 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002236
Johannes Berg43b19952010-10-07 13:10:30 +02002237 if (wdev->iftype != NL80211_IFTYPE_WDS)
2238 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002239
2240 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002241 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002242}
2243
Johannes Berg55682962007-09-20 13:09:35 -04002244static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2245{
2246 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002247 struct net_device *netdev = NULL;
2248 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002249 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002250 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002251 u32 changed;
2252 u8 retry_short = 0, retry_long = 0;
2253 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002254 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002255
Johannes Berg5fe231e2013-05-08 21:45:15 +02002256 ASSERT_RTNL();
2257
Johannes Bergf444de02010-05-05 15:25:02 +02002258 /*
2259 * Try to find the wiphy and netdev. Normally this
2260 * function shouldn't need the netdev, but this is
2261 * done for backward compatibility -- previously
2262 * setting the channel was done per wiphy, but now
2263 * it is per netdev. Previous userland like hostapd
2264 * also passed a netdev to set_wiphy, so that it is
2265 * possible to let that go to the right netdev!
2266 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002267
Johannes Bergf444de02010-05-05 15:25:02 +02002268 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2269 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2270
Ying Xue7f2b8562014-01-15 10:23:45 +08002271 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002272 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002273 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002274 else
Johannes Bergf444de02010-05-05 15:25:02 +02002275 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002276 }
2277
Johannes Bergf444de02010-05-05 15:25:02 +02002278 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002279 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2280 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002281 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002282 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002283 wdev = NULL;
2284 netdev = NULL;
2285 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002286 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002287 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002288
2289 /*
2290 * end workaround code, by now the rdev is available
2291 * and locked, and wdev may or may not be NULL.
2292 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002293
2294 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002295 result = cfg80211_dev_rename(
2296 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002297
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002298 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002300
Jouni Malinen31888482008-10-30 16:59:24 +02002301 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2302 struct ieee80211_txq_params txq_params;
2303 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2304
Ying Xue7f2b8562014-01-15 10:23:45 +08002305 if (!rdev->ops->set_txq_params)
2306 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002307
Ying Xue7f2b8562014-01-15 10:23:45 +08002308 if (!netdev)
2309 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002310
Johannes Berg133a3ff2011-11-03 14:50:13 +01002311 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002312 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2313 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002314
Ying Xue7f2b8562014-01-15 10:23:45 +08002315 if (!netif_running(netdev))
2316 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002317
Jouni Malinen31888482008-10-30 16:59:24 +02002318 nla_for_each_nested(nl_txq_params,
2319 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2320 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002321 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2322 nla_data(nl_txq_params),
2323 nla_len(nl_txq_params),
2324 txq_params_policy);
2325 if (result)
2326 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002327 result = parse_txq_params(tb, &txq_params);
2328 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002330
Hila Gonene35e4d22012-06-27 17:19:42 +03002331 result = rdev_set_txq_params(rdev, netdev,
2332 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002333 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002335 }
2336 }
2337
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002338 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002339 result = __nl80211_set_channel(
2340 rdev,
2341 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2342 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002343 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002344 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002345 }
2346
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002347 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002348 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002349 enum nl80211_tx_power_setting type;
2350 int idx, mbm = 0;
2351
Johannes Bergc8442112012-10-24 10:17:18 +02002352 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2353 txp_wdev = NULL;
2354
Ying Xue7f2b8562014-01-15 10:23:45 +08002355 if (!rdev->ops->set_tx_power)
2356 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002357
2358 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2359 type = nla_get_u32(info->attrs[idx]);
2360
2361 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002362 (type != NL80211_TX_POWER_AUTOMATIC))
2363 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002364
2365 if (type != NL80211_TX_POWER_AUTOMATIC) {
2366 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2367 mbm = nla_get_u32(info->attrs[idx]);
2368 }
2369
Johannes Bergc8442112012-10-24 10:17:18 +02002370 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002371 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002372 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002373 }
2374
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002375 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2376 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2377 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002378
Bruno Randolf7f531e02010-12-16 11:30:22 +09002379 if ((!rdev->wiphy.available_antennas_tx &&
2380 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002381 !rdev->ops->set_antenna)
2382 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002383
2384 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2385 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2386
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002387 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002388 * available antenna masks, except for the "all" mask */
2389 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002390 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2391 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002392
Bruno Randolf7f531e02010-12-16 11:30:22 +09002393 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2394 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002395
Hila Gonene35e4d22012-06-27 17:19:42 +03002396 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002397 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002398 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002399 }
2400
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002401 changed = 0;
2402
2403 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2404 retry_short = nla_get_u8(
2405 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002406 if (retry_short == 0)
2407 return -EINVAL;
2408
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002409 changed |= WIPHY_PARAM_RETRY_SHORT;
2410 }
2411
2412 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2413 retry_long = nla_get_u8(
2414 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002415 if (retry_long == 0)
2416 return -EINVAL;
2417
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002418 changed |= WIPHY_PARAM_RETRY_LONG;
2419 }
2420
2421 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2422 frag_threshold = nla_get_u32(
2423 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002424 if (frag_threshold < 256)
2425 return -EINVAL;
2426
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002427 if (frag_threshold != (u32) -1) {
2428 /*
2429 * Fragments (apart from the last one) are required to
2430 * have even length. Make the fragmentation code
2431 * simpler by stripping LSB should someone try to use
2432 * odd threshold value.
2433 */
2434 frag_threshold &= ~0x1;
2435 }
2436 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2437 }
2438
2439 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2440 rts_threshold = nla_get_u32(
2441 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2442 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2443 }
2444
Lukáš Turek81077e82009-12-21 22:50:47 +01002445 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002446 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2447 return -EINVAL;
2448
Lukáš Turek81077e82009-12-21 22:50:47 +01002449 coverage_class = nla_get_u8(
2450 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2451 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2452 }
2453
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002454 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2455 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2456 return -EOPNOTSUPP;
2457
2458 changed |= WIPHY_PARAM_DYN_ACK;
2459 }
2460
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002461 if (changed) {
2462 u8 old_retry_short, old_retry_long;
2463 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002464 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002465
Ying Xue7f2b8562014-01-15 10:23:45 +08002466 if (!rdev->ops->set_wiphy_params)
2467 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002468
2469 old_retry_short = rdev->wiphy.retry_short;
2470 old_retry_long = rdev->wiphy.retry_long;
2471 old_frag_threshold = rdev->wiphy.frag_threshold;
2472 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002473 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002474
2475 if (changed & WIPHY_PARAM_RETRY_SHORT)
2476 rdev->wiphy.retry_short = retry_short;
2477 if (changed & WIPHY_PARAM_RETRY_LONG)
2478 rdev->wiphy.retry_long = retry_long;
2479 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2480 rdev->wiphy.frag_threshold = frag_threshold;
2481 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2482 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002483 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2484 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002485
Hila Gonene35e4d22012-06-27 17:19:42 +03002486 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002487 if (result) {
2488 rdev->wiphy.retry_short = old_retry_short;
2489 rdev->wiphy.retry_long = old_retry_long;
2490 rdev->wiphy.frag_threshold = old_frag_threshold;
2491 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002492 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002493 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002494 }
2495 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002496 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002497}
2498
Johannes Berg71bbc992012-06-15 15:30:18 +02002499static inline u64 wdev_id(struct wireless_dev *wdev)
2500{
2501 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002502 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002503}
Johannes Berg55682962007-09-20 13:09:35 -04002504
Johannes Berg683b6d32012-11-08 21:25:48 +01002505static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002506 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002507{
Johannes Berg601555c2014-11-27 17:26:56 +01002508 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2509 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002510
Johannes Berg683b6d32012-11-08 21:25:48 +01002511 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2512 chandef->chan->center_freq))
2513 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002514 switch (chandef->width) {
2515 case NL80211_CHAN_WIDTH_20_NOHT:
2516 case NL80211_CHAN_WIDTH_20:
2517 case NL80211_CHAN_WIDTH_40:
2518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2519 cfg80211_get_chandef_type(chandef)))
2520 return -ENOBUFS;
2521 break;
2522 default:
2523 break;
2524 }
2525 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2526 return -ENOBUFS;
2527 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2528 return -ENOBUFS;
2529 if (chandef->center_freq2 &&
2530 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002531 return -ENOBUFS;
2532 return 0;
2533}
2534
Eric W. Biederman15e47302012-09-07 20:12:54 +00002535static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002536 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002537 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002538{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002539 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002540 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002541 void *hdr;
2542
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002543 if (removal)
2544 cmd = NL80211_CMD_DEL_INTERFACE;
2545
2546 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002547 if (!hdr)
2548 return -1;
2549
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002550 if (dev &&
2551 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002552 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002553 goto nla_put_failure;
2554
2555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2556 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002557 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2558 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002559 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002560 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2561 rdev->devlist_generation ^
2562 (cfg80211_rdev_list_generation << 2)))
2563 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002564
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002565 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002566 int ret;
2567 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002568
Johannes Berg683b6d32012-11-08 21:25:48 +01002569 ret = rdev_get_channel(rdev, wdev, &chandef);
2570 if (ret == 0) {
2571 if (nl80211_send_chandef(msg, &chandef))
2572 goto nla_put_failure;
2573 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002574 }
2575
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002576 if (rdev->ops->get_tx_power) {
2577 int dbm, ret;
2578
2579 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2580 if (ret == 0 &&
2581 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2582 DBM_TO_MBM(dbm)))
2583 goto nla_put_failure;
2584 }
2585
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002586 if (wdev->ssid_len) {
2587 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2588 goto nla_put_failure;
2589 }
2590
Johannes Berg053c0952015-01-16 22:09:00 +01002591 genlmsg_end(msg, hdr);
2592 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002593
2594 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002595 genlmsg_cancel(msg, hdr);
2596 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002597}
2598
2599static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2600{
2601 int wp_idx = 0;
2602 int if_idx = 0;
2603 int wp_start = cb->args[0];
2604 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002605 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002606 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002607 struct wireless_dev *wdev;
Johannes Berg56769e72017-03-15 14:26:04 +01002608 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002609
Johannes Berg5fe231e2013-05-08 21:45:15 +02002610 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002611 if (!cb->args[2]) {
2612 struct nl80211_dump_wiphy_state state = {
2613 .filter_wiphy = -1,
2614 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002615
2616 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2617 if (ret)
Johannes Berg56769e72017-03-15 14:26:04 +01002618 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002619
2620 filter_wiphy = state.filter_wiphy;
2621
2622 /*
2623 * if filtering, set cb->args[2] to +1 since 0 is the default
2624 * value needed to determine that parsing is necessary.
2625 */
2626 if (filter_wiphy >= 0)
2627 cb->args[2] = filter_wiphy + 1;
2628 else
2629 cb->args[2] = -1;
2630 } else if (cb->args[2] > 0) {
2631 filter_wiphy = cb->args[2] - 1;
2632 }
2633
Johannes Bergf5ea9122009-08-07 16:17:38 +02002634 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2635 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002636 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002637 if (wp_idx < wp_start) {
2638 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002639 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002640 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002641
2642 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2643 continue;
2644
Johannes Berg55682962007-09-20 13:09:35 -04002645 if_idx = 0;
2646
Johannes Berg53873f12016-05-03 16:52:04 +03002647 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002648 if (if_idx < if_start) {
2649 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002650 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002651 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002652 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002653 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002654 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002655 goto out;
2656 }
2657 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002658 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002659
2660 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002661 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002662 out:
Johannes Berg55682962007-09-20 13:09:35 -04002663 cb->args[0] = wp_idx;
2664 cb->args[1] = if_idx;
2665
Johannes Berg56769e72017-03-15 14:26:04 +01002666 ret = skb->len;
2667 out_unlock:
2668 rtnl_unlock();
2669
2670 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002671}
2672
2673static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2674{
2675 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002677 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002678
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002680 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002681 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002682
Eric W. Biederman15e47302012-09-07 20:12:54 +00002683 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002684 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002685 nlmsg_free(msg);
2686 return -ENOBUFS;
2687 }
Johannes Berg55682962007-09-20 13:09:35 -04002688
Johannes Berg134e6372009-07-10 09:51:34 +00002689 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002690}
2691
Michael Wu66f7ac52008-01-31 19:48:22 +01002692static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2693 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2694 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2695 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2696 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2697 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002698 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002699};
2700
2701static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2702{
2703 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2704 int flag;
2705
2706 *mntrflags = 0;
2707
2708 if (!nla)
2709 return -EINVAL;
2710
2711 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2712 nla, mntr_flags_policy))
2713 return -EINVAL;
2714
2715 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2716 if (flags[flag])
2717 *mntrflags |= (1<<flag);
2718
2719 return 0;
2720}
2721
Johannes Berg9bc383d2009-11-19 11:55:19 +01002722static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002723 struct net_device *netdev, u8 use_4addr,
2724 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002725{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002726 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002727 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002728 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002729 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002730 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002731
2732 switch (iftype) {
2733 case NL80211_IFTYPE_AP_VLAN:
2734 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2735 return 0;
2736 break;
2737 case NL80211_IFTYPE_STATION:
2738 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2739 return 0;
2740 break;
2741 default:
2742 break;
2743 }
2744
2745 return -EOPNOTSUPP;
2746}
2747
Johannes Berg55682962007-09-20 13:09:35 -04002748static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2749{
Johannes Berg4c476992010-10-04 21:36:35 +02002750 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002751 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002752 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002753 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002755 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002756 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002757
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002758 memset(&params, 0, sizeof(params));
2759
Johannes Berg04a773a2009-04-19 21:24:32 +02002760 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002761
Johannes Berg723b0382008-09-16 20:22:09 +02002762 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002763 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002764 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002765 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002766 if (ntype > NL80211_IFTYPE_MAX)
2767 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002768 }
2769
Johannes Berg92ffe052008-09-16 20:39:36 +02002770 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002771 struct wireless_dev *wdev = dev->ieee80211_ptr;
2772
Johannes Berg4c476992010-10-04 21:36:35 +02002773 if (ntype != NL80211_IFTYPE_MESH_POINT)
2774 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002775 if (netif_running(dev))
2776 return -EBUSY;
2777
2778 wdev_lock(wdev);
2779 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2780 IEEE80211_MAX_MESH_ID_LEN);
2781 wdev->mesh_id_up_len =
2782 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2783 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2784 wdev->mesh_id_up_len);
2785 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002786 }
2787
Felix Fietkau8b787642009-11-10 18:53:10 +01002788 if (info->attrs[NL80211_ATTR_4ADDR]) {
2789 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2790 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002791 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002792 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002793 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002794 } else {
2795 params.use_4addr = -1;
2796 }
2797
Johannes Berg92ffe052008-09-16 20:39:36 +02002798 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002799 if (ntype != NL80211_IFTYPE_MONITOR)
2800 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002801 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2802 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002803 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002804 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002805
2806 flags = &_flags;
2807 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002808 }
Johannes Berg3b858752009-03-12 09:55:09 +01002809
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002810 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2811 const u8 *mumimo_groups;
2812 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2813
2814 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2815 return -EOPNOTSUPP;
2816
2817 mumimo_groups =
2818 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2819
2820 /* bits 0 and 63 are reserved and must be zero */
2821 if ((mumimo_groups[0] & BIT(7)) ||
2822 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2823 return -EINVAL;
2824
2825 memcpy(params.vht_mumimo_groups, mumimo_groups,
2826 VHT_MUMIMO_GROUPS_DATA_LEN);
2827 change = true;
2828 }
2829
2830 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2831 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2832
2833 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2834 return -EOPNOTSUPP;
2835
2836 nla_memcpy(params.macaddr,
2837 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2838 ETH_ALEN);
2839 change = true;
2840 }
2841
Luciano Coelho18003292013-08-29 13:26:57 +03002842 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002843 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2844 return -EOPNOTSUPP;
2845
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002846 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002847 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002848 else
2849 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002850
Johannes Berg9bc383d2009-11-19 11:55:19 +01002851 if (!err && params.use_4addr != -1)
2852 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2853
Johannes Berg55682962007-09-20 13:09:35 -04002854 return err;
2855}
2856
2857static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2858{
Johannes Berg4c476992010-10-04 21:36:35 +02002859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002860 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002861 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002862 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002863 int err;
2864 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002865 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002866
Johannes Berg78f22b62014-03-24 17:57:27 +01002867 /* to avoid failing a new interface creation due to pending removal */
2868 cfg80211_destroy_ifaces(rdev);
2869
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002870 memset(&params, 0, sizeof(params));
2871
Johannes Berg55682962007-09-20 13:09:35 -04002872 if (!info->attrs[NL80211_ATTR_IFNAME])
2873 return -EINVAL;
2874
2875 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2876 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2877 if (type > NL80211_IFTYPE_MAX)
2878 return -EINVAL;
2879 }
2880
Johannes Berg79c97e92009-07-07 03:56:12 +02002881 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002882 !(rdev->wiphy.interface_modes & (1 << type)))
2883 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002884
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002885 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002886 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2887 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002888 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2889 ETH_ALEN);
2890 if (!is_valid_ether_addr(params.macaddr))
2891 return -EADDRNOTAVAIL;
2892 }
2893
Johannes Berg9bc383d2009-11-19 11:55:19 +01002894 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002895 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002896 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002897 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002898 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002899 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002900
Michael Wu66f7ac52008-01-31 19:48:22 +01002901 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2902 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2903 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002904
Luciano Coelho18003292013-08-29 13:26:57 +03002905 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002906 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2907 return -EOPNOTSUPP;
2908
Johannes Berga18c7192015-02-24 10:56:42 +01002909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2910 if (!msg)
2911 return -ENOMEM;
2912
Hila Gonene35e4d22012-06-27 17:19:42 +03002913 wdev = rdev_add_virtual_intf(rdev,
2914 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002915 NET_NAME_USER, type, err ? NULL : &flags,
2916 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002917 if (WARN_ON(!wdev)) {
2918 nlmsg_free(msg);
2919 return -EPROTO;
2920 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002921 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002922 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002923 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002924
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002925 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002926 wdev->owner_nlportid = info->snd_portid;
2927
Johannes Berg98104fde2012-06-16 00:19:54 +02002928 switch (type) {
2929 case NL80211_IFTYPE_MESH_POINT:
2930 if (!info->attrs[NL80211_ATTR_MESH_ID])
2931 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002932 wdev_lock(wdev);
2933 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2934 IEEE80211_MAX_MESH_ID_LEN);
2935 wdev->mesh_id_up_len =
2936 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2937 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2938 wdev->mesh_id_up_len);
2939 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002940 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002941 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002942 case NL80211_IFTYPE_P2P_DEVICE:
2943 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002944 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002945 * through the netdev notifier and must be added here
2946 */
2947 mutex_init(&wdev->mtx);
2948 INIT_LIST_HEAD(&wdev->event_list);
2949 spin_lock_init(&wdev->event_lock);
2950 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2951 spin_lock_init(&wdev->mgmt_registrations_lock);
2952
Johannes Berg98104fde2012-06-16 00:19:54 +02002953 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002954 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002955 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002956 break;
2957 default:
2958 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002959 }
2960
Eric W. Biederman15e47302012-09-07 20:12:54 +00002961 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002962 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002963 nlmsg_free(msg);
2964 return -ENOBUFS;
2965 }
2966
Denis Kenzior896ff062016-08-03 16:58:33 -05002967 /*
2968 * For wdevs which have no associated netdev object (e.g. of type
2969 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2970 * For all other types, the event will be generated from the
2971 * netdev notifier
2972 */
2973 if (!wdev->netdev)
2974 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002975
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002976 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002977}
2978
2979static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2980{
Johannes Berg4c476992010-10-04 21:36:35 +02002981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002982 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002983
Johannes Berg4c476992010-10-04 21:36:35 +02002984 if (!rdev->ops->del_virtual_intf)
2985 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002986
Johannes Berg84efbb82012-06-16 00:00:26 +02002987 /*
2988 * If we remove a wireless device without a netdev then clear
2989 * user_ptr[1] so that nl80211_post_doit won't dereference it
2990 * to check if it needs to do dev_put(). Otherwise it crashes
2991 * since the wdev has been freed, unlike with a netdev where
2992 * we need the dev_put() for the netdev to really be freed.
2993 */
2994 if (!wdev->netdev)
2995 info->user_ptr[1] = NULL;
2996
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002997 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002998}
2999
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003000static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3001{
3002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3003 struct net_device *dev = info->user_ptr[1];
3004 u16 noack_map;
3005
3006 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3007 return -EINVAL;
3008
3009 if (!rdev->ops->set_noack_map)
3010 return -EOPNOTSUPP;
3011
3012 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3013
Hila Gonene35e4d22012-06-27 17:19:42 +03003014 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003015}
3016
Johannes Berg41ade002007-12-19 02:03:29 +01003017struct get_key_cookie {
3018 struct sk_buff *msg;
3019 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003020 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003021};
3022
3023static void get_key_callback(void *c, struct key_params *params)
3024{
Johannes Bergb9454e82009-07-08 13:29:08 +02003025 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003026 struct get_key_cookie *cookie = c;
3027
David S. Miller9360ffd2012-03-29 04:41:26 -04003028 if ((params->key &&
3029 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3030 params->key_len, params->key)) ||
3031 (params->seq &&
3032 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3033 params->seq_len, params->seq)) ||
3034 (params->cipher &&
3035 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3036 params->cipher)))
3037 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003038
Johannes Bergb9454e82009-07-08 13:29:08 +02003039 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3040 if (!key)
3041 goto nla_put_failure;
3042
David S. Miller9360ffd2012-03-29 04:41:26 -04003043 if ((params->key &&
3044 nla_put(cookie->msg, NL80211_KEY_DATA,
3045 params->key_len, params->key)) ||
3046 (params->seq &&
3047 nla_put(cookie->msg, NL80211_KEY_SEQ,
3048 params->seq_len, params->seq)) ||
3049 (params->cipher &&
3050 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3051 params->cipher)))
3052 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003053
David S. Miller9360ffd2012-03-29 04:41:26 -04003054 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3055 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003056
3057 nla_nest_end(cookie->msg, key);
3058
Johannes Berg41ade002007-12-19 02:03:29 +01003059 return;
3060 nla_put_failure:
3061 cookie->error = 1;
3062}
3063
3064static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3065{
Johannes Berg4c476992010-10-04 21:36:35 +02003066 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003067 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003068 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003069 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003070 const u8 *mac_addr = NULL;
3071 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003072 struct get_key_cookie cookie = {
3073 .error = 0,
3074 };
3075 void *hdr;
3076 struct sk_buff *msg;
3077
3078 if (info->attrs[NL80211_ATTR_KEY_IDX])
3079 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3080
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003081 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003082 return -EINVAL;
3083
3084 if (info->attrs[NL80211_ATTR_MAC])
3085 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3086
Johannes Berge31b8212010-10-05 19:39:30 +02003087 pairwise = !!mac_addr;
3088 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3089 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003090
Johannes Berge31b8212010-10-05 19:39:30 +02003091 if (kt >= NUM_NL80211_KEYTYPES)
3092 return -EINVAL;
3093 if (kt != NL80211_KEYTYPE_GROUP &&
3094 kt != NL80211_KEYTYPE_PAIRWISE)
3095 return -EINVAL;
3096 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3097 }
3098
Johannes Berg4c476992010-10-04 21:36:35 +02003099 if (!rdev->ops->get_key)
3100 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003101
Johannes Berg0fa7b392015-01-23 11:10:12 +01003102 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3103 return -ENOENT;
3104
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003105 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003106 if (!msg)
3107 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003108
Eric W. Biederman15e47302012-09-07 20:12:54 +00003109 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003110 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003111 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003112 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003113
3114 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003115 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003116
David S. Miller9360ffd2012-03-29 04:41:26 -04003117 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3118 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3119 goto nla_put_failure;
3120 if (mac_addr &&
3121 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3122 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003123
Hila Gonene35e4d22012-06-27 17:19:42 +03003124 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3125 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003126
3127 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003128 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003129
3130 if (cookie.error)
3131 goto nla_put_failure;
3132
3133 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003134 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003135
3136 nla_put_failure:
3137 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003138 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003139 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003140 return err;
3141}
3142
3143static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3144{
Johannes Berg4c476992010-10-04 21:36:35 +02003145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003146 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003147 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003148 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003149
Johannes Bergb9454e82009-07-08 13:29:08 +02003150 err = nl80211_parse_key(info, &key);
3151 if (err)
3152 return err;
3153
3154 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003155 return -EINVAL;
3156
Johannes Bergb9454e82009-07-08 13:29:08 +02003157 /* only support setting default key */
3158 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003159 return -EINVAL;
3160
Johannes Bergfffd0932009-07-08 14:22:54 +02003161 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003162
3163 if (key.def) {
3164 if (!rdev->ops->set_default_key) {
3165 err = -EOPNOTSUPP;
3166 goto out;
3167 }
3168
3169 err = nl80211_key_allowed(dev->ieee80211_ptr);
3170 if (err)
3171 goto out;
3172
Hila Gonene35e4d22012-06-27 17:19:42 +03003173 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003174 key.def_uni, key.def_multi);
3175
3176 if (err)
3177 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003178
Johannes Berg3d23e342009-09-29 23:27:28 +02003179#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003180 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003181#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003182 } else {
3183 if (key.def_uni || !key.def_multi) {
3184 err = -EINVAL;
3185 goto out;
3186 }
3187
3188 if (!rdev->ops->set_default_mgmt_key) {
3189 err = -EOPNOTSUPP;
3190 goto out;
3191 }
3192
3193 err = nl80211_key_allowed(dev->ieee80211_ptr);
3194 if (err)
3195 goto out;
3196
Hila Gonene35e4d22012-06-27 17:19:42 +03003197 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003198 if (err)
3199 goto out;
3200
3201#ifdef CONFIG_CFG80211_WEXT
3202 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3203#endif
3204 }
3205
3206 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003207 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003208
Johannes Berg41ade002007-12-19 02:03:29 +01003209 return err;
3210}
3211
3212static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3213{
Johannes Berg4c476992010-10-04 21:36:35 +02003214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003215 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003216 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003217 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003218 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003219
Johannes Bergb9454e82009-07-08 13:29:08 +02003220 err = nl80211_parse_key(info, &key);
3221 if (err)
3222 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003223
Johannes Bergb9454e82009-07-08 13:29:08 +02003224 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003225 return -EINVAL;
3226
Johannes Berg41ade002007-12-19 02:03:29 +01003227 if (info->attrs[NL80211_ATTR_MAC])
3228 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3229
Johannes Berge31b8212010-10-05 19:39:30 +02003230 if (key.type == -1) {
3231 if (mac_addr)
3232 key.type = NL80211_KEYTYPE_PAIRWISE;
3233 else
3234 key.type = NL80211_KEYTYPE_GROUP;
3235 }
3236
3237 /* for now */
3238 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3239 key.type != NL80211_KEYTYPE_GROUP)
3240 return -EINVAL;
3241
Johannes Berg4c476992010-10-04 21:36:35 +02003242 if (!rdev->ops->add_key)
3243 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003244
Johannes Berge31b8212010-10-05 19:39:30 +02003245 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3246 key.type == NL80211_KEYTYPE_PAIRWISE,
3247 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003248 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003249
3250 wdev_lock(dev->ieee80211_ptr);
3251 err = nl80211_key_allowed(dev->ieee80211_ptr);
3252 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003253 err = rdev_add_key(rdev, dev, key.idx,
3254 key.type == NL80211_KEYTYPE_PAIRWISE,
3255 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003256 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003257
Johannes Berg41ade002007-12-19 02:03:29 +01003258 return err;
3259}
3260
3261static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3262{
Johannes Berg4c476992010-10-04 21:36:35 +02003263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003264 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003265 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003266 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003267 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003268
Johannes Bergb9454e82009-07-08 13:29:08 +02003269 err = nl80211_parse_key(info, &key);
3270 if (err)
3271 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003272
3273 if (info->attrs[NL80211_ATTR_MAC])
3274 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3275
Johannes Berge31b8212010-10-05 19:39:30 +02003276 if (key.type == -1) {
3277 if (mac_addr)
3278 key.type = NL80211_KEYTYPE_PAIRWISE;
3279 else
3280 key.type = NL80211_KEYTYPE_GROUP;
3281 }
3282
3283 /* for now */
3284 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3285 key.type != NL80211_KEYTYPE_GROUP)
3286 return -EINVAL;
3287
Johannes Berg4c476992010-10-04 21:36:35 +02003288 if (!rdev->ops->del_key)
3289 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003290
Johannes Bergfffd0932009-07-08 14:22:54 +02003291 wdev_lock(dev->ieee80211_ptr);
3292 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003293
Johannes Berg0fa7b392015-01-23 11:10:12 +01003294 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003295 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3296 err = -ENOENT;
3297
Johannes Bergfffd0932009-07-08 14:22:54 +02003298 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003299 err = rdev_del_key(rdev, dev, key.idx,
3300 key.type == NL80211_KEYTYPE_PAIRWISE,
3301 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003302
Johannes Berg3d23e342009-09-29 23:27:28 +02003303#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003304 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003305 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003306 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003307 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003308 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3309 }
3310#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003311 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003312
Johannes Berg41ade002007-12-19 02:03:29 +01003313 return err;
3314}
3315
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303316/* This function returns an error or the number of nested attributes */
3317static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3318{
3319 struct nlattr *attr;
3320 int n_entries = 0, tmp;
3321
3322 nla_for_each_nested(attr, nl_attr, tmp) {
3323 if (nla_len(attr) != ETH_ALEN)
3324 return -EINVAL;
3325
3326 n_entries++;
3327 }
3328
3329 return n_entries;
3330}
3331
3332/*
3333 * This function parses ACL information and allocates memory for ACL data.
3334 * On successful return, the calling function is responsible to free the
3335 * ACL buffer returned by this function.
3336 */
3337static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3338 struct genl_info *info)
3339{
3340 enum nl80211_acl_policy acl_policy;
3341 struct nlattr *attr;
3342 struct cfg80211_acl_data *acl;
3343 int i = 0, n_entries, tmp;
3344
3345 if (!wiphy->max_acl_mac_addrs)
3346 return ERR_PTR(-EOPNOTSUPP);
3347
3348 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3349 return ERR_PTR(-EINVAL);
3350
3351 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3352 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3353 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3354 return ERR_PTR(-EINVAL);
3355
3356 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3357 return ERR_PTR(-EINVAL);
3358
3359 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3360 if (n_entries < 0)
3361 return ERR_PTR(n_entries);
3362
3363 if (n_entries > wiphy->max_acl_mac_addrs)
3364 return ERR_PTR(-ENOTSUPP);
3365
3366 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3367 GFP_KERNEL);
3368 if (!acl)
3369 return ERR_PTR(-ENOMEM);
3370
3371 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3372 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3373 i++;
3374 }
3375
3376 acl->n_acl_entries = n_entries;
3377 acl->acl_policy = acl_policy;
3378
3379 return acl;
3380}
3381
3382static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3383{
3384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3385 struct net_device *dev = info->user_ptr[1];
3386 struct cfg80211_acl_data *acl;
3387 int err;
3388
3389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3390 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3391 return -EOPNOTSUPP;
3392
3393 if (!dev->ieee80211_ptr->beacon_interval)
3394 return -EINVAL;
3395
3396 acl = parse_acl_data(&rdev->wiphy, info);
3397 if (IS_ERR(acl))
3398 return PTR_ERR(acl);
3399
3400 err = rdev_set_mac_acl(rdev, dev, acl);
3401
3402 kfree(acl);
3403
3404 return err;
3405}
3406
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303407static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3408 u8 *rates, u8 rates_len)
3409{
3410 u8 i;
3411 u32 mask = 0;
3412
3413 for (i = 0; i < rates_len; i++) {
3414 int rate = (rates[i] & 0x7f) * 5;
3415 int ridx;
3416
3417 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3418 struct ieee80211_rate *srate =
3419 &sband->bitrates[ridx];
3420 if (rate == srate->bitrate) {
3421 mask |= 1 << ridx;
3422 break;
3423 }
3424 }
3425 if (ridx == sband->n_bitrates)
3426 return 0; /* rate not found */
3427 }
3428
3429 return mask;
3430}
3431
3432static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3433 u8 *rates, u8 rates_len,
3434 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3435{
3436 u8 i;
3437
3438 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3439
3440 for (i = 0; i < rates_len; i++) {
3441 int ridx, rbit;
3442
3443 ridx = rates[i] / 8;
3444 rbit = BIT(rates[i] % 8);
3445
3446 /* check validity */
3447 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3448 return false;
3449
3450 /* check availability */
3451 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3452 mcs[ridx] |= rbit;
3453 else
3454 return false;
3455 }
3456
3457 return true;
3458}
3459
3460static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3461{
3462 u16 mcs_mask = 0;
3463
3464 switch (vht_mcs_map) {
3465 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3466 break;
3467 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3468 mcs_mask = 0x00FF;
3469 break;
3470 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3471 mcs_mask = 0x01FF;
3472 break;
3473 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3474 mcs_mask = 0x03FF;
3475 break;
3476 default:
3477 break;
3478 }
3479
3480 return mcs_mask;
3481}
3482
3483static void vht_build_mcs_mask(u16 vht_mcs_map,
3484 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3485{
3486 u8 nss;
3487
3488 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3489 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3490 vht_mcs_map >>= 2;
3491 }
3492}
3493
3494static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3495 struct nl80211_txrate_vht *txrate,
3496 u16 mcs[NL80211_VHT_NSS_MAX])
3497{
3498 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3499 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3500 u8 i;
3501
3502 if (!sband->vht_cap.vht_supported)
3503 return false;
3504
3505 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3506
3507 /* Build vht_mcs_mask from VHT capabilities */
3508 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3509
3510 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3511 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3512 mcs[i] = txrate->mcs[i];
3513 else
3514 return false;
3515 }
3516
3517 return true;
3518}
3519
3520static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3521 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3522 .len = NL80211_MAX_SUPP_RATES },
3523 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3524 .len = NL80211_MAX_SUPP_HT_RATES },
3525 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3526 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3527};
3528
3529static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3530 struct cfg80211_bitrate_mask *mask)
3531{
3532 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3534 int rem, i;
3535 struct nlattr *tx_rates;
3536 struct ieee80211_supported_band *sband;
3537 u16 vht_tx_mcs_map;
3538
3539 memset(mask, 0, sizeof(*mask));
3540 /* Default to all rates enabled */
3541 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3542 sband = rdev->wiphy.bands[i];
3543
3544 if (!sband)
3545 continue;
3546
3547 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3548 memcpy(mask->control[i].ht_mcs,
3549 sband->ht_cap.mcs.rx_mask,
3550 sizeof(mask->control[i].ht_mcs));
3551
3552 if (!sband->vht_cap.vht_supported)
3553 continue;
3554
3555 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3556 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3557 }
3558
3559 /* if no rates are given set it back to the defaults */
3560 if (!info->attrs[NL80211_ATTR_TX_RATES])
3561 goto out;
3562
3563 /* The nested attribute uses enum nl80211_band as the index. This maps
3564 * directly to the enum nl80211_band values used in cfg80211.
3565 */
3566 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3567 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3568 enum nl80211_band band = nla_type(tx_rates);
3569 int err;
3570
3571 if (band < 0 || band >= NUM_NL80211_BANDS)
3572 return -EINVAL;
3573 sband = rdev->wiphy.bands[band];
3574 if (sband == NULL)
3575 return -EINVAL;
3576 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
3577 nla_len(tx_rates), nl80211_txattr_policy);
3578 if (err)
3579 return err;
3580 if (tb[NL80211_TXRATE_LEGACY]) {
3581 mask->control[band].legacy = rateset_to_mask(
3582 sband,
3583 nla_data(tb[NL80211_TXRATE_LEGACY]),
3584 nla_len(tb[NL80211_TXRATE_LEGACY]));
3585 if ((mask->control[band].legacy == 0) &&
3586 nla_len(tb[NL80211_TXRATE_LEGACY]))
3587 return -EINVAL;
3588 }
3589 if (tb[NL80211_TXRATE_HT]) {
3590 if (!ht_rateset_to_mask(
3591 sband,
3592 nla_data(tb[NL80211_TXRATE_HT]),
3593 nla_len(tb[NL80211_TXRATE_HT]),
3594 mask->control[band].ht_mcs))
3595 return -EINVAL;
3596 }
3597 if (tb[NL80211_TXRATE_VHT]) {
3598 if (!vht_set_mcs_mask(
3599 sband,
3600 nla_data(tb[NL80211_TXRATE_VHT]),
3601 mask->control[band].vht_mcs))
3602 return -EINVAL;
3603 }
3604 if (tb[NL80211_TXRATE_GI]) {
3605 mask->control[band].gi =
3606 nla_get_u8(tb[NL80211_TXRATE_GI]);
3607 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3608 return -EINVAL;
3609 }
3610
3611 if (mask->control[band].legacy == 0) {
3612 /* don't allow empty legacy rates if HT or VHT
3613 * are not even supported.
3614 */
3615 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3616 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3617 return -EINVAL;
3618
3619 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3620 if (mask->control[band].ht_mcs[i])
3621 goto out;
3622
3623 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3624 if (mask->control[band].vht_mcs[i])
3625 goto out;
3626
3627 /* legacy and mcs rates may not be both empty */
3628 return -EINVAL;
3629 }
3630 }
3631
3632out:
3633 return 0;
3634}
3635
Johannes Berg8564e382016-09-19 09:44:44 +02003636static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3637 enum nl80211_band band,
3638 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303639{
Johannes Berg8564e382016-09-19 09:44:44 +02003640 u32 count_ht, count_vht, i;
3641 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303642
3643 /* Allow only one rate */
3644 if (hweight32(rate) > 1)
3645 return -EINVAL;
3646
3647 count_ht = 0;
3648 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003649 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303650 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003651 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303652 count_ht++;
3653 if (count_ht > 1)
3654 return -EINVAL;
3655 }
3656 if (count_ht && rate)
3657 return -EINVAL;
3658 }
3659
3660 count_vht = 0;
3661 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003662 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303663 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003664 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303665 count_vht++;
3666 if (count_vht > 1)
3667 return -EINVAL;
3668 }
3669 if (count_vht && rate)
3670 return -EINVAL;
3671 }
3672
3673 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3674 return -EINVAL;
3675
Johannes Berg8564e382016-09-19 09:44:44 +02003676 if (rate &&
3677 !wiphy_ext_feature_isset(&rdev->wiphy,
3678 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3679 return -EINVAL;
3680 if (count_ht &&
3681 !wiphy_ext_feature_isset(&rdev->wiphy,
3682 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3683 return -EINVAL;
3684 if (count_vht &&
3685 !wiphy_ext_feature_isset(&rdev->wiphy,
3686 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3687 return -EINVAL;
3688
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303689 return 0;
3690}
3691
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003692static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003693 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003694{
Johannes Berg88600202012-02-13 15:17:18 +01003695 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003696
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003697 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3698 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3699 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3700 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003701 return -EINVAL;
3702
Johannes Berg88600202012-02-13 15:17:18 +01003703 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003704
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003705 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3706 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3707 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003708 if (!bcn->head_len)
3709 return -EINVAL;
3710 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003711 }
3712
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003713 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3714 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3715 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003716 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003717 }
3718
Johannes Berg4c476992010-10-04 21:36:35 +02003719 if (!haveinfo)
3720 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003721
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003722 if (attrs[NL80211_ATTR_IE]) {
3723 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3724 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003725 }
3726
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003727 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003728 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003729 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003730 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003731 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003732 }
3733
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003734 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003735 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003736 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003737 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003738 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003739 }
3740
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003741 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3742 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3743 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003744 }
3745
Johannes Berg88600202012-02-13 15:17:18 +01003746 return 0;
3747}
3748
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003749static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3750 struct cfg80211_ap_settings *params)
3751{
3752 struct wireless_dev *wdev;
3753 bool ret = false;
3754
Johannes Berg53873f12016-05-03 16:52:04 +03003755 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003756 if (wdev->iftype != NL80211_IFTYPE_AP &&
3757 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3758 continue;
3759
Johannes Berg683b6d32012-11-08 21:25:48 +01003760 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003761 continue;
3762
Johannes Berg683b6d32012-11-08 21:25:48 +01003763 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003764 ret = true;
3765 break;
3766 }
3767
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003768 return ret;
3769}
3770
Jouni Malinene39e5b52012-09-30 19:29:39 +03003771static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3772 enum nl80211_auth_type auth_type,
3773 enum nl80211_commands cmd)
3774{
3775 if (auth_type > NL80211_AUTHTYPE_MAX)
3776 return false;
3777
3778 switch (cmd) {
3779 case NL80211_CMD_AUTHENTICATE:
3780 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3781 auth_type == NL80211_AUTHTYPE_SAE)
3782 return false;
Jouni Malinene20f90f2016-10-27 00:42:02 +03003783 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3784 NL80211_EXT_FEATURE_FILS_STA) &&
3785 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3786 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3787 auth_type == NL80211_AUTHTYPE_FILS_PK))
3788 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003789 return true;
3790 case NL80211_CMD_CONNECT:
Srinivas Dasari6fe0e6f2018-01-25 17:13:39 +02003791 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3792 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03003793 return false;
Srinivas Dasari6fe0e6f2018-01-25 17:13:39 +02003794
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03003795 /* FILS with SK PFS or PK not supported yet */
3796 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3797 auth_type == NL80211_AUTHTYPE_FILS_PK)
3798 return false;
3799 if (!wiphy_ext_feature_isset(
3800 &rdev->wiphy,
3801 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3802 auth_type == NL80211_AUTHTYPE_FILS_SK)
3803 return false;
3804 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003805 case NL80211_CMD_START_AP:
3806 /* SAE not supported yet */
3807 if (auth_type == NL80211_AUTHTYPE_SAE)
3808 return false;
Jouni Malinene20f90f2016-10-27 00:42:02 +03003809 /* FILS not supported yet */
3810 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3811 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3812 auth_type == NL80211_AUTHTYPE_FILS_PK)
3813 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003814 return true;
3815 default:
3816 return false;
3817 }
3818}
3819
Johannes Berg88600202012-02-13 15:17:18 +01003820static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3821{
3822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3823 struct net_device *dev = info->user_ptr[1];
3824 struct wireless_dev *wdev = dev->ieee80211_ptr;
3825 struct cfg80211_ap_settings params;
3826 int err;
3827
3828 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3829 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3830 return -EOPNOTSUPP;
3831
3832 if (!rdev->ops->start_ap)
3833 return -EOPNOTSUPP;
3834
3835 if (wdev->beacon_interval)
3836 return -EALREADY;
3837
3838 memset(&params, 0, sizeof(params));
3839
3840 /* these are required for START_AP */
3841 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3842 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3843 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3844 return -EINVAL;
3845
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003846 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003847 if (err)
3848 return err;
3849
3850 params.beacon_interval =
3851 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3852 params.dtim_period =
3853 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3854
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05303855 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3856 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003857 if (err)
3858 return err;
3859
3860 /*
3861 * In theory, some of these attributes should be required here
3862 * but since they were not used when the command was originally
3863 * added, keep them optional for old user space programs to let
3864 * them continue to work with drivers that do not need the
3865 * additional information -- drivers must check!
3866 */
3867 if (info->attrs[NL80211_ATTR_SSID]) {
3868 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3869 params.ssid_len =
3870 nla_len(info->attrs[NL80211_ATTR_SSID]);
3871 if (params.ssid_len == 0 ||
3872 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3873 return -EINVAL;
3874 }
3875
3876 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3877 params.hidden_ssid = nla_get_u32(
3878 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3879 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3880 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3881 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3882 return -EINVAL;
3883 }
3884
3885 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3886
3887 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3888 params.auth_type = nla_get_u32(
3889 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003890 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3891 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003892 return -EINVAL;
3893 } else
3894 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3895
3896 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3897 NL80211_MAX_NR_CIPHER_SUITES);
3898 if (err)
3899 return err;
3900
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303901 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3902 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3903 return -EOPNOTSUPP;
3904 params.inactivity_timeout = nla_get_u16(
3905 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3906 }
3907
Johannes Berg53cabad2012-11-14 15:17:28 +01003908 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3909 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3910 return -EINVAL;
3911 params.p2p_ctwindow =
3912 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3913 if (params.p2p_ctwindow > 127)
3914 return -EINVAL;
3915 if (params.p2p_ctwindow != 0 &&
3916 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3917 return -EINVAL;
3918 }
3919
3920 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3921 u8 tmp;
3922
3923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3924 return -EINVAL;
3925 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3926 if (tmp > 1)
3927 return -EINVAL;
3928 params.p2p_opp_ps = tmp;
3929 if (params.p2p_opp_ps != 0 &&
3930 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3931 return -EINVAL;
3932 }
3933
Johannes Bergaa430da2012-05-16 23:50:18 +02003934 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003935 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3936 if (err)
3937 return err;
3938 } else if (wdev->preset_chandef.chan) {
3939 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003940 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003941 return -EINVAL;
3942
Arik Nemtsov923b3522015-07-08 15:41:44 +03003943 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3944 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003945 return -EINVAL;
3946
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303947 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3948 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3949 if (err)
3950 return err;
3951
Johannes Berg8564e382016-09-19 09:44:44 +02003952 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3953 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303954 if (err)
3955 return err;
3956 }
3957
Eliad Peller18998c32014-09-10 14:07:34 +03003958 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3959 params.smps_mode =
3960 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3961 switch (params.smps_mode) {
3962 case NL80211_SMPS_OFF:
3963 break;
3964 case NL80211_SMPS_STATIC:
3965 if (!(rdev->wiphy.features &
3966 NL80211_FEATURE_STATIC_SMPS))
3967 return -EINVAL;
3968 break;
3969 case NL80211_SMPS_DYNAMIC:
3970 if (!(rdev->wiphy.features &
3971 NL80211_FEATURE_DYNAMIC_SMPS))
3972 return -EINVAL;
3973 break;
3974 default:
3975 return -EINVAL;
3976 }
3977 } else {
3978 params.smps_mode = NL80211_SMPS_OFF;
3979 }
3980
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303981 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3982 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3983 return -EOPNOTSUPP;
3984
Ola Olsson4baf6be2015-10-29 07:04:58 +01003985 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3986 params.acl = parse_acl_data(&rdev->wiphy, info);
3987 if (IS_ERR(params.acl))
3988 return PTR_ERR(params.acl);
3989 }
3990
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003991 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003992 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003993 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003994 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003995 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003996 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003997 wdev->ssid_len = params.ssid_len;
3998 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003999 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004000 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304001
4002 kfree(params.acl);
4003
Johannes Berg56d18932011-05-09 18:41:15 +02004004 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004005}
4006
Johannes Berg88600202012-02-13 15:17:18 +01004007static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4008{
4009 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4010 struct net_device *dev = info->user_ptr[1];
4011 struct wireless_dev *wdev = dev->ieee80211_ptr;
4012 struct cfg80211_beacon_data params;
4013 int err;
4014
4015 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4016 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4017 return -EOPNOTSUPP;
4018
4019 if (!rdev->ops->change_beacon)
4020 return -EOPNOTSUPP;
4021
4022 if (!wdev->beacon_interval)
4023 return -EINVAL;
4024
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004025 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004026 if (err)
4027 return err;
4028
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004029 wdev_lock(wdev);
4030 err = rdev_change_beacon(rdev, dev, &params);
4031 wdev_unlock(wdev);
4032
4033 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004034}
4035
4036static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004037{
Johannes Berg4c476992010-10-04 21:36:35 +02004038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4039 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004040
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004041 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004042}
4043
Johannes Berg5727ef12007-12-19 02:03:34 +01004044static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4045 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4046 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4047 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004048 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004049 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004050 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004051};
4052
Johannes Bergeccb8e82009-05-11 21:57:56 +03004053static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004054 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004055 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004056{
4057 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004058 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004059 int flag;
4060
Johannes Bergeccb8e82009-05-11 21:57:56 +03004061 /*
4062 * Try parsing the new attribute first so userspace
4063 * can specify both for older kernels.
4064 */
4065 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4066 if (nla) {
4067 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004068
Johannes Bergeccb8e82009-05-11 21:57:56 +03004069 sta_flags = nla_data(nla);
4070 params->sta_flags_mask = sta_flags->mask;
4071 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004072 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004073 if ((params->sta_flags_mask |
4074 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4075 return -EINVAL;
4076 return 0;
4077 }
4078
4079 /* if present, parse the old attribute */
4080
4081 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 if (!nla)
4083 return 0;
4084
4085 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4086 nla, sta_flags_policy))
4087 return -EINVAL;
4088
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004089 /*
4090 * Only allow certain flags for interface types so that
4091 * other attributes are silently ignored. Remember that
4092 * this is backward compatibility code with old userspace
4093 * and shouldn't be hit in other cases anyway.
4094 */
4095 switch (iftype) {
4096 case NL80211_IFTYPE_AP:
4097 case NL80211_IFTYPE_AP_VLAN:
4098 case NL80211_IFTYPE_P2P_GO:
4099 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4100 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4101 BIT(NL80211_STA_FLAG_WME) |
4102 BIT(NL80211_STA_FLAG_MFP);
4103 break;
4104 case NL80211_IFTYPE_P2P_CLIENT:
4105 case NL80211_IFTYPE_STATION:
4106 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4107 BIT(NL80211_STA_FLAG_TDLS_PEER);
4108 break;
4109 case NL80211_IFTYPE_MESH_POINT:
4110 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4111 BIT(NL80211_STA_FLAG_MFP) |
4112 BIT(NL80211_STA_FLAG_AUTHORIZED);
4113 default:
4114 return -EINVAL;
4115 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004116
Johannes Berg3383b5a2012-05-10 20:14:43 +02004117 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4118 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004119 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004120
Johannes Berg3383b5a2012-05-10 20:14:43 +02004121 /* no longer support new API additions in old API */
4122 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4123 return -EINVAL;
4124 }
4125 }
4126
Johannes Berg5727ef12007-12-19 02:03:34 +01004127 return 0;
4128}
4129
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004130static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4131 int attr)
4132{
4133 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004134 u32 bitrate;
4135 u16 bitrate_compat;
Matthias Kaehlcke7164cb72017-04-17 15:59:52 -07004136 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004137
4138 rate = nla_nest_start(msg, attr);
4139 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004140 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004141
4142 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4143 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004144 /* report 16-bit bitrate only if we can */
4145 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004146 if (bitrate > 0 &&
4147 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4148 return false;
4149 if (bitrate_compat > 0 &&
4150 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4151 return false;
4152
Johannes Bergb51f3be2015-01-15 16:14:02 +01004153 switch (info->bw) {
4154 case RATE_INFO_BW_5:
4155 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4156 break;
4157 case RATE_INFO_BW_10:
4158 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4159 break;
4160 default:
4161 WARN_ON(1);
4162 /* fall through */
4163 case RATE_INFO_BW_20:
4164 rate_flg = 0;
4165 break;
4166 case RATE_INFO_BW_40:
4167 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4168 break;
4169 case RATE_INFO_BW_80:
4170 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4171 break;
4172 case RATE_INFO_BW_160:
4173 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4174 break;
4175 }
4176
4177 if (rate_flg && nla_put_flag(msg, rate_flg))
4178 return false;
4179
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004180 if (info->flags & RATE_INFO_FLAGS_MCS) {
4181 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4182 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004183 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4184 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4185 return false;
4186 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4187 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4188 return false;
4189 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4190 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004191 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4192 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4193 return false;
4194 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004195
4196 nla_nest_end(msg, rate);
4197 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004198}
4199
Felix Fietkau119363c2013-04-22 16:29:30 +02004200static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4201 int id)
4202{
4203 void *attr;
4204 int i = 0;
4205
4206 if (!mask)
4207 return true;
4208
4209 attr = nla_nest_start(msg, id);
4210 if (!attr)
4211 return false;
4212
4213 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4214 if (!(mask & BIT(i)))
4215 continue;
4216
4217 if (nla_put_u8(msg, i, signal[i]))
4218 return false;
4219 }
4220
4221 nla_nest_end(msg, attr);
4222
4223 return true;
4224}
4225
Johannes Bergcf5ead82014-11-14 17:14:00 +01004226static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4227 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004228 struct cfg80211_registered_device *rdev,
4229 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004230 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004231{
4232 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004233 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004234
Johannes Bergcf5ead82014-11-14 17:14:00 +01004235 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004236 if (!hdr)
4237 return -1;
4238
David S. Miller9360ffd2012-03-29 04:41:26 -04004239 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4240 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4241 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4242 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004243
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4245 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004246 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004247
4248#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004249 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304250 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004251 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4252 sinfo->memb)) \
4253 goto nla_put_failure; \
4254 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004255#define PUT_SINFO_U64(attr, memb) do { \
4256 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4257 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4258 sinfo->memb, NL80211_STA_INFO_PAD)) \
4259 goto nla_put_failure; \
4260 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004261
4262 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4263 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4264
4265 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4266 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004267 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004268 (u32)sinfo->rx_bytes))
4269 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004270
4271 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4272 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004273 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4274 (u32)sinfo->tx_bytes))
4275 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004276
Johannes Bergd686b922016-04-26 09:54:11 +02004277 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4278 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004279 PUT_SINFO(LLID, llid, u16);
4280 PUT_SINFO(PLID, plid, u16);
4281 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004282 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004283
John W. Linville66266b32012-03-15 13:25:41 -04004284 switch (rdev->wiphy.signal_type) {
4285 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004286 PUT_SINFO(SIGNAL, signal, u8);
4287 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004288 break;
4289 default:
4290 break;
4291 }
Johannes Berg319090b2014-11-17 14:08:11 +01004292 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004293 if (!nl80211_put_signal(msg, sinfo->chains,
4294 sinfo->chain_signal,
4295 NL80211_STA_INFO_CHAIN_SIGNAL))
4296 goto nla_put_failure;
4297 }
Johannes Berg319090b2014-11-17 14:08:11 +01004298 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004299 if (!nl80211_put_signal(msg, sinfo->chains,
4300 sinfo->chain_signal_avg,
4301 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4302 goto nla_put_failure;
4303 }
Johannes Berg319090b2014-11-17 14:08:11 +01004304 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004305 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4306 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004307 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004308 }
Johannes Berg319090b2014-11-17 14:08:11 +01004309 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004310 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4311 NL80211_STA_INFO_RX_BITRATE))
4312 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004313 }
Johannes Berg319090b2014-11-17 14:08:11 +01004314
4315 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4316 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4317 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4318 PUT_SINFO(TX_FAILED, tx_failed, u32);
4319 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4320 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4321 PUT_SINFO(LOCAL_PM, local_pm, u32);
4322 PUT_SINFO(PEER_PM, peer_pm, u32);
4323 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4324
4325 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004326 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4327 if (!bss_param)
4328 goto nla_put_failure;
4329
David S. Miller9360ffd2012-03-29 04:41:26 -04004330 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4331 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4332 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4333 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4334 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4335 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4336 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4337 sinfo->bss_param.dtim_period) ||
4338 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4339 sinfo->bss_param.beacon_interval))
4340 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004341
4342 nla_nest_end(msg, bss_param);
4343 }
Johannes Berg319090b2014-11-17 14:08:11 +01004344 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004345 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4346 sizeof(struct nl80211_sta_flag_update),
4347 &sinfo->sta_flags))
4348 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004349
Johannes Bergd686b922016-04-26 09:54:11 +02004350 PUT_SINFO_U64(T_OFFSET, t_offset);
4351 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4352 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004353 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004354
4355#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004356#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004357
4358 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4359 struct nlattr *tidsattr;
4360 int tid;
4361
4362 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4363 if (!tidsattr)
4364 goto nla_put_failure;
4365
4366 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4367 struct cfg80211_tid_stats *tidstats;
4368 struct nlattr *tidattr;
4369
4370 tidstats = &sinfo->pertid[tid];
4371
4372 if (!tidstats->filled)
4373 continue;
4374
4375 tidattr = nla_nest_start(msg, tid + 1);
4376 if (!tidattr)
4377 goto nla_put_failure;
4378
Johannes Bergd686b922016-04-26 09:54:11 +02004379#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004380 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004381 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4382 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004383 goto nla_put_failure; \
4384 } while (0)
4385
Johannes Bergd686b922016-04-26 09:54:11 +02004386 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4387 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4388 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4389 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004390
Johannes Bergd686b922016-04-26 09:54:11 +02004391#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004392 nla_nest_end(msg, tidattr);
4393 }
4394
4395 nla_nest_end(msg, tidsattr);
4396 }
4397
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004398 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004399
Johannes Berg319090b2014-11-17 14:08:11 +01004400 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004401 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4402 sinfo->assoc_req_ies))
4403 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004404
Johannes Berg053c0952015-01-16 22:09:00 +01004405 genlmsg_end(msg, hdr);
4406 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004407
4408 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004409 genlmsg_cancel(msg, hdr);
4410 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004411}
4412
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004413static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004414 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004415{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004417 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004418 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004419 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004420 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004421 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004422
Johannes Berg56769e72017-03-15 14:26:04 +01004423 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004424 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004425 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01004426 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004427
Johannes Berg97990a02013-04-19 01:02:55 +02004428 if (!wdev->netdev) {
4429 err = -EINVAL;
4430 goto out_err;
4431 }
4432
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004433 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004434 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004435 goto out_err;
4436 }
4437
Johannes Bergbba95fe2008-07-29 13:22:51 +02004438 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004439 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004440 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004441 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442 if (err == -ENOENT)
4443 break;
4444 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004445 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004446
Johannes Bergcf5ead82014-11-14 17:14:00 +01004447 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004448 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004449 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004450 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004451 &sinfo) < 0)
4452 goto out;
4453
4454 sta_idx++;
4455 }
4456
Johannes Bergbba95fe2008-07-29 13:22:51 +02004457 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004458 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004459 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004460 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01004461 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004462
4463 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004464}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004465
Johannes Berg5727ef12007-12-19 02:03:34 +01004466static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4467{
Johannes Berg4c476992010-10-04 21:36:35 +02004468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4469 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004470 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004471 struct sk_buff *msg;
4472 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004473 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004474
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004475 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004476
4477 if (!info->attrs[NL80211_ATTR_MAC])
4478 return -EINVAL;
4479
4480 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4481
Johannes Berg4c476992010-10-04 21:36:35 +02004482 if (!rdev->ops->get_station)
4483 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004484
Hila Gonene35e4d22012-06-27 17:19:42 +03004485 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004487 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004488
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004490 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004491 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004492
Johannes Bergcf5ead82014-11-14 17:14:00 +01004493 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4494 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004495 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004496 nlmsg_free(msg);
4497 return -ENOBUFS;
4498 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004499
Johannes Berg4c476992010-10-04 21:36:35 +02004500 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004501}
4502
Johannes Berg77ee7c82013-02-15 00:48:33 +01004503int cfg80211_check_station_change(struct wiphy *wiphy,
4504 struct station_parameters *params,
4505 enum cfg80211_station_type statype)
4506{
Ayala Bekere4208422015-10-23 11:20:06 +03004507 if (params->listen_interval != -1 &&
4508 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004509 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004510
Ayala Beker17b94242016-03-17 15:41:38 +02004511 if (params->support_p2p_ps != -1 &&
4512 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4513 return -EINVAL;
4514
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004515 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004516 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4517 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004518 return -EINVAL;
4519
4520 /* When you run into this, adjust the code below for the new flag */
4521 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4522
4523 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004524 case CFG80211_STA_MESH_PEER_KERNEL:
4525 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004526 /*
4527 * No ignoring the TDLS flag here -- the userspace mesh
4528 * code doesn't have the bug of including TDLS in the
4529 * mask everywhere.
4530 */
4531 if (params->sta_flags_mask &
4532 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4533 BIT(NL80211_STA_FLAG_MFP) |
4534 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4535 return -EINVAL;
4536 break;
4537 case CFG80211_STA_TDLS_PEER_SETUP:
4538 case CFG80211_STA_TDLS_PEER_ACTIVE:
4539 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4540 return -EINVAL;
4541 /* ignore since it can't change */
4542 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4543 break;
4544 default:
4545 /* disallow mesh-specific things */
4546 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4547 return -EINVAL;
4548 if (params->local_pm)
4549 return -EINVAL;
4550 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4551 return -EINVAL;
4552 }
4553
4554 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4555 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4556 /* TDLS can't be set, ... */
4557 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4558 return -EINVAL;
4559 /*
4560 * ... but don't bother the driver with it. This works around
4561 * a hostapd/wpa_supplicant issue -- it always includes the
4562 * TLDS_PEER flag in the mask even for AP mode.
4563 */
4564 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4565 }
4566
Ayala Beker47edb112015-09-21 15:49:53 +03004567 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4568 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004569 /* reject other things that can't change */
4570 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4571 return -EINVAL;
4572 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4573 return -EINVAL;
4574 if (params->supported_rates)
4575 return -EINVAL;
4576 if (params->ext_capab || params->ht_capa || params->vht_capa)
4577 return -EINVAL;
4578 }
4579
Ayala Beker47edb112015-09-21 15:49:53 +03004580 if (statype != CFG80211_STA_AP_CLIENT &&
4581 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004582 if (params->vlan)
4583 return -EINVAL;
4584 }
4585
4586 switch (statype) {
4587 case CFG80211_STA_AP_MLME_CLIENT:
4588 /* Use this only for authorizing/unauthorizing a station */
4589 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4590 return -EOPNOTSUPP;
4591 break;
4592 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004593 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004594 /* accept only the listed bits */
4595 if (params->sta_flags_mask &
4596 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4597 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4598 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4599 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4600 BIT(NL80211_STA_FLAG_WME) |
4601 BIT(NL80211_STA_FLAG_MFP)))
4602 return -EINVAL;
4603
4604 /* but authenticated/associated only if driver handles it */
4605 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4606 params->sta_flags_mask &
4607 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4608 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4609 return -EINVAL;
4610 break;
4611 case CFG80211_STA_IBSS:
4612 case CFG80211_STA_AP_STA:
4613 /* reject any changes other than AUTHORIZED */
4614 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4615 return -EINVAL;
4616 break;
4617 case CFG80211_STA_TDLS_PEER_SETUP:
4618 /* reject any changes other than AUTHORIZED or WME */
4619 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4620 BIT(NL80211_STA_FLAG_WME)))
4621 return -EINVAL;
4622 /* force (at least) rates when authorizing */
4623 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4624 !params->supported_rates)
4625 return -EINVAL;
4626 break;
4627 case CFG80211_STA_TDLS_PEER_ACTIVE:
4628 /* reject any changes */
4629 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004630 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004631 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4632 return -EINVAL;
4633 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004634 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004635 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4636 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004637 return -EINVAL;
4638 break;
4639 }
4640
4641 return 0;
4642}
4643EXPORT_SYMBOL(cfg80211_check_station_change);
4644
Johannes Berg5727ef12007-12-19 02:03:34 +01004645/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004646 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004647 */
Johannes Berg80b99892011-11-18 16:23:01 +01004648static struct net_device *get_vlan(struct genl_info *info,
4649 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004650{
Johannes Berg463d0182009-07-14 00:33:35 +02004651 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004652 struct net_device *v;
4653 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004654
Johannes Berg80b99892011-11-18 16:23:01 +01004655 if (!vlanattr)
4656 return NULL;
4657
4658 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4659 if (!v)
4660 return ERR_PTR(-ENODEV);
4661
4662 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4663 ret = -EINVAL;
4664 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004665 }
Johannes Berg80b99892011-11-18 16:23:01 +01004666
Johannes Berg77ee7c82013-02-15 00:48:33 +01004667 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4668 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4669 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4670 ret = -EINVAL;
4671 goto error;
4672 }
4673
Johannes Berg80b99892011-11-18 16:23:01 +01004674 if (!netif_running(v)) {
4675 ret = -ENETDOWN;
4676 goto error;
4677 }
4678
4679 return v;
4680 error:
4681 dev_put(v);
4682 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004683}
4684
Johannes Berg94e860f2014-01-20 23:58:15 +01004685static const struct nla_policy
4686nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004687 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4688 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4689};
4690
Johannes Bergff276692013-02-15 00:09:01 +01004691static int nl80211_parse_sta_wme(struct genl_info *info,
4692 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004693{
Jouni Malinendf881292013-02-14 21:10:54 +02004694 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4695 struct nlattr *nla;
4696 int err;
4697
Jouni Malinendf881292013-02-14 21:10:54 +02004698 /* parse WME attributes if present */
4699 if (!info->attrs[NL80211_ATTR_STA_WME])
4700 return 0;
4701
4702 nla = info->attrs[NL80211_ATTR_STA_WME];
4703 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4704 nl80211_sta_wme_policy);
4705 if (err)
4706 return err;
4707
4708 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4709 params->uapsd_queues = nla_get_u8(
4710 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4711 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4712 return -EINVAL;
4713
4714 if (tb[NL80211_STA_WME_MAX_SP])
4715 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4716
4717 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4718 return -EINVAL;
4719
4720 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4721
4722 return 0;
4723}
4724
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304725static int nl80211_parse_sta_channel_info(struct genl_info *info,
4726 struct station_parameters *params)
4727{
4728 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4729 params->supported_channels =
4730 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4731 params->supported_channels_len =
4732 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4733 /*
4734 * Need to include at least one (first channel, number of
4735 * channels) tuple for each subband, and must have proper
4736 * tuples for the rest of the data as well.
4737 */
4738 if (params->supported_channels_len < 2)
4739 return -EINVAL;
4740 if (params->supported_channels_len % 2)
4741 return -EINVAL;
4742 }
4743
4744 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4745 params->supported_oper_classes =
4746 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4747 params->supported_oper_classes_len =
4748 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4749 /*
4750 * The value of the Length field of the Supported Operating
4751 * Classes element is between 2 and 253.
4752 */
4753 if (params->supported_oper_classes_len < 2 ||
4754 params->supported_oper_classes_len > 253)
4755 return -EINVAL;
4756 }
4757 return 0;
4758}
4759
Johannes Bergff276692013-02-15 00:09:01 +01004760static int nl80211_set_station_tdls(struct genl_info *info,
4761 struct station_parameters *params)
4762{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304763 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004764 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004765 if (info->attrs[NL80211_ATTR_PEER_AID])
4766 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004767 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4768 params->ht_capa =
4769 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4770 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4771 params->vht_capa =
4772 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4773
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304774 err = nl80211_parse_sta_channel_info(info, params);
4775 if (err)
4776 return err;
4777
Johannes Bergff276692013-02-15 00:09:01 +01004778 return nl80211_parse_sta_wme(info, params);
4779}
4780
Johannes Berg5727ef12007-12-19 02:03:34 +01004781static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4782{
Johannes Berg4c476992010-10-04 21:36:35 +02004783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004784 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004785 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004786 u8 *mac_addr;
4787 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004788
4789 memset(&params, 0, sizeof(params));
4790
Johannes Berg77ee7c82013-02-15 00:48:33 +01004791 if (!rdev->ops->change_station)
4792 return -EOPNOTSUPP;
4793
Ayala Bekere4208422015-10-23 11:20:06 +03004794 /*
4795 * AID and listen_interval properties can be set only for unassociated
4796 * station. Include these parameters here and will check them in
4797 * cfg80211_check_station_change().
4798 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004799 if (info->attrs[NL80211_ATTR_STA_AID])
4800 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004801
4802 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4803 params.listen_interval =
4804 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4805 else
4806 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004807
Ayala Beker17b94242016-03-17 15:41:38 +02004808 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4809 u8 tmp;
4810
4811 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4812 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4813 return -EINVAL;
4814
4815 params.support_p2p_ps = tmp;
4816 } else {
4817 params.support_p2p_ps = -1;
4818 }
4819
Johannes Berg5727ef12007-12-19 02:03:34 +01004820 if (!info->attrs[NL80211_ATTR_MAC])
4821 return -EINVAL;
4822
4823 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4824
4825 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4826 params.supported_rates =
4827 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4828 params.supported_rates_len =
4829 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4830 }
4831
Jouni Malinen9d62a982013-02-14 21:10:13 +02004832 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4833 params.capability =
4834 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4835 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4836 }
4837
4838 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4839 params.ext_capab =
4840 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4841 params.ext_capab_len =
4842 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4843 }
4844
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004845 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004846 return -EINVAL;
4847
Johannes Bergf8bacc22013-02-14 23:27:01 +01004848 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004849 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004850 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4851 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4852 return -EINVAL;
4853 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004854
Johannes Bergf8bacc22013-02-14 23:27:01 +01004855 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004856 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004857 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4858 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4859 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004860 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4861 params.peer_aid = nla_get_u16(
4862 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4863 if (params.peer_aid > IEEE80211_MAX_AID)
4864 return -EINVAL;
4865 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004866 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4867 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004868
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004869 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4870 enum nl80211_mesh_power_mode pm = nla_get_u32(
4871 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4872
4873 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4874 pm > NL80211_MESH_POWER_MAX)
4875 return -EINVAL;
4876
4877 params.local_pm = pm;
4878 }
4879
Johannes Berg77ee7c82013-02-15 00:48:33 +01004880 /* Include parameters for TDLS peer (will check later) */
4881 err = nl80211_set_station_tdls(info, &params);
4882 if (err)
4883 return err;
4884
4885 params.vlan = get_vlan(info, rdev);
4886 if (IS_ERR(params.vlan))
4887 return PTR_ERR(params.vlan);
4888
Johannes Berga97f4422009-06-18 17:23:43 +02004889 switch (dev->ieee80211_ptr->iftype) {
4890 case NL80211_IFTYPE_AP:
4891 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004892 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004893 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004894 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004895 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004896 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004897 break;
4898 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004899 err = -EOPNOTSUPP;
4900 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004901 }
4902
Johannes Berg77ee7c82013-02-15 00:48:33 +01004903 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004904 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004905
Johannes Berg77ee7c82013-02-15 00:48:33 +01004906 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004907 if (params.vlan)
4908 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004909
Johannes Berg5727ef12007-12-19 02:03:34 +01004910 return err;
4911}
4912
4913static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4914{
Johannes Berg4c476992010-10-04 21:36:35 +02004915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004916 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004917 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004918 struct station_parameters params;
4919 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004920 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4921 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004922
4923 memset(&params, 0, sizeof(params));
4924
Johannes Berg984c3112013-02-14 23:43:25 +01004925 if (!rdev->ops->add_station)
4926 return -EOPNOTSUPP;
4927
Johannes Berg5727ef12007-12-19 02:03:34 +01004928 if (!info->attrs[NL80211_ATTR_MAC])
4929 return -EINVAL;
4930
Johannes Berg5727ef12007-12-19 02:03:34 +01004931 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4932 return -EINVAL;
4933
4934 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4935 return -EINVAL;
4936
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004937 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4938 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004939 return -EINVAL;
4940
Johannes Berg5727ef12007-12-19 02:03:34 +01004941 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4942 params.supported_rates =
4943 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4944 params.supported_rates_len =
4945 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4946 params.listen_interval =
4947 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004948
Ayala Beker17b94242016-03-17 15:41:38 +02004949 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4950 u8 tmp;
4951
4952 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4953 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4954 return -EINVAL;
4955
4956 params.support_p2p_ps = tmp;
4957 } else {
4958 /*
4959 * if not specified, assume it's supported for P2P GO interface,
4960 * and is NOT supported for AP interface
4961 */
4962 params.support_p2p_ps =
4963 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4964 }
4965
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004966 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004967 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004968 else
4969 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004970 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4971 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004972
Jouni Malinen9d62a982013-02-14 21:10:13 +02004973 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4974 params.capability =
4975 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4976 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4977 }
4978
4979 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4980 params.ext_capab =
4981 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4982 params.ext_capab_len =
4983 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4984 }
4985
Jouni Malinen36aedc902008-08-25 11:58:58 +03004986 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4987 params.ht_capa =
4988 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004989
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004990 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4991 params.vht_capa =
4992 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4993
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004994 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4995 params.opmode_notif_used = true;
4996 params.opmode_notif =
4997 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4998 }
4999
Johannes Bergf8bacc22013-02-14 23:27:01 +01005000 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005001 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005002 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5003 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5004 return -EINVAL;
5005 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005006
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305007 err = nl80211_parse_sta_channel_info(info, &params);
5008 if (err)
5009 return err;
5010
Johannes Bergff276692013-02-15 00:09:01 +01005011 err = nl80211_parse_sta_wme(info, &params);
5012 if (err)
5013 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005014
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005015 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005016 return -EINVAL;
5017
Johannes Berg496fcc22015-03-12 08:53:27 +02005018 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5019 * as userspace might just pass through the capabilities from the IEs
5020 * directly, rather than enforcing this restriction and returning an
5021 * error in this case.
5022 */
5023 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5024 params.ht_capa = NULL;
5025 params.vht_capa = NULL;
5026 }
5027
Johannes Berg77ee7c82013-02-15 00:48:33 +01005028 /* When you run into this, adjust the code below for the new flag */
5029 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5030
Johannes Bergbdd90d52011-12-14 12:20:27 +01005031 switch (dev->ieee80211_ptr->iftype) {
5032 case NL80211_IFTYPE_AP:
5033 case NL80211_IFTYPE_AP_VLAN:
5034 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005035 /* ignore WME attributes if iface/sta is not capable */
5036 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5037 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5038 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005039
Johannes Bergbdd90d52011-12-14 12:20:27 +01005040 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005041 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5042 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005043 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005044 /* but don't bother the driver with it */
5045 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005046
Johannes Bergd582cff2012-10-26 17:53:44 +02005047 /* allow authenticated/associated only if driver handles it */
5048 if (!(rdev->wiphy.features &
5049 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005050 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005051 return -EINVAL;
5052
Johannes Bergbda95eb2015-11-26 16:26:13 +01005053 /* Older userspace, or userspace wanting to be compatible with
5054 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5055 * and assoc flags in the mask, but assumes the station will be
5056 * added as associated anyway since this was the required driver
5057 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5058 * introduced.
5059 * In order to not bother drivers with this quirk in the API
5060 * set the flags in both the mask and set for new stations in
5061 * this case.
5062 */
5063 if (!(params.sta_flags_mask & auth_assoc)) {
5064 params.sta_flags_mask |= auth_assoc;
5065 params.sta_flags_set |= auth_assoc;
5066 }
5067
Johannes Bergbdd90d52011-12-14 12:20:27 +01005068 /* must be last in here for error handling */
5069 params.vlan = get_vlan(info, rdev);
5070 if (IS_ERR(params.vlan))
5071 return PTR_ERR(params.vlan);
5072 break;
5073 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005074 /* ignore uAPSD data */
5075 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5076
Johannes Bergd582cff2012-10-26 17:53:44 +02005077 /* associated is disallowed */
5078 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5079 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005080 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005081 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5082 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005083 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005084 break;
5085 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005086 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005087 /* ignore uAPSD data */
5088 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5089
Johannes Berg77ee7c82013-02-15 00:48:33 +01005090 /* these are disallowed */
5091 if (params.sta_flags_mask &
5092 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5093 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005094 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005095 /* Only TDLS peers can be added */
5096 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5097 return -EINVAL;
5098 /* Can only add if TDLS ... */
5099 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5100 return -EOPNOTSUPP;
5101 /* ... with external setup is supported */
5102 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5103 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005104 /*
5105 * Older wpa_supplicant versions always mark the TDLS peer
5106 * as authorized, but it shouldn't yet be.
5107 */
5108 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005109 break;
5110 default:
5111 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005112 }
5113
Johannes Bergbdd90d52011-12-14 12:20:27 +01005114 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005115
Hila Gonene35e4d22012-06-27 17:19:42 +03005116 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005117
Johannes Berg5727ef12007-12-19 02:03:34 +01005118 if (params.vlan)
5119 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005120 return err;
5121}
5122
5123static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5124{
Johannes Berg4c476992010-10-04 21:36:35 +02005125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5126 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005127 struct station_del_parameters params;
5128
5129 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005130
5131 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005132 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005133
Johannes Berge80cf852009-05-11 14:43:13 +02005134 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005135 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005136 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005137 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5138 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005139
Johannes Berg4c476992010-10-04 21:36:35 +02005140 if (!rdev->ops->del_station)
5141 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005142
Jouni Malinen98856862014-10-20 13:20:45 +03005143 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5144 params.subtype =
5145 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5146 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5147 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5148 return -EINVAL;
5149 } else {
5150 /* Default to Deauthentication frame */
5151 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5152 }
5153
5154 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5155 params.reason_code =
5156 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5157 if (params.reason_code == 0)
5158 return -EINVAL; /* 0 is reserved */
5159 } else {
5160 /* Default to reason code 2 */
5161 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5162 }
5163
Jouni Malinen89c771e2014-10-10 20:52:40 +03005164 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005165}
5166
Eric W. Biederman15e47302012-09-07 20:12:54 +00005167static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005168 int flags, struct net_device *dev,
5169 u8 *dst, u8 *next_hop,
5170 struct mpath_info *pinfo)
5171{
5172 void *hdr;
5173 struct nlattr *pinfoattr;
5174
Henning Rogge1ef4c852014-11-04 16:14:58 +01005175 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005176 if (!hdr)
5177 return -1;
5178
David S. Miller9360ffd2012-03-29 04:41:26 -04005179 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5180 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5181 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5182 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5183 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005184
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005185 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5186 if (!pinfoattr)
5187 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005188 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5189 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5190 pinfo->frame_qlen))
5191 goto nla_put_failure;
5192 if (((pinfo->filled & MPATH_INFO_SN) &&
5193 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5194 ((pinfo->filled & MPATH_INFO_METRIC) &&
5195 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5196 pinfo->metric)) ||
5197 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5198 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5199 pinfo->exptime)) ||
5200 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5201 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5202 pinfo->flags)) ||
5203 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5204 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5205 pinfo->discovery_timeout)) ||
5206 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5207 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5208 pinfo->discovery_retries)))
5209 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005210
5211 nla_nest_end(msg, pinfoattr);
5212
Johannes Berg053c0952015-01-16 22:09:00 +01005213 genlmsg_end(msg, hdr);
5214 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005215
5216 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005217 genlmsg_cancel(msg, hdr);
5218 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005219}
5220
5221static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005222 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005223{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005224 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005225 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005226 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005227 u8 dst[ETH_ALEN];
5228 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005229 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005230 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005231
Johannes Berg56769e72017-03-15 14:26:04 +01005232 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005233 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005234 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005235 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005236
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005237 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005238 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005239 goto out_err;
5240 }
5241
Johannes Berg97990a02013-04-19 01:02:55 +02005242 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005243 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005244 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005245 }
5246
Johannes Bergbba95fe2008-07-29 13:22:51 +02005247 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005248 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005249 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005250 if (err == -ENOENT)
5251 break;
5252 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005253 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005254
Eric W. Biederman15e47302012-09-07 20:12:54 +00005255 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005256 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005257 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005258 &pinfo) < 0)
5259 goto out;
5260
5261 path_idx++;
5262 }
5263
Johannes Bergbba95fe2008-07-29 13:22:51 +02005264 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005265 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005266 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005267 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005268 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005269 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005270}
5271
5272static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5273{
Johannes Berg4c476992010-10-04 21:36:35 +02005274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005275 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005276 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005277 struct mpath_info pinfo;
5278 struct sk_buff *msg;
5279 u8 *dst = NULL;
5280 u8 next_hop[ETH_ALEN];
5281
5282 memset(&pinfo, 0, sizeof(pinfo));
5283
5284 if (!info->attrs[NL80211_ATTR_MAC])
5285 return -EINVAL;
5286
5287 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5288
Johannes Berg4c476992010-10-04 21:36:35 +02005289 if (!rdev->ops->get_mpath)
5290 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005291
Johannes Berg4c476992010-10-04 21:36:35 +02005292 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5293 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005294
Hila Gonene35e4d22012-06-27 17:19:42 +03005295 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005296 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005297 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005298
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005300 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005301 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005302
Eric W. Biederman15e47302012-09-07 20:12:54 +00005303 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005304 dev, dst, next_hop, &pinfo) < 0) {
5305 nlmsg_free(msg);
5306 return -ENOBUFS;
5307 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005308
Johannes Berg4c476992010-10-04 21:36:35 +02005309 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005310}
5311
5312static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5313{
Johannes Berg4c476992010-10-04 21:36:35 +02005314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5315 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005316 u8 *dst = NULL;
5317 u8 *next_hop = NULL;
5318
5319 if (!info->attrs[NL80211_ATTR_MAC])
5320 return -EINVAL;
5321
5322 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5323 return -EINVAL;
5324
5325 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5326 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5327
Johannes Berg4c476992010-10-04 21:36:35 +02005328 if (!rdev->ops->change_mpath)
5329 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005330
Johannes Berg4c476992010-10-04 21:36:35 +02005331 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5332 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005333
Hila Gonene35e4d22012-06-27 17:19:42 +03005334 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005335}
Johannes Berg4c476992010-10-04 21:36:35 +02005336
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005337static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5338{
Johannes Berg4c476992010-10-04 21:36:35 +02005339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5340 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005341 u8 *dst = NULL;
5342 u8 *next_hop = NULL;
5343
5344 if (!info->attrs[NL80211_ATTR_MAC])
5345 return -EINVAL;
5346
5347 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5348 return -EINVAL;
5349
5350 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5351 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5352
Johannes Berg4c476992010-10-04 21:36:35 +02005353 if (!rdev->ops->add_mpath)
5354 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005355
Johannes Berg4c476992010-10-04 21:36:35 +02005356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5357 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005358
Hila Gonene35e4d22012-06-27 17:19:42 +03005359 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005360}
5361
5362static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5363{
Johannes Berg4c476992010-10-04 21:36:35 +02005364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5365 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005366 u8 *dst = NULL;
5367
5368 if (info->attrs[NL80211_ATTR_MAC])
5369 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5370
Johannes Berg4c476992010-10-04 21:36:35 +02005371 if (!rdev->ops->del_mpath)
5372 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005373
Hila Gonene35e4d22012-06-27 17:19:42 +03005374 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005375}
5376
Henning Rogge66be7d22014-09-12 08:58:49 +02005377static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5378{
5379 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5380 int err;
5381 struct net_device *dev = info->user_ptr[1];
5382 struct mpath_info pinfo;
5383 struct sk_buff *msg;
5384 u8 *dst = NULL;
5385 u8 mpp[ETH_ALEN];
5386
5387 memset(&pinfo, 0, sizeof(pinfo));
5388
5389 if (!info->attrs[NL80211_ATTR_MAC])
5390 return -EINVAL;
5391
5392 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5393
5394 if (!rdev->ops->get_mpp)
5395 return -EOPNOTSUPP;
5396
5397 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5398 return -EOPNOTSUPP;
5399
5400 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5401 if (err)
5402 return err;
5403
5404 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5405 if (!msg)
5406 return -ENOMEM;
5407
5408 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5409 dev, dst, mpp, &pinfo) < 0) {
5410 nlmsg_free(msg);
5411 return -ENOBUFS;
5412 }
5413
5414 return genlmsg_reply(msg, info);
5415}
5416
5417static int nl80211_dump_mpp(struct sk_buff *skb,
5418 struct netlink_callback *cb)
5419{
5420 struct mpath_info pinfo;
5421 struct cfg80211_registered_device *rdev;
5422 struct wireless_dev *wdev;
5423 u8 dst[ETH_ALEN];
5424 u8 mpp[ETH_ALEN];
5425 int path_idx = cb->args[2];
5426 int err;
5427
Johannes Berg56769e72017-03-15 14:26:04 +01005428 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005429 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5430 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005431 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005432
5433 if (!rdev->ops->dump_mpp) {
5434 err = -EOPNOTSUPP;
5435 goto out_err;
5436 }
5437
5438 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5439 err = -EOPNOTSUPP;
5440 goto out_err;
5441 }
5442
5443 while (1) {
5444 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5445 mpp, &pinfo);
5446 if (err == -ENOENT)
5447 break;
5448 if (err)
5449 goto out_err;
5450
5451 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5452 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5453 wdev->netdev, dst, mpp,
5454 &pinfo) < 0)
5455 goto out;
5456
5457 path_idx++;
5458 }
5459
5460 out:
5461 cb->args[2] = path_idx;
5462 err = skb->len;
5463 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005464 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005465 return err;
5466}
5467
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005468static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5469{
Johannes Berg4c476992010-10-04 21:36:35 +02005470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5471 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005472 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005473 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005474 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005475
5476 memset(&params, 0, sizeof(params));
5477 /* default to not changing parameters */
5478 params.use_cts_prot = -1;
5479 params.use_short_preamble = -1;
5480 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005481 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005482 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005483 params.p2p_ctwindow = -1;
5484 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005485
5486 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5487 params.use_cts_prot =
5488 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5489 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5490 params.use_short_preamble =
5491 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5492 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5493 params.use_short_slot_time =
5494 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005495 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5496 params.basic_rates =
5497 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5498 params.basic_rates_len =
5499 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5500 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005501 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5502 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005503 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5504 params.ht_opmode =
5505 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005506
Johannes Berg53cabad2012-11-14 15:17:28 +01005507 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5508 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5509 return -EINVAL;
5510 params.p2p_ctwindow =
5511 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5512 if (params.p2p_ctwindow < 0)
5513 return -EINVAL;
5514 if (params.p2p_ctwindow != 0 &&
5515 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5516 return -EINVAL;
5517 }
5518
5519 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5520 u8 tmp;
5521
5522 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5523 return -EINVAL;
5524 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5525 if (tmp > 1)
5526 return -EINVAL;
5527 params.p2p_opp_ps = tmp;
5528 if (params.p2p_opp_ps &&
5529 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5530 return -EINVAL;
5531 }
5532
Johannes Berg4c476992010-10-04 21:36:35 +02005533 if (!rdev->ops->change_bss)
5534 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005535
Johannes Berg074ac8d2010-09-16 14:58:22 +02005536 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005537 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5538 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005539
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005540 wdev_lock(wdev);
5541 err = rdev_change_bss(rdev, dev, &params);
5542 wdev_unlock(wdev);
5543
5544 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005545}
5546
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005547static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5548{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005549 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005550 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005551 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005552 u32 owner_nlportid;
5553
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005554 /*
5555 * You should only get this when cfg80211 hasn't yet initialized
5556 * completely when built-in to the kernel right between the time
5557 * window between nl80211_init() and regulatory_init(), if that is
5558 * even possible.
5559 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005560 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005561 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005562
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005563 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5564 user_reg_hint_type =
5565 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5566 else
5567 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5568
5569 switch (user_reg_hint_type) {
5570 case NL80211_USER_REG_HINT_USER:
5571 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005572 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5573 return -EINVAL;
5574
5575 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5576 return regulatory_hint_user(data, user_reg_hint_type);
5577 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005578 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5579 owner_nlportid = info->snd_portid;
5580 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5581 } else {
5582 owner_nlportid = 0;
5583 is_indoor = true;
5584 }
5585
5586 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005587 default:
5588 return -EINVAL;
5589 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005590}
5591
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005592static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005593 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005594{
Johannes Berg4c476992010-10-04 21:36:35 +02005595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005596 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005597 struct wireless_dev *wdev = dev->ieee80211_ptr;
5598 struct mesh_config cur_params;
5599 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005600 void *hdr;
5601 struct nlattr *pinfoattr;
5602 struct sk_buff *msg;
5603
Johannes Berg29cbe682010-12-03 09:20:44 +01005604 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5605 return -EOPNOTSUPP;
5606
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005607 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005608 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005609
Johannes Berg29cbe682010-12-03 09:20:44 +01005610 wdev_lock(wdev);
5611 /* If not connected, get default parameters */
5612 if (!wdev->mesh_id_len)
5613 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5614 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005615 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005616 wdev_unlock(wdev);
5617
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005618 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005619 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005620
5621 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005623 if (!msg)
5624 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005625 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005626 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005627 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005628 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005629 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005630 if (!pinfoattr)
5631 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005632 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5633 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5634 cur_params.dot11MeshRetryTimeout) ||
5635 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5636 cur_params.dot11MeshConfirmTimeout) ||
5637 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5638 cur_params.dot11MeshHoldingTimeout) ||
5639 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5640 cur_params.dot11MeshMaxPeerLinks) ||
5641 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5642 cur_params.dot11MeshMaxRetries) ||
5643 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5644 cur_params.dot11MeshTTL) ||
5645 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5646 cur_params.element_ttl) ||
5647 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5648 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005649 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5650 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005651 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5652 cur_params.dot11MeshHWMPmaxPREQretries) ||
5653 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5654 cur_params.path_refresh_time) ||
5655 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5656 cur_params.min_discovery_timeout) ||
5657 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5658 cur_params.dot11MeshHWMPactivePathTimeout) ||
5659 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5660 cur_params.dot11MeshHWMPpreqMinInterval) ||
5661 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5662 cur_params.dot11MeshHWMPperrMinInterval) ||
5663 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5664 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5665 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5666 cur_params.dot11MeshHWMPRootMode) ||
5667 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5668 cur_params.dot11MeshHWMPRannInterval) ||
5669 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5670 cur_params.dot11MeshGateAnnouncementProtocol) ||
5671 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5672 cur_params.dot11MeshForwarding) ||
5673 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005674 cur_params.rssi_threshold) ||
5675 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005676 cur_params.ht_opmode) ||
5677 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5678 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5679 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005680 cur_params.dot11MeshHWMProotInterval) ||
5681 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005682 cur_params.dot11MeshHWMPconfirmationInterval) ||
5683 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5684 cur_params.power_mode) ||
5685 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005686 cur_params.dot11MeshAwakeWindowDuration) ||
5687 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5688 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005689 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005690 nla_nest_end(msg, pinfoattr);
5691 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005692 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005693
Johannes Berg3b858752009-03-12 09:55:09 +01005694 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005695 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005696 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005697 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005698 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005699}
5700
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005701static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005702 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5703 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5704 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5705 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5706 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5707 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005708 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005709 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005710 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005711 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5712 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5713 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5714 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5715 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005716 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005717 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005718 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005719 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005720 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005721 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005722 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5723 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005724 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5725 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005726 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005727 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5728 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005729 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005730};
5731
Javier Cardonac80d5452010-12-16 17:37:49 -08005732static const struct nla_policy
5733 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005734 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005735 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5736 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005737 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005738 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005739 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005740 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005741 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005742 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005743};
5744
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005745static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5746{
5747 u8 val = nla_get_u8(nla);
5748 if (val < min || val > max)
5749 return -EINVAL;
5750 *out = val;
5751 return 0;
5752}
5753
5754static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5755{
5756 u8 val = nla_get_u8(nla);
5757 if (val < min || val > max)
5758 return -EINVAL;
5759 *out = val;
5760 return 0;
5761}
5762
5763static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5764{
5765 u16 val = nla_get_u16(nla);
5766 if (val < min || val > max)
5767 return -EINVAL;
5768 *out = val;
5769 return 0;
5770}
5771
5772static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5773{
5774 u32 val = nla_get_u32(nla);
5775 if (val < min || val > max)
5776 return -EINVAL;
5777 *out = val;
5778 return 0;
5779}
5780
5781static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5782{
5783 s32 val = nla_get_s32(nla);
5784 if (val < min || val > max)
5785 return -EINVAL;
5786 *out = val;
5787 return 0;
5788}
5789
Johannes Bergff9a71a2016-08-11 14:59:53 +02005790static int nl80211_check_power_mode(const struct nlattr *nla,
5791 enum nl80211_mesh_power_mode min,
5792 enum nl80211_mesh_power_mode max,
5793 enum nl80211_mesh_power_mode *out)
5794{
5795 u32 val = nla_get_u32(nla);
5796 if (val < min || val > max)
5797 return -EINVAL;
5798 *out = val;
5799 return 0;
5800}
5801
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005802static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005803 struct mesh_config *cfg,
5804 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005806 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005807 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005808 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005809
Marco Porschea54fba2013-01-07 16:04:48 +01005810#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5811do { \
5812 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005813 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005814 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005815 mask |= (1 << (attr - 1)); \
5816 } \
5817} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005818
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005819 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005820 return -EINVAL;
5821 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005822 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005823 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005824 return -EINVAL;
5825
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005826 /* This makes sure that there aren't more than 32 mesh config
5827 * parameters (otherwise our bitfield scheme would not work.) */
5828 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5829
5830 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005832 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005833 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005835 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005836 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005837 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005838 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005839 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005840 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005841 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005842 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005843 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005844 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005845 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005847 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005848 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005849 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005850 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005851 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005852 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005853 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5855 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005856 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005857 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005858 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005859 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005860 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005862 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005863 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005864 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005865 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005866 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5868 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005869 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005870 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005871 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005872 1, 65535, mask,
5873 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005874 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005876 1, 65535, mask,
5877 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005878 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005879 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005880 dot11MeshHWMPnetDiameterTraversalTime,
5881 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005882 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005883 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5885 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005886 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5888 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005889 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005891 dot11MeshGateAnnouncementProtocol, 0, 1,
5892 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005893 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005895 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005896 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005897 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005898 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005899 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005900 /*
5901 * Check HT operation mode based on
5902 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5903 */
5904 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5905 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5906
5907 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5908 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5909 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5910 return -EINVAL;
5911
5912 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5913 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5914 return -EINVAL;
5915
5916 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5917 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5918 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5919 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5920 return -EINVAL;
5921 break;
5922 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5923 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5924 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5925 return -EINVAL;
5926 break;
5927 }
5928 cfg->ht_opmode = ht_opmode;
Masashi Honmaf9bd7912017-01-26 08:56:13 +09005929 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09005930 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005932 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005933 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005934 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005935 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005936 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005937 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005939 dot11MeshHWMPconfirmationInterval,
5940 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005941 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005942 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5944 NL80211_MESH_POWER_ACTIVE,
5945 NL80211_MESH_POWER_MAX,
5946 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005947 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005948 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5949 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005950 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005952 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005953 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005954 if (mask_out)
5955 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005956
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005957 return 0;
5958
5959#undef FILL_IN_MESH_PARAM_IF_SET
5960}
5961
Javier Cardonac80d5452010-12-16 17:37:49 -08005962static int nl80211_parse_mesh_setup(struct genl_info *info,
5963 struct mesh_setup *setup)
5964{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005965 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005966 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5967
5968 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5969 return -EINVAL;
5970 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5971 info->attrs[NL80211_ATTR_MESH_SETUP],
5972 nl80211_mesh_setup_params_policy))
5973 return -EINVAL;
5974
Javier Cardonad299a1f2012-03-31 11:31:33 -07005975 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5976 setup->sync_method =
5977 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5978 IEEE80211_SYNC_METHOD_VENDOR :
5979 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5980
Javier Cardonac80d5452010-12-16 17:37:49 -08005981 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5982 setup->path_sel_proto =
5983 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5984 IEEE80211_PATH_PROTOCOL_VENDOR :
5985 IEEE80211_PATH_PROTOCOL_HWMP;
5986
5987 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5988 setup->path_metric =
5989 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5990 IEEE80211_PATH_METRIC_VENDOR :
5991 IEEE80211_PATH_METRIC_AIRTIME;
5992
Javier Cardona581a8b02011-04-07 15:08:27 -07005993 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005994 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005995 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005996 if (!is_valid_ie_attr(ieattr))
5997 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005998 setup->ie = nla_data(ieattr);
5999 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08006000 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006001 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6002 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6003 return -EINVAL;
6004 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006005 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6006 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006007 if (setup->is_secure)
6008 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006009
Colleen Twitty6e16d902013-05-08 11:45:59 -07006010 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6011 if (!setup->user_mpm)
6012 return -EINVAL;
6013 setup->auth_id =
6014 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6015 }
6016
Javier Cardonac80d5452010-12-16 17:37:49 -08006017 return 0;
6018}
6019
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006020static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006021 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006022{
6023 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6024 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006025 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006026 struct mesh_config cfg;
6027 u32 mask;
6028 int err;
6029
Johannes Berg29cbe682010-12-03 09:20:44 +01006030 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6031 return -EOPNOTSUPP;
6032
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006033 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006034 return -EOPNOTSUPP;
6035
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006036 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006037 if (err)
6038 return err;
6039
Johannes Berg29cbe682010-12-03 09:20:44 +01006040 wdev_lock(wdev);
6041 if (!wdev->mesh_id_len)
6042 err = -ENOLINK;
6043
6044 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006045 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006046
6047 wdev_unlock(wdev);
6048
6049 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006050}
6051
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006052static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6053 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006054{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006055 struct nlattr *nl_reg_rules;
6056 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006057
Johannes Berg458f4f92012-12-06 15:47:38 +01006058 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6059 (regdom->dfs_region &&
6060 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006061 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006062
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006063 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6064 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006065 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006066
Johannes Berg458f4f92012-12-06 15:47:38 +01006067 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006068 struct nlattr *nl_reg_rule;
6069 const struct ieee80211_reg_rule *reg_rule;
6070 const struct ieee80211_freq_range *freq_range;
6071 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006072 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006073
Johannes Berg458f4f92012-12-06 15:47:38 +01006074 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006075 freq_range = &reg_rule->freq_range;
6076 power_rule = &reg_rule->power_rule;
6077
6078 nl_reg_rule = nla_nest_start(msg, i);
6079 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006080 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006081
Janusz Dziedzic97524822014-01-30 09:52:20 +01006082 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6083 if (!max_bandwidth_khz)
6084 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6085 reg_rule);
6086
David S. Miller9360ffd2012-03-29 04:41:26 -04006087 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6088 reg_rule->flags) ||
6089 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6090 freq_range->start_freq_khz) ||
6091 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6092 freq_range->end_freq_khz) ||
6093 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006094 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006095 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6096 power_rule->max_antenna_gain) ||
6097 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006098 power_rule->max_eirp) ||
6099 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6100 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006101 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006102
6103 nla_nest_end(msg, nl_reg_rule);
6104 }
6105
6106 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006107 return 0;
6108
6109nla_put_failure:
6110 return -EMSGSIZE;
6111}
6112
6113static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6114{
6115 const struct ieee80211_regdomain *regdom = NULL;
6116 struct cfg80211_registered_device *rdev;
6117 struct wiphy *wiphy = NULL;
6118 struct sk_buff *msg;
6119 void *hdr;
6120
6121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6122 if (!msg)
6123 return -ENOBUFS;
6124
6125 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6126 NL80211_CMD_GET_REG);
6127 if (!hdr)
6128 goto put_failure;
6129
6130 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006131 bool self_managed;
6132
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006133 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6134 if (IS_ERR(rdev)) {
6135 nlmsg_free(msg);
6136 return PTR_ERR(rdev);
6137 }
6138
6139 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006140 self_managed = wiphy->regulatory_flags &
6141 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006142 regdom = get_wiphy_regdom(wiphy);
6143
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006144 /* a self-managed-reg device must have a private regdom */
6145 if (WARN_ON(!regdom && self_managed)) {
6146 nlmsg_free(msg);
6147 return -EINVAL;
6148 }
6149
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006150 if (regdom &&
6151 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6152 goto nla_put_failure;
6153 }
6154
6155 if (!wiphy && reg_last_request_cell_base() &&
6156 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6157 NL80211_USER_REG_HINT_CELL_BASE))
6158 goto nla_put_failure;
6159
6160 rcu_read_lock();
6161
6162 if (!regdom)
6163 regdom = rcu_dereference(cfg80211_regdomain);
6164
6165 if (nl80211_put_regdom(regdom, msg))
6166 goto nla_put_failure_rcu;
6167
6168 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006169
6170 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006171 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006172
Johannes Berg458f4f92012-12-06 15:47:38 +01006173nla_put_failure_rcu:
6174 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006175nla_put_failure:
6176 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006177put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006178 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006179 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006180}
6181
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006182static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6183 u32 seq, int flags, struct wiphy *wiphy,
6184 const struct ieee80211_regdomain *regdom)
6185{
6186 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6187 NL80211_CMD_GET_REG);
6188
6189 if (!hdr)
6190 return -1;
6191
6192 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6193
6194 if (nl80211_put_regdom(regdom, msg))
6195 goto nla_put_failure;
6196
6197 if (!wiphy && reg_last_request_cell_base() &&
6198 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6199 NL80211_USER_REG_HINT_CELL_BASE))
6200 goto nla_put_failure;
6201
6202 if (wiphy &&
6203 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6204 goto nla_put_failure;
6205
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006206 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6207 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6208 goto nla_put_failure;
6209
Johannes Berg053c0952015-01-16 22:09:00 +01006210 genlmsg_end(msg, hdr);
6211 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006212
6213nla_put_failure:
6214 genlmsg_cancel(msg, hdr);
6215 return -EMSGSIZE;
6216}
6217
6218static int nl80211_get_reg_dump(struct sk_buff *skb,
6219 struct netlink_callback *cb)
6220{
6221 const struct ieee80211_regdomain *regdom = NULL;
6222 struct cfg80211_registered_device *rdev;
6223 int err, reg_idx, start = cb->args[2];
6224
6225 rtnl_lock();
6226
6227 if (cfg80211_regdomain && start == 0) {
6228 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6229 NLM_F_MULTI, NULL,
6230 rtnl_dereference(cfg80211_regdomain));
6231 if (err < 0)
6232 goto out_err;
6233 }
6234
6235 /* the global regdom is idx 0 */
6236 reg_idx = 1;
6237 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6238 regdom = get_wiphy_regdom(&rdev->wiphy);
6239 if (!regdom)
6240 continue;
6241
6242 if (++reg_idx <= start)
6243 continue;
6244
6245 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6246 NLM_F_MULTI, &rdev->wiphy, regdom);
6247 if (err < 0) {
6248 reg_idx--;
6249 break;
6250 }
6251 }
6252
6253 cb->args[2] = reg_idx;
6254 err = skb->len;
6255out_err:
6256 rtnl_unlock();
6257 return err;
6258}
6259
Johannes Bergb6863032015-10-15 09:25:18 +02006260#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6261static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6262 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6263 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6264 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6265 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6266 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6267 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6268 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6269};
6270
6271static int parse_reg_rule(struct nlattr *tb[],
6272 struct ieee80211_reg_rule *reg_rule)
6273{
6274 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6275 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6276
6277 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6278 return -EINVAL;
6279 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6280 return -EINVAL;
6281 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6282 return -EINVAL;
6283 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6284 return -EINVAL;
6285 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6286 return -EINVAL;
6287
6288 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6289
6290 freq_range->start_freq_khz =
6291 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6292 freq_range->end_freq_khz =
6293 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6294 freq_range->max_bandwidth_khz =
6295 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6296
6297 power_rule->max_eirp =
6298 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6299
6300 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6301 power_rule->max_antenna_gain =
6302 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6303
6304 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6305 reg_rule->dfs_cac_ms =
6306 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6307
6308 return 0;
6309}
6310
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006311static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6312{
6313 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6314 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006315 char *alpha2;
6316 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006317 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006318 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006319 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006320
6321 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6322 return -EINVAL;
6323
6324 if (!info->attrs[NL80211_ATTR_REG_RULES])
6325 return -EINVAL;
6326
6327 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6328
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006329 if (info->attrs[NL80211_ATTR_DFS_REGION])
6330 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6331
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006332 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006333 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006334 num_rules++;
6335 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006336 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006337 }
6338
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006339 if (!reg_is_valid_request(alpha2))
6340 return -EINVAL;
6341
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006342 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006343 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006344
6345 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006346 if (!rd)
6347 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006348
6349 rd->n_reg_rules = num_rules;
6350 rd->alpha2[0] = alpha2[0];
6351 rd->alpha2[1] = alpha2[1];
6352
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006353 /*
6354 * Disable DFS master mode if the DFS region was
6355 * not supported or known on this kernel.
6356 */
6357 if (reg_supported_dfs_region(dfs_region))
6358 rd->dfs_region = dfs_region;
6359
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006360 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006361 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01006362 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
6363 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
6364 reg_rule_policy);
6365 if (r)
6366 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006367 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6368 if (r)
6369 goto bad_reg;
6370
6371 rule_idx++;
6372
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006373 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6374 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006375 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006376 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006377 }
6378
Johannes Berg06627992016-06-09 10:40:09 +02006379 /* set_regdom takes ownership of rd */
6380 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006381 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006382 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006383 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006384}
Johannes Bergb6863032015-10-15 09:25:18 +02006385#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006386
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006387static int validate_scan_freqs(struct nlattr *freqs)
6388{
6389 struct nlattr *attr1, *attr2;
6390 int n_channels = 0, tmp1, tmp2;
6391
Srinivas Dasarie4712902017-07-07 01:43:42 +03006392 nla_for_each_nested(attr1, freqs, tmp1)
6393 if (nla_len(attr1) != sizeof(u32))
6394 return 0;
6395
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006396 nla_for_each_nested(attr1, freqs, tmp1) {
6397 n_channels++;
6398 /*
6399 * Some hardware has a limited channel list for
6400 * scanning, and it is pretty much nonsensical
6401 * to scan for a channel twice, so disallow that
6402 * and don't require drivers to check that the
6403 * channel list they get isn't longer than what
6404 * they can scan, as long as they can scan all
6405 * the channels they registered at once.
6406 */
6407 nla_for_each_nested(attr2, freqs, tmp2)
6408 if (attr1 != attr2 &&
6409 nla_get_u32(attr1) == nla_get_u32(attr2))
6410 return 0;
6411 }
6412
6413 return n_channels;
6414}
6415
Johannes Berg57fbcce2016-04-12 15:56:15 +02006416static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006417{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006418 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006419}
6420
6421static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6422 struct cfg80211_bss_selection *bss_select)
6423{
6424 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6425 struct nlattr *nest;
6426 int err;
6427 bool found = false;
6428 int i;
6429
6430 /* only process one nested attribute */
6431 nest = nla_data(nla);
6432 if (!nla_ok(nest, nla_len(nest)))
6433 return -EINVAL;
6434
6435 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6436 nla_len(nest), nl80211_bss_select_policy);
6437 if (err)
6438 return err;
6439
6440 /* only one attribute may be given */
6441 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6442 if (attr[i]) {
6443 if (found)
6444 return -EINVAL;
6445 found = true;
6446 }
6447 }
6448
6449 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6450
6451 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6452 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6453
6454 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6455 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6456 bss_select->param.band_pref =
6457 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6458 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6459 return -EINVAL;
6460 }
6461
6462 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6463 struct nl80211_bss_select_rssi_adjust *adj_param;
6464
6465 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6466 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6467 bss_select->param.adjust.band = adj_param->band;
6468 bss_select->param.adjust.delta = adj_param->delta;
6469 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6470 return -EINVAL;
6471 }
6472
6473 /* user-space did not provide behaviour attribute */
6474 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6475 return -EINVAL;
6476
6477 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6478 return -EINVAL;
6479
6480 return 0;
6481}
6482
Johannes Bergad2b26a2014-06-12 21:39:05 +02006483static int nl80211_parse_random_mac(struct nlattr **attrs,
6484 u8 *mac_addr, u8 *mac_addr_mask)
6485{
6486 int i;
6487
6488 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006489 eth_zero_addr(mac_addr);
6490 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006491 mac_addr[0] = 0x2;
6492 mac_addr_mask[0] = 0x3;
6493
6494 return 0;
6495 }
6496
6497 /* need both or none */
6498 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6499 return -EINVAL;
6500
6501 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6502 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6503
6504 /* don't allow or configure an mcast address */
6505 if (!is_multicast_ether_addr(mac_addr_mask) ||
6506 is_multicast_ether_addr(mac_addr))
6507 return -EINVAL;
6508
6509 /*
6510 * allow users to pass a MAC address that has bits set outside
6511 * of the mask, but don't bother drivers with having to deal
6512 * with such bits
6513 */
6514 for (i = 0; i < ETH_ALEN; i++)
6515 mac_addr[i] &= mac_addr_mask[i];
6516
6517 return 0;
6518}
6519
Johannes Berg2a519312009-02-10 21:25:55 +01006520static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6521{
Johannes Berg4c476992010-10-04 21:36:35 +02006522 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006523 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006524 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006525 struct nlattr *attr;
6526 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006527 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006528 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006529
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006530 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6531 return -EINVAL;
6532
Johannes Berg79c97e92009-07-07 03:56:12 +02006533 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006534
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006535 if (wdev->iftype == NL80211_IFTYPE_NAN)
6536 return -EOPNOTSUPP;
6537
Johannes Berg4c476992010-10-04 21:36:35 +02006538 if (!rdev->ops->scan)
6539 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006540
Johannes Bergf9d15d12014-01-22 11:14:19 +02006541 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006542 err = -EBUSY;
6543 goto unlock;
6544 }
Johannes Berg2a519312009-02-10 21:25:55 +01006545
6546 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006547 n_channels = validate_scan_freqs(
6548 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006549 if (!n_channels) {
6550 err = -EINVAL;
6551 goto unlock;
6552 }
Johannes Berg2a519312009-02-10 21:25:55 +01006553 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006554 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006555 }
6556
6557 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6558 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6559 n_ssids++;
6560
Johannes Bergf9f47522013-03-19 15:04:07 +01006561 if (n_ssids > wiphy->max_scan_ssids) {
6562 err = -EINVAL;
6563 goto unlock;
6564 }
Johannes Berg2a519312009-02-10 21:25:55 +01006565
Jouni Malinen70692ad2009-02-16 19:39:13 +02006566 if (info->attrs[NL80211_ATTR_IE])
6567 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6568 else
6569 ie_len = 0;
6570
Johannes Bergf9f47522013-03-19 15:04:07 +01006571 if (ie_len > wiphy->max_scan_ie_len) {
6572 err = -EINVAL;
6573 goto unlock;
6574 }
Johannes Berg18a83652009-03-31 12:12:05 +02006575
Johannes Berg2a519312009-02-10 21:25:55 +01006576 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006577 + sizeof(*request->ssids) * n_ssids
6578 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006579 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006580 if (!request) {
6581 err = -ENOMEM;
6582 goto unlock;
6583 }
Johannes Berg2a519312009-02-10 21:25:55 +01006584
Johannes Berg2a519312009-02-10 21:25:55 +01006585 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006586 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006587 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006588 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006589 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006590 request->ie = (void *)(request->ssids + n_ssids);
6591 else
6592 request->ie = (void *)(request->channels + n_channels);
6593 }
Johannes Berg2a519312009-02-10 21:25:55 +01006594
Johannes Berg584991d2009-11-02 13:32:03 +01006595 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006596 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6597 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006598 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006599 struct ieee80211_channel *chan;
6600
6601 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6602
6603 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006604 err = -EINVAL;
6605 goto out_free;
6606 }
Johannes Berg584991d2009-11-02 13:32:03 +01006607
6608 /* ignore disabled channels */
6609 if (chan->flags & IEEE80211_CHAN_DISABLED)
6610 continue;
6611
6612 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006613 i++;
6614 }
6615 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006616 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006617
Johannes Berg2a519312009-02-10 21:25:55 +01006618 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006619 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006620 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006621
Johannes Berg2a519312009-02-10 21:25:55 +01006622 if (!wiphy->bands[band])
6623 continue;
6624 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006625 struct ieee80211_channel *chan;
6626
6627 chan = &wiphy->bands[band]->channels[j];
6628
6629 if (chan->flags & IEEE80211_CHAN_DISABLED)
6630 continue;
6631
6632 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006633 i++;
6634 }
6635 }
6636 }
6637
Johannes Berg584991d2009-11-02 13:32:03 +01006638 if (!i) {
6639 err = -EINVAL;
6640 goto out_free;
6641 }
6642
6643 request->n_channels = i;
6644
Johannes Berg2a519312009-02-10 21:25:55 +01006645 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006646 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006647 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006648 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006649 err = -EINVAL;
6650 goto out_free;
6651 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006652 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006653 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006654 i++;
6655 }
6656 }
6657
Jouni Malinen70692ad2009-02-16 19:39:13 +02006658 if (info->attrs[NL80211_ATTR_IE]) {
6659 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006660 memcpy((void *)request->ie,
6661 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006662 request->ie_len);
6663 }
6664
Johannes Berg57fbcce2016-04-12 15:56:15 +02006665 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006666 if (wiphy->bands[i])
6667 request->rates[i] =
6668 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006669
6670 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6671 nla_for_each_nested(attr,
6672 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6673 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006674 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006675
Johannes Berg57fbcce2016-04-12 15:56:15 +02006676 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006677 err = -EINVAL;
6678 goto out_free;
6679 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006680
6681 if (!wiphy->bands[band])
6682 continue;
6683
Johannes Berg34850ab2011-07-18 18:08:35 +02006684 err = ieee80211_get_ratemask(wiphy->bands[band],
6685 nla_data(attr),
6686 nla_len(attr),
6687 &request->rates[band]);
6688 if (err)
6689 goto out_free;
6690 }
6691 }
6692
Avraham Stern1d762502016-07-05 17:10:13 +03006693 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6694 if (!wiphy_ext_feature_isset(wiphy,
6695 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6696 err = -EOPNOTSUPP;
6697 goto out_free;
6698 }
6699
6700 request->duration =
6701 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6702 request->duration_mandatory =
6703 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6704 }
6705
Sam Leffler46856bb2012-10-11 21:03:32 -07006706 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006707 request->flags = nla_get_u32(
6708 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Srinivas Dasaridf7d3c62018-01-17 16:44:16 +05306709 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6710 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
6711 ((request->flags & NL80211_SCAN_FLAG_LOW_SPAN) &&
6712 !wiphy_ext_feature_isset(wiphy,
6713 NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) ||
6714 ((request->flags & NL80211_SCAN_FLAG_LOW_POWER) &&
6715 !wiphy_ext_feature_isset(wiphy,
6716 NL80211_EXT_FEATURE_LOW_POWER_SCAN)) ||
6717 ((request->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) &&
6718 !wiphy_ext_feature_isset(wiphy,
6719 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006720 err = -EOPNOTSUPP;
6721 goto out_free;
6722 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006723
6724 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6725 if (!(wiphy->features &
6726 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6727 err = -EOPNOTSUPP;
6728 goto out_free;
6729 }
6730
6731 if (wdev->current_bss) {
6732 err = -EOPNOTSUPP;
6733 goto out_free;
6734 }
6735
6736 err = nl80211_parse_random_mac(info->attrs,
6737 request->mac_addr,
6738 request->mac_addr_mask);
6739 if (err)
6740 goto out_free;
6741 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006742 }
Sam Lefflered4737712012-10-11 21:03:31 -07006743
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306744 request->no_cck =
6745 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6746
Vamsi Krishna45816392016-12-02 23:59:08 +02006747 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6748 * BSSID to scan for. This was problematic because that same attribute
6749 * was already used for another purpose (local random MAC address). The
6750 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6751 * compatibility with older userspace components, also use the
6752 * NL80211_ATTR_MAC value here if it can be determined to be used for
6753 * the specific BSSID use case instead of the random MAC address
6754 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6755 */
6756 if (info->attrs[NL80211_ATTR_BSSID])
6757 memcpy(request->bssid,
6758 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6759 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6760 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006761 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6762 ETH_ALEN);
6763 else
6764 eth_broadcast_addr(request->bssid);
6765
Johannes Bergfd014282012-06-18 19:17:03 +02006766 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006767 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006768 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006769
Johannes Berg79c97e92009-07-07 03:56:12 +02006770 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006771 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006772
Johannes Berg463d0182009-07-14 00:33:35 +02006773 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006774 nl80211_send_scan_start(rdev, wdev);
6775 if (wdev->netdev)
6776 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006777 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006778 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006779 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006780 kfree(request);
6781 }
Johannes Berg3b858752009-03-12 09:55:09 +01006782
Johannes Bergf9f47522013-03-19 15:04:07 +01006783 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006784 return err;
6785}
6786
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306787static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6788{
6789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6790 struct wireless_dev *wdev = info->user_ptr[1];
6791
6792 if (!rdev->ops->abort_scan)
6793 return -EOPNOTSUPP;
6794
6795 if (rdev->scan_msg)
6796 return 0;
6797
6798 if (!rdev->scan_req)
6799 return -ENOENT;
6800
6801 rdev_abort_scan(rdev, wdev);
6802 return 0;
6803}
6804
Avraham Stern3b06d272015-10-12 09:51:34 +03006805static int
6806nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6807 struct cfg80211_sched_scan_request *request,
6808 struct nlattr **attrs)
6809{
6810 int tmp, err, i = 0;
6811 struct nlattr *attr;
6812
6813 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6814 u32 interval;
6815
6816 /*
6817 * If scan plans are not specified,
6818 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6819 * case one scan plan will be set with the specified scan
6820 * interval and infinite number of iterations.
6821 */
6822 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6823 return -EINVAL;
6824
6825 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6826 if (!interval)
6827 return -EINVAL;
6828
6829 request->scan_plans[0].interval =
6830 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6831 if (!request->scan_plans[0].interval)
6832 return -EINVAL;
6833
6834 if (request->scan_plans[0].interval >
6835 wiphy->max_sched_scan_plan_interval)
6836 request->scan_plans[0].interval =
6837 wiphy->max_sched_scan_plan_interval;
6838
6839 return 0;
6840 }
6841
6842 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6843 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6844
6845 if (WARN_ON(i >= n_plans))
6846 return -EINVAL;
6847
6848 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6849 nla_data(attr), nla_len(attr),
6850 nl80211_plan_policy);
6851 if (err)
6852 return err;
6853
6854 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6855 return -EINVAL;
6856
6857 request->scan_plans[i].interval =
6858 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6859 if (!request->scan_plans[i].interval ||
6860 request->scan_plans[i].interval >
6861 wiphy->max_sched_scan_plan_interval)
6862 return -EINVAL;
6863
6864 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6865 request->scan_plans[i].iterations =
6866 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6867 if (!request->scan_plans[i].iterations ||
6868 (request->scan_plans[i].iterations >
6869 wiphy->max_sched_scan_plan_iterations))
6870 return -EINVAL;
6871 } else if (i < n_plans - 1) {
6872 /*
6873 * All scan plans but the last one must specify
6874 * a finite number of iterations
6875 */
6876 return -EINVAL;
6877 }
6878
6879 i++;
6880 }
6881
6882 /*
6883 * The last scan plan must not specify the number of
6884 * iterations, it is supposed to run infinitely
6885 */
6886 if (request->scan_plans[n_plans - 1].iterations)
6887 return -EINVAL;
6888
6889 return 0;
6890}
6891
Luciano Coelho256da022014-11-10 16:13:46 +02006892static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006893nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006894 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006895{
6896 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006897 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006898 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006899 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006900 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006901 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006902 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006903
Luciano Coelho256da022014-11-10 16:13:46 +02006904 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6905 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006906
Luciano Coelho256da022014-11-10 16:13:46 +02006907 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006908 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006909 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006910 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006911 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006912 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006913 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006914 }
6915
Luciano Coelho256da022014-11-10 16:13:46 +02006916 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6917 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006918 tmp)
6919 n_ssids++;
6920
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006921 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006922 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006923
Johannes Bergea73cbc2014-01-24 10:53:53 +01006924 /*
6925 * First, count the number of 'real' matchsets. Due to an issue with
6926 * the old implementation, matchsets containing only the RSSI attribute
6927 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6928 * RSSI for all matchsets, rather than their own matchset for reporting
6929 * all APs with a strong RSSI. This is needed to be compatible with
6930 * older userspace that treated a matchset with only the RSSI as the
6931 * global RSSI for all other matchsets - if there are other matchsets.
6932 */
Luciano Coelho256da022014-11-10 16:13:46 +02006933 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006934 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006935 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006936 tmp) {
6937 struct nlattr *rssi;
6938
6939 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6940 nla_data(attr), nla_len(attr),
6941 nl80211_match_policy);
6942 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006943 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006944 /* add other standalone attributes here */
6945 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6946 n_match_sets++;
6947 continue;
6948 }
6949 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6950 if (rssi)
6951 default_match_rssi = nla_get_s32(rssi);
6952 }
6953 }
6954
6955 /* However, if there's no other matchset, add the RSSI one */
6956 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6957 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006958
6959 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006960 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006961
Luciano Coelho256da022014-11-10 16:13:46 +02006962 if (attrs[NL80211_ATTR_IE])
6963 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006964 else
6965 ie_len = 0;
6966
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006967 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006968 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006969
Avraham Stern3b06d272015-10-12 09:51:34 +03006970 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6971 /*
6972 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6973 * each scan plan already specifies its own interval
6974 */
6975 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6976 return ERR_PTR(-EINVAL);
6977
6978 nla_for_each_nested(attr,
6979 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6980 n_plans++;
6981 } else {
6982 /*
6983 * The scan interval attribute is kept for backward
6984 * compatibility. If no scan plans are specified and sched scan
6985 * interval is specified, one scan plan will be set with this
6986 * scan interval and infinite number of iterations.
6987 */
6988 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6989 return ERR_PTR(-EINVAL);
6990
6991 n_plans = 1;
6992 }
6993
6994 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6995 return ERR_PTR(-EINVAL);
6996
vamsi krishnaf4f1a542017-01-13 01:12:20 +02006997 if (!wiphy_ext_feature_isset(
6998 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
6999 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
7000 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7001 return ERR_PTR(-EINVAL);
7002
Luciano Coelho807f8a82011-05-11 17:09:35 +03007003 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007004 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007005 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007006 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007007 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007008 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007009 if (!request)
7010 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007011
7012 if (n_ssids)
7013 request->ssids = (void *)&request->channels[n_channels];
7014 request->n_ssids = n_ssids;
7015 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007016 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007017 request->ie = (void *)(request->ssids + n_ssids);
7018 else
7019 request->ie = (void *)(request->channels + n_channels);
7020 }
7021
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007022 if (n_match_sets) {
7023 if (request->ie)
7024 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007025 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007026 request->match_sets =
7027 (void *)(request->ssids + n_ssids);
7028 else
7029 request->match_sets =
7030 (void *)(request->channels + n_channels);
7031 }
7032 request->n_match_sets = n_match_sets;
7033
Avraham Stern3b06d272015-10-12 09:51:34 +03007034 if (n_match_sets)
7035 request->scan_plans = (void *)(request->match_sets +
7036 n_match_sets);
7037 else if (request->ie)
7038 request->scan_plans = (void *)(request->ie + ie_len);
7039 else if (n_ssids)
7040 request->scan_plans = (void *)(request->ssids + n_ssids);
7041 else
7042 request->scan_plans = (void *)(request->channels + n_channels);
7043
7044 request->n_scan_plans = n_plans;
7045
Luciano Coelho807f8a82011-05-11 17:09:35 +03007046 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007047 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007048 /* user specified, bail out if channel not found */
7049 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007050 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007051 tmp) {
7052 struct ieee80211_channel *chan;
7053
7054 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7055
7056 if (!chan) {
7057 err = -EINVAL;
7058 goto out_free;
7059 }
7060
7061 /* ignore disabled channels */
7062 if (chan->flags & IEEE80211_CHAN_DISABLED)
7063 continue;
7064
7065 request->channels[i] = chan;
7066 i++;
7067 }
7068 } else {
7069 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007070 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007071 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007072
Luciano Coelho807f8a82011-05-11 17:09:35 +03007073 if (!wiphy->bands[band])
7074 continue;
7075 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7076 struct ieee80211_channel *chan;
7077
7078 chan = &wiphy->bands[band]->channels[j];
7079
7080 if (chan->flags & IEEE80211_CHAN_DISABLED)
7081 continue;
7082
7083 request->channels[i] = chan;
7084 i++;
7085 }
7086 }
7087 }
7088
7089 if (!i) {
7090 err = -EINVAL;
7091 goto out_free;
7092 }
7093
7094 request->n_channels = i;
7095
7096 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007097 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007098 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007099 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007100 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007101 err = -EINVAL;
7102 goto out_free;
7103 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007104 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007105 memcpy(request->ssids[i].ssid, nla_data(attr),
7106 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007107 i++;
7108 }
7109 }
7110
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007111 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007112 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007113 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007114 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007115 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007116 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007117
Johannes Bergae811e22014-01-24 10:17:47 +01007118 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7119 nla_data(attr), nla_len(attr),
7120 nl80211_match_policy);
7121 if (err)
7122 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007123 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007124 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007125 if (WARN_ON(i >= n_match_sets)) {
7126 /* this indicates a programming error,
7127 * the loop above should have verified
7128 * things properly
7129 */
7130 err = -EINVAL;
7131 goto out_free;
7132 }
7133
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007134 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7135 err = -EINVAL;
7136 goto out_free;
7137 }
7138 memcpy(request->match_sets[i].ssid.ssid,
7139 nla_data(ssid), nla_len(ssid));
7140 request->match_sets[i].ssid.ssid_len =
7141 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007142 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007143 request->match_sets[i].rssi_thold =
7144 default_match_rssi;
7145 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7146 if (rssi)
7147 request->match_sets[i].rssi_thold =
7148 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007149 }
7150 i++;
7151 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007152
7153 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007154 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007155 request->match_sets[0].rssi_thold = default_match_rssi;
7156
7157 request->min_rssi_thold = INT_MAX;
7158 for (i = 0; i < n_match_sets; i++)
7159 request->min_rssi_thold =
7160 min(request->match_sets[i].rssi_thold,
7161 request->min_rssi_thold);
7162 } else {
7163 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007164 }
7165
Johannes Berg9900e482014-02-04 21:01:25 +01007166 if (ie_len) {
7167 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007168 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007169 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007170 request->ie_len);
7171 }
7172
Luciano Coelho256da022014-11-10 16:13:46 +02007173 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007174 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007175 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007176 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7177 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007178 err = -EOPNOTSUPP;
7179 goto out_free;
7180 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007181
7182 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7183 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7184
7185 if (!wdev) /* must be net-detect */
7186 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7187
7188 if (!(wiphy->features & flg)) {
7189 err = -EOPNOTSUPP;
7190 goto out_free;
7191 }
7192
7193 if (wdev && wdev->current_bss) {
7194 err = -EOPNOTSUPP;
7195 goto out_free;
7196 }
7197
7198 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7199 request->mac_addr_mask);
7200 if (err)
7201 goto out_free;
7202 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007203 }
Sam Lefflered4737712012-10-11 21:03:31 -07007204
Luciano Coelho9c748932015-01-16 16:04:09 +02007205 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7206 request->delay =
7207 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7208
vamsi krishnaf4f1a542017-01-13 01:12:20 +02007209 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7210 request->relative_rssi = nla_get_s8(
7211 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7212 request->relative_rssi_set = true;
7213 }
7214
7215 if (request->relative_rssi_set &&
7216 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7217 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7218
7219 rssi_adjust = nla_data(
7220 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7221 request->rssi_adjust.band = rssi_adjust->band;
7222 request->rssi_adjust.delta = rssi_adjust->delta;
7223 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7224 err = -EINVAL;
7225 goto out_free;
7226 }
7227 }
7228
Avraham Stern3b06d272015-10-12 09:51:34 +03007229 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7230 if (err)
7231 goto out_free;
7232
Sam Leffler15d60302012-10-11 21:03:34 -07007233 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007234
Luciano Coelho256da022014-11-10 16:13:46 +02007235 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007236
7237out_free:
7238 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007239 return ERR_PTR(err);
7240}
7241
7242static int nl80211_start_sched_scan(struct sk_buff *skb,
7243 struct genl_info *info)
7244{
7245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7246 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007247 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007248 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007249 int err;
7250
7251 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7252 !rdev->ops->sched_scan_start)
7253 return -EOPNOTSUPP;
7254
7255 if (rdev->sched_scan_req)
7256 return -EINPROGRESS;
7257
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007258 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7259 info->attrs);
7260
7261 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007262 if (err)
7263 goto out_err;
7264
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007265 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007266 if (err)
7267 goto out_free;
7268
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007269 sched_scan_req->dev = dev;
7270 sched_scan_req->wiphy = &rdev->wiphy;
7271
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007272 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7273 sched_scan_req->owner_nlportid = info->snd_portid;
7274
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007275 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007276
7277 nl80211_send_sched_scan(rdev, dev,
7278 NL80211_CMD_START_SCHED_SCAN);
7279 return 0;
7280
7281out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007282 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007283out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007284 return err;
7285}
7286
7287static int nl80211_stop_sched_scan(struct sk_buff *skb,
7288 struct genl_info *info)
7289{
7290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7291
7292 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7293 !rdev->ops->sched_scan_stop)
7294 return -EOPNOTSUPP;
7295
Johannes Berg5fe231e2013-05-08 21:45:15 +02007296 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007297}
7298
Simon Wunderlich04f39042013-02-08 18:16:19 +01007299static int nl80211_start_radar_detection(struct sk_buff *skb,
7300 struct genl_info *info)
7301{
7302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7303 struct net_device *dev = info->user_ptr[1];
7304 struct wireless_dev *wdev = dev->ieee80211_ptr;
7305 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007306 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007307 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007308 int err;
7309
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007310 dfs_region = reg_get_dfs_region(wdev->wiphy);
7311 if (dfs_region == NL80211_DFS_UNSET)
7312 return -EINVAL;
7313
Simon Wunderlich04f39042013-02-08 18:16:19 +01007314 err = nl80211_parse_chandef(rdev, info, &chandef);
7315 if (err)
7316 return err;
7317
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007318 if (netif_carrier_ok(dev))
7319 return -EBUSY;
7320
Amar Singhal42839af2014-03-19 18:36:58 -07007321 if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD)
7322 return -EOPNOTSUPP;
7323
Simon Wunderlich04f39042013-02-08 18:16:19 +01007324 if (wdev->cac_started)
7325 return -EBUSY;
7326
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007327 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007328 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007329 if (err < 0)
7330 return err;
7331
7332 if (err == 0)
7333 return -EINVAL;
7334
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007335 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007336 return -EINVAL;
7337
7338 if (!rdev->ops->start_radar_detection)
7339 return -EOPNOTSUPP;
7340
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007341 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7342 if (WARN_ON(!cac_time_ms))
7343 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7344
Ilan Peera1056b12015-10-22 22:27:46 +03007345 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007346 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007347 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007348 wdev->cac_started = true;
7349 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007350 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007351 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007352 return err;
7353}
7354
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007355static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7356{
7357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7358 struct net_device *dev = info->user_ptr[1];
7359 struct wireless_dev *wdev = dev->ieee80211_ptr;
7360 struct cfg80211_csa_settings params;
7361 /* csa_attrs is defined static to avoid waste of stack size - this
7362 * function is called under RTNL lock, so this should not be a problem.
7363 */
7364 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007365 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007366 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007367 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007368 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007369
7370 if (!rdev->ops->channel_switch ||
7371 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7372 return -EOPNOTSUPP;
7373
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007374 switch (dev->ieee80211_ptr->iftype) {
7375 case NL80211_IFTYPE_AP:
7376 case NL80211_IFTYPE_P2P_GO:
7377 need_new_beacon = true;
7378
7379 /* useless if AP is not running */
7380 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007381 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007382 break;
7383 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007384 if (!wdev->ssid_len)
7385 return -ENOTCONN;
7386 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007387 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007388 if (!wdev->mesh_id_len)
7389 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007390 break;
7391 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007392 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007393 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007394
7395 memset(&params, 0, sizeof(params));
7396
7397 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7398 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7399 return -EINVAL;
7400
7401 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007402 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007403 return -EINVAL;
7404
Luciano Coelho252e07c2014-10-08 09:48:34 +03007405 /* Even though the attribute is u32, the specification says
7406 * u8, so let's make sure we don't overflow.
7407 */
7408 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7409 if (cs_count > 255)
7410 return -EINVAL;
7411
7412 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007413
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007414 if (!need_new_beacon)
7415 goto skip_beacons;
7416
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007417 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7418 if (err)
7419 return err;
7420
7421 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7422 info->attrs[NL80211_ATTR_CSA_IES],
7423 nl80211_policy);
7424 if (err)
7425 return err;
7426
7427 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7428 if (err)
7429 return err;
7430
7431 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7432 return -EINVAL;
7433
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007434 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7435 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007436 return -EINVAL;
7437
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007438 params.n_counter_offsets_beacon = len / sizeof(u16);
7439 if (rdev->wiphy.max_num_csa_counters &&
7440 (params.n_counter_offsets_beacon >
7441 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007442 return -EINVAL;
7443
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007444 params.counter_offsets_beacon =
7445 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7446
7447 /* sanity checks - counters should fit and be the same */
7448 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7449 u16 offset = params.counter_offsets_beacon[i];
7450
7451 if (offset >= params.beacon_csa.tail_len)
7452 return -EINVAL;
7453
7454 if (params.beacon_csa.tail[offset] != params.count)
7455 return -EINVAL;
7456 }
7457
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007458 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007459 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7460 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007461 return -EINVAL;
7462
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007463 params.n_counter_offsets_presp = len / sizeof(u16);
7464 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007465 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007466 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007467 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007468
7469 params.counter_offsets_presp =
7470 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7471
7472 /* sanity checks - counters should fit and be the same */
7473 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7474 u16 offset = params.counter_offsets_presp[i];
7475
7476 if (offset >= params.beacon_csa.probe_resp_len)
7477 return -EINVAL;
7478
7479 if (params.beacon_csa.probe_resp[offset] !=
7480 params.count)
7481 return -EINVAL;
7482 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007483 }
7484
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007485skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007486 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7487 if (err)
7488 return err;
7489
Arik Nemtsov923b3522015-07-08 15:41:44 +03007490 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7491 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007492 return -EINVAL;
7493
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007494 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7495 &params.chandef,
7496 wdev->iftype);
7497 if (err < 0)
7498 return err;
7499
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007500 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007501 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007502
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007503 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7504 params.block_tx = true;
7505
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007506 wdev_lock(wdev);
7507 err = rdev_channel_switch(rdev, dev, &params);
7508 wdev_unlock(wdev);
7509
7510 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007511}
7512
Johannes Berg9720bb32011-06-21 09:45:33 +02007513static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7514 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007515 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007516 struct wireless_dev *wdev,
7517 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007518{
Johannes Berg48ab9052009-07-10 18:42:31 +02007519 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007520 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007521 void *hdr;
7522 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007523
7524 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007525
Eric W. Biederman15e47302012-09-07 20:12:54 +00007526 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007527 NL80211_CMD_NEW_SCAN_RESULTS);
7528 if (!hdr)
7529 return -1;
7530
Johannes Berg9720bb32011-06-21 09:45:33 +02007531 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7532
Johannes Berg97990a02013-04-19 01:02:55 +02007533 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7534 goto nla_put_failure;
7535 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007536 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7537 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007538 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7539 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007540 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007541
7542 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7543 if (!bss)
7544 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007545 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007546 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007547 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007548
7549 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007550 /* indicate whether we have probe response data or not */
7551 if (rcu_access_pointer(res->proberesp_ies) &&
7552 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7553 goto fail_unlock_rcu;
7554
7555 /* this pointer prefers to be pointed to probe response data
7556 * but is always valid
7557 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007558 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007559 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007560 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7561 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007562 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007563 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7564 ies->len, ies->data))
7565 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007566 }
Johannes Berg0e227082014-08-12 20:34:30 +02007567
7568 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007569 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007570 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007571 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7572 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007573 goto fail_unlock_rcu;
7574 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7575 ies->len, ies->data))
7576 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007577 }
7578 rcu_read_unlock();
7579
David S. Miller9360ffd2012-03-29 04:41:26 -04007580 if (res->beacon_interval &&
7581 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7582 goto nla_put_failure;
7583 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7584 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007585 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007586 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7587 jiffies_to_msecs(jiffies - intbss->ts)))
7588 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007589
Avraham Stern1d762502016-07-05 17:10:13 +03007590 if (intbss->parent_tsf &&
7591 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7592 intbss->parent_tsf, NL80211_BSS_PAD) ||
7593 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7594 intbss->parent_bssid)))
7595 goto nla_put_failure;
7596
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007597 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007598 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7599 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007600 goto nla_put_failure;
7601
Sunil Dutt0c868482017-12-13 19:51:36 +02007602 if (!nl80211_put_signal(msg, intbss->pub.chains,
7603 intbss->pub.chain_signal,
7604 NL80211_BSS_CHAIN_SIGNAL))
7605 goto nla_put_failure;
7606
Johannes Berg77965c92009-02-18 18:45:06 +01007607 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007608 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007609 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7610 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007611 break;
7612 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007613 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7614 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007615 break;
7616 default:
7617 break;
7618 }
7619
Johannes Berg48ab9052009-07-10 18:42:31 +02007620 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007621 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007622 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007623 if (intbss == wdev->current_bss &&
7624 nla_put_u32(msg, NL80211_BSS_STATUS,
7625 NL80211_BSS_STATUS_ASSOCIATED))
7626 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007627 break;
7628 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007629 if (intbss == wdev->current_bss &&
7630 nla_put_u32(msg, NL80211_BSS_STATUS,
7631 NL80211_BSS_STATUS_IBSS_JOINED))
7632 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007633 break;
7634 default:
7635 break;
7636 }
7637
Johannes Berg2a519312009-02-10 21:25:55 +01007638 nla_nest_end(msg, bss);
7639
Johannes Berg053c0952015-01-16 22:09:00 +01007640 genlmsg_end(msg, hdr);
7641 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007642
Johannes Berg8cef2c92013-02-05 16:54:31 +01007643 fail_unlock_rcu:
7644 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007645 nla_put_failure:
7646 genlmsg_cancel(msg, hdr);
7647 return -EMSGSIZE;
7648}
7649
Johannes Berg97990a02013-04-19 01:02:55 +02007650static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007651{
Johannes Berg48ab9052009-07-10 18:42:31 +02007652 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007653 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007654 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007655 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007656 int err;
7657
Johannes Berg56769e72017-03-15 14:26:04 +01007658 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007659 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg56769e72017-03-15 14:26:04 +01007660 if (err) {
7661 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007662 return err;
Johannes Berg56769e72017-03-15 14:26:04 +01007663 }
Johannes Berg2a519312009-02-10 21:25:55 +01007664
Johannes Berg48ab9052009-07-10 18:42:31 +02007665 wdev_lock(wdev);
7666 spin_lock_bh(&rdev->bss_lock);
7667 cfg80211_bss_expire(rdev);
7668
Johannes Berg9720bb32011-06-21 09:45:33 +02007669 cb->seq = rdev->bss_generation;
7670
Johannes Berg48ab9052009-07-10 18:42:31 +02007671 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007672 if (++idx <= start)
7673 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007674 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007675 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007676 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007677 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007678 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007679 }
7680 }
7681
Johannes Berg48ab9052009-07-10 18:42:31 +02007682 spin_unlock_bh(&rdev->bss_lock);
7683 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007684
Johannes Berg97990a02013-04-19 01:02:55 +02007685 cb->args[2] = idx;
Johannes Berg56769e72017-03-15 14:26:04 +01007686 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007687
Johannes Berg67748892010-10-04 21:14:06 +02007688 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007689}
7690
Eric W. Biederman15e47302012-09-07 20:12:54 +00007691static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007692 int flags, struct net_device *dev,
7693 bool allow_radio_stats,
7694 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007695{
7696 void *hdr;
7697 struct nlattr *infoattr;
7698
Johannes Berg11f78ac2014-11-14 16:43:50 +01007699 /* skip radio stats if userspace didn't request them */
7700 if (!survey->channel && !allow_radio_stats)
7701 return 0;
7702
Eric W. Biederman15e47302012-09-07 20:12:54 +00007703 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007704 NL80211_CMD_NEW_SURVEY_RESULTS);
7705 if (!hdr)
7706 return -ENOMEM;
7707
David S. Miller9360ffd2012-03-29 04:41:26 -04007708 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7709 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007710
7711 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7712 if (!infoattr)
7713 goto nla_put_failure;
7714
Johannes Berg11f78ac2014-11-14 16:43:50 +01007715 if (survey->channel &&
7716 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007717 survey->channel->center_freq))
7718 goto nla_put_failure;
7719
7720 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7721 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7722 goto nla_put_failure;
7723 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7724 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7725 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007726 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007727 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7728 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007729 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007730 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007731 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7732 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007733 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007734 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007735 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7736 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007737 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007738 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007739 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7740 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007742 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007743 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7744 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007745 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007746 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007747 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7748 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007749 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007750
7751 nla_nest_end(msg, infoattr);
7752
Johannes Berg053c0952015-01-16 22:09:00 +01007753 genlmsg_end(msg, hdr);
7754 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007755
7756 nla_put_failure:
7757 genlmsg_cancel(msg, hdr);
7758 return -EMSGSIZE;
7759}
7760
Johannes Berg11f78ac2014-11-14 16:43:50 +01007761static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007762{
7763 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007764 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007765 struct wireless_dev *wdev;
7766 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007767 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007768 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007769
Johannes Berg56769e72017-03-15 14:26:04 +01007770 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007771 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007772 if (res)
Johannes Berg56769e72017-03-15 14:26:04 +01007773 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007774
Johannes Berg11f78ac2014-11-14 16:43:50 +01007775 /* prepare_wdev_dump parsed the attributes */
7776 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7777
Johannes Berg97990a02013-04-19 01:02:55 +02007778 if (!wdev->netdev) {
7779 res = -EINVAL;
7780 goto out_err;
7781 }
7782
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007783 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007784 res = -EOPNOTSUPP;
7785 goto out_err;
7786 }
7787
7788 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007789 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007790 if (res == -ENOENT)
7791 break;
7792 if (res)
7793 goto out_err;
7794
Johannes Berg11f78ac2014-11-14 16:43:50 +01007795 /* don't send disabled channels, but do send non-channel data */
7796 if (survey.channel &&
7797 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007798 survey_idx++;
7799 continue;
7800 }
7801
Holger Schurig61fa7132009-11-11 12:25:40 +01007802 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007803 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007804 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007805 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007806 goto out;
7807 survey_idx++;
7808 }
7809
7810 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007811 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007812 res = skb->len;
7813 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01007814 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007815 return res;
7816}
7817
Samuel Ortizb23aa672009-07-01 21:26:54 +02007818static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7819{
7820 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7821 NL80211_WPA_VERSION_2));
7822}
7823
Jouni Malinen636a5d32009-03-19 13:39:22 +02007824static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7825{
Johannes Berg4c476992010-10-04 21:36:35 +02007826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7827 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007828 struct ieee80211_channel *chan;
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007829 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7830 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007831 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007832 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007833 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007834
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007835 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7836 return -EINVAL;
7837
7838 if (!info->attrs[NL80211_ATTR_MAC])
7839 return -EINVAL;
7840
Jouni Malinen17780922009-03-27 20:52:47 +02007841 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7842 return -EINVAL;
7843
Johannes Berg19957bb2009-07-02 17:20:43 +02007844 if (!info->attrs[NL80211_ATTR_SSID])
7845 return -EINVAL;
7846
7847 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7848 return -EINVAL;
7849
Johannes Bergfffd0932009-07-08 14:22:54 +02007850 err = nl80211_parse_key(info, &key);
7851 if (err)
7852 return err;
7853
7854 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007855 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7856 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007857 if (!key.p.key || !key.p.key_len)
7858 return -EINVAL;
7859 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7860 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7861 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7862 key.p.key_len != WLAN_KEY_LEN_WEP104))
7863 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007864 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007865 return -EINVAL;
7866 } else {
7867 key.p.key_len = 0;
7868 key.p.key = NULL;
7869 }
7870
Johannes Bergafea0b72010-08-10 09:46:42 +02007871 if (key.idx >= 0) {
7872 int i;
7873 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007874
Johannes Bergafea0b72010-08-10 09:46:42 +02007875 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7876 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7877 ok = true;
7878 break;
7879 }
7880 }
Johannes Berg4c476992010-10-04 21:36:35 +02007881 if (!ok)
7882 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007883 }
7884
Johannes Berg4c476992010-10-04 21:36:35 +02007885 if (!rdev->ops->auth)
7886 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007887
Johannes Berg074ac8d2010-09-16 14:58:22 +02007888 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007889 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7890 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007891
Johannes Berg19957bb2009-07-02 17:20:43 +02007892 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007893 chan = nl80211_get_valid_chan(&rdev->wiphy,
7894 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7895 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007896 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007897
Johannes Berg19957bb2009-07-02 17:20:43 +02007898 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7899 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7900
7901 if (info->attrs[NL80211_ATTR_IE]) {
7902 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7903 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7904 }
7905
7906 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007907 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007908 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007909
Jouni Malinene20f90f2016-10-27 00:42:02 +03007910 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7911 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7912 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7913 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007914 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007915 return -EINVAL;
7916
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007917 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinene20f90f2016-10-27 00:42:02 +03007918 if (auth_type != NL80211_AUTHTYPE_SAE &&
7919 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7920 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7921 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007922 return -EINVAL;
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007923 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7924 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007925 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007926 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007927 return -EINVAL;
7928 }
7929
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007930 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7931
Johannes Berg95de8172012-01-20 13:55:25 +01007932 /*
7933 * Since we no longer track auth state, ignore
7934 * requests to only change local state.
7935 */
7936 if (local_state_change)
7937 return 0;
7938
Johannes Berg91bf9b22013-05-15 17:44:01 +02007939 wdev_lock(dev->ieee80211_ptr);
7940 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7941 ssid, ssid_len, ie, ie_len,
7942 key.p.key, key.p.key_len, key.idx,
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007943 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007944 wdev_unlock(dev->ieee80211_ptr);
7945 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007946}
7947
Johannes Bergc0692b82010-08-27 14:26:53 +03007948static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7949 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007950 struct cfg80211_crypto_settings *settings,
7951 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007952{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007953 memset(settings, 0, sizeof(*settings));
7954
Samuel Ortizb23aa672009-07-01 21:26:54 +02007955 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7956
Johannes Bergc0692b82010-08-27 14:26:53 +03007957 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7958 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007959
Johannes Bergc0692b82010-08-27 14:26:53 +03007960 proto = nla_get_u16(
7961 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7962 settings->control_port_ethertype = cpu_to_be16(proto);
7963 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7964 proto != ETH_P_PAE)
7965 return -EINVAL;
7966 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7967 settings->control_port_no_encrypt = true;
7968 } else
7969 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7970
Samuel Ortizb23aa672009-07-01 21:26:54 +02007971 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7972 void *data;
7973 int len, i;
7974
7975 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7976 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7977 settings->n_ciphers_pairwise = len / sizeof(u32);
7978
7979 if (len % sizeof(u32))
7980 return -EINVAL;
7981
Johannes Berg3dc27d22009-07-02 21:36:37 +02007982 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007983 return -EINVAL;
7984
7985 memcpy(settings->ciphers_pairwise, data, len);
7986
7987 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007988 if (!cfg80211_supported_cipher_suite(
7989 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007990 settings->ciphers_pairwise[i]))
7991 return -EINVAL;
7992 }
7993
7994 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7995 settings->cipher_group =
7996 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007997 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7998 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007999 return -EINVAL;
8000 }
8001
8002 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8003 settings->wpa_versions =
8004 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8005 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8006 return -EINVAL;
8007 }
8008
8009 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8010 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008011 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008012
8013 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8014 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8015 settings->n_akm_suites = len / sizeof(u32);
8016
8017 if (len % sizeof(u32))
8018 return -EINVAL;
8019
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008020 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8021 return -EINVAL;
8022
Samuel Ortizb23aa672009-07-01 21:26:54 +02008023 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008024 }
8025
8026 return 0;
8027}
8028
Jouni Malinen636a5d32009-03-19 13:39:22 +02008029static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8030{
Johannes Berg4c476992010-10-04 21:36:35 +02008031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8032 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008033 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008034 struct cfg80211_assoc_request req = {};
8035 const u8 *bssid, *ssid;
8036 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008037
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008038 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8039 return -EINVAL;
8040
8041 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008042 !info->attrs[NL80211_ATTR_SSID] ||
8043 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008044 return -EINVAL;
8045
Johannes Berg4c476992010-10-04 21:36:35 +02008046 if (!rdev->ops->assoc)
8047 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008048
Johannes Berg074ac8d2010-09-16 14:58:22 +02008049 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008050 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8051 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008052
Johannes Berg19957bb2009-07-02 17:20:43 +02008053 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008054
Jouni Malinen664834d2014-01-15 00:01:44 +02008055 chan = nl80211_get_valid_chan(&rdev->wiphy,
8056 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8057 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008058 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008059
Johannes Berg19957bb2009-07-02 17:20:43 +02008060 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8061 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008062
8063 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008064 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8065 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008066 }
8067
Jouni Malinendc6382c2009-05-06 22:09:37 +03008068 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008069 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03008070 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008071 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008072 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008073 else if (mfp != NL80211_MFP_NO)
8074 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03008075 }
8076
Johannes Berg3e5d7642009-07-07 14:37:26 +02008077 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008078 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008079
Ben Greear7e7c8922011-11-18 11:31:59 -08008080 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008081 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008082
8083 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008084 memcpy(&req.ht_capa_mask,
8085 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8086 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008087
8088 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008089 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008090 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008091 memcpy(&req.ht_capa,
8092 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8093 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008094 }
8095
Johannes Bergee2aca32013-02-21 17:36:01 +01008096 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008097 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008098
8099 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008100 memcpy(&req.vht_capa_mask,
8101 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8102 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008103
8104 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008105 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008106 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008107 memcpy(&req.vht_capa,
8108 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8109 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008110 }
8111
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008112 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008113 if (!((rdev->wiphy.features &
8114 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8115 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8116 !wiphy_ext_feature_isset(&rdev->wiphy,
8117 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008118 return -EINVAL;
8119 req.flags |= ASSOC_REQ_USE_RRM;
8120 }
8121
Jouni Malinenc9a63622016-10-27 00:42:03 +03008122 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8123 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8124 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8125 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8126 return -EINVAL;
8127 req.fils_nonces =
8128 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8129 }
8130
Johannes Bergf62fab72013-02-21 20:09:09 +01008131 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008132 if (!err) {
8133 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308134
Johannes Bergf62fab72013-02-21 20:09:09 +01008135 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8136 ssid, ssid_len, &req);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308137
8138 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8139 dev->ieee80211_ptr->conn_owner_nlportid =
8140 info->snd_portid;
8141 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8142 bssid, ETH_ALEN);
8143 }
8144
Johannes Berg91bf9b22013-05-15 17:44:01 +02008145 wdev_unlock(dev->ieee80211_ptr);
8146 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008147
Jouni Malinen636a5d32009-03-19 13:39:22 +02008148 return err;
8149}
8150
8151static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8152{
Johannes Berg4c476992010-10-04 21:36:35 +02008153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8154 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008155 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008156 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008157 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008158 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008159
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008160 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8161 return -EINVAL;
8162
8163 if (!info->attrs[NL80211_ATTR_MAC])
8164 return -EINVAL;
8165
8166 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8167 return -EINVAL;
8168
Johannes Berg4c476992010-10-04 21:36:35 +02008169 if (!rdev->ops->deauth)
8170 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008171
Johannes Berg074ac8d2010-09-16 14:58:22 +02008172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008173 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8174 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008175
Johannes Berg19957bb2009-07-02 17:20:43 +02008176 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008177
Johannes Berg19957bb2009-07-02 17:20:43 +02008178 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8179 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008180 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008181 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008182 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008183
8184 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008185 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8186 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008187 }
8188
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008189 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8190
Johannes Berg91bf9b22013-05-15 17:44:01 +02008191 wdev_lock(dev->ieee80211_ptr);
8192 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8193 local_state_change);
8194 wdev_unlock(dev->ieee80211_ptr);
8195 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008196}
8197
8198static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8199{
Johannes Berg4c476992010-10-04 21:36:35 +02008200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8201 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008202 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008203 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008204 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008205 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008206
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008207 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8208 return -EINVAL;
8209
8210 if (!info->attrs[NL80211_ATTR_MAC])
8211 return -EINVAL;
8212
8213 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8214 return -EINVAL;
8215
Johannes Berg4c476992010-10-04 21:36:35 +02008216 if (!rdev->ops->disassoc)
8217 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008218
Johannes Berg074ac8d2010-09-16 14:58:22 +02008219 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008220 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8221 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008222
Johannes Berg19957bb2009-07-02 17:20:43 +02008223 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008224
Johannes Berg19957bb2009-07-02 17:20:43 +02008225 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8226 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008227 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008228 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008229 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008230
8231 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008232 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8233 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008234 }
8235
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008236 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8237
Johannes Berg91bf9b22013-05-15 17:44:01 +02008238 wdev_lock(dev->ieee80211_ptr);
8239 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8240 local_state_change);
8241 wdev_unlock(dev->ieee80211_ptr);
8242 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008243}
8244
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008245static bool
8246nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008247 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008248 int rateval)
8249{
8250 struct wiphy *wiphy = &rdev->wiphy;
8251 bool found = false;
8252 int band, i;
8253
Johannes Berg57fbcce2016-04-12 15:56:15 +02008254 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008255 struct ieee80211_supported_band *sband;
8256
8257 sband = wiphy->bands[band];
8258 if (!sband)
8259 continue;
8260
8261 for (i = 0; i < sband->n_bitrates; i++) {
8262 if (sband->bitrates[i].bitrate == rateval) {
8263 mcast_rate[band] = i + 1;
8264 found = true;
8265 break;
8266 }
8267 }
8268 }
8269
8270 return found;
8271}
8272
Johannes Berg04a773a2009-04-19 21:24:32 +02008273static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8274{
Johannes Berg4c476992010-10-04 21:36:35 +02008275 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8276 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008277 struct cfg80211_ibss_params ibss;
8278 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008279 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008280 int err;
8281
Johannes Berg8e30bc52009-04-22 17:45:38 +02008282 memset(&ibss, 0, sizeof(ibss));
8283
Johannes Berg04a773a2009-04-19 21:24:32 +02008284 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8285 return -EINVAL;
8286
Johannes Berg683b6d32012-11-08 21:25:48 +01008287 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008288 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8289 return -EINVAL;
8290
Johannes Berg8e30bc52009-04-22 17:45:38 +02008291 ibss.beacon_interval = 100;
8292
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308293 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008294 ibss.beacon_interval =
8295 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308296
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05308297 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8298 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308299 if (err)
8300 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008301
Johannes Berg4c476992010-10-04 21:36:35 +02008302 if (!rdev->ops->join_ibss)
8303 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008304
Johannes Berg4c476992010-10-04 21:36:35 +02008305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8306 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008307
Johannes Berg79c97e92009-07-07 03:56:12 +02008308 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008309
Johannes Berg39193492011-09-16 13:45:25 +02008310 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008311 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008312
8313 if (!is_valid_ether_addr(ibss.bssid))
8314 return -EINVAL;
8315 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008316 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8317 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8318
8319 if (info->attrs[NL80211_ATTR_IE]) {
8320 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8321 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8322 }
8323
Johannes Berg683b6d32012-11-08 21:25:48 +01008324 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8325 if (err)
8326 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008327
Ilan Peer174e0cd2014-02-23 09:13:01 +02008328 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8329 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008330 return -EINVAL;
8331
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008332 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008333 case NL80211_CHAN_WIDTH_5:
8334 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008335 case NL80211_CHAN_WIDTH_20_NOHT:
8336 break;
8337 case NL80211_CHAN_WIDTH_20:
8338 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008339 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8340 return -EINVAL;
8341 break;
8342 case NL80211_CHAN_WIDTH_80:
8343 case NL80211_CHAN_WIDTH_80P80:
8344 case NL80211_CHAN_WIDTH_160:
8345 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8346 return -EINVAL;
8347 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8348 NL80211_EXT_FEATURE_VHT_IBSS))
8349 return -EINVAL;
8350 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008351 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008352 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008353 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008354
Johannes Berg04a773a2009-04-19 21:24:32 +02008355 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008356 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008357
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008358 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8359 u8 *rates =
8360 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8361 int n_rates =
8362 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8363 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008364 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008365
Johannes Berg34850ab2011-07-18 18:08:35 +02008366 err = ieee80211_get_ratemask(sband, rates, n_rates,
8367 &ibss.basic_rates);
8368 if (err)
8369 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008370 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008371
Simon Wunderlich803768f2013-06-28 10:39:58 +02008372 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8373 memcpy(&ibss.ht_capa_mask,
8374 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8375 sizeof(ibss.ht_capa_mask));
8376
8377 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8378 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8379 return -EINVAL;
8380 memcpy(&ibss.ht_capa,
8381 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8382 sizeof(ibss.ht_capa));
8383 }
8384
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008385 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8386 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8387 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8388 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008389
Johannes Berg4c476992010-10-04 21:36:35 +02008390 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308391 bool no_ht = false;
8392
Johannes Berg4c476992010-10-04 21:36:35 +02008393 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308394 info->attrs[NL80211_ATTR_KEYS],
8395 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008396 if (IS_ERR(connkeys))
8397 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308398
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008399 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8400 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008401 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308402 return -EINVAL;
8403 }
Johannes Berg4c476992010-10-04 21:36:35 +02008404 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008405
Antonio Quartulli267335d2012-01-31 20:25:47 +01008406 ibss.control_port =
8407 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8408
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008409 ibss.userspace_handles_dfs =
8410 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8411
Johannes Berg4c476992010-10-04 21:36:35 +02008412 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008413 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008414 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008415 return err;
8416}
8417
8418static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8419{
Johannes Berg4c476992010-10-04 21:36:35 +02008420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8421 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008422
Johannes Berg4c476992010-10-04 21:36:35 +02008423 if (!rdev->ops->leave_ibss)
8424 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008425
Johannes Berg4c476992010-10-04 21:36:35 +02008426 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8427 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008428
Johannes Berg4c476992010-10-04 21:36:35 +02008429 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008430}
8431
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008432static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8433{
8434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8435 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008436 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008437 u32 nla_rate;
8438 int err;
8439
8440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008441 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8442 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008443 return -EOPNOTSUPP;
8444
8445 if (!rdev->ops->set_mcast_rate)
8446 return -EOPNOTSUPP;
8447
8448 memset(mcast_rate, 0, sizeof(mcast_rate));
8449
8450 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8451 return -EINVAL;
8452
8453 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8454 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8455 return -EINVAL;
8456
Ilan Peera1056b12015-10-22 22:27:46 +03008457 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008458
8459 return err;
8460}
8461
Johannes Bergad7e7182013-11-13 13:37:47 +01008462static struct sk_buff *
8463__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008464 struct wireless_dev *wdev, int approxlen,
8465 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008466 enum nl80211_attrs attr,
8467 const struct nl80211_vendor_cmd_info *info,
8468 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008469{
8470 struct sk_buff *skb;
8471 void *hdr;
8472 struct nlattr *data;
8473
8474 skb = nlmsg_new(approxlen + 100, gfp);
8475 if (!skb)
8476 return NULL;
8477
8478 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8479 if (!hdr) {
8480 kfree_skb(skb);
8481 return NULL;
8482 }
8483
8484 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8485 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008486
8487 if (info) {
8488 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8489 info->vendor_id))
8490 goto nla_put_failure;
8491 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8492 info->subcmd))
8493 goto nla_put_failure;
8494 }
8495
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008496 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008497 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8498 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008499 goto nla_put_failure;
8500 if (wdev->netdev &&
8501 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8502 wdev->netdev->ifindex))
8503 goto nla_put_failure;
8504 }
8505
Johannes Bergad7e7182013-11-13 13:37:47 +01008506 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008507 if (!data)
8508 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008509
8510 ((void **)skb->cb)[0] = rdev;
8511 ((void **)skb->cb)[1] = hdr;
8512 ((void **)skb->cb)[2] = data;
8513
8514 return skb;
8515
8516 nla_put_failure:
8517 kfree_skb(skb);
8518 return NULL;
8519}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008520
Johannes Berge03ad6e2014-01-01 17:22:30 +01008521struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008522 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008523 enum nl80211_commands cmd,
8524 enum nl80211_attrs attr,
8525 int vendor_event_idx,
8526 int approxlen, gfp_t gfp)
8527{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008529 const struct nl80211_vendor_cmd_info *info;
8530
8531 switch (cmd) {
8532 case NL80211_CMD_TESTMODE:
8533 if (WARN_ON(vendor_event_idx != -1))
8534 return NULL;
8535 info = NULL;
8536 break;
8537 case NL80211_CMD_VENDOR:
8538 if (WARN_ON(vendor_event_idx < 0 ||
8539 vendor_event_idx >= wiphy->n_vendor_events))
8540 return NULL;
8541 info = &wiphy->vendor_events[vendor_event_idx];
8542 break;
8543 default:
8544 WARN_ON(1);
8545 return NULL;
8546 }
8547
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008548 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008549 cmd, attr, info, gfp);
8550}
8551EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8552
8553void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8554{
8555 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8556 void *hdr = ((void **)skb->cb)[1];
8557 struct nlattr *data = ((void **)skb->cb)[2];
8558 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8559
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008560 /* clear CB data for netlink core to own from now on */
8561 memset(skb->cb, 0, sizeof(skb->cb));
8562
Johannes Berge03ad6e2014-01-01 17:22:30 +01008563 nla_nest_end(skb, data);
8564 genlmsg_end(skb, hdr);
8565
8566 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8567 mcgrp = NL80211_MCGRP_VENDOR;
8568
8569 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8570 mcgrp, gfp);
8571}
8572EXPORT_SYMBOL(__cfg80211_send_event_skb);
8573
Johannes Bergaff89a92009-07-01 21:26:51 +02008574#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008575static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8576{
Johannes Berg4c476992010-10-04 21:36:35 +02008577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008578 struct wireless_dev *wdev =
8579 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008580 int err;
8581
David Spinadelfc73f112013-07-31 18:04:15 +03008582 if (!rdev->ops->testmode_cmd)
8583 return -EOPNOTSUPP;
8584
8585 if (IS_ERR(wdev)) {
8586 err = PTR_ERR(wdev);
8587 if (err != -EINVAL)
8588 return err;
8589 wdev = NULL;
8590 } else if (wdev->wiphy != &rdev->wiphy) {
8591 return -EINVAL;
8592 }
8593
Johannes Bergaff89a92009-07-01 21:26:51 +02008594 if (!info->attrs[NL80211_ATTR_TESTDATA])
8595 return -EINVAL;
8596
Johannes Bergad7e7182013-11-13 13:37:47 +01008597 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008598 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008599 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8600 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008601 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008602
Johannes Bergaff89a92009-07-01 21:26:51 +02008603 return err;
8604}
8605
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008606static int nl80211_testmode_dump(struct sk_buff *skb,
8607 struct netlink_callback *cb)
8608{
Johannes Berg00918d32011-12-13 17:22:05 +01008609 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008610 int err;
8611 long phy_idx;
8612 void *data = NULL;
8613 int data_len = 0;
8614
Johannes Berg5fe231e2013-05-08 21:45:15 +02008615 rtnl_lock();
8616
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008617 if (cb->args[0]) {
8618 /*
8619 * 0 is a valid index, but not valid for args[0],
8620 * so we need to offset by 1.
8621 */
8622 phy_idx = cb->args[0] - 1;
8623 } else {
8624 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8625 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8626 nl80211_policy);
8627 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008628 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008629
Johannes Berg2bd7e352012-06-15 14:23:16 +02008630 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8631 nl80211_fam.attrbuf);
8632 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008633 err = PTR_ERR(rdev);
8634 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008635 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008636 phy_idx = rdev->wiphy_idx;
8637 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008638
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008639 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8640 cb->args[1] =
8641 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8642 }
8643
8644 if (cb->args[1]) {
8645 data = nla_data((void *)cb->args[1]);
8646 data_len = nla_len((void *)cb->args[1]);
8647 }
8648
Johannes Berg00918d32011-12-13 17:22:05 +01008649 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8650 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008651 err = -ENOENT;
8652 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008653 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008654
Johannes Berg00918d32011-12-13 17:22:05 +01008655 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008656 err = -EOPNOTSUPP;
8657 goto out_err;
8658 }
8659
8660 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008661 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008662 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8663 NL80211_CMD_TESTMODE);
8664 struct nlattr *tmdata;
8665
Dan Carpentercb35fba2013-08-14 14:50:01 +03008666 if (!hdr)
8667 break;
8668
David S. Miller9360ffd2012-03-29 04:41:26 -04008669 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008670 genlmsg_cancel(skb, hdr);
8671 break;
8672 }
8673
8674 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8675 if (!tmdata) {
8676 genlmsg_cancel(skb, hdr);
8677 break;
8678 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008679 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008680 nla_nest_end(skb, tmdata);
8681
8682 if (err == -ENOBUFS || err == -ENOENT) {
8683 genlmsg_cancel(skb, hdr);
8684 break;
8685 } else if (err) {
8686 genlmsg_cancel(skb, hdr);
8687 goto out_err;
8688 }
8689
8690 genlmsg_end(skb, hdr);
8691 }
8692
8693 err = skb->len;
8694 /* see above */
8695 cb->args[0] = phy_idx + 1;
8696 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008697 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008698 return err;
8699}
Johannes Bergaff89a92009-07-01 21:26:51 +02008700#endif
8701
Samuel Ortizb23aa672009-07-01 21:26:54 +02008702static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8703{
Johannes Berg4c476992010-10-04 21:36:35 +02008704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8705 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008706 struct cfg80211_connect_params connect;
8707 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008708 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008709 int err;
8710
8711 memset(&connect, 0, sizeof(connect));
8712
8713 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8714 return -EINVAL;
8715
8716 if (!info->attrs[NL80211_ATTR_SSID] ||
8717 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8718 return -EINVAL;
8719
8720 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8721 connect.auth_type =
8722 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008723 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8724 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008725 return -EINVAL;
8726 } else
8727 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8728
8729 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8730
Johannes Bergc0692b82010-08-27 14:26:53 +03008731 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008732 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008733 if (err)
8734 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008735
Johannes Berg074ac8d2010-09-16 14:58:22 +02008736 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008737 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8738 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008739
Johannes Berg79c97e92009-07-07 03:56:12 +02008740 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008741
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308742 connect.bg_scan_period = -1;
8743 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8744 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8745 connect.bg_scan_period =
8746 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8747 }
8748
Samuel Ortizb23aa672009-07-01 21:26:54 +02008749 if (info->attrs[NL80211_ATTR_MAC])
8750 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008751 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8752 connect.bssid_hint =
8753 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008754 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8755 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8756
8757 if (info->attrs[NL80211_ATTR_IE]) {
8758 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8759 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8760 }
8761
Jouni Malinencee00a92013-01-15 17:15:57 +02008762 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8763 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8764 if (connect.mfp != NL80211_MFP_REQUIRED &&
8765 connect.mfp != NL80211_MFP_NO)
8766 return -EINVAL;
8767 } else {
8768 connect.mfp = NL80211_MFP_NO;
8769 }
8770
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008771 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8772 connect.prev_bssid =
8773 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8774
Samuel Ortizb23aa672009-07-01 21:26:54 +02008775 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008776 connect.channel = nl80211_get_valid_chan(
8777 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8778 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008779 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008780 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008781 connect.channel_hint = nl80211_get_valid_chan(
8782 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8783 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008784 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008785 }
8786
Johannes Bergfffd0932009-07-08 14:22:54 +02008787 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8788 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308789 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008790 if (IS_ERR(connkeys))
8791 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008792 }
8793
Ben Greear7e7c8922011-11-18 11:31:59 -08008794 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8795 connect.flags |= ASSOC_REQ_DISABLE_HT;
8796
8797 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8798 memcpy(&connect.ht_capa_mask,
8799 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8800 sizeof(connect.ht_capa_mask));
8801
8802 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008803 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008804 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008805 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008806 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008807 memcpy(&connect.ht_capa,
8808 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8809 sizeof(connect.ht_capa));
8810 }
8811
Johannes Bergee2aca32013-02-21 17:36:01 +01008812 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8813 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8814
8815 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8816 memcpy(&connect.vht_capa_mask,
8817 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8818 sizeof(connect.vht_capa_mask));
8819
8820 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8821 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008822 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008823 return -EINVAL;
8824 }
8825 memcpy(&connect.vht_capa,
8826 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8827 sizeof(connect.vht_capa));
8828 }
8829
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008830 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008831 if (!((rdev->wiphy.features &
8832 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8833 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8834 !wiphy_ext_feature_isset(&rdev->wiphy,
8835 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008836 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008837 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008838 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008839 connect.flags |= ASSOC_REQ_USE_RRM;
8840 }
8841
Lior David34d50512016-01-28 10:58:25 +02008842 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008843 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008844 kzfree(connkeys);
8845 return -EOPNOTSUPP;
8846 }
8847
Arend van Spriel38de03d2016-03-02 20:37:18 +01008848 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8849 /* bss selection makes no sense if bssid is set */
8850 if (connect.bssid) {
8851 kzfree(connkeys);
8852 return -EINVAL;
8853 }
8854
8855 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8856 wiphy, &connect.bss_select);
8857 if (err) {
8858 kzfree(connkeys);
8859 return err;
8860 }
8861 }
8862
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03008863 if (wiphy_ext_feature_isset(&rdev->wiphy,
8864 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
8865 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
8866 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
8867 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
8868 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8869 connect.fils_erp_username =
8870 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8871 connect.fils_erp_username_len =
8872 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8873 connect.fils_erp_realm =
8874 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8875 connect.fils_erp_realm_len =
8876 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8877 connect.fils_erp_next_seq_num =
8878 nla_get_u16(
8879 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
8880 connect.fils_erp_rrk =
8881 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8882 connect.fils_erp_rrk_len =
8883 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8884 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
8885 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
8886 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
8887 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8888 kzfree(connkeys);
8889 return -EINVAL;
8890 }
8891
Srinivas Dasarid041a1a2018-02-07 18:32:17 +05308892 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
8893 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8894 return -EINVAL;
8895 }
8896 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
8897 }
8898
Johannes Berg83739b02013-05-15 17:44:01 +02008899 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308900
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008901 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8902 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02008903 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008904 kzfree(connkeys);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308905
8906 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8907 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8908 if (connect.bssid)
8909 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8910 connect.bssid, ETH_ALEN);
8911 else
8912 memset(dev->ieee80211_ptr->disconnect_bssid,
8913 0, ETH_ALEN);
8914 }
8915
8916 wdev_unlock(dev->ieee80211_ptr);
8917
Samuel Ortizb23aa672009-07-01 21:26:54 +02008918 return err;
8919}
8920
vamsi krishna30da4e82016-10-27 16:51:11 +03008921static int nl80211_update_connect_params(struct sk_buff *skb,
8922 struct genl_info *info)
8923{
8924 struct cfg80211_connect_params connect = {};
8925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8926 struct net_device *dev = info->user_ptr[1];
8927 struct wireless_dev *wdev = dev->ieee80211_ptr;
8928 u32 changed = 0;
8929 int ret;
8930
8931 if (!rdev->ops->update_connect_params)
8932 return -EOPNOTSUPP;
8933
8934 if (info->attrs[NL80211_ATTR_IE]) {
8935 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8936 return -EINVAL;
8937 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8938 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8939 changed |= UPDATE_ASSOC_IES;
8940 }
8941
Vidyullatha Kanchanapally5f5a26b2017-08-02 16:31:40 +05308942 if (wiphy_ext_feature_isset(&rdev->wiphy,
8943 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
8944 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
8945 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
8946 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
8947 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8948 connect.fils_erp_username =
8949 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8950 connect.fils_erp_username_len =
8951 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8952 connect.fils_erp_realm =
8953 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8954 connect.fils_erp_realm_len =
8955 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8956 connect.fils_erp_next_seq_num =
8957 nla_get_u16(
8958 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
8959 connect.fils_erp_rrk =
8960 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8961 connect.fils_erp_rrk_len =
8962 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8963 changed |= UPDATE_FILS_ERP_INFO;
8964 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
8965 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
8966 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
8967 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8968 return -EINVAL;
8969 }
8970
8971 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8972 u32 auth_type =
8973 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
8974 if (!nl80211_valid_auth_type(rdev, auth_type,
8975 NL80211_CMD_CONNECT))
8976 return -EINVAL;
8977 connect.auth_type = auth_type;
8978 changed |= UPDATE_AUTH_TYPE;
8979 }
8980
vamsi krishna30da4e82016-10-27 16:51:11 +03008981 wdev_lock(dev->ieee80211_ptr);
8982 if (!wdev->current_bss)
8983 ret = -ENOLINK;
8984 else
8985 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
8986 wdev_unlock(dev->ieee80211_ptr);
8987
8988 return ret;
8989}
8990
Samuel Ortizb23aa672009-07-01 21:26:54 +02008991static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8992{
Johannes Berg4c476992010-10-04 21:36:35 +02008993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8994 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008995 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008996 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008997
8998 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8999 reason = WLAN_REASON_DEAUTH_LEAVING;
9000 else
9001 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9002
9003 if (reason == 0)
9004 return -EINVAL;
9005
Johannes Berg074ac8d2010-09-16 14:58:22 +02009006 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009007 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9008 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009009
Johannes Berg83739b02013-05-15 17:44:01 +02009010 wdev_lock(dev->ieee80211_ptr);
9011 ret = cfg80211_disconnect(rdev, dev, reason, true);
9012 wdev_unlock(dev->ieee80211_ptr);
9013 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009014}
9015
Johannes Berg463d0182009-07-14 00:33:35 +02009016static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9017{
Johannes Berg4c476992010-10-04 21:36:35 +02009018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009019 struct net *net;
9020 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009021
Vadim Kochan4b681c82015-01-12 16:34:05 +02009022 if (info->attrs[NL80211_ATTR_PID]) {
9023 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9024
9025 net = get_net_ns_by_pid(pid);
9026 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9027 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9028
9029 net = get_net_ns_by_fd(fd);
9030 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009031 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009032 }
Johannes Berg463d0182009-07-14 00:33:35 +02009033
Johannes Berg4c476992010-10-04 21:36:35 +02009034 if (IS_ERR(net))
9035 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009036
9037 err = 0;
9038
9039 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009040 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9041 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009042
Johannes Berg463d0182009-07-14 00:33:35 +02009043 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009044 return err;
9045}
9046
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009047static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9048{
Johannes Berg4c476992010-10-04 21:36:35 +02009049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009050 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9051 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009052 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009053 struct cfg80211_pmksa pmksa;
9054
9055 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9056
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009057 if (!info->attrs[NL80211_ATTR_PMKID])
9058 return -EINVAL;
9059
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009060 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03009061
9062 if (info->attrs[NL80211_ATTR_MAC]) {
9063 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9064 } else if (info->attrs[NL80211_ATTR_SSID] &&
9065 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9066 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9067 info->attrs[NL80211_ATTR_PMK])) {
9068 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9069 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9070 pmksa.cache_id =
9071 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9072 } else {
9073 return -EINVAL;
9074 }
9075 if (info->attrs[NL80211_ATTR_PMK]) {
9076 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9077 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9078 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009079
Johannes Berg074ac8d2010-09-16 14:58:22 +02009080 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009081 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9082 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009083
9084 switch (info->genlhdr->cmd) {
9085 case NL80211_CMD_SET_PMKSA:
9086 rdev_ops = rdev->ops->set_pmksa;
9087 break;
9088 case NL80211_CMD_DEL_PMKSA:
9089 rdev_ops = rdev->ops->del_pmksa;
9090 break;
9091 default:
9092 WARN_ON(1);
9093 break;
9094 }
9095
Johannes Berg4c476992010-10-04 21:36:35 +02009096 if (!rdev_ops)
9097 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009098
Johannes Berg4c476992010-10-04 21:36:35 +02009099 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009100}
9101
9102static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9103{
Johannes Berg4c476992010-10-04 21:36:35 +02009104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9105 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009106
Johannes Berg074ac8d2010-09-16 14:58:22 +02009107 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009108 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9109 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009110
Johannes Berg4c476992010-10-04 21:36:35 +02009111 if (!rdev->ops->flush_pmksa)
9112 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009113
Hila Gonene35e4d22012-06-27 17:19:42 +03009114 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009115}
9116
Arik Nemtsov109086c2011-09-28 14:12:50 +03009117static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9118{
9119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9120 struct net_device *dev = info->user_ptr[1];
9121 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309122 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009123 u16 status_code;
9124 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009125 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009126
9127 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9128 !rdev->ops->tdls_mgmt)
9129 return -EOPNOTSUPP;
9130
9131 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9132 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9133 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9134 !info->attrs[NL80211_ATTR_IE] ||
9135 !info->attrs[NL80211_ATTR_MAC])
9136 return -EINVAL;
9137
9138 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9139 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9140 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9141 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009142 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309143 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9144 peer_capability =
9145 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009146
Hila Gonene35e4d22012-06-27 17:19:42 +03009147 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309148 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009149 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009150 nla_data(info->attrs[NL80211_ATTR_IE]),
9151 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009152}
9153
9154static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9155{
9156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9157 struct net_device *dev = info->user_ptr[1];
9158 enum nl80211_tdls_operation operation;
9159 u8 *peer;
9160
9161 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9162 !rdev->ops->tdls_oper)
9163 return -EOPNOTSUPP;
9164
9165 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9166 !info->attrs[NL80211_ATTR_MAC])
9167 return -EINVAL;
9168
9169 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9170 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9171
Hila Gonene35e4d22012-06-27 17:19:42 +03009172 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009173}
9174
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009175static int nl80211_remain_on_channel(struct sk_buff *skb,
9176 struct genl_info *info)
9177{
Johannes Berg4c476992010-10-04 21:36:35 +02009178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009179 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009180 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009181 struct sk_buff *msg;
9182 void *hdr;
9183 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009184 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009185 int err;
9186
9187 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9188 !info->attrs[NL80211_ATTR_DURATION])
9189 return -EINVAL;
9190
9191 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9192
Johannes Berg7c4ef712011-11-18 15:33:48 +01009193 if (!rdev->ops->remain_on_channel ||
9194 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009195 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009196
Johannes Bergebf348f2012-06-01 12:50:54 +02009197 /*
9198 * We should be on that channel for at least a minimum amount of
9199 * time (10ms) but no longer than the driver supports.
9200 */
9201 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9202 duration > rdev->wiphy.max_remain_on_channel_duration)
9203 return -EINVAL;
9204
Johannes Berg683b6d32012-11-08 21:25:48 +01009205 err = nl80211_parse_chandef(rdev, info, &chandef);
9206 if (err)
9207 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009208
9209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009210 if (!msg)
9211 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009212
Eric W. Biederman15e47302012-09-07 20:12:54 +00009213 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009214 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009215 if (!hdr) {
9216 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009217 goto free_msg;
9218 }
9219
Johannes Berg683b6d32012-11-08 21:25:48 +01009220 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9221 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009222
9223 if (err)
9224 goto free_msg;
9225
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009226 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9227 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009228 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009229
9230 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009231
9232 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009233
9234 nla_put_failure:
9235 err = -ENOBUFS;
9236 free_msg:
9237 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009238 return err;
9239}
9240
9241static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9242 struct genl_info *info)
9243{
Johannes Berg4c476992010-10-04 21:36:35 +02009244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009245 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009246 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009247
9248 if (!info->attrs[NL80211_ATTR_COOKIE])
9249 return -EINVAL;
9250
Johannes Berg4c476992010-10-04 21:36:35 +02009251 if (!rdev->ops->cancel_remain_on_channel)
9252 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009253
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009254 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9255
Hila Gonene35e4d22012-06-27 17:19:42 +03009256 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009257}
9258
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009259static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9260 struct genl_info *info)
9261{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009262 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009264 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309265 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009266
Johannes Berg4c476992010-10-04 21:36:35 +02009267 if (!rdev->ops->set_bitrate_mask)
9268 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009269
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309270 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9271 if (err)
9272 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009273
Hila Gonene35e4d22012-06-27 17:19:42 +03009274 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009275}
9276
Johannes Berg2e161f72010-08-12 15:38:38 +02009277static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009278{
Johannes Berg4c476992010-10-04 21:36:35 +02009279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009280 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009281 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009282
9283 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9284 return -EINVAL;
9285
Johannes Berg2e161f72010-08-12 15:38:38 +02009286 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9287 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009288
Johannes Berg71bbc992012-06-15 15:30:18 +02009289 switch (wdev->iftype) {
9290 case NL80211_IFTYPE_STATION:
9291 case NL80211_IFTYPE_ADHOC:
9292 case NL80211_IFTYPE_P2P_CLIENT:
9293 case NL80211_IFTYPE_AP:
9294 case NL80211_IFTYPE_AP_VLAN:
9295 case NL80211_IFTYPE_MESH_POINT:
9296 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009297 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009298 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009299 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009300 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009301 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009302 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009303
9304 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009305 if (!rdev->ops->mgmt_tx)
9306 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009307
Eric W. Biederman15e47302012-09-07 20:12:54 +00009308 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009309 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9310 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009311}
9312
Johannes Berg2e161f72010-08-12 15:38:38 +02009313static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009314{
Johannes Berg4c476992010-10-04 21:36:35 +02009315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009316 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009317 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009318 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009319 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009320 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009321 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009322 struct cfg80211_mgmt_tx_params params = {
9323 .dont_wait_for_ack =
9324 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9325 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009326
Johannes Berg683b6d32012-11-08 21:25:48 +01009327 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009328 return -EINVAL;
9329
Johannes Berg4c476992010-10-04 21:36:35 +02009330 if (!rdev->ops->mgmt_tx)
9331 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009332
Johannes Berg71bbc992012-06-15 15:30:18 +02009333 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009334 case NL80211_IFTYPE_P2P_DEVICE:
9335 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9336 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009337 case NL80211_IFTYPE_STATION:
9338 case NL80211_IFTYPE_ADHOC:
9339 case NL80211_IFTYPE_P2P_CLIENT:
9340 case NL80211_IFTYPE_AP:
9341 case NL80211_IFTYPE_AP_VLAN:
9342 case NL80211_IFTYPE_MESH_POINT:
9343 case NL80211_IFTYPE_P2P_GO:
9344 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009345 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009346 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009347 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009348 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009349
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009350 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009351 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009352 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009353 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009354
9355 /*
9356 * We should wait on the channel for at least a minimum amount
9357 * of time (10ms) but no longer than the driver supports.
9358 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009359 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9360 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009361 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009362 }
9363
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009364 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009365
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009366 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009367 return -EINVAL;
9368
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009369 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309370
Antonio Quartulliea141b752013-06-11 14:20:03 +02009371 /* get the channel if any has been specified, otherwise pass NULL to
9372 * the driver. The latter will use the current one
9373 */
9374 chandef.chan = NULL;
9375 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9376 err = nl80211_parse_chandef(rdev, info, &chandef);
9377 if (err)
9378 return err;
9379 }
9380
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009381 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009382 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009383
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009384 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9385 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9386
9387 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9388 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9389 int i;
9390
9391 if (len % sizeof(u16))
9392 return -EINVAL;
9393
9394 params.n_csa_offsets = len / sizeof(u16);
9395 params.csa_offsets =
9396 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9397
9398 /* check that all the offsets fit the frame */
9399 for (i = 0; i < params.n_csa_offsets; i++) {
9400 if (params.csa_offsets[i] >= params.len)
9401 return -EINVAL;
9402 }
9403 }
9404
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009405 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9407 if (!msg)
9408 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009409
Eric W. Biederman15e47302012-09-07 20:12:54 +00009410 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009411 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009412 if (!hdr) {
9413 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009414 goto free_msg;
9415 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009416 }
Johannes Berge247bd902011-11-04 11:18:21 +01009417
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009418 params.chan = chandef.chan;
9419 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009420 if (err)
9421 goto free_msg;
9422
Johannes Berge247bd902011-11-04 11:18:21 +01009423 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009424 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9425 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009426 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009427
Johannes Berge247bd902011-11-04 11:18:21 +01009428 genlmsg_end(msg, hdr);
9429 return genlmsg_reply(msg, info);
9430 }
9431
9432 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009433
9434 nla_put_failure:
9435 err = -ENOBUFS;
9436 free_msg:
9437 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009438 return err;
9439}
9440
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009441static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9442{
9443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009444 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009445 u64 cookie;
9446
9447 if (!info->attrs[NL80211_ATTR_COOKIE])
9448 return -EINVAL;
9449
9450 if (!rdev->ops->mgmt_tx_cancel_wait)
9451 return -EOPNOTSUPP;
9452
Johannes Berg71bbc992012-06-15 15:30:18 +02009453 switch (wdev->iftype) {
9454 case NL80211_IFTYPE_STATION:
9455 case NL80211_IFTYPE_ADHOC:
9456 case NL80211_IFTYPE_P2P_CLIENT:
9457 case NL80211_IFTYPE_AP:
9458 case NL80211_IFTYPE_AP_VLAN:
9459 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009460 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009461 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009462 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009463 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009464 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009465 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009466
9467 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9468
Hila Gonene35e4d22012-06-27 17:19:42 +03009469 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009470}
9471
Kalle Valoffb9eb32010-02-17 17:58:10 +02009472static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9473{
Johannes Berg4c476992010-10-04 21:36:35 +02009474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009475 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009476 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009477 u8 ps_state;
9478 bool state;
9479 int err;
9480
Johannes Berg4c476992010-10-04 21:36:35 +02009481 if (!info->attrs[NL80211_ATTR_PS_STATE])
9482 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009483
9484 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9485
Johannes Berg4c476992010-10-04 21:36:35 +02009486 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9487 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009488
9489 wdev = dev->ieee80211_ptr;
9490
Johannes Berg4c476992010-10-04 21:36:35 +02009491 if (!rdev->ops->set_power_mgmt)
9492 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009493
9494 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9495
9496 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009497 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009498
Hila Gonene35e4d22012-06-27 17:19:42 +03009499 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009500 if (!err)
9501 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009502 return err;
9503}
9504
9505static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9506{
Johannes Berg4c476992010-10-04 21:36:35 +02009507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009508 enum nl80211_ps_state ps_state;
9509 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009510 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009511 struct sk_buff *msg;
9512 void *hdr;
9513 int err;
9514
Kalle Valoffb9eb32010-02-17 17:58:10 +02009515 wdev = dev->ieee80211_ptr;
9516
Johannes Berg4c476992010-10-04 21:36:35 +02009517 if (!rdev->ops->set_power_mgmt)
9518 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009519
9520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009521 if (!msg)
9522 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009523
Eric W. Biederman15e47302012-09-07 20:12:54 +00009524 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009525 NL80211_CMD_GET_POWER_SAVE);
9526 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009527 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009528 goto free_msg;
9529 }
9530
9531 if (wdev->ps)
9532 ps_state = NL80211_PS_ENABLED;
9533 else
9534 ps_state = NL80211_PS_DISABLED;
9535
David S. Miller9360ffd2012-03-29 04:41:26 -04009536 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9537 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009538
9539 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009540 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009541
Johannes Berg4c476992010-10-04 21:36:35 +02009542 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009543 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009544 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009545 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009546 return err;
9547}
9548
Johannes Berg94e860f2014-01-20 23:58:15 +01009549static const struct nla_policy
9550nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009551 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9552 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9553 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009554 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9555 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9556 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009557};
9558
Thomas Pedersen84f10702012-07-12 16:17:33 -07009559static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009560 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009561{
9562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009563 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009564 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009565
Johannes Bergd9d8b012012-11-26 12:51:52 +01009566 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009567 return -EINVAL;
9568
Thomas Pedersen84f10702012-07-12 16:17:33 -07009569 if (!rdev->ops->set_cqm_txe_config)
9570 return -EOPNOTSUPP;
9571
9572 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9573 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9574 return -EOPNOTSUPP;
9575
Hila Gonene35e4d22012-06-27 17:19:42 +03009576 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009577}
9578
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009579static int nl80211_set_cqm_rssi(struct genl_info *info,
9580 s32 threshold, u32 hysteresis)
9581{
Johannes Berg4c476992010-10-04 21:36:35 +02009582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009583 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009584 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009585
9586 if (threshold > 0)
9587 return -EINVAL;
9588
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009589 /* disabling - hysteresis should also be zero then */
9590 if (threshold == 0)
9591 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009592
Johannes Berg4c476992010-10-04 21:36:35 +02009593 if (!rdev->ops->set_cqm_rssi_config)
9594 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009595
Johannes Berg074ac8d2010-09-16 14:58:22 +02009596 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009597 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9598 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009599
Hila Gonene35e4d22012-06-27 17:19:42 +03009600 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009601}
9602
9603static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9604{
9605 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9606 struct nlattr *cqm;
9607 int err;
9608
9609 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009610 if (!cqm)
9611 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009612
9613 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9614 nl80211_attr_cqm_policy);
9615 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009616 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009617
9618 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9619 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009620 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9621 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009622
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009623 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9624 }
9625
9626 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9627 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9628 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9629 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9630 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9631 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9632
9633 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9634 }
9635
9636 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009637}
9638
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009639static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9640{
9641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9642 struct net_device *dev = info->user_ptr[1];
9643 struct ocb_setup setup = {};
9644 int err;
9645
9646 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9647 if (err)
9648 return err;
9649
9650 return cfg80211_join_ocb(rdev, dev, &setup);
9651}
9652
9653static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9654{
9655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9656 struct net_device *dev = info->user_ptr[1];
9657
9658 return cfg80211_leave_ocb(rdev, dev);
9659}
9660
Johannes Berg29cbe682010-12-03 09:20:44 +01009661static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9662{
9663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9664 struct net_device *dev = info->user_ptr[1];
9665 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009666 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009667 int err;
9668
9669 /* start with default */
9670 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009671 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009672
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009673 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009674 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009675 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009676 if (err)
9677 return err;
9678 }
9679
9680 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9681 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9682 return -EINVAL;
9683
Javier Cardonac80d5452010-12-16 17:37:49 -08009684 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9685 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9686
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009687 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9688 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9689 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9690 return -EINVAL;
9691
Marco Porsch9bdbf042013-01-07 16:04:51 +01009692 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9693 setup.beacon_interval =
9694 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309695
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05309696 err = cfg80211_validate_beacon_int(rdev,
9697 NL80211_IFTYPE_MESH_POINT,
9698 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309699 if (err)
9700 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009701 }
9702
9703 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9704 setup.dtim_period =
9705 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9706 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9707 return -EINVAL;
9708 }
9709
Javier Cardonac80d5452010-12-16 17:37:49 -08009710 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9711 /* parse additional setup parameters if given */
9712 err = nl80211_parse_mesh_setup(info, &setup);
9713 if (err)
9714 return err;
9715 }
9716
Thomas Pedersend37bb182013-03-04 13:06:13 -08009717 if (setup.user_mpm)
9718 cfg.auto_open_plinks = false;
9719
Johannes Bergcc1d2802012-05-16 23:50:20 +02009720 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009721 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9722 if (err)
9723 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009724 } else {
9725 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009726 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009727 }
9728
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009729 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9730 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9731 int n_rates =
9732 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9733 struct ieee80211_supported_band *sband;
9734
9735 if (!setup.chandef.chan)
9736 return -EINVAL;
9737
9738 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9739
9740 err = ieee80211_get_ratemask(sband, rates, n_rates,
9741 &setup.basic_rates);
9742 if (err)
9743 return err;
9744 }
9745
Johannes Berg8564e382016-09-19 09:44:44 +02009746 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9747 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9748 if (err)
9749 return err;
9750
Johannes Berg091eac32017-09-18 22:46:36 +02009751 if (!setup.chandef.chan)
9752 return -EINVAL;
9753
Johannes Berg8564e382016-09-19 09:44:44 +02009754 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9755 &setup.beacon_rate);
9756 if (err)
9757 return err;
9758 }
9759
Javier Cardonac80d5452010-12-16 17:37:49 -08009760 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009761}
9762
9763static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9764{
9765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9766 struct net_device *dev = info->user_ptr[1];
9767
9768 return cfg80211_leave_mesh(rdev, dev);
9769}
9770
Johannes Bergdfb89c52012-06-27 09:23:48 +02009771#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009772static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9773 struct cfg80211_registered_device *rdev)
9774{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009775 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009776 struct nlattr *nl_pats, *nl_pat;
9777 int i, pat_len;
9778
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009779 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009780 return 0;
9781
9782 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9783 if (!nl_pats)
9784 return -ENOBUFS;
9785
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009786 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009787 nl_pat = nla_nest_start(msg, i + 1);
9788 if (!nl_pat)
9789 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009790 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009791 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009792 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009793 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9794 wowlan->patterns[i].pattern) ||
9795 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009796 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009797 return -ENOBUFS;
9798 nla_nest_end(msg, nl_pat);
9799 }
9800 nla_nest_end(msg, nl_pats);
9801
9802 return 0;
9803}
9804
Johannes Berg2a0e0472013-01-23 22:57:40 +01009805static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9806 struct cfg80211_wowlan_tcp *tcp)
9807{
9808 struct nlattr *nl_tcp;
9809
9810 if (!tcp)
9811 return 0;
9812
9813 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9814 if (!nl_tcp)
9815 return -ENOBUFS;
9816
Jiri Benc930345e2015-03-29 16:59:25 +02009817 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9818 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009819 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9820 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9821 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9822 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9823 tcp->payload_len, tcp->payload) ||
9824 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9825 tcp->data_interval) ||
9826 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9827 tcp->wake_len, tcp->wake_data) ||
9828 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9829 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9830 return -ENOBUFS;
9831
9832 if (tcp->payload_seq.len &&
9833 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9834 sizeof(tcp->payload_seq), &tcp->payload_seq))
9835 return -ENOBUFS;
9836
9837 if (tcp->payload_tok.len &&
9838 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9839 sizeof(tcp->payload_tok) + tcp->tokens_size,
9840 &tcp->payload_tok))
9841 return -ENOBUFS;
9842
Johannes Berge248ad32013-05-16 10:24:28 +02009843 nla_nest_end(msg, nl_tcp);
9844
Johannes Berg2a0e0472013-01-23 22:57:40 +01009845 return 0;
9846}
9847
Luciano Coelho75453cc2015-01-09 14:06:37 +02009848static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9849 struct cfg80211_sched_scan_request *req)
9850{
Avraham Stern3b06d272015-10-12 09:51:34 +03009851 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009852 int i;
9853
9854 if (!req)
9855 return 0;
9856
9857 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9858 if (!nd)
9859 return -ENOBUFS;
9860
Avraham Stern3b06d272015-10-12 09:51:34 +03009861 if (req->n_scan_plans == 1 &&
9862 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9863 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009864 return -ENOBUFS;
9865
Luciano Coelho21fea562015-03-17 16:36:01 +02009866 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9867 return -ENOBUFS;
9868
vamsi krishnaf4f1a542017-01-13 01:12:20 +02009869 if (req->relative_rssi_set) {
9870 struct nl80211_bss_select_rssi_adjust rssi_adjust;
9871
9872 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
9873 req->relative_rssi))
9874 return -ENOBUFS;
9875
9876 rssi_adjust.band = req->rssi_adjust.band;
9877 rssi_adjust.delta = req->rssi_adjust.delta;
9878 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
9879 sizeof(rssi_adjust), &rssi_adjust))
9880 return -ENOBUFS;
9881 }
9882
Luciano Coelho75453cc2015-01-09 14:06:37 +02009883 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9884 if (!freqs)
9885 return -ENOBUFS;
9886
Johannes Berg53b18982016-09-14 09:59:21 +02009887 for (i = 0; i < req->n_channels; i++) {
9888 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9889 return -ENOBUFS;
9890 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009891
9892 nla_nest_end(msg, freqs);
9893
9894 if (req->n_match_sets) {
9895 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009896 if (!matches)
9897 return -ENOBUFS;
9898
Luciano Coelho75453cc2015-01-09 14:06:37 +02009899 for (i = 0; i < req->n_match_sets; i++) {
9900 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009901 if (!match)
9902 return -ENOBUFS;
9903
Johannes Berg53b18982016-09-14 09:59:21 +02009904 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9905 req->match_sets[i].ssid.ssid_len,
9906 req->match_sets[i].ssid.ssid))
9907 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009908 nla_nest_end(msg, match);
9909 }
9910 nla_nest_end(msg, matches);
9911 }
9912
Avraham Stern3b06d272015-10-12 09:51:34 +03009913 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9914 if (!scan_plans)
9915 return -ENOBUFS;
9916
9917 for (i = 0; i < req->n_scan_plans; i++) {
9918 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009919 if (!scan_plan)
9920 return -ENOBUFS;
9921
Avraham Stern3b06d272015-10-12 09:51:34 +03009922 if (!scan_plan ||
9923 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9924 req->scan_plans[i].interval) ||
9925 (req->scan_plans[i].iterations &&
9926 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9927 req->scan_plans[i].iterations)))
9928 return -ENOBUFS;
9929 nla_nest_end(msg, scan_plan);
9930 }
9931 nla_nest_end(msg, scan_plans);
9932
Luciano Coelho75453cc2015-01-09 14:06:37 +02009933 nla_nest_end(msg, nd);
9934
9935 return 0;
9936}
9937
Johannes Bergff1b6e62011-05-04 15:37:28 +02009938static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9939{
9940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9941 struct sk_buff *msg;
9942 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009943 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009944
Johannes Berg964dc9e2013-06-03 17:25:34 +02009945 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009946 return -EOPNOTSUPP;
9947
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009948 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009949 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009950 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9951 rdev->wiphy.wowlan_config->tcp->payload_len +
9952 rdev->wiphy.wowlan_config->tcp->wake_len +
9953 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009954 }
9955
9956 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009957 if (!msg)
9958 return -ENOMEM;
9959
Eric W. Biederman15e47302012-09-07 20:12:54 +00009960 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009961 NL80211_CMD_GET_WOWLAN);
9962 if (!hdr)
9963 goto nla_put_failure;
9964
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009965 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009966 struct nlattr *nl_wowlan;
9967
9968 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9969 if (!nl_wowlan)
9970 goto nla_put_failure;
9971
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009972 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009974 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009975 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009976 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009978 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009980 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009981 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009982 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009983 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009984 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009985 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9986 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009987
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009988 if (nl80211_send_wowlan_patterns(msg, rdev))
9989 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009990
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009991 if (nl80211_send_wowlan_tcp(msg,
9992 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009993 goto nla_put_failure;
9994
Luciano Coelho75453cc2015-01-09 14:06:37 +02009995 if (nl80211_send_wowlan_nd(
9996 msg,
9997 rdev->wiphy.wowlan_config->nd_config))
9998 goto nla_put_failure;
9999
Johannes Bergff1b6e62011-05-04 15:37:28 +020010000 nla_nest_end(msg, nl_wowlan);
10001 }
10002
10003 genlmsg_end(msg, hdr);
10004 return genlmsg_reply(msg, info);
10005
10006nla_put_failure:
10007 nlmsg_free(msg);
10008 return -ENOBUFS;
10009}
10010
Johannes Berg2a0e0472013-01-23 22:57:40 +010010011static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10012 struct nlattr *attr,
10013 struct cfg80211_wowlan *trig)
10014{
10015 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10016 struct cfg80211_wowlan_tcp *cfg;
10017 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10018 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10019 u32 size;
10020 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10021 int err, port;
10022
Johannes Berg964dc9e2013-06-03 17:25:34 +020010023 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010024 return -EINVAL;
10025
10026 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
10027 nla_data(attr), nla_len(attr),
10028 nl80211_wowlan_tcp_policy);
10029 if (err)
10030 return err;
10031
10032 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10033 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10034 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10035 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10036 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10037 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10038 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10039 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10040 return -EINVAL;
10041
10042 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010043 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010044 return -EINVAL;
10045
10046 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010047 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010048 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010049 return -EINVAL;
10050
10051 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010052 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010053 return -EINVAL;
10054
10055 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10056 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10057 return -EINVAL;
10058
10059 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10060 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10061
10062 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10063 tokens_size = tokln - sizeof(*tok);
10064
10065 if (!tok->len || tokens_size % tok->len)
10066 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010067 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010068 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010069 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010070 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010071 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010072 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010073 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010074 return -EINVAL;
10075 if (tok->offset + tok->len > data_size)
10076 return -EINVAL;
10077 }
10078
10079 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10080 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010081 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010082 return -EINVAL;
10083 if (seq->len == 0 || seq->len > 4)
10084 return -EINVAL;
10085 if (seq->len + seq->offset > data_size)
10086 return -EINVAL;
10087 }
10088
10089 size = sizeof(*cfg);
10090 size += data_size;
10091 size += wake_size + wake_mask_size;
10092 size += tokens_size;
10093
10094 cfg = kzalloc(size, GFP_KERNEL);
10095 if (!cfg)
10096 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010097 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10098 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010099 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10100 ETH_ALEN);
10101 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10102 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10103 else
10104 port = 0;
10105#ifdef CONFIG_INET
10106 /* allocate a socket and port for it and use it */
10107 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10108 IPPROTO_TCP, &cfg->sock, 1);
10109 if (err) {
10110 kfree(cfg);
10111 return err;
10112 }
10113 if (inet_csk_get_port(cfg->sock->sk, port)) {
10114 sock_release(cfg->sock);
10115 kfree(cfg);
10116 return -EADDRINUSE;
10117 }
10118 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10119#else
10120 if (!port) {
10121 kfree(cfg);
10122 return -EINVAL;
10123 }
10124 cfg->src_port = port;
10125#endif
10126
10127 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10128 cfg->payload_len = data_size;
10129 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10130 memcpy((void *)cfg->payload,
10131 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10132 data_size);
10133 if (seq)
10134 cfg->payload_seq = *seq;
10135 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10136 cfg->wake_len = wake_size;
10137 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10138 memcpy((void *)cfg->wake_data,
10139 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10140 wake_size);
10141 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10142 data_size + wake_size;
10143 memcpy((void *)cfg->wake_mask,
10144 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10145 wake_mask_size);
10146 if (tok) {
10147 cfg->tokens_size = tokens_size;
10148 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10149 }
10150
10151 trig->tcp = cfg;
10152
10153 return 0;
10154}
10155
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010156static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10157 const struct wiphy_wowlan_support *wowlan,
10158 struct nlattr *attr,
10159 struct cfg80211_wowlan *trig)
10160{
10161 struct nlattr **tb;
10162 int err;
10163
10164 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10165 if (!tb)
10166 return -ENOMEM;
10167
10168 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10169 err = -EOPNOTSUPP;
10170 goto out;
10171 }
10172
10173 err = nla_parse(tb, NL80211_ATTR_MAX,
10174 nla_data(attr), nla_len(attr),
10175 nl80211_policy);
10176 if (err)
10177 goto out;
10178
Johannes Bergad2b26a2014-06-12 21:39:05 +020010179 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010180 err = PTR_ERR_OR_ZERO(trig->nd_config);
10181 if (err)
10182 trig->nd_config = NULL;
10183
10184out:
10185 kfree(tb);
10186 return err;
10187}
10188
Johannes Bergff1b6e62011-05-04 15:37:28 +020010189static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10190{
10191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10192 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010193 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010194 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010195 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010196 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010197 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010198 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010199
Johannes Berg964dc9e2013-06-03 17:25:34 +020010200 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010201 return -EOPNOTSUPP;
10202
Johannes Bergae33bd82012-07-12 16:25:02 +020010203 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10204 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010205 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010206 goto set_wakeup;
10207 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010208
10209 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
10210 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
10211 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
10212 nl80211_wowlan_policy);
10213 if (err)
10214 return err;
10215
10216 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10217 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10218 return -EINVAL;
10219 new_triggers.any = true;
10220 }
10221
10222 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10223 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10224 return -EINVAL;
10225 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010226 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010227 }
10228
10229 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10230 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10231 return -EINVAL;
10232 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010233 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010234 }
10235
Johannes Berg77dbbb12011-07-13 10:48:55 +020010236 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10237 return -EINVAL;
10238
10239 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10240 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10241 return -EINVAL;
10242 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010243 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010244 }
10245
10246 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10247 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10248 return -EINVAL;
10249 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010250 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010251 }
10252
10253 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10254 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10255 return -EINVAL;
10256 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010257 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010258 }
10259
10260 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10261 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10262 return -EINVAL;
10263 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010264 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010265 }
10266
Johannes Bergff1b6e62011-05-04 15:37:28 +020010267 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10268 struct nlattr *pat;
10269 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010270 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010271 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010272
Johannes Berg98fc4382015-03-01 09:10:13 +020010273 regular = true;
10274
Johannes Bergff1b6e62011-05-04 15:37:28 +020010275 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10276 rem)
10277 n_patterns++;
10278 if (n_patterns > wowlan->n_patterns)
10279 return -EINVAL;
10280
10281 new_triggers.patterns = kcalloc(n_patterns,
10282 sizeof(new_triggers.patterns[0]),
10283 GFP_KERNEL);
10284 if (!new_triggers.patterns)
10285 return -ENOMEM;
10286
10287 new_triggers.n_patterns = n_patterns;
10288 i = 0;
10289
10290 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10291 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010292 u8 *mask_pat;
10293
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010294 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
Peng Xu4ec90fd2017-10-10 13:56:53 -070010295 nla_len(pat), nl80211_packet_pattern_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010296 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010297 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10298 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010299 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010300 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010301 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010302 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010303 goto error;
10304 if (pat_len > wowlan->pattern_max_len ||
10305 pat_len < wowlan->pattern_min_len)
10306 goto error;
10307
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010308 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010309 pkt_offset = 0;
10310 else
10311 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010312 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010313 if (pkt_offset > wowlan->max_pkt_offset)
10314 goto error;
10315 new_triggers.patterns[i].pkt_offset = pkt_offset;
10316
Johannes Berg922bd802014-05-19 17:59:50 +020010317 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10318 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010319 err = -ENOMEM;
10320 goto error;
10321 }
Johannes Berg922bd802014-05-19 17:59:50 +020010322 new_triggers.patterns[i].mask = mask_pat;
10323 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010324 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010325 mask_pat += mask_len;
10326 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010327 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010328 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010329 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010330 pat_len);
10331 i++;
10332 }
10333 }
10334
Johannes Berg2a0e0472013-01-23 22:57:40 +010010335 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010336 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010337 err = nl80211_parse_wowlan_tcp(
10338 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10339 &new_triggers);
10340 if (err)
10341 goto error;
10342 }
10343
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010344 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010345 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010346 err = nl80211_parse_wowlan_nd(
10347 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10348 &new_triggers);
10349 if (err)
10350 goto error;
10351 }
10352
Johannes Berg98fc4382015-03-01 09:10:13 +020010353 /* The 'any' trigger means the device continues operating more or less
10354 * as in its normal operation mode and wakes up the host on most of the
10355 * normal interrupts (like packet RX, ...)
10356 * It therefore makes little sense to combine with the more constrained
10357 * wakeup trigger modes.
10358 */
10359 if (new_triggers.any && regular) {
10360 err = -EINVAL;
10361 goto error;
10362 }
10363
Johannes Bergae33bd82012-07-12 16:25:02 +020010364 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10365 if (!ntrig) {
10366 err = -ENOMEM;
10367 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010368 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010369 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010370 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010371
Johannes Bergae33bd82012-07-12 16:25:02 +020010372 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010373 if (rdev->ops->set_wakeup &&
10374 prev_enabled != !!rdev->wiphy.wowlan_config)
10375 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010376
Johannes Bergff1b6e62011-05-04 15:37:28 +020010377 return 0;
10378 error:
10379 for (i = 0; i < new_triggers.n_patterns; i++)
10380 kfree(new_triggers.patterns[i].mask);
10381 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010382 if (new_triggers.tcp && new_triggers.tcp->sock)
10383 sock_release(new_triggers.tcp->sock);
10384 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010385 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010386 return err;
10387}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010388#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010389
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010390static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10391 struct cfg80211_registered_device *rdev)
10392{
10393 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10394 int i, j, pat_len;
10395 struct cfg80211_coalesce_rules *rule;
10396
10397 if (!rdev->coalesce->n_rules)
10398 return 0;
10399
10400 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10401 if (!nl_rules)
10402 return -ENOBUFS;
10403
10404 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10405 nl_rule = nla_nest_start(msg, i + 1);
10406 if (!nl_rule)
10407 return -ENOBUFS;
10408
10409 rule = &rdev->coalesce->rules[i];
10410 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10411 rule->delay))
10412 return -ENOBUFS;
10413
10414 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10415 rule->condition))
10416 return -ENOBUFS;
10417
10418 nl_pats = nla_nest_start(msg,
10419 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10420 if (!nl_pats)
10421 return -ENOBUFS;
10422
10423 for (j = 0; j < rule->n_patterns; j++) {
10424 nl_pat = nla_nest_start(msg, j + 1);
10425 if (!nl_pat)
10426 return -ENOBUFS;
10427 pat_len = rule->patterns[j].pattern_len;
10428 if (nla_put(msg, NL80211_PKTPAT_MASK,
10429 DIV_ROUND_UP(pat_len, 8),
10430 rule->patterns[j].mask) ||
10431 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10432 rule->patterns[j].pattern) ||
10433 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10434 rule->patterns[j].pkt_offset))
10435 return -ENOBUFS;
10436 nla_nest_end(msg, nl_pat);
10437 }
10438 nla_nest_end(msg, nl_pats);
10439 nla_nest_end(msg, nl_rule);
10440 }
10441 nla_nest_end(msg, nl_rules);
10442
10443 return 0;
10444}
10445
10446static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10447{
10448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10449 struct sk_buff *msg;
10450 void *hdr;
10451
10452 if (!rdev->wiphy.coalesce)
10453 return -EOPNOTSUPP;
10454
10455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10456 if (!msg)
10457 return -ENOMEM;
10458
10459 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10460 NL80211_CMD_GET_COALESCE);
10461 if (!hdr)
10462 goto nla_put_failure;
10463
10464 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10465 goto nla_put_failure;
10466
10467 genlmsg_end(msg, hdr);
10468 return genlmsg_reply(msg, info);
10469
10470nla_put_failure:
10471 nlmsg_free(msg);
10472 return -ENOBUFS;
10473}
10474
10475void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10476{
10477 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10478 int i, j;
10479 struct cfg80211_coalesce_rules *rule;
10480
10481 if (!coalesce)
10482 return;
10483
10484 for (i = 0; i < coalesce->n_rules; i++) {
10485 rule = &coalesce->rules[i];
10486 for (j = 0; j < rule->n_patterns; j++)
10487 kfree(rule->patterns[j].mask);
10488 kfree(rule->patterns);
10489 }
10490 kfree(coalesce->rules);
10491 kfree(coalesce);
10492 rdev->coalesce = NULL;
10493}
10494
10495static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10496 struct nlattr *rule,
10497 struct cfg80211_coalesce_rules *new_rule)
10498{
10499 int err, i;
10500 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10501 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10502 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10503 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10504
10505 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10506 nla_len(rule), nl80211_coalesce_policy);
10507 if (err)
10508 return err;
10509
10510 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10511 new_rule->delay =
10512 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10513 if (new_rule->delay > coalesce->max_delay)
10514 return -EINVAL;
10515
10516 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10517 new_rule->condition =
10518 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10519 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10520 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10521 return -EINVAL;
10522
10523 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10524 return -EINVAL;
10525
10526 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10527 rem)
10528 n_patterns++;
10529 if (n_patterns > coalesce->n_patterns)
10530 return -EINVAL;
10531
10532 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10533 GFP_KERNEL);
10534 if (!new_rule->patterns)
10535 return -ENOMEM;
10536
10537 new_rule->n_patterns = n_patterns;
10538 i = 0;
10539
10540 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10541 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010542 u8 *mask_pat;
10543
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010544 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
Peng Xu4ec90fd2017-10-10 13:56:53 -070010545 nla_len(pat), nl80211_packet_pattern_policy);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010546 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10547 !pat_tb[NL80211_PKTPAT_PATTERN])
10548 return -EINVAL;
10549 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10550 mask_len = DIV_ROUND_UP(pat_len, 8);
10551 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10552 return -EINVAL;
10553 if (pat_len > coalesce->pattern_max_len ||
10554 pat_len < coalesce->pattern_min_len)
10555 return -EINVAL;
10556
10557 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10558 pkt_offset = 0;
10559 else
10560 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10561 if (pkt_offset > coalesce->max_pkt_offset)
10562 return -EINVAL;
10563 new_rule->patterns[i].pkt_offset = pkt_offset;
10564
Johannes Berg922bd802014-05-19 17:59:50 +020010565 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10566 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010567 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010568
10569 new_rule->patterns[i].mask = mask_pat;
10570 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10571 mask_len);
10572
10573 mask_pat += mask_len;
10574 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010575 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010576 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10577 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010578 i++;
10579 }
10580
10581 return 0;
10582}
10583
10584static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10585{
10586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10587 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10588 struct cfg80211_coalesce new_coalesce = {};
10589 struct cfg80211_coalesce *n_coalesce;
10590 int err, rem_rule, n_rules = 0, i, j;
10591 struct nlattr *rule;
10592 struct cfg80211_coalesce_rules *tmp_rule;
10593
10594 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10595 return -EOPNOTSUPP;
10596
10597 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10598 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010599 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010600 return 0;
10601 }
10602
10603 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10604 rem_rule)
10605 n_rules++;
10606 if (n_rules > coalesce->n_rules)
10607 return -EINVAL;
10608
10609 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10610 GFP_KERNEL);
10611 if (!new_coalesce.rules)
10612 return -ENOMEM;
10613
10614 new_coalesce.n_rules = n_rules;
10615 i = 0;
10616
10617 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10618 rem_rule) {
10619 err = nl80211_parse_coalesce_rule(rdev, rule,
10620 &new_coalesce.rules[i]);
10621 if (err)
10622 goto error;
10623
10624 i++;
10625 }
10626
Ilan Peera1056b12015-10-22 22:27:46 +030010627 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010628 if (err)
10629 goto error;
10630
10631 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10632 if (!n_coalesce) {
10633 err = -ENOMEM;
10634 goto error;
10635 }
10636 cfg80211_rdev_free_coalesce(rdev);
10637 rdev->coalesce = n_coalesce;
10638
10639 return 0;
10640error:
10641 for (i = 0; i < new_coalesce.n_rules; i++) {
10642 tmp_rule = &new_coalesce.rules[i];
10643 for (j = 0; j < tmp_rule->n_patterns; j++)
10644 kfree(tmp_rule->patterns[j].mask);
10645 kfree(tmp_rule->patterns);
10646 }
10647 kfree(new_coalesce.rules);
10648
10649 return err;
10650}
10651
Johannes Berge5497d72011-07-05 16:35:40 +020010652static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10653{
10654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10655 struct net_device *dev = info->user_ptr[1];
10656 struct wireless_dev *wdev = dev->ieee80211_ptr;
10657 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10658 struct cfg80211_gtk_rekey_data rekey_data;
10659 int err;
10660
10661 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10662 return -EINVAL;
10663
10664 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10665 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10666 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10667 nl80211_rekey_policy);
10668 if (err)
10669 return err;
10670
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010671 if (!tb[NL80211_REKEY_DATA_KEK] || !tb[NL80211_REKEY_DATA_REPLAY_CTR] ||
10672 (!wiphy_ext_feature_isset(&rdev->wiphy,
10673 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10674 !wiphy_ext_feature_isset(&rdev->wiphy,
10675 NL80211_EXT_FEATURE_FILS_STA) &&
10676 !tb[NL80211_REKEY_DATA_KCK]))
10677 return -EINVAL;
10678
Johannes Berge5497d72011-07-05 16:35:40 +020010679 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10680 return -ERANGE;
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010681 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) < NL80211_KEK_LEN)
Johannes Berge5497d72011-07-05 16:35:40 +020010682 return -ERANGE;
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010683 if (tb[NL80211_REKEY_DATA_KCK] &&
10684 nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
Johannes Berge5497d72011-07-05 16:35:40 +020010685 return -ERANGE;
10686
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010687 memset(&rekey_data, 0, sizeof(rekey_data));
Johannes Berg78f686c2014-09-10 22:28:06 +030010688 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010689 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
10690 if (tb[NL80211_REKEY_DATA_KCK])
10691 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
Johannes Berg78f686c2014-09-10 22:28:06 +030010692 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010693
10694 wdev_lock(wdev);
10695 if (!wdev->current_bss) {
10696 err = -ENOTCONN;
10697 goto out;
10698 }
10699
10700 if (!rdev->ops->set_rekey_data) {
10701 err = -EOPNOTSUPP;
10702 goto out;
10703 }
10704
Hila Gonene35e4d22012-06-27 17:19:42 +030010705 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010706 out:
10707 wdev_unlock(wdev);
10708 return err;
10709}
10710
Johannes Berg28946da2011-11-04 11:18:12 +010010711static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10712 struct genl_info *info)
10713{
10714 struct net_device *dev = info->user_ptr[1];
10715 struct wireless_dev *wdev = dev->ieee80211_ptr;
10716
10717 if (wdev->iftype != NL80211_IFTYPE_AP &&
10718 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10719 return -EINVAL;
10720
Eric W. Biederman15e47302012-09-07 20:12:54 +000010721 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010722 return -EBUSY;
10723
Eric W. Biederman15e47302012-09-07 20:12:54 +000010724 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010725 return 0;
10726}
10727
Johannes Berg7f6cf312011-11-04 11:18:15 +010010728static int nl80211_probe_client(struct sk_buff *skb,
10729 struct genl_info *info)
10730{
10731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10732 struct net_device *dev = info->user_ptr[1];
10733 struct wireless_dev *wdev = dev->ieee80211_ptr;
10734 struct sk_buff *msg;
10735 void *hdr;
10736 const u8 *addr;
10737 u64 cookie;
10738 int err;
10739
10740 if (wdev->iftype != NL80211_IFTYPE_AP &&
10741 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10742 return -EOPNOTSUPP;
10743
10744 if (!info->attrs[NL80211_ATTR_MAC])
10745 return -EINVAL;
10746
10747 if (!rdev->ops->probe_client)
10748 return -EOPNOTSUPP;
10749
10750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10751 if (!msg)
10752 return -ENOMEM;
10753
Eric W. Biederman15e47302012-09-07 20:12:54 +000010754 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010755 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010756 if (!hdr) {
10757 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010758 goto free_msg;
10759 }
10760
10761 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10762
Hila Gonene35e4d22012-06-27 17:19:42 +030010763 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010764 if (err)
10765 goto free_msg;
10766
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010767 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10768 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010769 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010770
10771 genlmsg_end(msg, hdr);
10772
10773 return genlmsg_reply(msg, info);
10774
10775 nla_put_failure:
10776 err = -ENOBUFS;
10777 free_msg:
10778 nlmsg_free(msg);
10779 return err;
10780}
10781
Johannes Berg5e7602302011-11-04 11:18:17 +010010782static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10783{
10784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010785 struct cfg80211_beacon_registration *reg, *nreg;
10786 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010787
10788 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10789 return -EOPNOTSUPP;
10790
Ben Greear37c73b52012-10-26 14:49:25 -070010791 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10792 if (!nreg)
10793 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010794
Ben Greear37c73b52012-10-26 14:49:25 -070010795 /* First, check if already registered. */
10796 spin_lock_bh(&rdev->beacon_registrations_lock);
10797 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10798 if (reg->nlportid == info->snd_portid) {
10799 rv = -EALREADY;
10800 goto out_err;
10801 }
10802 }
10803 /* Add it to the list */
10804 nreg->nlportid = info->snd_portid;
10805 list_add(&nreg->list, &rdev->beacon_registrations);
10806
10807 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010808
10809 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010810out_err:
10811 spin_unlock_bh(&rdev->beacon_registrations_lock);
10812 kfree(nreg);
10813 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010814}
10815
Johannes Berg98104fde2012-06-16 00:19:54 +020010816static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10817{
10818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10819 struct wireless_dev *wdev = info->user_ptr[1];
10820 int err;
10821
10822 if (!rdev->ops->start_p2p_device)
10823 return -EOPNOTSUPP;
10824
10825 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10826 return -EOPNOTSUPP;
10827
10828 if (wdev->p2p_started)
10829 return 0;
10830
Luciano Coelhob6a55012014-02-27 11:07:21 +020010831 if (rfkill_blocked(rdev->rfkill))
10832 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010833
Johannes Bergeeb126e2012-10-23 15:16:50 +020010834 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010835 if (err)
10836 return err;
10837
10838 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010839 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010840
10841 return 0;
10842}
10843
10844static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10845{
10846 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10847 struct wireless_dev *wdev = info->user_ptr[1];
10848
10849 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10850 return -EOPNOTSUPP;
10851
10852 if (!rdev->ops->stop_p2p_device)
10853 return -EOPNOTSUPP;
10854
Johannes Bergf9f47522013-03-19 15:04:07 +010010855 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010856
10857 return 0;
10858}
10859
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010860static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10861{
10862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10863 struct wireless_dev *wdev = info->user_ptr[1];
10864 struct cfg80211_nan_conf conf = {};
10865 int err;
10866
10867 if (wdev->iftype != NL80211_IFTYPE_NAN)
10868 return -EOPNOTSUPP;
10869
10870 if (wdev->nan_started)
10871 return -EEXIST;
10872
10873 if (rfkill_blocked(rdev->rfkill))
10874 return -ERFKILL;
10875
10876 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10877 return -EINVAL;
10878
10879 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10880 return -EINVAL;
10881
10882 conf.master_pref =
10883 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10884 if (!conf.master_pref)
10885 return -EINVAL;
10886
10887 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10888
10889 err = rdev_start_nan(rdev, wdev, &conf);
10890 if (err)
10891 return err;
10892
10893 wdev->nan_started = true;
10894 rdev->opencount++;
10895
10896 return 0;
10897}
10898
10899static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10900{
10901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10902 struct wireless_dev *wdev = info->user_ptr[1];
10903
10904 if (wdev->iftype != NL80211_IFTYPE_NAN)
10905 return -EOPNOTSUPP;
10906
10907 cfg80211_stop_nan(rdev, wdev);
10908
10909 return 0;
10910}
10911
Ayala Bekera442b762016-09-20 17:31:15 +030010912static int validate_nan_filter(struct nlattr *filter_attr)
10913{
10914 struct nlattr *attr;
10915 int len = 0, n_entries = 0, rem;
10916
10917 nla_for_each_nested(attr, filter_attr, rem) {
10918 len += nla_len(attr);
10919 n_entries++;
10920 }
10921
10922 if (len >= U8_MAX)
10923 return -EINVAL;
10924
10925 return n_entries;
10926}
10927
10928static int handle_nan_filter(struct nlattr *attr_filter,
10929 struct cfg80211_nan_func *func,
10930 bool tx)
10931{
10932 struct nlattr *attr;
10933 int n_entries, rem, i;
10934 struct cfg80211_nan_func_filter *filter;
10935
10936 n_entries = validate_nan_filter(attr_filter);
10937 if (n_entries < 0)
10938 return n_entries;
10939
10940 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10941
10942 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10943 if (!filter)
10944 return -ENOMEM;
10945
10946 i = 0;
10947 nla_for_each_nested(attr, attr_filter, rem) {
10948 filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10949 GFP_KERNEL);
10950 filter[i].len = nla_len(attr);
10951 i++;
10952 }
10953 if (tx) {
10954 func->num_tx_filters = n_entries;
10955 func->tx_filters = filter;
10956 } else {
10957 func->num_rx_filters = n_entries;
10958 func->rx_filters = filter;
10959 }
10960
10961 return 0;
10962}
10963
10964static int nl80211_nan_add_func(struct sk_buff *skb,
10965 struct genl_info *info)
10966{
10967 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10968 struct wireless_dev *wdev = info->user_ptr[1];
10969 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10970 struct cfg80211_nan_func *func;
10971 struct sk_buff *msg = NULL;
10972 void *hdr = NULL;
10973 int err = 0;
10974
10975 if (wdev->iftype != NL80211_IFTYPE_NAN)
10976 return -EOPNOTSUPP;
10977
10978 if (!wdev->nan_started)
10979 return -ENOTCONN;
10980
10981 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10982 return -EINVAL;
10983
10984 if (wdev->owner_nlportid &&
10985 wdev->owner_nlportid != info->snd_portid)
10986 return -ENOTCONN;
10987
10988 err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
10989 nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
10990 nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
10991 nl80211_nan_func_policy);
10992 if (err)
10993 return err;
10994
10995 func = kzalloc(sizeof(*func), GFP_KERNEL);
10996 if (!func)
10997 return -ENOMEM;
10998
10999 func->cookie = wdev->wiphy->cookie_counter++;
11000
11001 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11002 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11003 err = -EINVAL;
11004 goto out;
11005 }
11006
11007
11008 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11009
11010 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11011 err = -EINVAL;
11012 goto out;
11013 }
11014
11015 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11016 sizeof(func->service_id));
11017
11018 func->close_range =
11019 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11020
11021 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11022 func->serv_spec_info_len =
11023 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11024 func->serv_spec_info =
11025 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11026 func->serv_spec_info_len,
11027 GFP_KERNEL);
11028 if (!func->serv_spec_info) {
11029 err = -ENOMEM;
11030 goto out;
11031 }
11032 }
11033
11034 if (tb[NL80211_NAN_FUNC_TTL])
11035 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11036
11037 switch (func->type) {
11038 case NL80211_NAN_FUNC_PUBLISH:
11039 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11040 err = -EINVAL;
11041 goto out;
11042 }
11043
11044 func->publish_type =
11045 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11046 func->publish_bcast =
11047 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11048
11049 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11050 func->publish_bcast) {
11051 err = -EINVAL;
11052 goto out;
11053 }
11054 break;
11055 case NL80211_NAN_FUNC_SUBSCRIBE:
11056 func->subscribe_active =
11057 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11058 break;
11059 case NL80211_NAN_FUNC_FOLLOW_UP:
11060 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen4ec2b1c2018-01-03 11:00:31 +080011061 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
11062 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030011063 err = -EINVAL;
11064 goto out;
11065 }
11066
11067 func->followup_id =
11068 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11069 func->followup_reqid =
11070 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11071 memcpy(func->followup_dest.addr,
11072 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11073 sizeof(func->followup_dest.addr));
11074 if (func->ttl) {
11075 err = -EINVAL;
11076 goto out;
11077 }
11078 break;
11079 default:
11080 err = -EINVAL;
11081 goto out;
11082 }
11083
11084 if (tb[NL80211_NAN_FUNC_SRF]) {
11085 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11086
11087 err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11088 nla_data(tb[NL80211_NAN_FUNC_SRF]),
11089 nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
11090 if (err)
11091 goto out;
11092
11093 func->srf_include =
11094 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11095
11096 if (srf_tb[NL80211_NAN_SRF_BF]) {
11097 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11098 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11099 err = -EINVAL;
11100 goto out;
11101 }
11102
11103 func->srf_bf_len =
11104 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11105 func->srf_bf =
11106 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11107 func->srf_bf_len, GFP_KERNEL);
11108 if (!func->srf_bf) {
11109 err = -ENOMEM;
11110 goto out;
11111 }
11112
11113 func->srf_bf_idx =
11114 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11115 } else {
11116 struct nlattr *attr, *mac_attr =
11117 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11118 int n_entries, rem, i = 0;
11119
11120 if (!mac_attr) {
11121 err = -EINVAL;
11122 goto out;
11123 }
11124
11125 n_entries = validate_acl_mac_addrs(mac_attr);
11126 if (n_entries <= 0) {
11127 err = -EINVAL;
11128 goto out;
11129 }
11130
11131 func->srf_num_macs = n_entries;
11132 func->srf_macs =
11133 kzalloc(sizeof(*func->srf_macs) * n_entries,
11134 GFP_KERNEL);
11135 if (!func->srf_macs) {
11136 err = -ENOMEM;
11137 goto out;
11138 }
11139
11140 nla_for_each_nested(attr, mac_attr, rem)
11141 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11142 sizeof(*func->srf_macs));
11143 }
11144 }
11145
11146 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11147 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11148 func, true);
11149 if (err)
11150 goto out;
11151 }
11152
11153 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11154 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11155 func, false);
11156 if (err)
11157 goto out;
11158 }
11159
11160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11161 if (!msg) {
11162 err = -ENOMEM;
11163 goto out;
11164 }
11165
11166 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11167 NL80211_CMD_ADD_NAN_FUNCTION);
11168 /* This can't really happen - we just allocated 4KB */
11169 if (WARN_ON(!hdr)) {
11170 err = -ENOMEM;
11171 goto out;
11172 }
11173
11174 err = rdev_add_nan_func(rdev, wdev, func);
11175out:
11176 if (err < 0) {
11177 cfg80211_free_nan_func(func);
11178 nlmsg_free(msg);
11179 return err;
11180 }
11181
11182 /* propagate the instance id and cookie to userspace */
11183 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11184 NL80211_ATTR_PAD))
11185 goto nla_put_failure;
11186
11187 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11188 if (!func_attr)
11189 goto nla_put_failure;
11190
11191 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11192 func->instance_id))
11193 goto nla_put_failure;
11194
11195 nla_nest_end(msg, func_attr);
11196
11197 genlmsg_end(msg, hdr);
11198 return genlmsg_reply(msg, info);
11199
11200nla_put_failure:
11201 nlmsg_free(msg);
11202 return -ENOBUFS;
11203}
11204
11205static int nl80211_nan_del_func(struct sk_buff *skb,
11206 struct genl_info *info)
11207{
11208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11209 struct wireless_dev *wdev = info->user_ptr[1];
11210 u64 cookie;
11211
11212 if (wdev->iftype != NL80211_IFTYPE_NAN)
11213 return -EOPNOTSUPP;
11214
11215 if (!wdev->nan_started)
11216 return -ENOTCONN;
11217
11218 if (!info->attrs[NL80211_ATTR_COOKIE])
11219 return -EINVAL;
11220
11221 if (wdev->owner_nlportid &&
11222 wdev->owner_nlportid != info->snd_portid)
11223 return -ENOTCONN;
11224
11225 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11226
11227 rdev_del_nan_func(rdev, wdev, cookie);
11228
11229 return 0;
11230}
11231
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011232static int nl80211_nan_change_config(struct sk_buff *skb,
11233 struct genl_info *info)
11234{
11235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11236 struct wireless_dev *wdev = info->user_ptr[1];
11237 struct cfg80211_nan_conf conf = {};
11238 u32 changed = 0;
11239
11240 if (wdev->iftype != NL80211_IFTYPE_NAN)
11241 return -EOPNOTSUPP;
11242
11243 if (!wdev->nan_started)
11244 return -ENOTCONN;
11245
11246 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11247 conf.master_pref =
11248 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11249 if (conf.master_pref <= 1 || conf.master_pref == 255)
11250 return -EINVAL;
11251
11252 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11253 }
11254
11255 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
11256 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
11257 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
11258 }
11259
11260 if (!changed)
11261 return -EINVAL;
11262
11263 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11264}
11265
Ayala Beker50bcd312016-09-20 17:31:17 +030011266void cfg80211_nan_match(struct wireless_dev *wdev,
11267 struct cfg80211_nan_match_params *match, gfp_t gfp)
11268{
11269 struct wiphy *wiphy = wdev->wiphy;
11270 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11271 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11272 struct sk_buff *msg;
11273 void *hdr;
11274
11275 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11276 return;
11277
11278 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11279 if (!msg)
11280 return;
11281
11282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11283 if (!hdr) {
11284 nlmsg_free(msg);
11285 return;
11286 }
11287
11288 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11289 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11290 wdev->netdev->ifindex)) ||
11291 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11292 NL80211_ATTR_PAD))
11293 goto nla_put_failure;
11294
11295 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11296 NL80211_ATTR_PAD) ||
11297 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11298 goto nla_put_failure;
11299
11300 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11301 if (!match_attr)
11302 goto nla_put_failure;
11303
11304 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11305 if (!local_func_attr)
11306 goto nla_put_failure;
11307
11308 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11309 goto nla_put_failure;
11310
11311 nla_nest_end(msg, local_func_attr);
11312
11313 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11314 if (!peer_func_attr)
11315 goto nla_put_failure;
11316
11317 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11318 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11319 goto nla_put_failure;
11320
11321 if (match->info && match->info_len &&
11322 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11323 match->info))
11324 goto nla_put_failure;
11325
11326 nla_nest_end(msg, peer_func_attr);
11327 nla_nest_end(msg, match_attr);
11328 genlmsg_end(msg, hdr);
11329
11330 if (!wdev->owner_nlportid)
11331 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11332 msg, 0, NL80211_MCGRP_NAN, gfp);
11333 else
11334 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11335 wdev->owner_nlportid);
11336
11337 return;
11338
11339nla_put_failure:
11340 nlmsg_free(msg);
11341}
11342EXPORT_SYMBOL(cfg80211_nan_match);
11343
Ayala Beker368e5a72016-09-20 17:31:18 +030011344void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11345 u8 inst_id,
11346 enum nl80211_nan_func_term_reason reason,
11347 u64 cookie, gfp_t gfp)
11348{
11349 struct wiphy *wiphy = wdev->wiphy;
11350 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11351 struct sk_buff *msg;
11352 struct nlattr *func_attr;
11353 void *hdr;
11354
11355 if (WARN_ON(!inst_id))
11356 return;
11357
11358 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11359 if (!msg)
11360 return;
11361
11362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11363 if (!hdr) {
11364 nlmsg_free(msg);
11365 return;
11366 }
11367
11368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11369 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11370 wdev->netdev->ifindex)) ||
11371 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11372 NL80211_ATTR_PAD))
11373 goto nla_put_failure;
11374
11375 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11376 NL80211_ATTR_PAD))
11377 goto nla_put_failure;
11378
11379 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11380 if (!func_attr)
11381 goto nla_put_failure;
11382
11383 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11384 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11385 goto nla_put_failure;
11386
11387 nla_nest_end(msg, func_attr);
11388 genlmsg_end(msg, hdr);
11389
11390 if (!wdev->owner_nlportid)
11391 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11392 msg, 0, NL80211_MCGRP_NAN, gfp);
11393 else
11394 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11395 wdev->owner_nlportid);
11396
11397 return;
11398
11399nla_put_failure:
11400 nlmsg_free(msg);
11401}
11402EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11403
Johannes Berg3713b4e2013-02-14 16:19:38 +010011404static int nl80211_get_protocol_features(struct sk_buff *skb,
11405 struct genl_info *info)
11406{
11407 void *hdr;
11408 struct sk_buff *msg;
11409
11410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11411 if (!msg)
11412 return -ENOMEM;
11413
11414 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11415 NL80211_CMD_GET_PROTOCOL_FEATURES);
11416 if (!hdr)
11417 goto nla_put_failure;
11418
11419 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11420 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11421 goto nla_put_failure;
11422
11423 genlmsg_end(msg, hdr);
11424 return genlmsg_reply(msg, info);
11425
11426 nla_put_failure:
11427 kfree_skb(msg);
11428 return -ENOBUFS;
11429}
11430
Jouni Malinen355199e2013-02-27 17:14:27 +020011431static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11432{
11433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11434 struct cfg80211_update_ft_ies_params ft_params;
11435 struct net_device *dev = info->user_ptr[1];
11436
11437 if (!rdev->ops->update_ft_ies)
11438 return -EOPNOTSUPP;
11439
11440 if (!info->attrs[NL80211_ATTR_MDID] ||
Arunk Khandavalli1a648fb2018-08-21 14:20:20 +053011441 !info->attrs[NL80211_ATTR_IE] ||
Jouni Malinen355199e2013-02-27 17:14:27 +020011442 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11443 return -EINVAL;
11444
11445 memset(&ft_params, 0, sizeof(ft_params));
11446 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11447 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11448 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11449
11450 return rdev_update_ft_ies(rdev, dev, &ft_params);
11451}
11452
Arend van Spriel5de17982013-04-18 15:49:00 +020011453static int nl80211_crit_protocol_start(struct sk_buff *skb,
11454 struct genl_info *info)
11455{
11456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11457 struct wireless_dev *wdev = info->user_ptr[1];
11458 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11459 u16 duration;
11460 int ret;
11461
11462 if (!rdev->ops->crit_proto_start)
11463 return -EOPNOTSUPP;
11464
11465 if (WARN_ON(!rdev->ops->crit_proto_stop))
11466 return -EINVAL;
11467
11468 if (rdev->crit_proto_nlportid)
11469 return -EBUSY;
11470
11471 /* determine protocol if provided */
11472 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11473 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11474
11475 if (proto >= NUM_NL80211_CRIT_PROTO)
11476 return -EINVAL;
11477
11478 /* timeout must be provided */
11479 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11480 return -EINVAL;
11481
11482 duration =
11483 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11484
11485 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11486 return -ERANGE;
11487
11488 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11489 if (!ret)
11490 rdev->crit_proto_nlportid = info->snd_portid;
11491
11492 return ret;
11493}
11494
11495static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11496 struct genl_info *info)
11497{
11498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11499 struct wireless_dev *wdev = info->user_ptr[1];
11500
11501 if (!rdev->ops->crit_proto_stop)
11502 return -EOPNOTSUPP;
11503
11504 if (rdev->crit_proto_nlportid) {
11505 rdev->crit_proto_nlportid = 0;
11506 rdev_crit_proto_stop(rdev, wdev);
11507 }
11508 return 0;
11509}
11510
Johannes Bergad7e7182013-11-13 13:37:47 +010011511static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11512{
11513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11514 struct wireless_dev *wdev =
11515 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11516 int i, err;
11517 u32 vid, subcmd;
11518
11519 if (!rdev->wiphy.vendor_commands)
11520 return -EOPNOTSUPP;
11521
11522 if (IS_ERR(wdev)) {
11523 err = PTR_ERR(wdev);
11524 if (err != -EINVAL)
11525 return err;
11526 wdev = NULL;
11527 } else if (wdev->wiphy != &rdev->wiphy) {
11528 return -EINVAL;
11529 }
11530
11531 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11532 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11533 return -EINVAL;
11534
11535 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11536 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11537 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11538 const struct wiphy_vendor_command *vcmd;
11539 void *data = NULL;
11540 int len = 0;
11541
11542 vcmd = &rdev->wiphy.vendor_commands[i];
11543
11544 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11545 continue;
11546
11547 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11548 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11549 if (!wdev)
11550 return -EINVAL;
11551 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11552 !wdev->netdev)
11553 return -EINVAL;
11554
11555 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11556 if (wdev->netdev &&
11557 !netif_running(wdev->netdev))
11558 return -ENETDOWN;
11559 if (!wdev->netdev && !wdev->p2p_started)
11560 return -ENETDOWN;
11561 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011562
11563 if (!vcmd->doit)
11564 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011565 } else {
11566 wdev = NULL;
11567 }
11568
11569 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11570 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11571 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11572 }
11573
11574 rdev->cur_cmd_info = info;
11575 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11576 data, len);
11577 rdev->cur_cmd_info = NULL;
11578 return err;
11579 }
11580
11581 return -EOPNOTSUPP;
11582}
11583
Johannes Berg7bdbe402015-08-15 22:39:49 +030011584static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11585 struct netlink_callback *cb,
11586 struct cfg80211_registered_device **rdev,
11587 struct wireless_dev **wdev)
11588{
11589 u32 vid, subcmd;
11590 unsigned int i;
11591 int vcmd_idx = -1;
11592 int err;
11593 void *data = NULL;
11594 unsigned int data_len = 0;
11595
Johannes Berg7bdbe402015-08-15 22:39:49 +030011596 if (cb->args[0]) {
11597 /* subtract the 1 again here */
11598 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11599 struct wireless_dev *tmp;
11600
Johannes Berg56769e72017-03-15 14:26:04 +010011601 if (!wiphy)
11602 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011603 *rdev = wiphy_to_rdev(wiphy);
11604 *wdev = NULL;
11605
11606 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011607 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011608 if (tmp->identifier == cb->args[1] - 1) {
11609 *wdev = tmp;
11610 break;
11611 }
11612 }
11613 }
11614
11615 /* keep rtnl locked in successful case */
11616 return 0;
11617 }
11618
11619 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
11620 nl80211_fam.attrbuf, nl80211_fam.maxattr,
11621 nl80211_policy);
11622 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011623 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011624
11625 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg56769e72017-03-15 14:26:04 +010011626 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11627 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011628
11629 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
11630 nl80211_fam.attrbuf);
11631 if (IS_ERR(*wdev))
11632 *wdev = NULL;
11633
11634 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
11635 nl80211_fam.attrbuf);
Johannes Berg56769e72017-03-15 14:26:04 +010011636 if (IS_ERR(*rdev))
11637 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011638
11639 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
11640 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11641
11642 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11643 const struct wiphy_vendor_command *vcmd;
11644
11645 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11646
11647 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11648 continue;
11649
Johannes Berg56769e72017-03-15 14:26:04 +010011650 if (!vcmd->dumpit)
11651 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011652
11653 vcmd_idx = i;
11654 break;
11655 }
11656
Johannes Berg56769e72017-03-15 14:26:04 +010011657 if (vcmd_idx < 0)
11658 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011659
11660 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11661 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11662 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11663 }
11664
11665 /* 0 is the first index - add 1 to parse only once */
11666 cb->args[0] = (*rdev)->wiphy_idx + 1;
11667 /* add 1 to know if it was NULL */
11668 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11669 cb->args[2] = vcmd_idx;
11670 cb->args[3] = (unsigned long)data;
11671 cb->args[4] = data_len;
11672
11673 /* keep rtnl locked in successful case */
11674 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011675}
11676
11677static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11678 struct netlink_callback *cb)
11679{
11680 struct cfg80211_registered_device *rdev;
11681 struct wireless_dev *wdev;
11682 unsigned int vcmd_idx;
11683 const struct wiphy_vendor_command *vcmd;
11684 void *data;
11685 int data_len;
11686 int err;
11687 struct nlattr *vendor_data;
11688
Johannes Berg56769e72017-03-15 14:26:04 +010011689 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011690 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11691 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011692 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011693
11694 vcmd_idx = cb->args[2];
11695 data = (void *)cb->args[3];
11696 data_len = cb->args[4];
11697 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11698
11699 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11700 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Berg56769e72017-03-15 14:26:04 +010011701 if (!wdev) {
11702 err = -EINVAL;
11703 goto out;
11704 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011705 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Berg56769e72017-03-15 14:26:04 +010011706 !wdev->netdev) {
11707 err = -EINVAL;
11708 goto out;
11709 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011710
11711 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11712 if (wdev->netdev &&
Johannes Berg56769e72017-03-15 14:26:04 +010011713 !netif_running(wdev->netdev)) {
11714 err = -ENETDOWN;
11715 goto out;
11716 }
11717 if (!wdev->netdev && !wdev->p2p_started) {
11718 err = -ENETDOWN;
11719 goto out;
11720 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011721 }
11722 }
11723
11724 while (1) {
11725 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11727 NL80211_CMD_VENDOR);
11728 if (!hdr)
11729 break;
11730
11731 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011732 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11733 wdev_id(wdev),
11734 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011735 genlmsg_cancel(skb, hdr);
11736 break;
11737 }
11738
11739 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11740 if (!vendor_data) {
11741 genlmsg_cancel(skb, hdr);
11742 break;
11743 }
11744
11745 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11746 (unsigned long *)&cb->args[5]);
11747 nla_nest_end(skb, vendor_data);
11748
11749 if (err == -ENOBUFS || err == -ENOENT) {
11750 genlmsg_cancel(skb, hdr);
11751 break;
11752 } else if (err) {
11753 genlmsg_cancel(skb, hdr);
11754 goto out;
11755 }
11756
11757 genlmsg_end(skb, hdr);
11758 }
11759
11760 err = skb->len;
11761 out:
11762 rtnl_unlock();
11763 return err;
11764}
11765
Johannes Bergad7e7182013-11-13 13:37:47 +010011766struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11767 enum nl80211_commands cmd,
11768 enum nl80211_attrs attr,
11769 int approxlen)
11770{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011771 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011772
11773 if (WARN_ON(!rdev->cur_cmd_info))
11774 return NULL;
11775
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011776 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011777 rdev->cur_cmd_info->snd_portid,
11778 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011779 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011780}
11781EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11782
11783int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11784{
11785 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11786 void *hdr = ((void **)skb->cb)[1];
11787 struct nlattr *data = ((void **)skb->cb)[2];
11788
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011789 /* clear CB data for netlink core to own from now on */
11790 memset(skb->cb, 0, sizeof(skb->cb));
11791
Johannes Bergad7e7182013-11-13 13:37:47 +010011792 if (WARN_ON(!rdev->cur_cmd_info)) {
11793 kfree_skb(skb);
11794 return -EINVAL;
11795 }
11796
11797 nla_nest_end(skb, data);
11798 genlmsg_end(skb, hdr);
11799 return genlmsg_reply(skb, rdev->cur_cmd_info);
11800}
11801EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11802
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011803static int nl80211_set_qos_map(struct sk_buff *skb,
11804 struct genl_info *info)
11805{
11806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11807 struct cfg80211_qos_map *qos_map = NULL;
11808 struct net_device *dev = info->user_ptr[1];
11809 u8 *pos, len, num_des, des_len, des;
11810 int ret;
11811
11812 if (!rdev->ops->set_qos_map)
11813 return -EOPNOTSUPP;
11814
11815 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11816 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11817 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11818
11819 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11820 len > IEEE80211_QOS_MAP_LEN_MAX)
11821 return -EINVAL;
11822
11823 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11824 if (!qos_map)
11825 return -ENOMEM;
11826
11827 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11828 if (num_des) {
11829 des_len = num_des *
11830 sizeof(struct cfg80211_dscp_exception);
11831 memcpy(qos_map->dscp_exception, pos, des_len);
11832 qos_map->num_des = num_des;
11833 for (des = 0; des < num_des; des++) {
11834 if (qos_map->dscp_exception[des].up > 7) {
11835 kfree(qos_map);
11836 return -EINVAL;
11837 }
11838 }
11839 pos += des_len;
11840 }
11841 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11842 }
11843
11844 wdev_lock(dev->ieee80211_ptr);
11845 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11846 if (!ret)
11847 ret = rdev_set_qos_map(rdev, dev, qos_map);
11848 wdev_unlock(dev->ieee80211_ptr);
11849
11850 kfree(qos_map);
11851 return ret;
11852}
11853
Johannes Berg960d01a2014-09-09 22:55:35 +030011854static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11855{
11856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11857 struct net_device *dev = info->user_ptr[1];
11858 struct wireless_dev *wdev = dev->ieee80211_ptr;
11859 const u8 *peer;
11860 u8 tsid, up;
11861 u16 admitted_time = 0;
11862 int err;
11863
Johannes Berg723e73a2014-10-22 09:25:06 +020011864 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011865 return -EOPNOTSUPP;
11866
11867 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11868 !info->attrs[NL80211_ATTR_USER_PRIO])
11869 return -EINVAL;
11870
11871 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11872 if (tsid >= IEEE80211_NUM_TIDS)
11873 return -EINVAL;
11874
11875 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11876 if (up >= IEEE80211_NUM_UPS)
11877 return -EINVAL;
11878
11879 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011880 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011881 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011882 * need more attributes for that (e.g. BA session requirement);
11883 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011884 */
11885 return -EINVAL;
11886 }
11887
11888 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11889
11890 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11891 admitted_time =
11892 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11893 if (!admitted_time)
11894 return -EINVAL;
11895 }
11896
11897 wdev_lock(wdev);
11898 switch (wdev->iftype) {
11899 case NL80211_IFTYPE_STATION:
11900 case NL80211_IFTYPE_P2P_CLIENT:
11901 if (wdev->current_bss)
11902 break;
11903 err = -ENOTCONN;
11904 goto out;
11905 default:
11906 err = -EOPNOTSUPP;
11907 goto out;
11908 }
11909
11910 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11911
11912 out:
11913 wdev_unlock(wdev);
11914 return err;
11915}
11916
11917static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11918{
11919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11920 struct net_device *dev = info->user_ptr[1];
11921 struct wireless_dev *wdev = dev->ieee80211_ptr;
11922 const u8 *peer;
11923 u8 tsid;
11924 int err;
11925
11926 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11927 return -EINVAL;
11928
11929 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11930 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11931
11932 wdev_lock(wdev);
11933 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11934 wdev_unlock(wdev);
11935
11936 return err;
11937}
11938
Arik Nemtsov1057d352014-11-19 12:54:26 +020011939static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11940 struct genl_info *info)
11941{
11942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11943 struct net_device *dev = info->user_ptr[1];
11944 struct wireless_dev *wdev = dev->ieee80211_ptr;
11945 struct cfg80211_chan_def chandef = {};
11946 const u8 *addr;
11947 u8 oper_class;
11948 int err;
11949
11950 if (!rdev->ops->tdls_channel_switch ||
11951 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11952 return -EOPNOTSUPP;
11953
11954 switch (dev->ieee80211_ptr->iftype) {
11955 case NL80211_IFTYPE_STATION:
11956 case NL80211_IFTYPE_P2P_CLIENT:
11957 break;
11958 default:
11959 return -EOPNOTSUPP;
11960 }
11961
11962 if (!info->attrs[NL80211_ATTR_MAC] ||
11963 !info->attrs[NL80211_ATTR_OPER_CLASS])
11964 return -EINVAL;
11965
11966 err = nl80211_parse_chandef(rdev, info, &chandef);
11967 if (err)
11968 return err;
11969
11970 /*
11971 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11972 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11973 * specification is not defined for them.
11974 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011975 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011976 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11977 chandef.width != NL80211_CHAN_WIDTH_20)
11978 return -EINVAL;
11979
11980 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011981 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11982 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011983 return -EINVAL;
11984
11985 /* don't allow switching to DFS channels */
11986 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11987 return -EINVAL;
11988
11989 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11990 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11991
11992 wdev_lock(wdev);
11993 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11994 wdev_unlock(wdev);
11995
11996 return err;
11997}
11998
11999static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
12000 struct genl_info *info)
12001{
12002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12003 struct net_device *dev = info->user_ptr[1];
12004 struct wireless_dev *wdev = dev->ieee80211_ptr;
12005 const u8 *addr;
12006
12007 if (!rdev->ops->tdls_channel_switch ||
12008 !rdev->ops->tdls_cancel_channel_switch ||
12009 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12010 return -EOPNOTSUPP;
12011
12012 switch (dev->ieee80211_ptr->iftype) {
12013 case NL80211_IFTYPE_STATION:
12014 case NL80211_IFTYPE_P2P_CLIENT:
12015 break;
12016 default:
12017 return -EOPNOTSUPP;
12018 }
12019
12020 if (!info->attrs[NL80211_ATTR_MAC])
12021 return -EINVAL;
12022
12023 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12024
12025 wdev_lock(wdev);
12026 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12027 wdev_unlock(wdev);
12028
12029 return 0;
12030}
12031
Michael Braund757efc2016-10-10 19:12:22 +020012032static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12033 struct genl_info *info)
12034{
12035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12036 struct net_device *dev = info->user_ptr[1];
12037 struct wireless_dev *wdev = dev->ieee80211_ptr;
12038 const struct nlattr *nla;
12039 bool enabled;
12040
12041 if (netif_running(dev))
12042 return -EBUSY;
12043
12044 if (!rdev->ops->set_multicast_to_unicast)
12045 return -EOPNOTSUPP;
12046
12047 if (wdev->iftype != NL80211_IFTYPE_AP &&
12048 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12049 return -EOPNOTSUPP;
12050
12051 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12052 enabled = nla_get_flag(nla);
12053
12054 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12055}
12056
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053012057static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
12058{
12059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12060 struct net_device *dev = info->user_ptr[1];
12061 struct cfg80211_external_auth_params params;
12062
Srinivas Dasari05c8cd32018-02-02 11:15:27 +020012063 if (!rdev->ops->external_auth)
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053012064 return -EOPNOTSUPP;
12065
12066 if (!info->attrs[NL80211_ATTR_SSID])
12067 return -EINVAL;
12068
12069 if (!info->attrs[NL80211_ATTR_BSSID])
12070 return -EINVAL;
12071
12072 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
12073 return -EINVAL;
12074
12075 memset(&params, 0, sizeof(params));
12076
12077 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12078 if (params.ssid.ssid_len == 0 ||
12079 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
12080 return -EINVAL;
12081 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
12082 params.ssid.ssid_len);
12083
12084 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
12085 ETH_ALEN);
12086
12087 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12088
12089 return rdev_external_auth(rdev, dev, &params);
12090}
12091
Johannes Berg4c476992010-10-04 21:36:35 +020012092#define NL80211_FLAG_NEED_WIPHY 0x01
12093#define NL80211_FLAG_NEED_NETDEV 0x02
12094#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012095#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12096#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12097 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012098#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012099/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012100#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12101 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012102#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012103
Johannes Bergf84f7712013-11-14 17:14:45 +010012104static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012105 struct genl_info *info)
12106{
12107 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012108 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012109 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012110 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12111
12112 if (rtnl)
12113 rtnl_lock();
12114
12115 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012116 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012117 if (IS_ERR(rdev)) {
12118 if (rtnl)
12119 rtnl_unlock();
12120 return PTR_ERR(rdev);
12121 }
12122 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012123 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12124 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012125 ASSERT_RTNL();
12126
Johannes Berg89a54e42012-06-15 14:33:17 +020012127 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12128 info->attrs);
12129 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012130 if (rtnl)
12131 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012132 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012133 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012134
Johannes Berg89a54e42012-06-15 14:33:17 +020012135 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012136 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012137
Johannes Berg1bf614e2012-06-15 15:23:36 +020012138 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12139 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012140 if (rtnl)
12141 rtnl_unlock();
12142 return -EINVAL;
12143 }
12144
12145 info->user_ptr[1] = dev;
12146 } else {
12147 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012148 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012149
Johannes Berg1bf614e2012-06-15 15:23:36 +020012150 if (dev) {
12151 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12152 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012153 if (rtnl)
12154 rtnl_unlock();
12155 return -ENETDOWN;
12156 }
12157
12158 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012159 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012160 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
12161 !wdev->p2p_started) {
12162 if (rtnl)
12163 rtnl_unlock();
12164 return -ENETDOWN;
12165 }
12166 if (wdev->iftype == NL80211_IFTYPE_NAN &&
12167 !wdev->nan_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020012168 if (rtnl)
12169 rtnl_unlock();
12170 return -ENETDOWN;
12171 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020012172 }
12173
Johannes Berg4c476992010-10-04 21:36:35 +020012174 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012175 }
12176
12177 return 0;
12178}
12179
Johannes Bergf84f7712013-11-14 17:14:45 +010012180static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012181 struct genl_info *info)
12182{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012183 if (info->user_ptr[1]) {
12184 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12185 struct wireless_dev *wdev = info->user_ptr[1];
12186
12187 if (wdev->netdev)
12188 dev_put(wdev->netdev);
12189 } else {
12190 dev_put(info->user_ptr[1]);
12191 }
12192 }
Johannes Berg5393b912014-09-10 15:00:16 +030012193
Johannes Berg4c476992010-10-04 21:36:35 +020012194 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12195 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012196
12197 /* If needed, clear the netlink message payload from the SKB
12198 * as it might contain key data that shouldn't stick around on
12199 * the heap after the SKB is freed. The netlink message header
12200 * is still needed for further processing, so leave it intact.
12201 */
12202 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12203 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12204
12205 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12206 }
Johannes Berg4c476992010-10-04 21:36:35 +020012207}
12208
Johannes Berg4534de82013-11-14 17:14:46 +010012209static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012210 {
12211 .cmd = NL80211_CMD_GET_WIPHY,
12212 .doit = nl80211_get_wiphy,
12213 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012214 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012215 .policy = nl80211_policy,
12216 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012217 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12218 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012219 },
12220 {
12221 .cmd = NL80211_CMD_SET_WIPHY,
12222 .doit = nl80211_set_wiphy,
12223 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012224 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012225 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012226 },
12227 {
12228 .cmd = NL80211_CMD_GET_INTERFACE,
12229 .doit = nl80211_get_interface,
12230 .dumpit = nl80211_dump_interface,
12231 .policy = nl80211_policy,
12232 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012233 .internal_flags = NL80211_FLAG_NEED_WDEV |
12234 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012235 },
12236 {
12237 .cmd = NL80211_CMD_SET_INTERFACE,
12238 .doit = nl80211_set_interface,
12239 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012240 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012241 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12242 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012243 },
12244 {
12245 .cmd = NL80211_CMD_NEW_INTERFACE,
12246 .doit = nl80211_new_interface,
12247 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012248 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012249 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12250 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012251 },
12252 {
12253 .cmd = NL80211_CMD_DEL_INTERFACE,
12254 .doit = nl80211_del_interface,
12255 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012256 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012257 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012258 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012259 },
Johannes Berg41ade002007-12-19 02:03:29 +010012260 {
12261 .cmd = NL80211_CMD_GET_KEY,
12262 .doit = nl80211_get_key,
12263 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012264 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012266 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012267 },
12268 {
12269 .cmd = NL80211_CMD_SET_KEY,
12270 .doit = nl80211_set_key,
12271 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012272 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012273 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012274 NL80211_FLAG_NEED_RTNL |
12275 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012276 },
12277 {
12278 .cmd = NL80211_CMD_NEW_KEY,
12279 .doit = nl80211_new_key,
12280 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012281 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012283 NL80211_FLAG_NEED_RTNL |
12284 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012285 },
12286 {
12287 .cmd = NL80211_CMD_DEL_KEY,
12288 .doit = nl80211_del_key,
12289 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012290 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012291 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012292 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012293 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012294 {
12295 .cmd = NL80211_CMD_SET_BEACON,
12296 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012297 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012298 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012299 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012300 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012301 },
12302 {
Johannes Berg88600202012-02-13 15:17:18 +010012303 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012304 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012305 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012306 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012307 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012308 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012309 },
12310 {
Johannes Berg88600202012-02-13 15:17:18 +010012311 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012312 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012313 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012314 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012316 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012317 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012318 {
12319 .cmd = NL80211_CMD_GET_STATION,
12320 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012321 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012322 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012323 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12324 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012325 },
12326 {
12327 .cmd = NL80211_CMD_SET_STATION,
12328 .doit = nl80211_set_station,
12329 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012330 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012332 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012333 },
12334 {
12335 .cmd = NL80211_CMD_NEW_STATION,
12336 .doit = nl80211_new_station,
12337 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012338 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012339 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012340 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012341 },
12342 {
12343 .cmd = NL80211_CMD_DEL_STATION,
12344 .doit = nl80211_del_station,
12345 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012346 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012347 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012348 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012349 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012350 {
12351 .cmd = NL80211_CMD_GET_MPATH,
12352 .doit = nl80211_get_mpath,
12353 .dumpit = nl80211_dump_mpath,
12354 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012355 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012357 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012358 },
12359 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012360 .cmd = NL80211_CMD_GET_MPP,
12361 .doit = nl80211_get_mpp,
12362 .dumpit = nl80211_dump_mpp,
12363 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012364 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12366 NL80211_FLAG_NEED_RTNL,
12367 },
12368 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012369 .cmd = NL80211_CMD_SET_MPATH,
12370 .doit = nl80211_set_mpath,
12371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012372 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012374 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012375 },
12376 {
12377 .cmd = NL80211_CMD_NEW_MPATH,
12378 .doit = nl80211_new_mpath,
12379 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012380 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012382 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012383 },
12384 {
12385 .cmd = NL80211_CMD_DEL_MPATH,
12386 .doit = nl80211_del_mpath,
12387 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012388 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012390 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012391 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012392 {
12393 .cmd = NL80211_CMD_SET_BSS,
12394 .doit = nl80211_set_bss,
12395 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012396 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012398 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012399 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012400 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012401 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012402 .doit = nl80211_get_reg_do,
12403 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012404 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012405 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012406 /* can be retrieved by unprivileged users */
12407 },
Johannes Bergb6863032015-10-15 09:25:18 +020012408#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012409 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012410 .cmd = NL80211_CMD_SET_REG,
12411 .doit = nl80211_set_reg,
12412 .policy = nl80211_policy,
12413 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012414 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012415 },
Johannes Bergb6863032015-10-15 09:25:18 +020012416#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012417 {
12418 .cmd = NL80211_CMD_REQ_SET_REG,
12419 .doit = nl80211_req_set_reg,
12420 .policy = nl80211_policy,
12421 .flags = GENL_ADMIN_PERM,
12422 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012423 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012424 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12425 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012426 .policy = nl80211_policy,
12427 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012429 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012430 },
12431 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012432 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12433 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012434 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012435 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012437 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012438 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012439 {
Johannes Berg2a519312009-02-10 21:25:55 +010012440 .cmd = NL80211_CMD_TRIGGER_SCAN,
12441 .doit = nl80211_trigger_scan,
12442 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012443 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012444 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012445 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012446 },
12447 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012448 .cmd = NL80211_CMD_ABORT_SCAN,
12449 .doit = nl80211_abort_scan,
12450 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012451 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012452 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12453 NL80211_FLAG_NEED_RTNL,
12454 },
12455 {
Johannes Berg2a519312009-02-10 21:25:55 +010012456 .cmd = NL80211_CMD_GET_SCAN,
12457 .policy = nl80211_policy,
12458 .dumpit = nl80211_dump_scan,
12459 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012460 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012461 .cmd = NL80211_CMD_START_SCHED_SCAN,
12462 .doit = nl80211_start_sched_scan,
12463 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012464 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12466 NL80211_FLAG_NEED_RTNL,
12467 },
12468 {
12469 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12470 .doit = nl80211_stop_sched_scan,
12471 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012472 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12474 NL80211_FLAG_NEED_RTNL,
12475 },
12476 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012477 .cmd = NL80211_CMD_AUTHENTICATE,
12478 .doit = nl80211_authenticate,
12479 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012480 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012482 NL80211_FLAG_NEED_RTNL |
12483 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012484 },
12485 {
12486 .cmd = NL80211_CMD_ASSOCIATE,
12487 .doit = nl80211_associate,
12488 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012489 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012490 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012491 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012492 },
12493 {
12494 .cmd = NL80211_CMD_DEAUTHENTICATE,
12495 .doit = nl80211_deauthenticate,
12496 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012497 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012498 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012499 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012500 },
12501 {
12502 .cmd = NL80211_CMD_DISASSOCIATE,
12503 .doit = nl80211_disassociate,
12504 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012505 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012507 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012508 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012509 {
12510 .cmd = NL80211_CMD_JOIN_IBSS,
12511 .doit = nl80211_join_ibss,
12512 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012513 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012515 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012516 },
12517 {
12518 .cmd = NL80211_CMD_LEAVE_IBSS,
12519 .doit = nl80211_leave_ibss,
12520 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012521 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012523 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012524 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012525#ifdef CONFIG_NL80211_TESTMODE
12526 {
12527 .cmd = NL80211_CMD_TESTMODE,
12528 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012529 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012530 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012531 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012532 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12533 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012534 },
12535#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012536 {
12537 .cmd = NL80211_CMD_CONNECT,
12538 .doit = nl80211_connect,
12539 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012540 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012542 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012543 },
12544 {
vamsi krishna30da4e82016-10-27 16:51:11 +030012545 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12546 .doit = nl80211_update_connect_params,
12547 .policy = nl80211_policy,
12548 .flags = GENL_ADMIN_PERM,
12549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12550 NL80211_FLAG_NEED_RTNL,
12551 },
12552 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012553 .cmd = NL80211_CMD_DISCONNECT,
12554 .doit = nl80211_disconnect,
12555 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012556 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012557 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012558 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012559 },
Johannes Berg463d0182009-07-14 00:33:35 +020012560 {
12561 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12562 .doit = nl80211_wiphy_netns,
12563 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012564 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012565 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12566 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012567 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012568 {
12569 .cmd = NL80211_CMD_GET_SURVEY,
12570 .policy = nl80211_policy,
12571 .dumpit = nl80211_dump_survey,
12572 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012573 {
12574 .cmd = NL80211_CMD_SET_PMKSA,
12575 .doit = nl80211_setdel_pmksa,
12576 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012577 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012579 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012580 },
12581 {
12582 .cmd = NL80211_CMD_DEL_PMKSA,
12583 .doit = nl80211_setdel_pmksa,
12584 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012585 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012587 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012588 },
12589 {
12590 .cmd = NL80211_CMD_FLUSH_PMKSA,
12591 .doit = nl80211_flush_pmksa,
12592 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012593 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012595 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012596 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012597 {
12598 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12599 .doit = nl80211_remain_on_channel,
12600 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012601 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012602 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012603 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012604 },
12605 {
12606 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12607 .doit = nl80211_cancel_remain_on_channel,
12608 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012609 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012610 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012611 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012612 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012613 {
12614 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12615 .doit = nl80211_set_tx_bitrate_mask,
12616 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012617 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012618 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12619 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012620 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012621 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012622 .cmd = NL80211_CMD_REGISTER_FRAME,
12623 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012624 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012625 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012626 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012627 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012628 },
12629 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012630 .cmd = NL80211_CMD_FRAME,
12631 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012632 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012633 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012634 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012635 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012636 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012637 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012638 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12639 .doit = nl80211_tx_mgmt_cancel_wait,
12640 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012641 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012642 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012643 NL80211_FLAG_NEED_RTNL,
12644 },
12645 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012646 .cmd = NL80211_CMD_SET_POWER_SAVE,
12647 .doit = nl80211_set_power_save,
12648 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012649 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012650 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12651 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012652 },
12653 {
12654 .cmd = NL80211_CMD_GET_POWER_SAVE,
12655 .doit = nl80211_get_power_save,
12656 .policy = nl80211_policy,
12657 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012658 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12659 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012660 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012661 {
12662 .cmd = NL80211_CMD_SET_CQM,
12663 .doit = nl80211_set_cqm,
12664 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012665 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012666 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12667 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012668 },
Johannes Bergf444de02010-05-05 15:25:02 +020012669 {
12670 .cmd = NL80211_CMD_SET_CHANNEL,
12671 .doit = nl80211_set_channel,
12672 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012673 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012674 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12675 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012676 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012677 {
12678 .cmd = NL80211_CMD_SET_WDS_PEER,
12679 .doit = nl80211_set_wds_peer,
12680 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012681 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012682 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12683 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012684 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012685 {
12686 .cmd = NL80211_CMD_JOIN_MESH,
12687 .doit = nl80211_join_mesh,
12688 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012689 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12691 NL80211_FLAG_NEED_RTNL,
12692 },
12693 {
12694 .cmd = NL80211_CMD_LEAVE_MESH,
12695 .doit = nl80211_leave_mesh,
12696 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012697 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12699 NL80211_FLAG_NEED_RTNL,
12700 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012701 {
12702 .cmd = NL80211_CMD_JOIN_OCB,
12703 .doit = nl80211_join_ocb,
12704 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012705 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12707 NL80211_FLAG_NEED_RTNL,
12708 },
12709 {
12710 .cmd = NL80211_CMD_LEAVE_OCB,
12711 .doit = nl80211_leave_ocb,
12712 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012713 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012714 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12715 NL80211_FLAG_NEED_RTNL,
12716 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012717#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012718 {
12719 .cmd = NL80211_CMD_GET_WOWLAN,
12720 .doit = nl80211_get_wowlan,
12721 .policy = nl80211_policy,
12722 /* can be retrieved by unprivileged users */
12723 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12724 NL80211_FLAG_NEED_RTNL,
12725 },
12726 {
12727 .cmd = NL80211_CMD_SET_WOWLAN,
12728 .doit = nl80211_set_wowlan,
12729 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012730 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012731 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12732 NL80211_FLAG_NEED_RTNL,
12733 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012734#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012735 {
12736 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12737 .doit = nl80211_set_rekey_data,
12738 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012739 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012741 NL80211_FLAG_NEED_RTNL |
12742 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012743 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012744 {
12745 .cmd = NL80211_CMD_TDLS_MGMT,
12746 .doit = nl80211_tdls_mgmt,
12747 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012748 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012749 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12750 NL80211_FLAG_NEED_RTNL,
12751 },
12752 {
12753 .cmd = NL80211_CMD_TDLS_OPER,
12754 .doit = nl80211_tdls_oper,
12755 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012756 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12758 NL80211_FLAG_NEED_RTNL,
12759 },
Johannes Berg28946da2011-11-04 11:18:12 +010012760 {
12761 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12762 .doit = nl80211_register_unexpected_frame,
12763 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012764 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012765 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12766 NL80211_FLAG_NEED_RTNL,
12767 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012768 {
12769 .cmd = NL80211_CMD_PROBE_CLIENT,
12770 .doit = nl80211_probe_client,
12771 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012772 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012774 NL80211_FLAG_NEED_RTNL,
12775 },
Johannes Berg5e7602302011-11-04 11:18:17 +010012776 {
12777 .cmd = NL80211_CMD_REGISTER_BEACONS,
12778 .doit = nl80211_register_beacons,
12779 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012780 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010012781 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12782 NL80211_FLAG_NEED_RTNL,
12783 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012784 {
12785 .cmd = NL80211_CMD_SET_NOACK_MAP,
12786 .doit = nl80211_set_noack_map,
12787 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012788 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012789 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12790 NL80211_FLAG_NEED_RTNL,
12791 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012792 {
12793 .cmd = NL80211_CMD_START_P2P_DEVICE,
12794 .doit = nl80211_start_p2p_device,
12795 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012796 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012797 .internal_flags = NL80211_FLAG_NEED_WDEV |
12798 NL80211_FLAG_NEED_RTNL,
12799 },
12800 {
12801 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12802 .doit = nl80211_stop_p2p_device,
12803 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012804 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012805 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12806 NL80211_FLAG_NEED_RTNL,
12807 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012808 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012809 .cmd = NL80211_CMD_START_NAN,
12810 .doit = nl80211_start_nan,
12811 .policy = nl80211_policy,
12812 .flags = GENL_ADMIN_PERM,
12813 .internal_flags = NL80211_FLAG_NEED_WDEV |
12814 NL80211_FLAG_NEED_RTNL,
12815 },
12816 {
12817 .cmd = NL80211_CMD_STOP_NAN,
12818 .doit = nl80211_stop_nan,
12819 .policy = nl80211_policy,
12820 .flags = GENL_ADMIN_PERM,
12821 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12822 NL80211_FLAG_NEED_RTNL,
12823 },
12824 {
Ayala Bekera442b762016-09-20 17:31:15 +030012825 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12826 .doit = nl80211_nan_add_func,
12827 .policy = nl80211_policy,
12828 .flags = GENL_ADMIN_PERM,
12829 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12830 NL80211_FLAG_NEED_RTNL,
12831 },
12832 {
12833 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12834 .doit = nl80211_nan_del_func,
12835 .policy = nl80211_policy,
12836 .flags = GENL_ADMIN_PERM,
12837 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12838 NL80211_FLAG_NEED_RTNL,
12839 },
12840 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012841 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12842 .doit = nl80211_nan_change_config,
12843 .policy = nl80211_policy,
12844 .flags = GENL_ADMIN_PERM,
12845 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12846 NL80211_FLAG_NEED_RTNL,
12847 },
12848 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012849 .cmd = NL80211_CMD_SET_MCAST_RATE,
12850 .doit = nl80211_set_mcast_rate,
12851 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012852 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012853 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12854 NL80211_FLAG_NEED_RTNL,
12855 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012856 {
12857 .cmd = NL80211_CMD_SET_MAC_ACL,
12858 .doit = nl80211_set_mac_acl,
12859 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012860 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012861 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12862 NL80211_FLAG_NEED_RTNL,
12863 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012864 {
12865 .cmd = NL80211_CMD_RADAR_DETECT,
12866 .doit = nl80211_start_radar_detection,
12867 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012868 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12870 NL80211_FLAG_NEED_RTNL,
12871 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012872 {
12873 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12874 .doit = nl80211_get_protocol_features,
12875 .policy = nl80211_policy,
12876 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012877 {
12878 .cmd = NL80211_CMD_UPDATE_FT_IES,
12879 .doit = nl80211_update_ft_ies,
12880 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012881 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12883 NL80211_FLAG_NEED_RTNL,
12884 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012885 {
12886 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12887 .doit = nl80211_crit_protocol_start,
12888 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012889 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012890 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12891 NL80211_FLAG_NEED_RTNL,
12892 },
12893 {
12894 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12895 .doit = nl80211_crit_protocol_stop,
12896 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012897 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012898 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12899 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012900 },
12901 {
12902 .cmd = NL80211_CMD_GET_COALESCE,
12903 .doit = nl80211_get_coalesce,
12904 .policy = nl80211_policy,
12905 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12906 NL80211_FLAG_NEED_RTNL,
12907 },
12908 {
12909 .cmd = NL80211_CMD_SET_COALESCE,
12910 .doit = nl80211_set_coalesce,
12911 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012912 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012913 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12914 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012915 },
12916 {
12917 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12918 .doit = nl80211_channel_switch,
12919 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012920 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12922 NL80211_FLAG_NEED_RTNL,
12923 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012924 {
12925 .cmd = NL80211_CMD_VENDOR,
12926 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012927 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012928 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012929 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012930 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12931 NL80211_FLAG_NEED_RTNL,
12932 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012933 {
12934 .cmd = NL80211_CMD_SET_QOS_MAP,
12935 .doit = nl80211_set_qos_map,
12936 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012937 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012938 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12939 NL80211_FLAG_NEED_RTNL,
12940 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012941 {
12942 .cmd = NL80211_CMD_ADD_TX_TS,
12943 .doit = nl80211_add_tx_ts,
12944 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012945 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012946 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12947 NL80211_FLAG_NEED_RTNL,
12948 },
12949 {
12950 .cmd = NL80211_CMD_DEL_TX_TS,
12951 .doit = nl80211_del_tx_ts,
12952 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012953 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012954 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12955 NL80211_FLAG_NEED_RTNL,
12956 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012957 {
12958 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12959 .doit = nl80211_tdls_channel_switch,
12960 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012961 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012962 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12963 NL80211_FLAG_NEED_RTNL,
12964 },
12965 {
12966 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12967 .doit = nl80211_tdls_cancel_channel_switch,
12968 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012969 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12971 NL80211_FLAG_NEED_RTNL,
12972 },
Michael Braund757efc2016-10-10 19:12:22 +020012973 {
12974 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
12975 .doit = nl80211_set_multicast_to_unicast,
12976 .policy = nl80211_policy,
12977 .flags = GENL_UNS_ADMIN_PERM,
12978 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12979 NL80211_FLAG_NEED_RTNL,
12980 },
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053012981 {
12982 .cmd = NL80211_CMD_EXTERNAL_AUTH,
12983 .doit = nl80211_external_auth,
12984 .policy = nl80211_policy,
12985 .flags = GENL_ADMIN_PERM,
12986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12987 NL80211_FLAG_NEED_RTNL,
12988 },
Johannes Berg55682962007-09-20 13:09:35 -040012989};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012990
Johannes Berg55682962007-09-20 13:09:35 -040012991/* notification functions */
12992
Johannes Berg3bb20552014-05-26 13:52:25 +020012993void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12994 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012995{
12996 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012997 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012998
Johannes Berg3bb20552014-05-26 13:52:25 +020012999 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
13000 cmd != NL80211_CMD_DEL_WIPHY);
13001
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013003 if (!msg)
13004 return;
13005
Johannes Berg3bb20552014-05-26 13:52:25 +020013006 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013007 nlmsg_free(msg);
13008 return;
13009 }
13010
Johannes Berg68eb5502013-11-19 15:19:38 +010013011 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013012 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013013}
13014
Denis Kenzior896ff062016-08-03 16:58:33 -050013015void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13016 struct wireless_dev *wdev,
13017 enum nl80211_commands cmd)
13018{
13019 struct sk_buff *msg;
13020
13021 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13022 cmd != NL80211_CMD_DEL_INTERFACE);
13023
13024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13025 if (!msg)
13026 return;
13027
13028 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13029 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13030 nlmsg_free(msg);
13031 return;
13032 }
13033
13034 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13035 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13036}
13037
Johannes Berg362a4152009-05-24 16:43:15 +020013038static int nl80211_add_scan_req(struct sk_buff *msg,
13039 struct cfg80211_registered_device *rdev)
13040{
13041 struct cfg80211_scan_request *req = rdev->scan_req;
13042 struct nlattr *nest;
13043 int i;
13044
13045 if (WARN_ON(!req))
13046 return 0;
13047
13048 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13049 if (!nest)
13050 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013051 for (i = 0; i < req->n_ssids; i++) {
13052 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13053 goto nla_put_failure;
13054 }
Johannes Berg362a4152009-05-24 16:43:15 +020013055 nla_nest_end(msg, nest);
13056
13057 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13058 if (!nest)
13059 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013060 for (i = 0; i < req->n_channels; i++) {
13061 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13062 goto nla_put_failure;
13063 }
Johannes Berg362a4152009-05-24 16:43:15 +020013064 nla_nest_end(msg, nest);
13065
David S. Miller9360ffd2012-03-29 04:41:26 -040013066 if (req->ie &&
13067 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13068 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013069
Johannes Bergae917c92013-10-25 11:05:22 +020013070 if (req->flags &&
13071 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13072 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013073
Avraham Stern1d762502016-07-05 17:10:13 +030013074 if (req->info.scan_start_tsf &&
13075 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13076 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13077 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13078 req->info.tsf_bssid)))
13079 goto nla_put_failure;
13080
Johannes Berg362a4152009-05-24 16:43:15 +020013081 return 0;
13082 nla_put_failure:
13083 return -ENOBUFS;
13084}
13085
Johannes Berga538e2d2009-06-16 19:56:42 +020013086static int nl80211_send_scan_msg(struct sk_buff *msg,
13087 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013088 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013089 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013090 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013091{
13092 void *hdr;
13093
Eric W. Biederman15e47302012-09-07 20:12:54 +000013094 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013095 if (!hdr)
13096 return -1;
13097
David S. Miller9360ffd2012-03-29 04:41:26 -040013098 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013099 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13100 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013101 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13102 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013103 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013104
Johannes Berg362a4152009-05-24 16:43:15 +020013105 /* ignore errors and send incomplete event anyway */
13106 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013107
Johannes Berg053c0952015-01-16 22:09:00 +010013108 genlmsg_end(msg, hdr);
13109 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013110
13111 nla_put_failure:
13112 genlmsg_cancel(msg, hdr);
13113 return -EMSGSIZE;
13114}
13115
Luciano Coelho807f8a82011-05-11 17:09:35 +030013116static int
13117nl80211_send_sched_scan_msg(struct sk_buff *msg,
13118 struct cfg80211_registered_device *rdev,
13119 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013120 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013121{
13122 void *hdr;
13123
Eric W. Biederman15e47302012-09-07 20:12:54 +000013124 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013125 if (!hdr)
13126 return -1;
13127
David S. Miller9360ffd2012-03-29 04:41:26 -040013128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13129 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13130 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013131
Johannes Berg053c0952015-01-16 22:09:00 +010013132 genlmsg_end(msg, hdr);
13133 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013134
13135 nla_put_failure:
13136 genlmsg_cancel(msg, hdr);
13137 return -EMSGSIZE;
13138}
13139
Johannes Berga538e2d2009-06-16 19:56:42 +020013140void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013141 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013142{
13143 struct sk_buff *msg;
13144
Thomas Graf58050fc2012-06-28 03:57:45 +000013145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013146 if (!msg)
13147 return;
13148
Johannes Bergfd014282012-06-18 19:17:03 +020013149 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013150 NL80211_CMD_TRIGGER_SCAN) < 0) {
13151 nlmsg_free(msg);
13152 return;
13153 }
13154
Johannes Berg68eb5502013-11-19 15:19:38 +010013155 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013156 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013157}
13158
Johannes Bergf9d15d12014-01-22 11:14:19 +020013159struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13160 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013161{
13162 struct sk_buff *msg;
13163
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013165 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013166 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013167
Johannes Bergfd014282012-06-18 19:17:03 +020013168 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013169 aborted ? NL80211_CMD_SCAN_ABORTED :
13170 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013171 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013172 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013173 }
13174
Johannes Bergf9d15d12014-01-22 11:14:19 +020013175 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013176}
13177
Johannes Bergf9d15d12014-01-22 11:14:19 +020013178void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
13179 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013180{
Johannes Berg2a519312009-02-10 21:25:55 +010013181 if (!msg)
13182 return;
13183
Johannes Berg68eb5502013-11-19 15:19:38 +010013184 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013185 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013186}
13187
Luciano Coelho807f8a82011-05-11 17:09:35 +030013188void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
13189 struct net_device *netdev)
13190{
13191 struct sk_buff *msg;
13192
13193 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13194 if (!msg)
13195 return;
13196
13197 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
13198 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
13199 nlmsg_free(msg);
13200 return;
13201 }
13202
Johannes Berg68eb5502013-11-19 15:19:38 +010013203 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013204 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013205}
13206
13207void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
13208 struct net_device *netdev, u32 cmd)
13209{
13210 struct sk_buff *msg;
13211
Thomas Graf58050fc2012-06-28 03:57:45 +000013212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013213 if (!msg)
13214 return;
13215
13216 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
13217 nlmsg_free(msg);
13218 return;
13219 }
13220
Johannes Berg68eb5502013-11-19 15:19:38 +010013221 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013222 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013223}
13224
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013225static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13226 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013227{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013228 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013229 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13230 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013231
David S. Miller9360ffd2012-03-29 04:41:26 -040013232 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13233 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13234 NL80211_REGDOM_TYPE_WORLD))
13235 goto nla_put_failure;
13236 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13237 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13238 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13239 goto nla_put_failure;
13240 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13241 request->intersect) {
13242 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13243 NL80211_REGDOM_TYPE_INTERSECTION))
13244 goto nla_put_failure;
13245 } else {
13246 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13247 NL80211_REGDOM_TYPE_COUNTRY) ||
13248 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13249 request->alpha2))
13250 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013251 }
13252
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013253 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13254 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13255
13256 if (wiphy &&
13257 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13258 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013259
13260 if (wiphy &&
13261 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13262 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13263 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013264 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013265
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013266 return true;
13267
13268nla_put_failure:
13269 return false;
13270}
13271
13272/*
13273 * This can happen on global regulatory changes or device specific settings
13274 * based on custom regulatory domains.
13275 */
13276void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13277 struct regulatory_request *request)
13278{
13279 struct sk_buff *msg;
13280 void *hdr;
13281
13282 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13283 if (!msg)
13284 return;
13285
13286 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13287 if (!hdr) {
13288 nlmsg_free(msg);
13289 return;
13290 }
13291
13292 if (nl80211_reg_change_event_fill(msg, request) == false)
13293 goto nla_put_failure;
13294
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013295 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013296
Johannes Bergbc43b282009-07-25 10:54:13 +020013297 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013298 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013299 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013300 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013301
13302 return;
13303
13304nla_put_failure:
13305 genlmsg_cancel(msg, hdr);
13306 nlmsg_free(msg);
13307}
13308
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013309static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13310 struct net_device *netdev,
13311 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013312 enum nl80211_commands cmd, gfp_t gfp,
13313 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013314{
13315 struct sk_buff *msg;
13316 void *hdr;
13317
Johannes Berg14459722017-01-09 11:10:42 +010013318 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013319 if (!msg)
13320 return;
13321
13322 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13323 if (!hdr) {
13324 nlmsg_free(msg);
13325 return;
13326 }
13327
David S. Miller9360ffd2012-03-29 04:41:26 -040013328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13330 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13331 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013332
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013333 if (uapsd_queues >= 0) {
13334 struct nlattr *nla_wmm =
13335 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13336 if (!nla_wmm)
13337 goto nla_put_failure;
13338
13339 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13340 uapsd_queues))
13341 goto nla_put_failure;
13342
13343 nla_nest_end(msg, nla_wmm);
13344 }
13345
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013346 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013347
Johannes Berg68eb5502013-11-19 15:19:38 +010013348 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013349 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013350 return;
13351
13352 nla_put_failure:
13353 genlmsg_cancel(msg, hdr);
13354 nlmsg_free(msg);
13355}
13356
13357void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013358 struct net_device *netdev, const u8 *buf,
13359 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013360{
13361 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013362 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013363}
13364
13365void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13366 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013367 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013368{
Johannes Berge6d6e342009-07-01 21:26:47 +020013369 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013370 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013371}
13372
Jouni Malinen53b46b82009-03-27 20:53:56 +020013373void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013374 struct net_device *netdev, const u8 *buf,
13375 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013376{
13377 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013378 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013379}
13380
Jouni Malinen53b46b82009-03-27 20:53:56 +020013381void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13382 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013383 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013384{
13385 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013386 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013387}
13388
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013389void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13390 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013391{
Johannes Berg947add32013-02-22 22:05:20 +010013392 struct wireless_dev *wdev = dev->ieee80211_ptr;
13393 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013394 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013395 const struct ieee80211_mgmt *mgmt = (void *)buf;
13396 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013397
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013398 if (WARN_ON(len < 2))
13399 return;
13400
13401 if (ieee80211_is_deauth(mgmt->frame_control))
13402 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13403 else
13404 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13405
13406 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013407 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013408}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013409EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013410
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013411static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13412 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013413 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013414{
13415 struct sk_buff *msg;
13416 void *hdr;
13417
Johannes Berge6d6e342009-07-01 21:26:47 +020013418 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013419 if (!msg)
13420 return;
13421
13422 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13423 if (!hdr) {
13424 nlmsg_free(msg);
13425 return;
13426 }
13427
David S. Miller9360ffd2012-03-29 04:41:26 -040013428 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13429 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13430 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13431 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13432 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013433
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013434 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013435
Johannes Berg68eb5502013-11-19 15:19:38 +010013436 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013437 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013438 return;
13439
13440 nla_put_failure:
13441 genlmsg_cancel(msg, hdr);
13442 nlmsg_free(msg);
13443}
13444
13445void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013446 struct net_device *netdev, const u8 *addr,
13447 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013448{
13449 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013450 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013451}
13452
13453void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013454 struct net_device *netdev, const u8 *addr,
13455 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013456{
Johannes Berge6d6e342009-07-01 21:26:47 +020013457 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13458 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013459}
13460
Samuel Ortizb23aa672009-07-01 21:26:54 +020013461void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013462 struct net_device *netdev,
13463 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwahadf935062017-01-13 01:12:21 +020013464 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013465{
13466 struct sk_buff *msg;
13467 void *hdr;
13468
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +030013469 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13470 cr->fils_kek_len + cr->pmk_len +
13471 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013472 if (!msg)
13473 return;
13474
13475 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13476 if (!hdr) {
13477 nlmsg_free(msg);
13478 return;
13479 }
13480
David S. Miller9360ffd2012-03-29 04:41:26 -040013481 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13482 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013483 (cr->bssid &&
13484 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013485 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013486 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13487 cr->status) ||
13488 (cr->status < 0 &&
Purushottam Kushwahadf935062017-01-13 01:12:21 +020013489 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013490 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13491 cr->timeout_reason))) ||
13492 (cr->req_ie &&
13493 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13494 (cr->resp_ie &&
13495 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +030013496 cr->resp_ie)) ||
13497 (cr->update_erp_next_seq_num &&
13498 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13499 cr->fils_erp_next_seq_num)) ||
13500 (cr->status == WLAN_STATUS_SUCCESS &&
13501 ((cr->fils_kek &&
13502 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13503 cr->fils_kek)) ||
13504 (cr->pmk &&
13505 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13506 (cr->pmkid &&
13507 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013508 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013509
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013510 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013511
Johannes Berg68eb5502013-11-19 15:19:38 +010013512 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013513 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013514 return;
13515
13516 nla_put_failure:
13517 genlmsg_cancel(msg, hdr);
13518 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013519}
13520
13521void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern9e841a62017-04-26 10:58:49 +030013522 struct net_device *netdev,
13523 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013524{
13525 struct sk_buff *msg;
13526 void *hdr;
Avraham Stern9e841a62017-04-26 10:58:49 +030013527 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013528
Avraham Stern9e841a62017-04-26 10:58:49 +030013529 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013530 if (!msg)
13531 return;
13532
13533 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13534 if (!hdr) {
13535 nlmsg_free(msg);
13536 return;
13537 }
13538
David S. Miller9360ffd2012-03-29 04:41:26 -040013539 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13540 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13541 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern9e841a62017-04-26 10:58:49 +030013542 (info->req_ie &&
13543 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13544 info->req_ie)) ||
13545 (info->resp_ie &&
13546 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern562be6e2017-06-09 13:08:45 +010013547 info->resp_ie)) ||
13548 (info->authorized &&
13549 nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013550 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013551
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013552 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013553
Johannes Berg68eb5502013-11-19 15:19:38 +010013554 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013555 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013556 return;
13557
13558 nla_put_failure:
13559 genlmsg_cancel(msg, hdr);
13560 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013561}
13562
13563void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13564 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020013565 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013566{
13567 struct sk_buff *msg;
13568 void *hdr;
13569
Johannes Berg14459722017-01-09 11:10:42 +010013570 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013571 if (!msg)
13572 return;
13573
13574 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13575 if (!hdr) {
13576 nlmsg_free(msg);
13577 return;
13578 }
13579
David S. Miller9360ffd2012-03-29 04:41:26 -040013580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13581 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13582 (from_ap && reason &&
13583 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13584 (from_ap &&
13585 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13586 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13587 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013588
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013589 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013590
Johannes Berg68eb5502013-11-19 15:19:38 +010013591 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013592 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013593 return;
13594
13595 nla_put_failure:
13596 genlmsg_cancel(msg, hdr);
13597 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013598}
13599
Johannes Berg04a773a2009-04-19 21:24:32 +020013600void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13601 struct net_device *netdev, const u8 *bssid,
13602 gfp_t gfp)
13603{
13604 struct sk_buff *msg;
13605 void *hdr;
13606
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013608 if (!msg)
13609 return;
13610
13611 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13612 if (!hdr) {
13613 nlmsg_free(msg);
13614 return;
13615 }
13616
David S. Miller9360ffd2012-03-29 04:41:26 -040013617 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13618 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13620 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013621
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013622 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013623
Johannes Berg68eb5502013-11-19 15:19:38 +010013624 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013625 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013626 return;
13627
13628 nla_put_failure:
13629 genlmsg_cancel(msg, hdr);
13630 nlmsg_free(msg);
13631}
13632
Johannes Berg947add32013-02-22 22:05:20 +010013633void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13634 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013635{
Johannes Berg947add32013-02-22 22:05:20 +010013636 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013637 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013638 struct sk_buff *msg;
13639 void *hdr;
13640
Johannes Berg947add32013-02-22 22:05:20 +010013641 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13642 return;
13643
13644 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13645
Johannes Berg14459722017-01-09 11:10:42 +010013646 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013647 if (!msg)
13648 return;
13649
13650 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13651 if (!hdr) {
13652 nlmsg_free(msg);
13653 return;
13654 }
13655
David S. Miller9360ffd2012-03-29 04:41:26 -040013656 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013657 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13658 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013659 (ie_len && ie &&
13660 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13661 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013662
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013663 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013664
Johannes Berg68eb5502013-11-19 15:19:38 +010013665 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013666 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013667 return;
13668
13669 nla_put_failure:
13670 genlmsg_cancel(msg, hdr);
13671 nlmsg_free(msg);
13672}
Johannes Berg947add32013-02-22 22:05:20 +010013673EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013674
Jouni Malinena3b8b052009-03-27 21:59:49 +020013675void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13676 struct net_device *netdev, const u8 *addr,
13677 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013678 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013679{
13680 struct sk_buff *msg;
13681 void *hdr;
13682
Johannes Berge6d6e342009-07-01 21:26:47 +020013683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013684 if (!msg)
13685 return;
13686
13687 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13688 if (!hdr) {
13689 nlmsg_free(msg);
13690 return;
13691 }
13692
David S. Miller9360ffd2012-03-29 04:41:26 -040013693 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13694 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13695 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13696 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13697 (key_id != -1 &&
13698 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13699 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13700 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013701
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013702 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013703
Johannes Berg68eb5502013-11-19 15:19:38 +010013704 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013705 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013706 return;
13707
13708 nla_put_failure:
13709 genlmsg_cancel(msg, hdr);
13710 nlmsg_free(msg);
13711}
13712
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013713void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13714 struct ieee80211_channel *channel_before,
13715 struct ieee80211_channel *channel_after)
13716{
13717 struct sk_buff *msg;
13718 void *hdr;
13719 struct nlattr *nl_freq;
13720
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013722 if (!msg)
13723 return;
13724
13725 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13726 if (!hdr) {
13727 nlmsg_free(msg);
13728 return;
13729 }
13730
13731 /*
13732 * Since we are applying the beacon hint to a wiphy we know its
13733 * wiphy_idx is valid
13734 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013735 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13736 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013737
13738 /* Before */
13739 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13740 if (!nl_freq)
13741 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013742 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013743 goto nla_put_failure;
13744 nla_nest_end(msg, nl_freq);
13745
13746 /* After */
13747 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13748 if (!nl_freq)
13749 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013750 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013751 goto nla_put_failure;
13752 nla_nest_end(msg, nl_freq);
13753
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013754 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013755
Johannes Berg463d0182009-07-14 00:33:35 +020013756 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013757 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013758 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013759 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013760
13761 return;
13762
13763nla_put_failure:
13764 genlmsg_cancel(msg, hdr);
13765 nlmsg_free(msg);
13766}
13767
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013768static void nl80211_send_remain_on_chan_event(
13769 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013770 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013771 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013772 unsigned int duration, gfp_t gfp)
13773{
13774 struct sk_buff *msg;
13775 void *hdr;
13776
13777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13778 if (!msg)
13779 return;
13780
13781 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13782 if (!hdr) {
13783 nlmsg_free(msg);
13784 return;
13785 }
13786
David S. Miller9360ffd2012-03-29 04:41:26 -040013787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013788 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13789 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013790 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13791 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013792 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013793 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13794 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013795 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13796 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013797 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013798
David S. Miller9360ffd2012-03-29 04:41:26 -040013799 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13800 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13801 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013802
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013803 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013804
Johannes Berg68eb5502013-11-19 15:19:38 +010013805 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013806 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013807 return;
13808
13809 nla_put_failure:
13810 genlmsg_cancel(msg, hdr);
13811 nlmsg_free(msg);
13812}
13813
Johannes Berg947add32013-02-22 22:05:20 +010013814void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13815 struct ieee80211_channel *chan,
13816 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013817{
Johannes Berg947add32013-02-22 22:05:20 +010013818 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013819 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013820
13821 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013822 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013823 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013824 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013825}
Johannes Berg947add32013-02-22 22:05:20 +010013826EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013827
Johannes Berg947add32013-02-22 22:05:20 +010013828void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13829 struct ieee80211_channel *chan,
13830 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013831{
Johannes Berg947add32013-02-22 22:05:20 +010013832 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013833 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013834
13835 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013836 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013837 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013838}
Johannes Berg947add32013-02-22 22:05:20 +010013839EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013840
Johannes Berg947add32013-02-22 22:05:20 +010013841void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13842 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013843{
Johannes Berg947add32013-02-22 22:05:20 +010013844 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013845 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013846 struct sk_buff *msg;
13847
Johannes Berg947add32013-02-22 22:05:20 +010013848 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13849
Thomas Graf58050fc2012-06-28 03:57:45 +000013850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013851 if (!msg)
13852 return;
13853
Johannes Bergcf5ead82014-11-14 17:14:00 +010013854 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013855 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013856 nlmsg_free(msg);
13857 return;
13858 }
13859
Johannes Berg68eb5502013-11-19 15:19:38 +010013860 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013861 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013862}
Johannes Berg947add32013-02-22 22:05:20 +010013863EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013864
Johannes Bergcf5ead82014-11-14 17:14:00 +010013865void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13866 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013867{
Johannes Berg947add32013-02-22 22:05:20 +010013868 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013869 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013870 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013871 struct station_info empty_sinfo = {};
13872
13873 if (!sinfo)
13874 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013875
Johannes Berg947add32013-02-22 22:05:20 +010013876 trace_cfg80211_del_sta(dev, mac_addr);
13877
Thomas Graf58050fc2012-06-28 03:57:45 +000013878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013879 if (!msg)
13880 return;
13881
Johannes Bergcf5ead82014-11-14 17:14:00 +010013882 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013883 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013884 nlmsg_free(msg);
13885 return;
13886 }
13887
Johannes Berg68eb5502013-11-19 15:19:38 +010013888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013889 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013890}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013891EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013892
Johannes Berg947add32013-02-22 22:05:20 +010013893void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13894 enum nl80211_connect_failed_reason reason,
13895 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013896{
Johannes Berg947add32013-02-22 22:05:20 +010013897 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013898 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013899 struct sk_buff *msg;
13900 void *hdr;
13901
13902 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13903 if (!msg)
13904 return;
13905
13906 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13907 if (!hdr) {
13908 nlmsg_free(msg);
13909 return;
13910 }
13911
13912 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13913 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13914 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13915 goto nla_put_failure;
13916
13917 genlmsg_end(msg, hdr);
13918
Johannes Berg68eb5502013-11-19 15:19:38 +010013919 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013920 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013921 return;
13922
13923 nla_put_failure:
13924 genlmsg_cancel(msg, hdr);
13925 nlmsg_free(msg);
13926}
Johannes Berg947add32013-02-22 22:05:20 +010013927EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013928
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013929static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13930 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013931{
13932 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013933 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013934 struct sk_buff *msg;
13935 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013936 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013937
Eric W. Biederman15e47302012-09-07 20:12:54 +000013938 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013939 return false;
13940
13941 msg = nlmsg_new(100, gfp);
13942 if (!msg)
13943 return true;
13944
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013945 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013946 if (!hdr) {
13947 nlmsg_free(msg);
13948 return true;
13949 }
13950
David S. Miller9360ffd2012-03-29 04:41:26 -040013951 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13952 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13953 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13954 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013955
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013956 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013957 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013958 return true;
13959
13960 nla_put_failure:
13961 genlmsg_cancel(msg, hdr);
13962 nlmsg_free(msg);
13963 return true;
13964}
13965
Johannes Berg947add32013-02-22 22:05:20 +010013966bool cfg80211_rx_spurious_frame(struct net_device *dev,
13967 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013968{
Johannes Berg947add32013-02-22 22:05:20 +010013969 struct wireless_dev *wdev = dev->ieee80211_ptr;
13970 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013971
Johannes Berg947add32013-02-22 22:05:20 +010013972 trace_cfg80211_rx_spurious_frame(dev, addr);
13973
13974 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13975 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13976 trace_cfg80211_return_bool(false);
13977 return false;
13978 }
13979 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13980 addr, gfp);
13981 trace_cfg80211_return_bool(ret);
13982 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013983}
Johannes Berg947add32013-02-22 22:05:20 +010013984EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13985
13986bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13987 const u8 *addr, gfp_t gfp)
13988{
13989 struct wireless_dev *wdev = dev->ieee80211_ptr;
13990 bool ret;
13991
13992 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13993
13994 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13995 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13996 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13997 trace_cfg80211_return_bool(false);
13998 return false;
13999 }
14000 ret = __nl80211_unexpected_frame(dev,
14001 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
14002 addr, gfp);
14003 trace_cfg80211_return_bool(ret);
14004 return ret;
14005}
14006EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014007
Johannes Berg2e161f72010-08-12 15:38:38 +020014008int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014009 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014010 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014011 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014012{
Johannes Berg71bbc992012-06-15 15:30:18 +020014013 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014014 struct sk_buff *msg;
14015 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014016
Johannes Berg14459722017-01-09 11:10:42 +010014017 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014018 if (!msg)
14019 return -ENOMEM;
14020
Johannes Berg2e161f72010-08-12 15:38:38 +020014021 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014022 if (!hdr) {
14023 nlmsg_free(msg);
14024 return -ENOMEM;
14025 }
14026
David S. Miller9360ffd2012-03-29 04:41:26 -040014027 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014028 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14029 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014030 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14031 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014032 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14033 (sig_dbm &&
14034 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014035 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14036 (flags &&
14037 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014038 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014039
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014040 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014041
Eric W. Biederman15e47302012-09-07 20:12:54 +000014042 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014043
14044 nla_put_failure:
14045 genlmsg_cancel(msg, hdr);
14046 nlmsg_free(msg);
14047 return -ENOBUFS;
14048}
14049
Johannes Berg947add32013-02-22 22:05:20 +010014050void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14051 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014052{
Johannes Berg947add32013-02-22 22:05:20 +010014053 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014054 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014055 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014056 struct sk_buff *msg;
14057 void *hdr;
14058
Johannes Berg947add32013-02-22 22:05:20 +010014059 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14060
Johannes Berg14459722017-01-09 11:10:42 +010014061 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014062 if (!msg)
14063 return;
14064
Johannes Berg2e161f72010-08-12 15:38:38 +020014065 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014066 if (!hdr) {
14067 nlmsg_free(msg);
14068 return;
14069 }
14070
David S. Miller9360ffd2012-03-29 04:41:26 -040014071 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014072 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14073 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014074 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14075 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014076 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014077 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14078 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014079 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14080 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014081
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014082 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014083
Johannes Berg68eb5502013-11-19 15:19:38 +010014084 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014085 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014086 return;
14087
14088 nla_put_failure:
14089 genlmsg_cancel(msg, hdr);
14090 nlmsg_free(msg);
14091}
Johannes Berg947add32013-02-22 22:05:20 +010014092EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014093
Johannes Berg5b97f492014-11-26 12:37:43 +010014094static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14095 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014096{
Johannes Berg947add32013-02-22 22:05:20 +010014097 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014098 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14099 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14100 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014101
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014102 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014103 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014104
Johannes Berg5b97f492014-11-26 12:37:43 +010014105 cb = (void **)msg->cb;
14106
14107 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14108 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014109 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014110 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014111 }
14112
David S. Miller9360ffd2012-03-29 04:41:26 -040014113 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014114 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014115 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014116
Johannes Berg5b97f492014-11-26 12:37:43 +010014117 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014118 goto nla_put_failure;
14119
Johannes Berg5b97f492014-11-26 12:37:43 +010014120 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14121 if (!cb[1])
14122 goto nla_put_failure;
14123
14124 cb[2] = rdev;
14125
14126 return msg;
14127 nla_put_failure:
14128 nlmsg_free(msg);
14129 return NULL;
14130}
14131
14132static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14133{
14134 void **cb = (void **)msg->cb;
14135 struct cfg80211_registered_device *rdev = cb[2];
14136
14137 nla_nest_end(msg, cb[1]);
14138 genlmsg_end(msg, cb[0]);
14139
14140 memset(msg->cb, 0, sizeof(msg->cb));
14141
14142 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14143 NL80211_MCGRP_MLME, gfp);
14144}
14145
14146void cfg80211_cqm_rssi_notify(struct net_device *dev,
14147 enum nl80211_cqm_rssi_threshold_event rssi_event,
14148 gfp_t gfp)
14149{
14150 struct sk_buff *msg;
14151
14152 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
14153
Johannes Berg98f03342014-11-26 12:42:02 +010014154 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14155 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14156 return;
14157
Johannes Berg5b97f492014-11-26 12:37:43 +010014158 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14159 if (!msg)
14160 return;
14161
David S. Miller9360ffd2012-03-29 04:41:26 -040014162 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14163 rssi_event))
14164 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014165
Johannes Berg5b97f492014-11-26 12:37:43 +010014166 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014167
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014168 return;
14169
14170 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014171 nlmsg_free(msg);
14172}
Johannes Berg947add32013-02-22 22:05:20 +010014173EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014174
Johannes Berg5b97f492014-11-26 12:37:43 +010014175void cfg80211_cqm_txe_notify(struct net_device *dev,
14176 const u8 *peer, u32 num_packets,
14177 u32 rate, u32 intvl, gfp_t gfp)
14178{
14179 struct sk_buff *msg;
14180
14181 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14182 if (!msg)
14183 return;
14184
14185 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14186 goto nla_put_failure;
14187
14188 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14189 goto nla_put_failure;
14190
14191 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14192 goto nla_put_failure;
14193
14194 cfg80211_send_cqm(msg, gfp);
14195 return;
14196
14197 nla_put_failure:
14198 nlmsg_free(msg);
14199}
14200EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14201
14202void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14203 const u8 *peer, u32 num_packets, gfp_t gfp)
14204{
14205 struct sk_buff *msg;
14206
14207 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14208
14209 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14210 if (!msg)
14211 return;
14212
14213 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14214 goto nla_put_failure;
14215
14216 cfg80211_send_cqm(msg, gfp);
14217 return;
14218
14219 nla_put_failure:
14220 nlmsg_free(msg);
14221}
14222EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14223
Johannes Berg98f03342014-11-26 12:42:02 +010014224void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14225{
14226 struct sk_buff *msg;
14227
14228 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14229 if (!msg)
14230 return;
14231
14232 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14233 goto nla_put_failure;
14234
14235 cfg80211_send_cqm(msg, gfp);
14236 return;
14237
14238 nla_put_failure:
14239 nlmsg_free(msg);
14240}
14241EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14242
Johannes Berg947add32013-02-22 22:05:20 +010014243static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14244 struct net_device *netdev, const u8 *bssid,
14245 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014246{
14247 struct sk_buff *msg;
14248 struct nlattr *rekey_attr;
14249 void *hdr;
14250
Thomas Graf58050fc2012-06-28 03:57:45 +000014251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014252 if (!msg)
14253 return;
14254
14255 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14256 if (!hdr) {
14257 nlmsg_free(msg);
14258 return;
14259 }
14260
David S. Miller9360ffd2012-03-29 04:41:26 -040014261 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14262 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14263 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14264 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014265
14266 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14267 if (!rekey_attr)
14268 goto nla_put_failure;
14269
David S. Miller9360ffd2012-03-29 04:41:26 -040014270 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14271 NL80211_REPLAY_CTR_LEN, replay_ctr))
14272 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014273
14274 nla_nest_end(msg, rekey_attr);
14275
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014276 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014277
Johannes Berg68eb5502013-11-19 15:19:38 +010014278 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014279 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014280 return;
14281
14282 nla_put_failure:
14283 genlmsg_cancel(msg, hdr);
14284 nlmsg_free(msg);
14285}
14286
Johannes Berg947add32013-02-22 22:05:20 +010014287void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14288 const u8 *replay_ctr, gfp_t gfp)
14289{
14290 struct wireless_dev *wdev = dev->ieee80211_ptr;
14291 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014292 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014293
14294 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14295 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14296}
14297EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14298
14299static void
14300nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14301 struct net_device *netdev, int index,
14302 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014303{
14304 struct sk_buff *msg;
14305 struct nlattr *attr;
14306 void *hdr;
14307
Thomas Graf58050fc2012-06-28 03:57:45 +000014308 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014309 if (!msg)
14310 return;
14311
14312 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14313 if (!hdr) {
14314 nlmsg_free(msg);
14315 return;
14316 }
14317
David S. Miller9360ffd2012-03-29 04:41:26 -040014318 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14319 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14320 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014321
14322 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14323 if (!attr)
14324 goto nla_put_failure;
14325
David S. Miller9360ffd2012-03-29 04:41:26 -040014326 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14327 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14328 (preauth &&
14329 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14330 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014331
14332 nla_nest_end(msg, attr);
14333
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014334 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014335
Johannes Berg68eb5502013-11-19 15:19:38 +010014336 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014337 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014338 return;
14339
14340 nla_put_failure:
14341 genlmsg_cancel(msg, hdr);
14342 nlmsg_free(msg);
14343}
14344
Johannes Berg947add32013-02-22 22:05:20 +010014345void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14346 const u8 *bssid, bool preauth, gfp_t gfp)
14347{
14348 struct wireless_dev *wdev = dev->ieee80211_ptr;
14349 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014350 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014351
14352 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14353 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14354}
14355EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14356
14357static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14358 struct net_device *netdev,
14359 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014360 gfp_t gfp,
14361 enum nl80211_commands notif,
14362 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014363{
14364 struct sk_buff *msg;
14365 void *hdr;
14366
Thomas Graf58050fc2012-06-28 03:57:45 +000014367 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014368 if (!msg)
14369 return;
14370
Luciano Coelhof8d75522014-11-07 14:31:35 +020014371 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014372 if (!hdr) {
14373 nlmsg_free(msg);
14374 return;
14375 }
14376
Johannes Berg683b6d32012-11-08 21:25:48 +010014377 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14378 goto nla_put_failure;
14379
14380 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014381 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014382
Luciano Coelhof8d75522014-11-07 14:31:35 +020014383 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14384 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14385 goto nla_put_failure;
14386
Thomas Pedersen53145262012-04-06 13:35:47 -070014387 genlmsg_end(msg, hdr);
14388
Johannes Berg68eb5502013-11-19 15:19:38 +010014389 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014390 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014391 return;
14392
14393 nla_put_failure:
14394 genlmsg_cancel(msg, hdr);
14395 nlmsg_free(msg);
14396}
14397
Johannes Berg947add32013-02-22 22:05:20 +010014398void cfg80211_ch_switch_notify(struct net_device *dev,
14399 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014400{
Johannes Berg947add32013-02-22 22:05:20 +010014401 struct wireless_dev *wdev = dev->ieee80211_ptr;
14402 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014404
Simon Wunderliche487eae2013-11-21 18:19:51 +010014405 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014406
Simon Wunderliche487eae2013-11-21 18:19:51 +010014407 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014408
Michal Kazior9e0e2962014-01-29 14:22:27 +010014409 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014410 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014411 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14412 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014413}
14414EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14415
Luciano Coelhof8d75522014-11-07 14:31:35 +020014416void cfg80211_ch_switch_started_notify(struct net_device *dev,
14417 struct cfg80211_chan_def *chandef,
14418 u8 count)
14419{
14420 struct wireless_dev *wdev = dev->ieee80211_ptr;
14421 struct wiphy *wiphy = wdev->wiphy;
14422 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14423
14424 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14425
14426 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14427 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14428}
14429EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14430
Thomas Pedersen84f10702012-07-12 16:17:33 -070014431void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014432nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014433 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014434 enum nl80211_radar_event event,
14435 struct net_device *netdev, gfp_t gfp)
14436{
14437 struct sk_buff *msg;
14438 void *hdr;
14439
14440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14441 if (!msg)
14442 return;
14443
14444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14445 if (!hdr) {
14446 nlmsg_free(msg);
14447 return;
14448 }
14449
14450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14451 goto nla_put_failure;
14452
14453 /* NOP and radar events don't need a netdev parameter */
14454 if (netdev) {
14455 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14456
14457 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014458 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14459 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014460 goto nla_put_failure;
14461 }
14462
14463 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14464 goto nla_put_failure;
14465
14466 if (nl80211_send_chandef(msg, chandef))
14467 goto nla_put_failure;
14468
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014469 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014470
Johannes Berg68eb5502013-11-19 15:19:38 +010014471 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014472 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014473 return;
14474
14475 nla_put_failure:
14476 genlmsg_cancel(msg, hdr);
14477 nlmsg_free(msg);
14478}
14479
Johannes Berg7f6cf312011-11-04 11:18:15 +010014480void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14481 u64 cookie, bool acked, gfp_t gfp)
14482{
14483 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014484 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014485 struct sk_buff *msg;
14486 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014487
Beni Lev4ee3e062012-08-27 12:49:39 +030014488 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14489
Thomas Graf58050fc2012-06-28 03:57:45 +000014490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014491
Johannes Berg7f6cf312011-11-04 11:18:15 +010014492 if (!msg)
14493 return;
14494
14495 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14496 if (!hdr) {
14497 nlmsg_free(msg);
14498 return;
14499 }
14500
David S. Miller9360ffd2012-03-29 04:41:26 -040014501 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14502 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14503 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014504 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14505 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014506 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14507 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014508
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014509 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014510
Johannes Berg68eb5502013-11-19 15:19:38 +010014511 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014512 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014513 return;
14514
14515 nla_put_failure:
14516 genlmsg_cancel(msg, hdr);
14517 nlmsg_free(msg);
14518}
14519EXPORT_SYMBOL(cfg80211_probe_status);
14520
Johannes Berg5e7602302011-11-04 11:18:17 +010014521void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14522 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014523 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010014524{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014525 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010014526 struct sk_buff *msg;
14527 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014528 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010014529
Beni Lev4ee3e062012-08-27 12:49:39 +030014530 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14531
Ben Greear37c73b52012-10-26 14:49:25 -070014532 spin_lock_bh(&rdev->beacon_registrations_lock);
14533 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14534 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14535 if (!msg) {
14536 spin_unlock_bh(&rdev->beacon_registrations_lock);
14537 return;
14538 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014539
Ben Greear37c73b52012-10-26 14:49:25 -070014540 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14541 if (!hdr)
14542 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010014543
Ben Greear37c73b52012-10-26 14:49:25 -070014544 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14545 (freq &&
14546 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14547 (sig_dbm &&
14548 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14549 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14550 goto nla_put_failure;
14551
14552 genlmsg_end(msg, hdr);
14553
14554 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010014555 }
Ben Greear37c73b52012-10-26 14:49:25 -070014556 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010014557 return;
14558
14559 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014560 spin_unlock_bh(&rdev->beacon_registrations_lock);
14561 if (hdr)
14562 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010014563 nlmsg_free(msg);
14564}
14565EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14566
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014567#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014568static int cfg80211_net_detect_results(struct sk_buff *msg,
14569 struct cfg80211_wowlan_wakeup *wakeup)
14570{
14571 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14572 struct nlattr *nl_results, *nl_match, *nl_freqs;
14573 int i, j;
14574
14575 nl_results = nla_nest_start(
14576 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14577 if (!nl_results)
14578 return -EMSGSIZE;
14579
14580 for (i = 0; i < nd->n_matches; i++) {
14581 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14582
14583 nl_match = nla_nest_start(msg, i);
14584 if (!nl_match)
14585 break;
14586
14587 /* The SSID attribute is optional in nl80211, but for
14588 * simplicity reasons it's always present in the
14589 * cfg80211 structure. If a driver can't pass the
14590 * SSID, that needs to be changed. A zero length SSID
14591 * is still a valid SSID (wildcard), so it cannot be
14592 * used for this purpose.
14593 */
14594 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14595 match->ssid.ssid)) {
14596 nla_nest_cancel(msg, nl_match);
14597 goto out;
14598 }
14599
14600 if (match->n_channels) {
14601 nl_freqs = nla_nest_start(
14602 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14603 if (!nl_freqs) {
14604 nla_nest_cancel(msg, nl_match);
14605 goto out;
14606 }
14607
14608 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014609 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014610 nla_nest_cancel(msg, nl_freqs);
14611 nla_nest_cancel(msg, nl_match);
14612 goto out;
14613 }
14614 }
14615
14616 nla_nest_end(msg, nl_freqs);
14617 }
14618
14619 nla_nest_end(msg, nl_match);
14620 }
14621
14622out:
14623 nla_nest_end(msg, nl_results);
14624 return 0;
14625}
14626
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014627void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14628 struct cfg80211_wowlan_wakeup *wakeup,
14629 gfp_t gfp)
14630{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014631 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014632 struct sk_buff *msg;
14633 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014634 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014635
14636 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14637
14638 if (wakeup)
14639 size += wakeup->packet_present_len;
14640
14641 msg = nlmsg_new(size, gfp);
14642 if (!msg)
14643 return;
14644
14645 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14646 if (!hdr)
14647 goto free_msg;
14648
14649 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014650 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14651 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014652 goto free_msg;
14653
14654 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14655 wdev->netdev->ifindex))
14656 goto free_msg;
14657
14658 if (wakeup) {
14659 struct nlattr *reasons;
14660
14661 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014662 if (!reasons)
14663 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014664
14665 if (wakeup->disconnect &&
14666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14667 goto free_msg;
14668 if (wakeup->magic_pkt &&
14669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14670 goto free_msg;
14671 if (wakeup->gtk_rekey_failure &&
14672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14673 goto free_msg;
14674 if (wakeup->eap_identity_req &&
14675 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14676 goto free_msg;
14677 if (wakeup->four_way_handshake &&
14678 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14679 goto free_msg;
14680 if (wakeup->rfkill_release &&
14681 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14682 goto free_msg;
14683
14684 if (wakeup->pattern_idx >= 0 &&
14685 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14686 wakeup->pattern_idx))
14687 goto free_msg;
14688
Johannes Bergae917c92013-10-25 11:05:22 +020014689 if (wakeup->tcp_match &&
14690 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14691 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014692
Johannes Bergae917c92013-10-25 11:05:22 +020014693 if (wakeup->tcp_connlost &&
14694 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14695 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014696
Johannes Bergae917c92013-10-25 11:05:22 +020014697 if (wakeup->tcp_nomoretokens &&
14698 nla_put_flag(msg,
14699 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14700 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014701
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014702 if (wakeup->packet) {
14703 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14704 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14705
14706 if (!wakeup->packet_80211) {
14707 pkt_attr =
14708 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14709 len_attr =
14710 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14711 }
14712
14713 if (wakeup->packet_len &&
14714 nla_put_u32(msg, len_attr, wakeup->packet_len))
14715 goto free_msg;
14716
14717 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14718 wakeup->packet))
14719 goto free_msg;
14720 }
14721
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014722 if (wakeup->net_detect &&
14723 cfg80211_net_detect_results(msg, wakeup))
14724 goto free_msg;
14725
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014726 nla_nest_end(msg, reasons);
14727 }
14728
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014729 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014730
Johannes Berg68eb5502013-11-19 15:19:38 +010014731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014732 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014733 return;
14734
14735 free_msg:
14736 nlmsg_free(msg);
14737}
14738EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14739#endif
14740
Jouni Malinen3475b092012-11-16 22:49:57 +020014741void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14742 enum nl80211_tdls_operation oper,
14743 u16 reason_code, gfp_t gfp)
14744{
14745 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014746 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014747 struct sk_buff *msg;
14748 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014749
14750 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14751 reason_code);
14752
14753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14754 if (!msg)
14755 return;
14756
14757 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14758 if (!hdr) {
14759 nlmsg_free(msg);
14760 return;
14761 }
14762
14763 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14764 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14765 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14766 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14767 (reason_code > 0 &&
14768 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14769 goto nla_put_failure;
14770
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014771 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014772
Johannes Berg68eb5502013-11-19 15:19:38 +010014773 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014774 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014775 return;
14776
14777 nla_put_failure:
14778 genlmsg_cancel(msg, hdr);
14779 nlmsg_free(msg);
14780}
14781EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14782
Jouni Malinen026331c2010-02-15 12:53:10 +020014783static int nl80211_netlink_notify(struct notifier_block * nb,
14784 unsigned long state,
14785 void *_notify)
14786{
14787 struct netlink_notify *notify = _notify;
14788 struct cfg80211_registered_device *rdev;
14789 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014790 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014791
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014792 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014793 return NOTIFY_DONE;
14794
14795 rcu_read_lock();
14796
Johannes Berg5e7602302011-11-04 11:18:17 +010014797 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014798 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014799 struct cfg80211_sched_scan_request *sched_scan_req =
14800 rcu_dereference(rdev->sched_scan_req);
14801
14802 if (sched_scan_req && notify->portid &&
Johannes Berg0a28f532017-01-05 10:57:14 +010014803 sched_scan_req->owner_nlportid == notify->portid) {
14804 sched_scan_req->owner_nlportid = 0;
14805
14806 if (rdev->ops->sched_scan_stop &&
14807 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14808 schedule_work(&rdev->sched_scan_stop_wk);
14809 }
Johannes Berg78f22b62014-03-24 17:57:27 +010014810
Johannes Berg53873f12016-05-03 16:52:04 +030014811 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014812 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014813
Johannes Berg78f22b62014-03-24 17:57:27 +010014814 if (wdev->owner_nlportid == notify->portid)
14815 schedule_destroy_work = true;
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +053014816 else if (wdev->conn_owner_nlportid == notify->portid)
14817 schedule_work(&wdev->disconnect_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014818 }
14819
Ben Greear37c73b52012-10-26 14:49:25 -070014820 spin_lock_bh(&rdev->beacon_registrations_lock);
14821 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14822 list) {
14823 if (reg->nlportid == notify->portid) {
14824 list_del(&reg->list);
14825 kfree(reg);
14826 break;
14827 }
14828 }
14829 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014830
14831 if (schedule_destroy_work) {
14832 struct cfg80211_iface_destroy *destroy;
14833
14834 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14835 if (destroy) {
14836 destroy->nlportid = notify->portid;
14837 spin_lock(&rdev->destroy_list_lock);
14838 list_add(&destroy->list, &rdev->destroy_list);
14839 spin_unlock(&rdev->destroy_list_lock);
14840 schedule_work(&rdev->destroy_work);
14841 }
14842 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014843 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014844
14845 rcu_read_unlock();
14846
Ilan peer05050752015-03-04 00:32:06 -050014847 /*
14848 * It is possible that the user space process that is controlling the
14849 * indoor setting disappeared, so notify the regulatory core.
14850 */
14851 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014852 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014853}
14854
14855static struct notifier_block nl80211_netlink_notifier = {
14856 .notifier_call = nl80211_netlink_notify,
14857};
14858
Jouni Malinen355199e2013-02-27 17:14:27 +020014859void cfg80211_ft_event(struct net_device *netdev,
14860 struct cfg80211_ft_event_params *ft_event)
14861{
14862 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014863 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014864 struct sk_buff *msg;
14865 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014866
14867 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14868
14869 if (!ft_event->target_ap)
14870 return;
14871
Dedy Lanskyfe064512018-05-17 13:46:22 +030014872 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
14873 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020014874 if (!msg)
14875 return;
14876
14877 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014878 if (!hdr)
14879 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014880
Johannes Bergae917c92013-10-25 11:05:22 +020014881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14884 goto out;
14885
14886 if (ft_event->ies &&
14887 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14888 goto out;
14889 if (ft_event->ric_ies &&
14890 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14891 ft_event->ric_ies))
14892 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014893
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014894 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014895
Johannes Berg68eb5502013-11-19 15:19:38 +010014896 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014897 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014898 return;
14899 out:
14900 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014901}
14902EXPORT_SYMBOL(cfg80211_ft_event);
14903
Arend van Spriel5de17982013-04-18 15:49:00 +020014904void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14905{
14906 struct cfg80211_registered_device *rdev;
14907 struct sk_buff *msg;
14908 void *hdr;
14909 u32 nlportid;
14910
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014911 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014912 if (!rdev->crit_proto_nlportid)
14913 return;
14914
14915 nlportid = rdev->crit_proto_nlportid;
14916 rdev->crit_proto_nlportid = 0;
14917
14918 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14919 if (!msg)
14920 return;
14921
14922 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14923 if (!hdr)
14924 goto nla_put_failure;
14925
14926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014927 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14928 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014929 goto nla_put_failure;
14930
14931 genlmsg_end(msg, hdr);
14932
14933 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14934 return;
14935
14936 nla_put_failure:
14937 if (hdr)
14938 genlmsg_cancel(msg, hdr);
14939 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014940}
14941EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14942
Sameer Thalappilfaa4c4a2013-07-05 14:58:32 -070014943void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
14944{
14945 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14946 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14947
14948 nl80211_send_mlme_event(rdev, netdev, NULL, 0,
14949 NL80211_CMD_STOP_AP, gfp, -1);
14950}
14951EXPORT_SYMBOL(cfg80211_ap_stopped);
14952
Johannes Berg348baf02014-01-24 14:06:29 +010014953void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14954{
14955 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014956 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014957 struct sk_buff *msg;
14958 void *hdr;
14959
14960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14961 if (!msg)
14962 return;
14963
14964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14965 if (!hdr)
14966 goto out;
14967
14968 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14969 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014970 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14971 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014972 goto out;
14973
14974 genlmsg_end(msg, hdr);
14975
14976 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14977 NL80211_MCGRP_MLME, GFP_KERNEL);
14978 return;
14979 out:
14980 nlmsg_free(msg);
14981}
14982
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053014983int cfg80211_external_auth_request(struct net_device *dev,
14984 struct cfg80211_external_auth_params *params,
14985 gfp_t gfp)
14986{
14987 struct wireless_dev *wdev = dev->ieee80211_ptr;
14988 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14989 struct sk_buff *msg;
14990 void *hdr;
14991
14992 if (!wdev->conn_owner_nlportid)
14993 return -EINVAL;
14994
14995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14996 if (!msg)
14997 return -ENOMEM;
14998
14999 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
15000 if (!hdr)
15001 goto nla_put_failure;
15002
15003 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15004 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15005 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
15006 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
15007 params->action) ||
15008 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
15009 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
15010 params->ssid.ssid))
15011 goto nla_put_failure;
15012
15013 genlmsg_end(msg, hdr);
15014 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
15015 wdev->conn_owner_nlportid);
15016 return 0;
15017
15018 nla_put_failure:
15019 nlmsg_free(msg);
15020 return -ENOBUFS;
15021}
15022EXPORT_SYMBOL(cfg80211_external_auth_request);
15023
Johannes Berg55682962007-09-20 13:09:35 -040015024/* initialisation/exit functions */
15025
15026int nl80211_init(void)
15027{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015028 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015029
Johannes Berg2a94fe42013-11-19 15:19:39 +010015030 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
15031 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040015032 if (err)
15033 return err;
15034
Jouni Malinen026331c2010-02-15 12:53:10 +020015035 err = netlink_register_notifier(&nl80211_netlink_notifier);
15036 if (err)
15037 goto err_out;
15038
Johannes Berg55682962007-09-20 13:09:35 -040015039 return 0;
15040 err_out:
15041 genl_unregister_family(&nl80211_fam);
15042 return err;
15043}
15044
15045void nl80211_exit(void)
15046{
Jouni Malinen026331c2010-02-15 12:53:10 +020015047 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015048 genl_unregister_family(&nl80211_fam);
15049}