blob: eb5f421424c4c8af0c4aad788da55c949cf421dc [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:
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03003791 /* SAE not supported yet */
3792 if (auth_type == NL80211_AUTHTYPE_SAE)
3793 return false;
3794 /* FILS with SK PFS or PK not supported yet */
3795 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3796 auth_type == NL80211_AUTHTYPE_FILS_PK)
3797 return false;
3798 if (!wiphy_ext_feature_isset(
3799 &rdev->wiphy,
3800 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
3801 auth_type == NL80211_AUTHTYPE_FILS_SK)
3802 return false;
3803 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003804 case NL80211_CMD_START_AP:
3805 /* SAE not supported yet */
3806 if (auth_type == NL80211_AUTHTYPE_SAE)
3807 return false;
Jouni Malinene20f90f2016-10-27 00:42:02 +03003808 /* FILS not supported yet */
3809 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3810 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3811 auth_type == NL80211_AUTHTYPE_FILS_PK)
3812 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003813 return true;
3814 default:
3815 return false;
3816 }
3817}
3818
Johannes Berg88600202012-02-13 15:17:18 +01003819static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3820{
3821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3822 struct net_device *dev = info->user_ptr[1];
3823 struct wireless_dev *wdev = dev->ieee80211_ptr;
3824 struct cfg80211_ap_settings params;
3825 int err;
3826
3827 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3828 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3829 return -EOPNOTSUPP;
3830
3831 if (!rdev->ops->start_ap)
3832 return -EOPNOTSUPP;
3833
3834 if (wdev->beacon_interval)
3835 return -EALREADY;
3836
3837 memset(&params, 0, sizeof(params));
3838
3839 /* these are required for START_AP */
3840 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3841 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3842 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3843 return -EINVAL;
3844
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003845 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003846 if (err)
3847 return err;
3848
3849 params.beacon_interval =
3850 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3851 params.dtim_period =
3852 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3853
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05303854 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3855 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003856 if (err)
3857 return err;
3858
3859 /*
3860 * In theory, some of these attributes should be required here
3861 * but since they were not used when the command was originally
3862 * added, keep them optional for old user space programs to let
3863 * them continue to work with drivers that do not need the
3864 * additional information -- drivers must check!
3865 */
3866 if (info->attrs[NL80211_ATTR_SSID]) {
3867 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3868 params.ssid_len =
3869 nla_len(info->attrs[NL80211_ATTR_SSID]);
3870 if (params.ssid_len == 0 ||
3871 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3872 return -EINVAL;
3873 }
3874
3875 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3876 params.hidden_ssid = nla_get_u32(
3877 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3878 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3879 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3880 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3881 return -EINVAL;
3882 }
3883
3884 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3885
3886 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3887 params.auth_type = nla_get_u32(
3888 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003889 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3890 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003891 return -EINVAL;
3892 } else
3893 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3894
3895 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3896 NL80211_MAX_NR_CIPHER_SUITES);
3897 if (err)
3898 return err;
3899
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303900 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3901 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3902 return -EOPNOTSUPP;
3903 params.inactivity_timeout = nla_get_u16(
3904 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3905 }
3906
Johannes Berg53cabad2012-11-14 15:17:28 +01003907 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3909 return -EINVAL;
3910 params.p2p_ctwindow =
3911 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3912 if (params.p2p_ctwindow > 127)
3913 return -EINVAL;
3914 if (params.p2p_ctwindow != 0 &&
3915 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3916 return -EINVAL;
3917 }
3918
3919 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3920 u8 tmp;
3921
3922 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3923 return -EINVAL;
3924 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3925 if (tmp > 1)
3926 return -EINVAL;
3927 params.p2p_opp_ps = tmp;
3928 if (params.p2p_opp_ps != 0 &&
3929 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3930 return -EINVAL;
3931 }
3932
Johannes Bergaa430da2012-05-16 23:50:18 +02003933 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003934 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3935 if (err)
3936 return err;
3937 } else if (wdev->preset_chandef.chan) {
3938 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003939 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003940 return -EINVAL;
3941
Arik Nemtsov923b3522015-07-08 15:41:44 +03003942 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3943 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003944 return -EINVAL;
3945
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303946 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3947 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3948 if (err)
3949 return err;
3950
Johannes Berg8564e382016-09-19 09:44:44 +02003951 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3952 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303953 if (err)
3954 return err;
3955 }
3956
Eliad Peller18998c32014-09-10 14:07:34 +03003957 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3958 params.smps_mode =
3959 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3960 switch (params.smps_mode) {
3961 case NL80211_SMPS_OFF:
3962 break;
3963 case NL80211_SMPS_STATIC:
3964 if (!(rdev->wiphy.features &
3965 NL80211_FEATURE_STATIC_SMPS))
3966 return -EINVAL;
3967 break;
3968 case NL80211_SMPS_DYNAMIC:
3969 if (!(rdev->wiphy.features &
3970 NL80211_FEATURE_DYNAMIC_SMPS))
3971 return -EINVAL;
3972 break;
3973 default:
3974 return -EINVAL;
3975 }
3976 } else {
3977 params.smps_mode = NL80211_SMPS_OFF;
3978 }
3979
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303980 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3981 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3982 return -EOPNOTSUPP;
3983
Ola Olsson4baf6be2015-10-29 07:04:58 +01003984 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3985 params.acl = parse_acl_data(&rdev->wiphy, info);
3986 if (IS_ERR(params.acl))
3987 return PTR_ERR(params.acl);
3988 }
3989
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003990 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003991 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003992 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003993 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003994 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003995 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003996 wdev->ssid_len = params.ssid_len;
3997 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003998 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003999 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304000
4001 kfree(params.acl);
4002
Johannes Berg56d18932011-05-09 18:41:15 +02004003 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004004}
4005
Johannes Berg88600202012-02-13 15:17:18 +01004006static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
4007{
4008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4009 struct net_device *dev = info->user_ptr[1];
4010 struct wireless_dev *wdev = dev->ieee80211_ptr;
4011 struct cfg80211_beacon_data params;
4012 int err;
4013
4014 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4015 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4016 return -EOPNOTSUPP;
4017
4018 if (!rdev->ops->change_beacon)
4019 return -EOPNOTSUPP;
4020
4021 if (!wdev->beacon_interval)
4022 return -EINVAL;
4023
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004024 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004025 if (err)
4026 return err;
4027
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004028 wdev_lock(wdev);
4029 err = rdev_change_beacon(rdev, dev, &params);
4030 wdev_unlock(wdev);
4031
4032 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004033}
4034
4035static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004036{
Johannes Berg4c476992010-10-04 21:36:35 +02004037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4038 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004039
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004040 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004041}
4042
Johannes Berg5727ef12007-12-19 02:03:34 +01004043static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4044 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4045 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4046 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004047 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004048 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004049 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004050};
4051
Johannes Bergeccb8e82009-05-11 21:57:56 +03004052static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004053 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004054 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004055{
4056 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004057 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004058 int flag;
4059
Johannes Bergeccb8e82009-05-11 21:57:56 +03004060 /*
4061 * Try parsing the new attribute first so userspace
4062 * can specify both for older kernels.
4063 */
4064 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4065 if (nla) {
4066 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004067
Johannes Bergeccb8e82009-05-11 21:57:56 +03004068 sta_flags = nla_data(nla);
4069 params->sta_flags_mask = sta_flags->mask;
4070 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004072 if ((params->sta_flags_mask |
4073 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4074 return -EINVAL;
4075 return 0;
4076 }
4077
4078 /* if present, parse the old attribute */
4079
4080 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004081 if (!nla)
4082 return 0;
4083
4084 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4085 nla, sta_flags_policy))
4086 return -EINVAL;
4087
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004088 /*
4089 * Only allow certain flags for interface types so that
4090 * other attributes are silently ignored. Remember that
4091 * this is backward compatibility code with old userspace
4092 * and shouldn't be hit in other cases anyway.
4093 */
4094 switch (iftype) {
4095 case NL80211_IFTYPE_AP:
4096 case NL80211_IFTYPE_AP_VLAN:
4097 case NL80211_IFTYPE_P2P_GO:
4098 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4099 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4100 BIT(NL80211_STA_FLAG_WME) |
4101 BIT(NL80211_STA_FLAG_MFP);
4102 break;
4103 case NL80211_IFTYPE_P2P_CLIENT:
4104 case NL80211_IFTYPE_STATION:
4105 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4106 BIT(NL80211_STA_FLAG_TDLS_PEER);
4107 break;
4108 case NL80211_IFTYPE_MESH_POINT:
4109 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4110 BIT(NL80211_STA_FLAG_MFP) |
4111 BIT(NL80211_STA_FLAG_AUTHORIZED);
4112 default:
4113 return -EINVAL;
4114 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004115
Johannes Berg3383b5a2012-05-10 20:14:43 +02004116 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4117 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004118 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004119
Johannes Berg3383b5a2012-05-10 20:14:43 +02004120 /* no longer support new API additions in old API */
4121 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4122 return -EINVAL;
4123 }
4124 }
4125
Johannes Berg5727ef12007-12-19 02:03:34 +01004126 return 0;
4127}
4128
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004129static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4130 int attr)
4131{
4132 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004133 u32 bitrate;
4134 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004135 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004136
4137 rate = nla_nest_start(msg, attr);
4138 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004139 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004140
4141 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4142 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004143 /* report 16-bit bitrate only if we can */
4144 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004145 if (bitrate > 0 &&
4146 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4147 return false;
4148 if (bitrate_compat > 0 &&
4149 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4150 return false;
4151
Johannes Bergb51f3be2015-01-15 16:14:02 +01004152 switch (info->bw) {
4153 case RATE_INFO_BW_5:
4154 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4155 break;
4156 case RATE_INFO_BW_10:
4157 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4158 break;
4159 default:
4160 WARN_ON(1);
4161 /* fall through */
4162 case RATE_INFO_BW_20:
4163 rate_flg = 0;
4164 break;
4165 case RATE_INFO_BW_40:
4166 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4167 break;
4168 case RATE_INFO_BW_80:
4169 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4170 break;
4171 case RATE_INFO_BW_160:
4172 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4173 break;
4174 }
4175
4176 if (rate_flg && nla_put_flag(msg, rate_flg))
4177 return false;
4178
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004179 if (info->flags & RATE_INFO_FLAGS_MCS) {
4180 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4181 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004182 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4183 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4184 return false;
4185 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4186 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4187 return false;
4188 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4189 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004190 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4191 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4192 return false;
4193 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004194
4195 nla_nest_end(msg, rate);
4196 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004197}
4198
Felix Fietkau119363c2013-04-22 16:29:30 +02004199static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4200 int id)
4201{
4202 void *attr;
4203 int i = 0;
4204
4205 if (!mask)
4206 return true;
4207
4208 attr = nla_nest_start(msg, id);
4209 if (!attr)
4210 return false;
4211
4212 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4213 if (!(mask & BIT(i)))
4214 continue;
4215
4216 if (nla_put_u8(msg, i, signal[i]))
4217 return false;
4218 }
4219
4220 nla_nest_end(msg, attr);
4221
4222 return true;
4223}
4224
Johannes Bergcf5ead82014-11-14 17:14:00 +01004225static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4226 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004227 struct cfg80211_registered_device *rdev,
4228 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004229 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004230{
4231 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004232 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004233
Johannes Bergcf5ead82014-11-14 17:14:00 +01004234 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004235 if (!hdr)
4236 return -1;
4237
David S. Miller9360ffd2012-03-29 04:41:26 -04004238 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4239 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4240 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4241 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004242
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004243 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4244 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004245 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004246
4247#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004248 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304249 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004250 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4251 sinfo->memb)) \
4252 goto nla_put_failure; \
4253 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004254#define PUT_SINFO_U64(attr, memb) do { \
4255 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4256 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4257 sinfo->memb, NL80211_STA_INFO_PAD)) \
4258 goto nla_put_failure; \
4259 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004260
4261 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4262 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4263
4264 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4265 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004266 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004267 (u32)sinfo->rx_bytes))
4268 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004269
4270 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4271 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004272 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4273 (u32)sinfo->tx_bytes))
4274 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004275
Johannes Bergd686b922016-04-26 09:54:11 +02004276 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4277 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004278 PUT_SINFO(LLID, llid, u16);
4279 PUT_SINFO(PLID, plid, u16);
4280 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004281 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004282
John W. Linville66266b32012-03-15 13:25:41 -04004283 switch (rdev->wiphy.signal_type) {
4284 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004285 PUT_SINFO(SIGNAL, signal, u8);
4286 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004287 break;
4288 default:
4289 break;
4290 }
Johannes Berg319090b2014-11-17 14:08:11 +01004291 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004292 if (!nl80211_put_signal(msg, sinfo->chains,
4293 sinfo->chain_signal,
4294 NL80211_STA_INFO_CHAIN_SIGNAL))
4295 goto nla_put_failure;
4296 }
Johannes Berg319090b2014-11-17 14:08:11 +01004297 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004298 if (!nl80211_put_signal(msg, sinfo->chains,
4299 sinfo->chain_signal_avg,
4300 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4301 goto nla_put_failure;
4302 }
Johannes Berg319090b2014-11-17 14:08:11 +01004303 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004304 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4305 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004306 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004307 }
Johannes Berg319090b2014-11-17 14:08:11 +01004308 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004309 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4310 NL80211_STA_INFO_RX_BITRATE))
4311 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004312 }
Johannes Berg319090b2014-11-17 14:08:11 +01004313
4314 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4315 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4316 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4317 PUT_SINFO(TX_FAILED, tx_failed, u32);
4318 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4319 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4320 PUT_SINFO(LOCAL_PM, local_pm, u32);
4321 PUT_SINFO(PEER_PM, peer_pm, u32);
4322 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4323
4324 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004325 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4326 if (!bss_param)
4327 goto nla_put_failure;
4328
David S. Miller9360ffd2012-03-29 04:41:26 -04004329 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4330 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4331 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4332 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4333 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4334 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4335 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4336 sinfo->bss_param.dtim_period) ||
4337 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4338 sinfo->bss_param.beacon_interval))
4339 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004340
4341 nla_nest_end(msg, bss_param);
4342 }
Johannes Berg319090b2014-11-17 14:08:11 +01004343 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004344 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4345 sizeof(struct nl80211_sta_flag_update),
4346 &sinfo->sta_flags))
4347 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004348
Johannes Bergd686b922016-04-26 09:54:11 +02004349 PUT_SINFO_U64(T_OFFSET, t_offset);
4350 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4351 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004352 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004353
4354#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004355#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004356
4357 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4358 struct nlattr *tidsattr;
4359 int tid;
4360
4361 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4362 if (!tidsattr)
4363 goto nla_put_failure;
4364
4365 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4366 struct cfg80211_tid_stats *tidstats;
4367 struct nlattr *tidattr;
4368
4369 tidstats = &sinfo->pertid[tid];
4370
4371 if (!tidstats->filled)
4372 continue;
4373
4374 tidattr = nla_nest_start(msg, tid + 1);
4375 if (!tidattr)
4376 goto nla_put_failure;
4377
Johannes Bergd686b922016-04-26 09:54:11 +02004378#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004379 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004380 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4381 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004382 goto nla_put_failure; \
4383 } while (0)
4384
Johannes Bergd686b922016-04-26 09:54:11 +02004385 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4386 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4387 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4388 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004389
Johannes Bergd686b922016-04-26 09:54:11 +02004390#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004391 nla_nest_end(msg, tidattr);
4392 }
4393
4394 nla_nest_end(msg, tidsattr);
4395 }
4396
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004398
Johannes Berg319090b2014-11-17 14:08:11 +01004399 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004400 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4401 sinfo->assoc_req_ies))
4402 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004403
Johannes Berg053c0952015-01-16 22:09:00 +01004404 genlmsg_end(msg, hdr);
4405 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004406
4407 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004408 genlmsg_cancel(msg, hdr);
4409 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004410}
4411
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004412static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004413 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004414{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004415 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004416 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004417 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004418 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004419 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004420 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004421
Johannes Berg56769e72017-03-15 14:26:04 +01004422 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004423 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004424 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01004425 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004426
Johannes Berg97990a02013-04-19 01:02:55 +02004427 if (!wdev->netdev) {
4428 err = -EINVAL;
4429 goto out_err;
4430 }
4431
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004432 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004433 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004434 goto out_err;
4435 }
4436
Johannes Bergbba95fe2008-07-29 13:22:51 +02004437 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004438 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004439 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004440 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004441 if (err == -ENOENT)
4442 break;
4443 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004444 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004445
Johannes Bergcf5ead82014-11-14 17:14:00 +01004446 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004447 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004448 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004449 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004450 &sinfo) < 0)
4451 goto out;
4452
4453 sta_idx++;
4454 }
4455
Johannes Bergbba95fe2008-07-29 13:22:51 +02004456 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004457 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004458 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004459 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01004460 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004461
4462 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004463}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004464
Johannes Berg5727ef12007-12-19 02:03:34 +01004465static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4466{
Johannes Berg4c476992010-10-04 21:36:35 +02004467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4468 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004469 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004470 struct sk_buff *msg;
4471 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004472 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004473
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004474 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004475
4476 if (!info->attrs[NL80211_ATTR_MAC])
4477 return -EINVAL;
4478
4479 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4480
Johannes Berg4c476992010-10-04 21:36:35 +02004481 if (!rdev->ops->get_station)
4482 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004483
Hila Gonene35e4d22012-06-27 17:19:42 +03004484 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004485 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004486 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004487
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004489 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004490 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004491
Johannes Bergcf5ead82014-11-14 17:14:00 +01004492 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4493 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004494 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004495 nlmsg_free(msg);
4496 return -ENOBUFS;
4497 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004498
Johannes Berg4c476992010-10-04 21:36:35 +02004499 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004500}
4501
Johannes Berg77ee7c82013-02-15 00:48:33 +01004502int cfg80211_check_station_change(struct wiphy *wiphy,
4503 struct station_parameters *params,
4504 enum cfg80211_station_type statype)
4505{
Ayala Bekere4208422015-10-23 11:20:06 +03004506 if (params->listen_interval != -1 &&
4507 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004508 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004509
Ayala Beker17b94242016-03-17 15:41:38 +02004510 if (params->support_p2p_ps != -1 &&
4511 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4512 return -EINVAL;
4513
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004514 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004515 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4516 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004517 return -EINVAL;
4518
4519 /* When you run into this, adjust the code below for the new flag */
4520 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4521
4522 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004523 case CFG80211_STA_MESH_PEER_KERNEL:
4524 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004525 /*
4526 * No ignoring the TDLS flag here -- the userspace mesh
4527 * code doesn't have the bug of including TDLS in the
4528 * mask everywhere.
4529 */
4530 if (params->sta_flags_mask &
4531 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4532 BIT(NL80211_STA_FLAG_MFP) |
4533 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4534 return -EINVAL;
4535 break;
4536 case CFG80211_STA_TDLS_PEER_SETUP:
4537 case CFG80211_STA_TDLS_PEER_ACTIVE:
4538 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4539 return -EINVAL;
4540 /* ignore since it can't change */
4541 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4542 break;
4543 default:
4544 /* disallow mesh-specific things */
4545 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4546 return -EINVAL;
4547 if (params->local_pm)
4548 return -EINVAL;
4549 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4550 return -EINVAL;
4551 }
4552
4553 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4554 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4555 /* TDLS can't be set, ... */
4556 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4557 return -EINVAL;
4558 /*
4559 * ... but don't bother the driver with it. This works around
4560 * a hostapd/wpa_supplicant issue -- it always includes the
4561 * TLDS_PEER flag in the mask even for AP mode.
4562 */
4563 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4564 }
4565
Ayala Beker47edb112015-09-21 15:49:53 +03004566 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4567 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004568 /* reject other things that can't change */
4569 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4570 return -EINVAL;
4571 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4572 return -EINVAL;
4573 if (params->supported_rates)
4574 return -EINVAL;
4575 if (params->ext_capab || params->ht_capa || params->vht_capa)
4576 return -EINVAL;
4577 }
4578
Ayala Beker47edb112015-09-21 15:49:53 +03004579 if (statype != CFG80211_STA_AP_CLIENT &&
4580 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004581 if (params->vlan)
4582 return -EINVAL;
4583 }
4584
4585 switch (statype) {
4586 case CFG80211_STA_AP_MLME_CLIENT:
4587 /* Use this only for authorizing/unauthorizing a station */
4588 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4589 return -EOPNOTSUPP;
4590 break;
4591 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004592 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004593 /* accept only the listed bits */
4594 if (params->sta_flags_mask &
4595 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4596 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4597 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4598 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4599 BIT(NL80211_STA_FLAG_WME) |
4600 BIT(NL80211_STA_FLAG_MFP)))
4601 return -EINVAL;
4602
4603 /* but authenticated/associated only if driver handles it */
4604 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4605 params->sta_flags_mask &
4606 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4607 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4608 return -EINVAL;
4609 break;
4610 case CFG80211_STA_IBSS:
4611 case CFG80211_STA_AP_STA:
4612 /* reject any changes other than AUTHORIZED */
4613 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4614 return -EINVAL;
4615 break;
4616 case CFG80211_STA_TDLS_PEER_SETUP:
4617 /* reject any changes other than AUTHORIZED or WME */
4618 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4619 BIT(NL80211_STA_FLAG_WME)))
4620 return -EINVAL;
4621 /* force (at least) rates when authorizing */
4622 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4623 !params->supported_rates)
4624 return -EINVAL;
4625 break;
4626 case CFG80211_STA_TDLS_PEER_ACTIVE:
4627 /* reject any changes */
4628 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004629 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004630 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4631 return -EINVAL;
4632 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004633 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004634 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4635 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004636 return -EINVAL;
4637 break;
4638 }
4639
4640 return 0;
4641}
4642EXPORT_SYMBOL(cfg80211_check_station_change);
4643
Johannes Berg5727ef12007-12-19 02:03:34 +01004644/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004645 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004646 */
Johannes Berg80b99892011-11-18 16:23:01 +01004647static struct net_device *get_vlan(struct genl_info *info,
4648 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004649{
Johannes Berg463d0182009-07-14 00:33:35 +02004650 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004651 struct net_device *v;
4652 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004653
Johannes Berg80b99892011-11-18 16:23:01 +01004654 if (!vlanattr)
4655 return NULL;
4656
4657 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4658 if (!v)
4659 return ERR_PTR(-ENODEV);
4660
4661 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4662 ret = -EINVAL;
4663 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004664 }
Johannes Berg80b99892011-11-18 16:23:01 +01004665
Johannes Berg77ee7c82013-02-15 00:48:33 +01004666 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4667 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4668 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4669 ret = -EINVAL;
4670 goto error;
4671 }
4672
Johannes Berg80b99892011-11-18 16:23:01 +01004673 if (!netif_running(v)) {
4674 ret = -ENETDOWN;
4675 goto error;
4676 }
4677
4678 return v;
4679 error:
4680 dev_put(v);
4681 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004682}
4683
Johannes Berg94e860f2014-01-20 23:58:15 +01004684static const struct nla_policy
4685nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004686 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4687 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4688};
4689
Johannes Bergff276692013-02-15 00:09:01 +01004690static int nl80211_parse_sta_wme(struct genl_info *info,
4691 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004692{
Jouni Malinendf881292013-02-14 21:10:54 +02004693 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4694 struct nlattr *nla;
4695 int err;
4696
Jouni Malinendf881292013-02-14 21:10:54 +02004697 /* parse WME attributes if present */
4698 if (!info->attrs[NL80211_ATTR_STA_WME])
4699 return 0;
4700
4701 nla = info->attrs[NL80211_ATTR_STA_WME];
4702 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4703 nl80211_sta_wme_policy);
4704 if (err)
4705 return err;
4706
4707 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4708 params->uapsd_queues = nla_get_u8(
4709 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4710 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4711 return -EINVAL;
4712
4713 if (tb[NL80211_STA_WME_MAX_SP])
4714 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4715
4716 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4717 return -EINVAL;
4718
4719 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4720
4721 return 0;
4722}
4723
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304724static int nl80211_parse_sta_channel_info(struct genl_info *info,
4725 struct station_parameters *params)
4726{
4727 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4728 params->supported_channels =
4729 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4730 params->supported_channels_len =
4731 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4732 /*
4733 * Need to include at least one (first channel, number of
4734 * channels) tuple for each subband, and must have proper
4735 * tuples for the rest of the data as well.
4736 */
4737 if (params->supported_channels_len < 2)
4738 return -EINVAL;
4739 if (params->supported_channels_len % 2)
4740 return -EINVAL;
4741 }
4742
4743 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4744 params->supported_oper_classes =
4745 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4746 params->supported_oper_classes_len =
4747 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4748 /*
4749 * The value of the Length field of the Supported Operating
4750 * Classes element is between 2 and 253.
4751 */
4752 if (params->supported_oper_classes_len < 2 ||
4753 params->supported_oper_classes_len > 253)
4754 return -EINVAL;
4755 }
4756 return 0;
4757}
4758
Johannes Bergff276692013-02-15 00:09:01 +01004759static int nl80211_set_station_tdls(struct genl_info *info,
4760 struct station_parameters *params)
4761{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304762 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004763 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004764 if (info->attrs[NL80211_ATTR_PEER_AID])
4765 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004766 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4767 params->ht_capa =
4768 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4769 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4770 params->vht_capa =
4771 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4772
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304773 err = nl80211_parse_sta_channel_info(info, params);
4774 if (err)
4775 return err;
4776
Johannes Bergff276692013-02-15 00:09:01 +01004777 return nl80211_parse_sta_wme(info, params);
4778}
4779
Johannes Berg5727ef12007-12-19 02:03:34 +01004780static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4781{
Johannes Berg4c476992010-10-04 21:36:35 +02004782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004783 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004784 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004785 u8 *mac_addr;
4786 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004787
4788 memset(&params, 0, sizeof(params));
4789
Johannes Berg77ee7c82013-02-15 00:48:33 +01004790 if (!rdev->ops->change_station)
4791 return -EOPNOTSUPP;
4792
Ayala Bekere4208422015-10-23 11:20:06 +03004793 /*
4794 * AID and listen_interval properties can be set only for unassociated
4795 * station. Include these parameters here and will check them in
4796 * cfg80211_check_station_change().
4797 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004798 if (info->attrs[NL80211_ATTR_STA_AID])
4799 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004800
4801 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4802 params.listen_interval =
4803 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4804 else
4805 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004806
Ayala Beker17b94242016-03-17 15:41:38 +02004807 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4808 u8 tmp;
4809
4810 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4811 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4812 return -EINVAL;
4813
4814 params.support_p2p_ps = tmp;
4815 } else {
4816 params.support_p2p_ps = -1;
4817 }
4818
Johannes Berg5727ef12007-12-19 02:03:34 +01004819 if (!info->attrs[NL80211_ATTR_MAC])
4820 return -EINVAL;
4821
4822 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4823
4824 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4825 params.supported_rates =
4826 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4827 params.supported_rates_len =
4828 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4829 }
4830
Jouni Malinen9d62a982013-02-14 21:10:13 +02004831 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4832 params.capability =
4833 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4834 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4835 }
4836
4837 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4838 params.ext_capab =
4839 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4840 params.ext_capab_len =
4841 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4842 }
4843
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004844 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004845 return -EINVAL;
4846
Johannes Bergf8bacc22013-02-14 23:27:01 +01004847 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004848 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004849 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4850 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4851 return -EINVAL;
4852 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004853
Johannes Bergf8bacc22013-02-14 23:27:01 +01004854 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004855 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004856 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4857 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4858 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004859 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4860 params.peer_aid = nla_get_u16(
4861 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4862 if (params.peer_aid > IEEE80211_MAX_AID)
4863 return -EINVAL;
4864 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004865 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4866 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004867
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004868 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4869 enum nl80211_mesh_power_mode pm = nla_get_u32(
4870 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4871
4872 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4873 pm > NL80211_MESH_POWER_MAX)
4874 return -EINVAL;
4875
4876 params.local_pm = pm;
4877 }
4878
Johannes Berg77ee7c82013-02-15 00:48:33 +01004879 /* Include parameters for TDLS peer (will check later) */
4880 err = nl80211_set_station_tdls(info, &params);
4881 if (err)
4882 return err;
4883
4884 params.vlan = get_vlan(info, rdev);
4885 if (IS_ERR(params.vlan))
4886 return PTR_ERR(params.vlan);
4887
Johannes Berga97f4422009-06-18 17:23:43 +02004888 switch (dev->ieee80211_ptr->iftype) {
4889 case NL80211_IFTYPE_AP:
4890 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004891 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004892 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004893 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004894 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004895 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004896 break;
4897 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004898 err = -EOPNOTSUPP;
4899 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004900 }
4901
Johannes Berg77ee7c82013-02-15 00:48:33 +01004902 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004903 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004904
Johannes Berg77ee7c82013-02-15 00:48:33 +01004905 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004906 if (params.vlan)
4907 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004908
Johannes Berg5727ef12007-12-19 02:03:34 +01004909 return err;
4910}
4911
4912static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4913{
Johannes Berg4c476992010-10-04 21:36:35 +02004914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004915 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004916 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004917 struct station_parameters params;
4918 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004919 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4920 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004921
4922 memset(&params, 0, sizeof(params));
4923
Johannes Berg984c3112013-02-14 23:43:25 +01004924 if (!rdev->ops->add_station)
4925 return -EOPNOTSUPP;
4926
Johannes Berg5727ef12007-12-19 02:03:34 +01004927 if (!info->attrs[NL80211_ATTR_MAC])
4928 return -EINVAL;
4929
Johannes Berg5727ef12007-12-19 02:03:34 +01004930 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4931 return -EINVAL;
4932
4933 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4934 return -EINVAL;
4935
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004936 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4937 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004938 return -EINVAL;
4939
Johannes Berg5727ef12007-12-19 02:03:34 +01004940 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4941 params.supported_rates =
4942 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4943 params.supported_rates_len =
4944 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4945 params.listen_interval =
4946 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004947
Ayala Beker17b94242016-03-17 15:41:38 +02004948 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4949 u8 tmp;
4950
4951 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4952 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4953 return -EINVAL;
4954
4955 params.support_p2p_ps = tmp;
4956 } else {
4957 /*
4958 * if not specified, assume it's supported for P2P GO interface,
4959 * and is NOT supported for AP interface
4960 */
4961 params.support_p2p_ps =
4962 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4963 }
4964
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004965 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004966 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004967 else
4968 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004969 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4970 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004971
Jouni Malinen9d62a982013-02-14 21:10:13 +02004972 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4973 params.capability =
4974 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4975 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4976 }
4977
4978 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4979 params.ext_capab =
4980 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4981 params.ext_capab_len =
4982 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4983 }
4984
Jouni Malinen36aedc902008-08-25 11:58:58 +03004985 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4986 params.ht_capa =
4987 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004988
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004989 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4990 params.vht_capa =
4991 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4992
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004993 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4994 params.opmode_notif_used = true;
4995 params.opmode_notif =
4996 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4997 }
4998
Johannes Bergf8bacc22013-02-14 23:27:01 +01004999 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07005000 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005001 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
5002 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
5003 return -EINVAL;
5004 }
Javier Cardona96b78df2011-04-07 15:08:33 -07005005
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305006 err = nl80211_parse_sta_channel_info(info, &params);
5007 if (err)
5008 return err;
5009
Johannes Bergff276692013-02-15 00:09:01 +01005010 err = nl80211_parse_sta_wme(info, &params);
5011 if (err)
5012 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005013
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005014 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005015 return -EINVAL;
5016
Johannes Berg496fcc22015-03-12 08:53:27 +02005017 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5018 * as userspace might just pass through the capabilities from the IEs
5019 * directly, rather than enforcing this restriction and returning an
5020 * error in this case.
5021 */
5022 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5023 params.ht_capa = NULL;
5024 params.vht_capa = NULL;
5025 }
5026
Johannes Berg77ee7c82013-02-15 00:48:33 +01005027 /* When you run into this, adjust the code below for the new flag */
5028 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5029
Johannes Bergbdd90d52011-12-14 12:20:27 +01005030 switch (dev->ieee80211_ptr->iftype) {
5031 case NL80211_IFTYPE_AP:
5032 case NL80211_IFTYPE_AP_VLAN:
5033 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005034 /* ignore WME attributes if iface/sta is not capable */
5035 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5036 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5037 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005038
Johannes Bergbdd90d52011-12-14 12:20:27 +01005039 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005040 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5041 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005042 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005043 /* but don't bother the driver with it */
5044 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005045
Johannes Bergd582cff2012-10-26 17:53:44 +02005046 /* allow authenticated/associated only if driver handles it */
5047 if (!(rdev->wiphy.features &
5048 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005049 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005050 return -EINVAL;
5051
Johannes Bergbda95eb2015-11-26 16:26:13 +01005052 /* Older userspace, or userspace wanting to be compatible with
5053 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5054 * and assoc flags in the mask, but assumes the station will be
5055 * added as associated anyway since this was the required driver
5056 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5057 * introduced.
5058 * In order to not bother drivers with this quirk in the API
5059 * set the flags in both the mask and set for new stations in
5060 * this case.
5061 */
5062 if (!(params.sta_flags_mask & auth_assoc)) {
5063 params.sta_flags_mask |= auth_assoc;
5064 params.sta_flags_set |= auth_assoc;
5065 }
5066
Johannes Bergbdd90d52011-12-14 12:20:27 +01005067 /* must be last in here for error handling */
5068 params.vlan = get_vlan(info, rdev);
5069 if (IS_ERR(params.vlan))
5070 return PTR_ERR(params.vlan);
5071 break;
5072 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005073 /* ignore uAPSD data */
5074 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5075
Johannes Bergd582cff2012-10-26 17:53:44 +02005076 /* associated is disallowed */
5077 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5078 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005079 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005080 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5081 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005082 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005083 break;
5084 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005085 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005086 /* ignore uAPSD data */
5087 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5088
Johannes Berg77ee7c82013-02-15 00:48:33 +01005089 /* these are disallowed */
5090 if (params.sta_flags_mask &
5091 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5092 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005093 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005094 /* Only TDLS peers can be added */
5095 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5096 return -EINVAL;
5097 /* Can only add if TDLS ... */
5098 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5099 return -EOPNOTSUPP;
5100 /* ... with external setup is supported */
5101 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5102 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005103 /*
5104 * Older wpa_supplicant versions always mark the TDLS peer
5105 * as authorized, but it shouldn't yet be.
5106 */
5107 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005108 break;
5109 default:
5110 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005111 }
5112
Johannes Bergbdd90d52011-12-14 12:20:27 +01005113 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005114
Hila Gonene35e4d22012-06-27 17:19:42 +03005115 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005116
Johannes Berg5727ef12007-12-19 02:03:34 +01005117 if (params.vlan)
5118 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005119 return err;
5120}
5121
5122static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5123{
Johannes Berg4c476992010-10-04 21:36:35 +02005124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5125 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005126 struct station_del_parameters params;
5127
5128 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005129
5130 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005131 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005132
Johannes Berge80cf852009-05-11 14:43:13 +02005133 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005134 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005135 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005136 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5137 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005138
Johannes Berg4c476992010-10-04 21:36:35 +02005139 if (!rdev->ops->del_station)
5140 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005141
Jouni Malinen98856862014-10-20 13:20:45 +03005142 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5143 params.subtype =
5144 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5145 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5146 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5147 return -EINVAL;
5148 } else {
5149 /* Default to Deauthentication frame */
5150 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5151 }
5152
5153 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5154 params.reason_code =
5155 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5156 if (params.reason_code == 0)
5157 return -EINVAL; /* 0 is reserved */
5158 } else {
5159 /* Default to reason code 2 */
5160 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5161 }
5162
Jouni Malinen89c771e2014-10-10 20:52:40 +03005163 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005164}
5165
Eric W. Biederman15e47302012-09-07 20:12:54 +00005166static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005167 int flags, struct net_device *dev,
5168 u8 *dst, u8 *next_hop,
5169 struct mpath_info *pinfo)
5170{
5171 void *hdr;
5172 struct nlattr *pinfoattr;
5173
Henning Rogge1ef4c852014-11-04 16:14:58 +01005174 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005175 if (!hdr)
5176 return -1;
5177
David S. Miller9360ffd2012-03-29 04:41:26 -04005178 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5180 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5181 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5182 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005183
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005184 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5185 if (!pinfoattr)
5186 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005187 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5188 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5189 pinfo->frame_qlen))
5190 goto nla_put_failure;
5191 if (((pinfo->filled & MPATH_INFO_SN) &&
5192 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5193 ((pinfo->filled & MPATH_INFO_METRIC) &&
5194 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5195 pinfo->metric)) ||
5196 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5197 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5198 pinfo->exptime)) ||
5199 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5200 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5201 pinfo->flags)) ||
5202 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5203 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5204 pinfo->discovery_timeout)) ||
5205 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5206 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5207 pinfo->discovery_retries)))
5208 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005209
5210 nla_nest_end(msg, pinfoattr);
5211
Johannes Berg053c0952015-01-16 22:09:00 +01005212 genlmsg_end(msg, hdr);
5213 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005214
5215 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005216 genlmsg_cancel(msg, hdr);
5217 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005218}
5219
5220static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005221 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005222{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005223 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005224 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005225 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005226 u8 dst[ETH_ALEN];
5227 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005228 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005229 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005230
Johannes Berg56769e72017-03-15 14:26:04 +01005231 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005232 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005233 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005234 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005235
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005236 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005237 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005238 goto out_err;
5239 }
5240
Johannes Berg97990a02013-04-19 01:02:55 +02005241 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005242 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005243 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005244 }
5245
Johannes Bergbba95fe2008-07-29 13:22:51 +02005246 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005247 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005248 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005249 if (err == -ENOENT)
5250 break;
5251 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005252 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005253
Eric W. Biederman15e47302012-09-07 20:12:54 +00005254 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005255 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005256 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005257 &pinfo) < 0)
5258 goto out;
5259
5260 path_idx++;
5261 }
5262
Johannes Bergbba95fe2008-07-29 13:22:51 +02005263 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005264 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005265 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005266 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005267 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005268 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005269}
5270
5271static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5272{
Johannes Berg4c476992010-10-04 21:36:35 +02005273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005274 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005275 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005276 struct mpath_info pinfo;
5277 struct sk_buff *msg;
5278 u8 *dst = NULL;
5279 u8 next_hop[ETH_ALEN];
5280
5281 memset(&pinfo, 0, sizeof(pinfo));
5282
5283 if (!info->attrs[NL80211_ATTR_MAC])
5284 return -EINVAL;
5285
5286 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5287
Johannes Berg4c476992010-10-04 21:36:35 +02005288 if (!rdev->ops->get_mpath)
5289 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005290
Johannes Berg4c476992010-10-04 21:36:35 +02005291 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5292 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005293
Hila Gonene35e4d22012-06-27 17:19:42 +03005294 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005295 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005296 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005297
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005298 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005299 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005300 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005301
Eric W. Biederman15e47302012-09-07 20:12:54 +00005302 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005303 dev, dst, next_hop, &pinfo) < 0) {
5304 nlmsg_free(msg);
5305 return -ENOBUFS;
5306 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005307
Johannes Berg4c476992010-10-04 21:36:35 +02005308 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005309}
5310
5311static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5312{
Johannes Berg4c476992010-10-04 21:36:35 +02005313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5314 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005315 u8 *dst = NULL;
5316 u8 *next_hop = NULL;
5317
5318 if (!info->attrs[NL80211_ATTR_MAC])
5319 return -EINVAL;
5320
5321 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5322 return -EINVAL;
5323
5324 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5325 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5326
Johannes Berg4c476992010-10-04 21:36:35 +02005327 if (!rdev->ops->change_mpath)
5328 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005329
Johannes Berg4c476992010-10-04 21:36:35 +02005330 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5331 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005332
Hila Gonene35e4d22012-06-27 17:19:42 +03005333 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005334}
Johannes Berg4c476992010-10-04 21:36:35 +02005335
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005336static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5337{
Johannes Berg4c476992010-10-04 21:36:35 +02005338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5339 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005340 u8 *dst = NULL;
5341 u8 *next_hop = NULL;
5342
5343 if (!info->attrs[NL80211_ATTR_MAC])
5344 return -EINVAL;
5345
5346 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5347 return -EINVAL;
5348
5349 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5350 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5351
Johannes Berg4c476992010-10-04 21:36:35 +02005352 if (!rdev->ops->add_mpath)
5353 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005354
Johannes Berg4c476992010-10-04 21:36:35 +02005355 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5356 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005357
Hila Gonene35e4d22012-06-27 17:19:42 +03005358 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005359}
5360
5361static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5362{
Johannes Berg4c476992010-10-04 21:36:35 +02005363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5364 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005365 u8 *dst = NULL;
5366
5367 if (info->attrs[NL80211_ATTR_MAC])
5368 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5369
Johannes Berg4c476992010-10-04 21:36:35 +02005370 if (!rdev->ops->del_mpath)
5371 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005372
Hila Gonene35e4d22012-06-27 17:19:42 +03005373 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005374}
5375
Henning Rogge66be7d22014-09-12 08:58:49 +02005376static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5377{
5378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5379 int err;
5380 struct net_device *dev = info->user_ptr[1];
5381 struct mpath_info pinfo;
5382 struct sk_buff *msg;
5383 u8 *dst = NULL;
5384 u8 mpp[ETH_ALEN];
5385
5386 memset(&pinfo, 0, sizeof(pinfo));
5387
5388 if (!info->attrs[NL80211_ATTR_MAC])
5389 return -EINVAL;
5390
5391 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5392
5393 if (!rdev->ops->get_mpp)
5394 return -EOPNOTSUPP;
5395
5396 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5397 return -EOPNOTSUPP;
5398
5399 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5400 if (err)
5401 return err;
5402
5403 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5404 if (!msg)
5405 return -ENOMEM;
5406
5407 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5408 dev, dst, mpp, &pinfo) < 0) {
5409 nlmsg_free(msg);
5410 return -ENOBUFS;
5411 }
5412
5413 return genlmsg_reply(msg, info);
5414}
5415
5416static int nl80211_dump_mpp(struct sk_buff *skb,
5417 struct netlink_callback *cb)
5418{
5419 struct mpath_info pinfo;
5420 struct cfg80211_registered_device *rdev;
5421 struct wireless_dev *wdev;
5422 u8 dst[ETH_ALEN];
5423 u8 mpp[ETH_ALEN];
5424 int path_idx = cb->args[2];
5425 int err;
5426
Johannes Berg56769e72017-03-15 14:26:04 +01005427 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005428 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5429 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005430 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005431
5432 if (!rdev->ops->dump_mpp) {
5433 err = -EOPNOTSUPP;
5434 goto out_err;
5435 }
5436
5437 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5438 err = -EOPNOTSUPP;
5439 goto out_err;
5440 }
5441
5442 while (1) {
5443 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5444 mpp, &pinfo);
5445 if (err == -ENOENT)
5446 break;
5447 if (err)
5448 goto out_err;
5449
5450 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5451 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5452 wdev->netdev, dst, mpp,
5453 &pinfo) < 0)
5454 goto out;
5455
5456 path_idx++;
5457 }
5458
5459 out:
5460 cb->args[2] = path_idx;
5461 err = skb->len;
5462 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005463 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005464 return err;
5465}
5466
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005467static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5468{
Johannes Berg4c476992010-10-04 21:36:35 +02005469 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5470 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005471 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005472 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005473 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005474
5475 memset(&params, 0, sizeof(params));
5476 /* default to not changing parameters */
5477 params.use_cts_prot = -1;
5478 params.use_short_preamble = -1;
5479 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005480 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005481 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005482 params.p2p_ctwindow = -1;
5483 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005484
5485 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5486 params.use_cts_prot =
5487 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5488 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5489 params.use_short_preamble =
5490 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5491 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5492 params.use_short_slot_time =
5493 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005494 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5495 params.basic_rates =
5496 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5497 params.basic_rates_len =
5498 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5499 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005500 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5501 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005502 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5503 params.ht_opmode =
5504 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005505
Johannes Berg53cabad2012-11-14 15:17:28 +01005506 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5507 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5508 return -EINVAL;
5509 params.p2p_ctwindow =
5510 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5511 if (params.p2p_ctwindow < 0)
5512 return -EINVAL;
5513 if (params.p2p_ctwindow != 0 &&
5514 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5515 return -EINVAL;
5516 }
5517
5518 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5519 u8 tmp;
5520
5521 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5522 return -EINVAL;
5523 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5524 if (tmp > 1)
5525 return -EINVAL;
5526 params.p2p_opp_ps = tmp;
5527 if (params.p2p_opp_ps &&
5528 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5529 return -EINVAL;
5530 }
5531
Johannes Berg4c476992010-10-04 21:36:35 +02005532 if (!rdev->ops->change_bss)
5533 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005534
Johannes Berg074ac8d2010-09-16 14:58:22 +02005535 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005536 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5537 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005538
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005539 wdev_lock(wdev);
5540 err = rdev_change_bss(rdev, dev, &params);
5541 wdev_unlock(wdev);
5542
5543 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005544}
5545
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005546static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5547{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005548 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005549 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005550 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005551 u32 owner_nlportid;
5552
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005553 /*
5554 * You should only get this when cfg80211 hasn't yet initialized
5555 * completely when built-in to the kernel right between the time
5556 * window between nl80211_init() and regulatory_init(), if that is
5557 * even possible.
5558 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005559 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005560 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005561
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005562 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5563 user_reg_hint_type =
5564 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5565 else
5566 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5567
5568 switch (user_reg_hint_type) {
5569 case NL80211_USER_REG_HINT_USER:
5570 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005571 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5572 return -EINVAL;
5573
5574 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5575 return regulatory_hint_user(data, user_reg_hint_type);
5576 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005577 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5578 owner_nlportid = info->snd_portid;
5579 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5580 } else {
5581 owner_nlportid = 0;
5582 is_indoor = true;
5583 }
5584
5585 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005586 default:
5587 return -EINVAL;
5588 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005589}
5590
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005591static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005592 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005593{
Johannes Berg4c476992010-10-04 21:36:35 +02005594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005595 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005596 struct wireless_dev *wdev = dev->ieee80211_ptr;
5597 struct mesh_config cur_params;
5598 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005599 void *hdr;
5600 struct nlattr *pinfoattr;
5601 struct sk_buff *msg;
5602
Johannes Berg29cbe682010-12-03 09:20:44 +01005603 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5604 return -EOPNOTSUPP;
5605
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005606 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005607 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005608
Johannes Berg29cbe682010-12-03 09:20:44 +01005609 wdev_lock(wdev);
5610 /* If not connected, get default parameters */
5611 if (!wdev->mesh_id_len)
5612 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5613 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005614 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005615 wdev_unlock(wdev);
5616
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005617 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005618 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005619
5620 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005622 if (!msg)
5623 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005624 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005625 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005626 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005627 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005628 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005629 if (!pinfoattr)
5630 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005631 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5632 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5633 cur_params.dot11MeshRetryTimeout) ||
5634 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5635 cur_params.dot11MeshConfirmTimeout) ||
5636 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5637 cur_params.dot11MeshHoldingTimeout) ||
5638 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5639 cur_params.dot11MeshMaxPeerLinks) ||
5640 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5641 cur_params.dot11MeshMaxRetries) ||
5642 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5643 cur_params.dot11MeshTTL) ||
5644 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5645 cur_params.element_ttl) ||
5646 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5647 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005648 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5649 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005650 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5651 cur_params.dot11MeshHWMPmaxPREQretries) ||
5652 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5653 cur_params.path_refresh_time) ||
5654 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5655 cur_params.min_discovery_timeout) ||
5656 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5657 cur_params.dot11MeshHWMPactivePathTimeout) ||
5658 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5659 cur_params.dot11MeshHWMPpreqMinInterval) ||
5660 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5661 cur_params.dot11MeshHWMPperrMinInterval) ||
5662 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5663 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5664 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5665 cur_params.dot11MeshHWMPRootMode) ||
5666 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5667 cur_params.dot11MeshHWMPRannInterval) ||
5668 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5669 cur_params.dot11MeshGateAnnouncementProtocol) ||
5670 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5671 cur_params.dot11MeshForwarding) ||
5672 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005673 cur_params.rssi_threshold) ||
5674 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005675 cur_params.ht_opmode) ||
5676 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5677 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5678 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005679 cur_params.dot11MeshHWMProotInterval) ||
5680 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005681 cur_params.dot11MeshHWMPconfirmationInterval) ||
5682 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5683 cur_params.power_mode) ||
5684 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005685 cur_params.dot11MeshAwakeWindowDuration) ||
5686 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5687 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005688 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005689 nla_nest_end(msg, pinfoattr);
5690 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005691 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005692
Johannes Berg3b858752009-03-12 09:55:09 +01005693 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005694 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005695 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005696 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005697 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005698}
5699
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005700static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005701 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5702 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5703 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5704 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5705 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5706 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005707 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005708 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005709 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005710 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5711 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5712 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5713 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5714 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005715 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005716 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005717 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005718 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005719 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005720 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005721 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5722 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005723 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5724 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005725 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005726 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5727 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005728 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005729};
5730
Javier Cardonac80d5452010-12-16 17:37:49 -08005731static const struct nla_policy
5732 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005733 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005734 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5735 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005736 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005737 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005738 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005739 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005740 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005741 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005742};
5743
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005744static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5745{
5746 u8 val = nla_get_u8(nla);
5747 if (val < min || val > max)
5748 return -EINVAL;
5749 *out = val;
5750 return 0;
5751}
5752
5753static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5754{
5755 u8 val = nla_get_u8(nla);
5756 if (val < min || val > max)
5757 return -EINVAL;
5758 *out = val;
5759 return 0;
5760}
5761
5762static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5763{
5764 u16 val = nla_get_u16(nla);
5765 if (val < min || val > max)
5766 return -EINVAL;
5767 *out = val;
5768 return 0;
5769}
5770
5771static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5772{
5773 u32 val = nla_get_u32(nla);
5774 if (val < min || val > max)
5775 return -EINVAL;
5776 *out = val;
5777 return 0;
5778}
5779
5780static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5781{
5782 s32 val = nla_get_s32(nla);
5783 if (val < min || val > max)
5784 return -EINVAL;
5785 *out = val;
5786 return 0;
5787}
5788
Johannes Bergff9a71a2016-08-11 14:59:53 +02005789static int nl80211_check_power_mode(const struct nlattr *nla,
5790 enum nl80211_mesh_power_mode min,
5791 enum nl80211_mesh_power_mode max,
5792 enum nl80211_mesh_power_mode *out)
5793{
5794 u32 val = nla_get_u32(nla);
5795 if (val < min || val > max)
5796 return -EINVAL;
5797 *out = val;
5798 return 0;
5799}
5800
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005801static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005802 struct mesh_config *cfg,
5803 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005804{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005806 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005807 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005808
Marco Porschea54fba2013-01-07 16:04:48 +01005809#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5810do { \
5811 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005812 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005813 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005814 mask |= (1 << (attr - 1)); \
5815 } \
5816} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005817
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005818 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005819 return -EINVAL;
5820 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005821 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005822 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005823 return -EINVAL;
5824
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005825 /* This makes sure that there aren't more than 32 mesh config
5826 * parameters (otherwise our bitfield scheme would not work.) */
5827 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5828
5829 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005830 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005831 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005832 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005834 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005835 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005836 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005837 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005838 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005840 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005841 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005843 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005844 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005846 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005847 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005848 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005849 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005851 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005852 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5854 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005855 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005856 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005858 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005859 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005861 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005862 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005863 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005864 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005865 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5867 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005868 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005869 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005871 1, 65535, mask,
5872 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005873 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005874 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005875 1, 65535, mask,
5876 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005877 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005879 dot11MeshHWMPnetDiameterTraversalTime,
5880 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005881 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005882 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005883 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5884 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005885 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005886 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5887 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005888 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005890 dot11MeshGateAnnouncementProtocol, 0, 1,
5891 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005892 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005894 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005895 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005896 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005897 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005898 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005899 /*
5900 * Check HT operation mode based on
5901 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5902 */
5903 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5904 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5905
5906 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5907 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5908 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5909 return -EINVAL;
5910
5911 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5912 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5913 return -EINVAL;
5914
5915 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5916 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5917 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5918 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5919 return -EINVAL;
5920 break;
5921 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5922 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5923 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5924 return -EINVAL;
5925 break;
5926 }
5927 cfg->ht_opmode = ht_opmode;
Masashi Honmaf9bd7912017-01-26 08:56:13 +09005928 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09005929 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005930 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005931 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005932 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005933 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005935 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005936 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005938 dot11MeshHWMPconfirmationInterval,
5939 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005940 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005941 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5943 NL80211_MESH_POWER_ACTIVE,
5944 NL80211_MESH_POWER_MAX,
5945 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005946 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5948 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005949 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005951 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005952 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005953 if (mask_out)
5954 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005955
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005956 return 0;
5957
5958#undef FILL_IN_MESH_PARAM_IF_SET
5959}
5960
Javier Cardonac80d5452010-12-16 17:37:49 -08005961static int nl80211_parse_mesh_setup(struct genl_info *info,
5962 struct mesh_setup *setup)
5963{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005965 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5966
5967 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5968 return -EINVAL;
5969 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5970 info->attrs[NL80211_ATTR_MESH_SETUP],
5971 nl80211_mesh_setup_params_policy))
5972 return -EINVAL;
5973
Javier Cardonad299a1f2012-03-31 11:31:33 -07005974 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5975 setup->sync_method =
5976 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5977 IEEE80211_SYNC_METHOD_VENDOR :
5978 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5979
Javier Cardonac80d5452010-12-16 17:37:49 -08005980 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5981 setup->path_sel_proto =
5982 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5983 IEEE80211_PATH_PROTOCOL_VENDOR :
5984 IEEE80211_PATH_PROTOCOL_HWMP;
5985
5986 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5987 setup->path_metric =
5988 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5989 IEEE80211_PATH_METRIC_VENDOR :
5990 IEEE80211_PATH_METRIC_AIRTIME;
5991
Javier Cardona581a8b02011-04-07 15:08:27 -07005992 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005993 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005994 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005995 if (!is_valid_ie_attr(ieattr))
5996 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005997 setup->ie = nla_data(ieattr);
5998 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005999 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006000 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
6001 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
6002 return -EINVAL;
6003 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07006004 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
6005 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006006 if (setup->is_secure)
6007 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08006008
Colleen Twitty6e16d902013-05-08 11:45:59 -07006009 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
6010 if (!setup->user_mpm)
6011 return -EINVAL;
6012 setup->auth_id =
6013 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
6014 }
6015
Javier Cardonac80d5452010-12-16 17:37:49 -08006016 return 0;
6017}
6018
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006019static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006020 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006021{
6022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6023 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006024 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006025 struct mesh_config cfg;
6026 u32 mask;
6027 int err;
6028
Johannes Berg29cbe682010-12-03 09:20:44 +01006029 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6030 return -EOPNOTSUPP;
6031
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006032 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006033 return -EOPNOTSUPP;
6034
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006035 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006036 if (err)
6037 return err;
6038
Johannes Berg29cbe682010-12-03 09:20:44 +01006039 wdev_lock(wdev);
6040 if (!wdev->mesh_id_len)
6041 err = -ENOLINK;
6042
6043 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006044 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006045
6046 wdev_unlock(wdev);
6047
6048 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006049}
6050
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006051static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6052 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006053{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006054 struct nlattr *nl_reg_rules;
6055 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006056
Johannes Berg458f4f92012-12-06 15:47:38 +01006057 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6058 (regdom->dfs_region &&
6059 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006060 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006061
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006062 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6063 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006064 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006065
Johannes Berg458f4f92012-12-06 15:47:38 +01006066 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006067 struct nlattr *nl_reg_rule;
6068 const struct ieee80211_reg_rule *reg_rule;
6069 const struct ieee80211_freq_range *freq_range;
6070 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006071 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006072
Johannes Berg458f4f92012-12-06 15:47:38 +01006073 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006074 freq_range = &reg_rule->freq_range;
6075 power_rule = &reg_rule->power_rule;
6076
6077 nl_reg_rule = nla_nest_start(msg, i);
6078 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006079 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006080
Janusz Dziedzic97524822014-01-30 09:52:20 +01006081 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6082 if (!max_bandwidth_khz)
6083 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6084 reg_rule);
6085
David S. Miller9360ffd2012-03-29 04:41:26 -04006086 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6087 reg_rule->flags) ||
6088 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6089 freq_range->start_freq_khz) ||
6090 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6091 freq_range->end_freq_khz) ||
6092 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006093 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006094 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6095 power_rule->max_antenna_gain) ||
6096 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006097 power_rule->max_eirp) ||
6098 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6099 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006100 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006101
6102 nla_nest_end(msg, nl_reg_rule);
6103 }
6104
6105 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006106 return 0;
6107
6108nla_put_failure:
6109 return -EMSGSIZE;
6110}
6111
6112static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6113{
6114 const struct ieee80211_regdomain *regdom = NULL;
6115 struct cfg80211_registered_device *rdev;
6116 struct wiphy *wiphy = NULL;
6117 struct sk_buff *msg;
6118 void *hdr;
6119
6120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6121 if (!msg)
6122 return -ENOBUFS;
6123
6124 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6125 NL80211_CMD_GET_REG);
6126 if (!hdr)
6127 goto put_failure;
6128
6129 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006130 bool self_managed;
6131
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006132 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6133 if (IS_ERR(rdev)) {
6134 nlmsg_free(msg);
6135 return PTR_ERR(rdev);
6136 }
6137
6138 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006139 self_managed = wiphy->regulatory_flags &
6140 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006141 regdom = get_wiphy_regdom(wiphy);
6142
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006143 /* a self-managed-reg device must have a private regdom */
6144 if (WARN_ON(!regdom && self_managed)) {
6145 nlmsg_free(msg);
6146 return -EINVAL;
6147 }
6148
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006149 if (regdom &&
6150 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6151 goto nla_put_failure;
6152 }
6153
6154 if (!wiphy && reg_last_request_cell_base() &&
6155 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6156 NL80211_USER_REG_HINT_CELL_BASE))
6157 goto nla_put_failure;
6158
6159 rcu_read_lock();
6160
6161 if (!regdom)
6162 regdom = rcu_dereference(cfg80211_regdomain);
6163
6164 if (nl80211_put_regdom(regdom, msg))
6165 goto nla_put_failure_rcu;
6166
6167 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006168
6169 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006170 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006171
Johannes Berg458f4f92012-12-06 15:47:38 +01006172nla_put_failure_rcu:
6173 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006174nla_put_failure:
6175 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006176put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006177 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006178 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006179}
6180
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006181static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6182 u32 seq, int flags, struct wiphy *wiphy,
6183 const struct ieee80211_regdomain *regdom)
6184{
6185 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6186 NL80211_CMD_GET_REG);
6187
6188 if (!hdr)
6189 return -1;
6190
6191 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6192
6193 if (nl80211_put_regdom(regdom, msg))
6194 goto nla_put_failure;
6195
6196 if (!wiphy && reg_last_request_cell_base() &&
6197 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6198 NL80211_USER_REG_HINT_CELL_BASE))
6199 goto nla_put_failure;
6200
6201 if (wiphy &&
6202 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6203 goto nla_put_failure;
6204
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006205 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6206 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6207 goto nla_put_failure;
6208
Johannes Berg053c0952015-01-16 22:09:00 +01006209 genlmsg_end(msg, hdr);
6210 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006211
6212nla_put_failure:
6213 genlmsg_cancel(msg, hdr);
6214 return -EMSGSIZE;
6215}
6216
6217static int nl80211_get_reg_dump(struct sk_buff *skb,
6218 struct netlink_callback *cb)
6219{
6220 const struct ieee80211_regdomain *regdom = NULL;
6221 struct cfg80211_registered_device *rdev;
6222 int err, reg_idx, start = cb->args[2];
6223
6224 rtnl_lock();
6225
6226 if (cfg80211_regdomain && start == 0) {
6227 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6228 NLM_F_MULTI, NULL,
6229 rtnl_dereference(cfg80211_regdomain));
6230 if (err < 0)
6231 goto out_err;
6232 }
6233
6234 /* the global regdom is idx 0 */
6235 reg_idx = 1;
6236 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6237 regdom = get_wiphy_regdom(&rdev->wiphy);
6238 if (!regdom)
6239 continue;
6240
6241 if (++reg_idx <= start)
6242 continue;
6243
6244 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6245 NLM_F_MULTI, &rdev->wiphy, regdom);
6246 if (err < 0) {
6247 reg_idx--;
6248 break;
6249 }
6250 }
6251
6252 cb->args[2] = reg_idx;
6253 err = skb->len;
6254out_err:
6255 rtnl_unlock();
6256 return err;
6257}
6258
Johannes Bergb6863032015-10-15 09:25:18 +02006259#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6260static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6261 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6262 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6263 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6264 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6265 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6266 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6267 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6268};
6269
6270static int parse_reg_rule(struct nlattr *tb[],
6271 struct ieee80211_reg_rule *reg_rule)
6272{
6273 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6274 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6275
6276 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6277 return -EINVAL;
6278 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6279 return -EINVAL;
6280 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6281 return -EINVAL;
6282 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6283 return -EINVAL;
6284 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6285 return -EINVAL;
6286
6287 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6288
6289 freq_range->start_freq_khz =
6290 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6291 freq_range->end_freq_khz =
6292 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6293 freq_range->max_bandwidth_khz =
6294 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6295
6296 power_rule->max_eirp =
6297 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6298
6299 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6300 power_rule->max_antenna_gain =
6301 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6302
6303 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6304 reg_rule->dfs_cac_ms =
6305 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6306
6307 return 0;
6308}
6309
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006310static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6311{
6312 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6313 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006314 char *alpha2;
6315 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006316 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006317 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006318 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006319
6320 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6321 return -EINVAL;
6322
6323 if (!info->attrs[NL80211_ATTR_REG_RULES])
6324 return -EINVAL;
6325
6326 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6327
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006328 if (info->attrs[NL80211_ATTR_DFS_REGION])
6329 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6330
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006331 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006332 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006333 num_rules++;
6334 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006335 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006336 }
6337
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006338 if (!reg_is_valid_request(alpha2))
6339 return -EINVAL;
6340
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006341 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006342 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006343
6344 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006345 if (!rd)
6346 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006347
6348 rd->n_reg_rules = num_rules;
6349 rd->alpha2[0] = alpha2[0];
6350 rd->alpha2[1] = alpha2[1];
6351
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006352 /*
6353 * Disable DFS master mode if the DFS region was
6354 * not supported or known on this kernel.
6355 */
6356 if (reg_supported_dfs_region(dfs_region))
6357 rd->dfs_region = dfs_region;
6358
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006359 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006360 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01006361 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
6362 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
6363 reg_rule_policy);
6364 if (r)
6365 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006366 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6367 if (r)
6368 goto bad_reg;
6369
6370 rule_idx++;
6371
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006372 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6373 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006374 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006375 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006376 }
6377
Johannes Berg06627992016-06-09 10:40:09 +02006378 /* set_regdom takes ownership of rd */
6379 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006380 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006381 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006382 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006383}
Johannes Bergb6863032015-10-15 09:25:18 +02006384#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006385
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006386static int validate_scan_freqs(struct nlattr *freqs)
6387{
6388 struct nlattr *attr1, *attr2;
6389 int n_channels = 0, tmp1, tmp2;
6390
Srinivas Dasarie4712902017-07-07 01:43:42 +03006391 nla_for_each_nested(attr1, freqs, tmp1)
6392 if (nla_len(attr1) != sizeof(u32))
6393 return 0;
6394
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006395 nla_for_each_nested(attr1, freqs, tmp1) {
6396 n_channels++;
6397 /*
6398 * Some hardware has a limited channel list for
6399 * scanning, and it is pretty much nonsensical
6400 * to scan for a channel twice, so disallow that
6401 * and don't require drivers to check that the
6402 * channel list they get isn't longer than what
6403 * they can scan, as long as they can scan all
6404 * the channels they registered at once.
6405 */
6406 nla_for_each_nested(attr2, freqs, tmp2)
6407 if (attr1 != attr2 &&
6408 nla_get_u32(attr1) == nla_get_u32(attr2))
6409 return 0;
6410 }
6411
6412 return n_channels;
6413}
6414
Johannes Berg57fbcce2016-04-12 15:56:15 +02006415static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006416{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006417 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006418}
6419
6420static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6421 struct cfg80211_bss_selection *bss_select)
6422{
6423 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6424 struct nlattr *nest;
6425 int err;
6426 bool found = false;
6427 int i;
6428
6429 /* only process one nested attribute */
6430 nest = nla_data(nla);
6431 if (!nla_ok(nest, nla_len(nest)))
6432 return -EINVAL;
6433
6434 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6435 nla_len(nest), nl80211_bss_select_policy);
6436 if (err)
6437 return err;
6438
6439 /* only one attribute may be given */
6440 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6441 if (attr[i]) {
6442 if (found)
6443 return -EINVAL;
6444 found = true;
6445 }
6446 }
6447
6448 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6449
6450 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6451 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6452
6453 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6454 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6455 bss_select->param.band_pref =
6456 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6457 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6458 return -EINVAL;
6459 }
6460
6461 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6462 struct nl80211_bss_select_rssi_adjust *adj_param;
6463
6464 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6465 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6466 bss_select->param.adjust.band = adj_param->band;
6467 bss_select->param.adjust.delta = adj_param->delta;
6468 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6469 return -EINVAL;
6470 }
6471
6472 /* user-space did not provide behaviour attribute */
6473 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6474 return -EINVAL;
6475
6476 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6477 return -EINVAL;
6478
6479 return 0;
6480}
6481
Johannes Bergad2b26a2014-06-12 21:39:05 +02006482static int nl80211_parse_random_mac(struct nlattr **attrs,
6483 u8 *mac_addr, u8 *mac_addr_mask)
6484{
6485 int i;
6486
6487 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006488 eth_zero_addr(mac_addr);
6489 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006490 mac_addr[0] = 0x2;
6491 mac_addr_mask[0] = 0x3;
6492
6493 return 0;
6494 }
6495
6496 /* need both or none */
6497 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6498 return -EINVAL;
6499
6500 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6501 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6502
6503 /* don't allow or configure an mcast address */
6504 if (!is_multicast_ether_addr(mac_addr_mask) ||
6505 is_multicast_ether_addr(mac_addr))
6506 return -EINVAL;
6507
6508 /*
6509 * allow users to pass a MAC address that has bits set outside
6510 * of the mask, but don't bother drivers with having to deal
6511 * with such bits
6512 */
6513 for (i = 0; i < ETH_ALEN; i++)
6514 mac_addr[i] &= mac_addr_mask[i];
6515
6516 return 0;
6517}
6518
Johannes Berg2a519312009-02-10 21:25:55 +01006519static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6520{
Johannes Berg4c476992010-10-04 21:36:35 +02006521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006522 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006523 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006524 struct nlattr *attr;
6525 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006526 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006527 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006528
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006529 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6530 return -EINVAL;
6531
Johannes Berg79c97e92009-07-07 03:56:12 +02006532 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006533
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006534 if (wdev->iftype == NL80211_IFTYPE_NAN)
6535 return -EOPNOTSUPP;
6536
Johannes Berg4c476992010-10-04 21:36:35 +02006537 if (!rdev->ops->scan)
6538 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006539
Johannes Bergf9d15d12014-01-22 11:14:19 +02006540 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006541 err = -EBUSY;
6542 goto unlock;
6543 }
Johannes Berg2a519312009-02-10 21:25:55 +01006544
6545 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006546 n_channels = validate_scan_freqs(
6547 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006548 if (!n_channels) {
6549 err = -EINVAL;
6550 goto unlock;
6551 }
Johannes Berg2a519312009-02-10 21:25:55 +01006552 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006553 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006554 }
6555
6556 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6557 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6558 n_ssids++;
6559
Johannes Bergf9f47522013-03-19 15:04:07 +01006560 if (n_ssids > wiphy->max_scan_ssids) {
6561 err = -EINVAL;
6562 goto unlock;
6563 }
Johannes Berg2a519312009-02-10 21:25:55 +01006564
Jouni Malinen70692ad2009-02-16 19:39:13 +02006565 if (info->attrs[NL80211_ATTR_IE])
6566 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6567 else
6568 ie_len = 0;
6569
Johannes Bergf9f47522013-03-19 15:04:07 +01006570 if (ie_len > wiphy->max_scan_ie_len) {
6571 err = -EINVAL;
6572 goto unlock;
6573 }
Johannes Berg18a83652009-03-31 12:12:05 +02006574
Johannes Berg2a519312009-02-10 21:25:55 +01006575 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006576 + sizeof(*request->ssids) * n_ssids
6577 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006578 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006579 if (!request) {
6580 err = -ENOMEM;
6581 goto unlock;
6582 }
Johannes Berg2a519312009-02-10 21:25:55 +01006583
Johannes Berg2a519312009-02-10 21:25:55 +01006584 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006585 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006586 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006587 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006588 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006589 request->ie = (void *)(request->ssids + n_ssids);
6590 else
6591 request->ie = (void *)(request->channels + n_channels);
6592 }
Johannes Berg2a519312009-02-10 21:25:55 +01006593
Johannes Berg584991d2009-11-02 13:32:03 +01006594 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006595 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6596 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006597 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006598 struct ieee80211_channel *chan;
6599
6600 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6601
6602 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006603 err = -EINVAL;
6604 goto out_free;
6605 }
Johannes Berg584991d2009-11-02 13:32:03 +01006606
6607 /* ignore disabled channels */
6608 if (chan->flags & IEEE80211_CHAN_DISABLED)
6609 continue;
6610
6611 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006612 i++;
6613 }
6614 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006615 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006616
Johannes Berg2a519312009-02-10 21:25:55 +01006617 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006618 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006619 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006620
Johannes Berg2a519312009-02-10 21:25:55 +01006621 if (!wiphy->bands[band])
6622 continue;
6623 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006624 struct ieee80211_channel *chan;
6625
6626 chan = &wiphy->bands[band]->channels[j];
6627
6628 if (chan->flags & IEEE80211_CHAN_DISABLED)
6629 continue;
6630
6631 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006632 i++;
6633 }
6634 }
6635 }
6636
Johannes Berg584991d2009-11-02 13:32:03 +01006637 if (!i) {
6638 err = -EINVAL;
6639 goto out_free;
6640 }
6641
6642 request->n_channels = i;
6643
Johannes Berg2a519312009-02-10 21:25:55 +01006644 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006645 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006646 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006647 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006648 err = -EINVAL;
6649 goto out_free;
6650 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006651 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006652 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006653 i++;
6654 }
6655 }
6656
Jouni Malinen70692ad2009-02-16 19:39:13 +02006657 if (info->attrs[NL80211_ATTR_IE]) {
6658 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006659 memcpy((void *)request->ie,
6660 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006661 request->ie_len);
6662 }
6663
Johannes Berg57fbcce2016-04-12 15:56:15 +02006664 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006665 if (wiphy->bands[i])
6666 request->rates[i] =
6667 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006668
6669 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6670 nla_for_each_nested(attr,
6671 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6672 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006673 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006674
Johannes Berg57fbcce2016-04-12 15:56:15 +02006675 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006676 err = -EINVAL;
6677 goto out_free;
6678 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006679
6680 if (!wiphy->bands[band])
6681 continue;
6682
Johannes Berg34850ab2011-07-18 18:08:35 +02006683 err = ieee80211_get_ratemask(wiphy->bands[band],
6684 nla_data(attr),
6685 nla_len(attr),
6686 &request->rates[band]);
6687 if (err)
6688 goto out_free;
6689 }
6690 }
6691
Avraham Stern1d762502016-07-05 17:10:13 +03006692 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6693 if (!wiphy_ext_feature_isset(wiphy,
6694 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6695 err = -EOPNOTSUPP;
6696 goto out_free;
6697 }
6698
6699 request->duration =
6700 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6701 request->duration_mandatory =
6702 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6703 }
6704
Sam Leffler46856bb2012-10-11 21:03:32 -07006705 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006706 request->flags = nla_get_u32(
6707 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Srinivas Dasaridf7d3c62018-01-17 16:44:16 +05306708 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6709 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
6710 ((request->flags & NL80211_SCAN_FLAG_LOW_SPAN) &&
6711 !wiphy_ext_feature_isset(wiphy,
6712 NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) ||
6713 ((request->flags & NL80211_SCAN_FLAG_LOW_POWER) &&
6714 !wiphy_ext_feature_isset(wiphy,
6715 NL80211_EXT_FEATURE_LOW_POWER_SCAN)) ||
6716 ((request->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) &&
6717 !wiphy_ext_feature_isset(wiphy,
6718 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006719 err = -EOPNOTSUPP;
6720 goto out_free;
6721 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006722
6723 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6724 if (!(wiphy->features &
6725 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6726 err = -EOPNOTSUPP;
6727 goto out_free;
6728 }
6729
6730 if (wdev->current_bss) {
6731 err = -EOPNOTSUPP;
6732 goto out_free;
6733 }
6734
6735 err = nl80211_parse_random_mac(info->attrs,
6736 request->mac_addr,
6737 request->mac_addr_mask);
6738 if (err)
6739 goto out_free;
6740 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006741 }
Sam Lefflered4737712012-10-11 21:03:31 -07006742
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306743 request->no_cck =
6744 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6745
Vamsi Krishna45816392016-12-02 23:59:08 +02006746 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6747 * BSSID to scan for. This was problematic because that same attribute
6748 * was already used for another purpose (local random MAC address). The
6749 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6750 * compatibility with older userspace components, also use the
6751 * NL80211_ATTR_MAC value here if it can be determined to be used for
6752 * the specific BSSID use case instead of the random MAC address
6753 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6754 */
6755 if (info->attrs[NL80211_ATTR_BSSID])
6756 memcpy(request->bssid,
6757 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6758 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6759 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006760 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6761 ETH_ALEN);
6762 else
6763 eth_broadcast_addr(request->bssid);
6764
Johannes Bergfd014282012-06-18 19:17:03 +02006765 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006766 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006767 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006768
Johannes Berg79c97e92009-07-07 03:56:12 +02006769 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006770 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006771
Johannes Berg463d0182009-07-14 00:33:35 +02006772 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006773 nl80211_send_scan_start(rdev, wdev);
6774 if (wdev->netdev)
6775 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006776 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006777 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006778 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006779 kfree(request);
6780 }
Johannes Berg3b858752009-03-12 09:55:09 +01006781
Johannes Bergf9f47522013-03-19 15:04:07 +01006782 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006783 return err;
6784}
6785
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306786static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6787{
6788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6789 struct wireless_dev *wdev = info->user_ptr[1];
6790
6791 if (!rdev->ops->abort_scan)
6792 return -EOPNOTSUPP;
6793
6794 if (rdev->scan_msg)
6795 return 0;
6796
6797 if (!rdev->scan_req)
6798 return -ENOENT;
6799
6800 rdev_abort_scan(rdev, wdev);
6801 return 0;
6802}
6803
Avraham Stern3b06d272015-10-12 09:51:34 +03006804static int
6805nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6806 struct cfg80211_sched_scan_request *request,
6807 struct nlattr **attrs)
6808{
6809 int tmp, err, i = 0;
6810 struct nlattr *attr;
6811
6812 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6813 u32 interval;
6814
6815 /*
6816 * If scan plans are not specified,
6817 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6818 * case one scan plan will be set with the specified scan
6819 * interval and infinite number of iterations.
6820 */
6821 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6822 return -EINVAL;
6823
6824 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6825 if (!interval)
6826 return -EINVAL;
6827
6828 request->scan_plans[0].interval =
6829 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6830 if (!request->scan_plans[0].interval)
6831 return -EINVAL;
6832
6833 if (request->scan_plans[0].interval >
6834 wiphy->max_sched_scan_plan_interval)
6835 request->scan_plans[0].interval =
6836 wiphy->max_sched_scan_plan_interval;
6837
6838 return 0;
6839 }
6840
6841 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6842 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6843
6844 if (WARN_ON(i >= n_plans))
6845 return -EINVAL;
6846
6847 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6848 nla_data(attr), nla_len(attr),
6849 nl80211_plan_policy);
6850 if (err)
6851 return err;
6852
6853 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6854 return -EINVAL;
6855
6856 request->scan_plans[i].interval =
6857 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6858 if (!request->scan_plans[i].interval ||
6859 request->scan_plans[i].interval >
6860 wiphy->max_sched_scan_plan_interval)
6861 return -EINVAL;
6862
6863 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6864 request->scan_plans[i].iterations =
6865 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6866 if (!request->scan_plans[i].iterations ||
6867 (request->scan_plans[i].iterations >
6868 wiphy->max_sched_scan_plan_iterations))
6869 return -EINVAL;
6870 } else if (i < n_plans - 1) {
6871 /*
6872 * All scan plans but the last one must specify
6873 * a finite number of iterations
6874 */
6875 return -EINVAL;
6876 }
6877
6878 i++;
6879 }
6880
6881 /*
6882 * The last scan plan must not specify the number of
6883 * iterations, it is supposed to run infinitely
6884 */
6885 if (request->scan_plans[n_plans - 1].iterations)
6886 return -EINVAL;
6887
6888 return 0;
6889}
6890
Luciano Coelho256da022014-11-10 16:13:46 +02006891static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006892nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006893 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006894{
6895 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006896 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006897 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006898 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006899 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006900 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006901 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006902
Luciano Coelho256da022014-11-10 16:13:46 +02006903 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6904 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006905
Luciano Coelho256da022014-11-10 16:13:46 +02006906 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006907 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006908 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006909 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006910 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006911 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006912 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006913 }
6914
Luciano Coelho256da022014-11-10 16:13:46 +02006915 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6916 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006917 tmp)
6918 n_ssids++;
6919
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006920 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006921 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006922
Johannes Bergea73cbc2014-01-24 10:53:53 +01006923 /*
6924 * First, count the number of 'real' matchsets. Due to an issue with
6925 * the old implementation, matchsets containing only the RSSI attribute
6926 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6927 * RSSI for all matchsets, rather than their own matchset for reporting
6928 * all APs with a strong RSSI. This is needed to be compatible with
6929 * older userspace that treated a matchset with only the RSSI as the
6930 * global RSSI for all other matchsets - if there are other matchsets.
6931 */
Luciano Coelho256da022014-11-10 16:13:46 +02006932 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006933 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006934 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006935 tmp) {
6936 struct nlattr *rssi;
6937
6938 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6939 nla_data(attr), nla_len(attr),
6940 nl80211_match_policy);
6941 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006942 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006943 /* add other standalone attributes here */
6944 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6945 n_match_sets++;
6946 continue;
6947 }
6948 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6949 if (rssi)
6950 default_match_rssi = nla_get_s32(rssi);
6951 }
6952 }
6953
6954 /* However, if there's no other matchset, add the RSSI one */
6955 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6956 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006957
6958 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006959 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006960
Luciano Coelho256da022014-11-10 16:13:46 +02006961 if (attrs[NL80211_ATTR_IE])
6962 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006963 else
6964 ie_len = 0;
6965
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006966 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006967 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006968
Avraham Stern3b06d272015-10-12 09:51:34 +03006969 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6970 /*
6971 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6972 * each scan plan already specifies its own interval
6973 */
6974 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6975 return ERR_PTR(-EINVAL);
6976
6977 nla_for_each_nested(attr,
6978 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6979 n_plans++;
6980 } else {
6981 /*
6982 * The scan interval attribute is kept for backward
6983 * compatibility. If no scan plans are specified and sched scan
6984 * interval is specified, one scan plan will be set with this
6985 * scan interval and infinite number of iterations.
6986 */
6987 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6988 return ERR_PTR(-EINVAL);
6989
6990 n_plans = 1;
6991 }
6992
6993 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6994 return ERR_PTR(-EINVAL);
6995
vamsi krishnaf4f1a542017-01-13 01:12:20 +02006996 if (!wiphy_ext_feature_isset(
6997 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
6998 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
6999 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
7000 return ERR_PTR(-EINVAL);
7001
Luciano Coelho807f8a82011-05-11 17:09:35 +03007002 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007003 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007004 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03007005 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007006 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03007007 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02007008 if (!request)
7009 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007010
7011 if (n_ssids)
7012 request->ssids = (void *)&request->channels[n_channels];
7013 request->n_ssids = n_ssids;
7014 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007015 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03007016 request->ie = (void *)(request->ssids + n_ssids);
7017 else
7018 request->ie = (void *)(request->channels + n_channels);
7019 }
7020
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007021 if (n_match_sets) {
7022 if (request->ie)
7023 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01007024 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007025 request->match_sets =
7026 (void *)(request->ssids + n_ssids);
7027 else
7028 request->match_sets =
7029 (void *)(request->channels + n_channels);
7030 }
7031 request->n_match_sets = n_match_sets;
7032
Avraham Stern3b06d272015-10-12 09:51:34 +03007033 if (n_match_sets)
7034 request->scan_plans = (void *)(request->match_sets +
7035 n_match_sets);
7036 else if (request->ie)
7037 request->scan_plans = (void *)(request->ie + ie_len);
7038 else if (n_ssids)
7039 request->scan_plans = (void *)(request->ssids + n_ssids);
7040 else
7041 request->scan_plans = (void *)(request->channels + n_channels);
7042
7043 request->n_scan_plans = n_plans;
7044
Luciano Coelho807f8a82011-05-11 17:09:35 +03007045 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007046 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007047 /* user specified, bail out if channel not found */
7048 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007049 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007050 tmp) {
7051 struct ieee80211_channel *chan;
7052
7053 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7054
7055 if (!chan) {
7056 err = -EINVAL;
7057 goto out_free;
7058 }
7059
7060 /* ignore disabled channels */
7061 if (chan->flags & IEEE80211_CHAN_DISABLED)
7062 continue;
7063
7064 request->channels[i] = chan;
7065 i++;
7066 }
7067 } else {
7068 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007069 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007070 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007071
Luciano Coelho807f8a82011-05-11 17:09:35 +03007072 if (!wiphy->bands[band])
7073 continue;
7074 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7075 struct ieee80211_channel *chan;
7076
7077 chan = &wiphy->bands[band]->channels[j];
7078
7079 if (chan->flags & IEEE80211_CHAN_DISABLED)
7080 continue;
7081
7082 request->channels[i] = chan;
7083 i++;
7084 }
7085 }
7086 }
7087
7088 if (!i) {
7089 err = -EINVAL;
7090 goto out_free;
7091 }
7092
7093 request->n_channels = i;
7094
7095 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007096 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007097 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007098 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007099 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007100 err = -EINVAL;
7101 goto out_free;
7102 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007103 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007104 memcpy(request->ssids[i].ssid, nla_data(attr),
7105 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007106 i++;
7107 }
7108 }
7109
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007110 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007111 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007112 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007113 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007114 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007115 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007116
Johannes Bergae811e22014-01-24 10:17:47 +01007117 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7118 nla_data(attr), nla_len(attr),
7119 nl80211_match_policy);
7120 if (err)
7121 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007122 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007123 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007124 if (WARN_ON(i >= n_match_sets)) {
7125 /* this indicates a programming error,
7126 * the loop above should have verified
7127 * things properly
7128 */
7129 err = -EINVAL;
7130 goto out_free;
7131 }
7132
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007133 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7134 err = -EINVAL;
7135 goto out_free;
7136 }
7137 memcpy(request->match_sets[i].ssid.ssid,
7138 nla_data(ssid), nla_len(ssid));
7139 request->match_sets[i].ssid.ssid_len =
7140 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007141 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007142 request->match_sets[i].rssi_thold =
7143 default_match_rssi;
7144 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7145 if (rssi)
7146 request->match_sets[i].rssi_thold =
7147 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007148 }
7149 i++;
7150 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007151
7152 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007153 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007154 request->match_sets[0].rssi_thold = default_match_rssi;
7155
7156 request->min_rssi_thold = INT_MAX;
7157 for (i = 0; i < n_match_sets; i++)
7158 request->min_rssi_thold =
7159 min(request->match_sets[i].rssi_thold,
7160 request->min_rssi_thold);
7161 } else {
7162 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007163 }
7164
Johannes Berg9900e482014-02-04 21:01:25 +01007165 if (ie_len) {
7166 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007167 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007168 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007169 request->ie_len);
7170 }
7171
Luciano Coelho256da022014-11-10 16:13:46 +02007172 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007173 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007174 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007175 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7176 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007177 err = -EOPNOTSUPP;
7178 goto out_free;
7179 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007180
7181 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7182 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7183
7184 if (!wdev) /* must be net-detect */
7185 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7186
7187 if (!(wiphy->features & flg)) {
7188 err = -EOPNOTSUPP;
7189 goto out_free;
7190 }
7191
7192 if (wdev && wdev->current_bss) {
7193 err = -EOPNOTSUPP;
7194 goto out_free;
7195 }
7196
7197 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7198 request->mac_addr_mask);
7199 if (err)
7200 goto out_free;
7201 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007202 }
Sam Lefflered4737712012-10-11 21:03:31 -07007203
Luciano Coelho9c748932015-01-16 16:04:09 +02007204 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7205 request->delay =
7206 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7207
vamsi krishnaf4f1a542017-01-13 01:12:20 +02007208 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
7209 request->relative_rssi = nla_get_s8(
7210 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
7211 request->relative_rssi_set = true;
7212 }
7213
7214 if (request->relative_rssi_set &&
7215 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
7216 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
7217
7218 rssi_adjust = nla_data(
7219 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
7220 request->rssi_adjust.band = rssi_adjust->band;
7221 request->rssi_adjust.delta = rssi_adjust->delta;
7222 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
7223 err = -EINVAL;
7224 goto out_free;
7225 }
7226 }
7227
Avraham Stern3b06d272015-10-12 09:51:34 +03007228 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7229 if (err)
7230 goto out_free;
7231
Sam Leffler15d60302012-10-11 21:03:34 -07007232 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007233
Luciano Coelho256da022014-11-10 16:13:46 +02007234 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007235
7236out_free:
7237 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007238 return ERR_PTR(err);
7239}
7240
7241static int nl80211_start_sched_scan(struct sk_buff *skb,
7242 struct genl_info *info)
7243{
7244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7245 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007246 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007247 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007248 int err;
7249
7250 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7251 !rdev->ops->sched_scan_start)
7252 return -EOPNOTSUPP;
7253
7254 if (rdev->sched_scan_req)
7255 return -EINPROGRESS;
7256
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007257 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7258 info->attrs);
7259
7260 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007261 if (err)
7262 goto out_err;
7263
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007264 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007265 if (err)
7266 goto out_free;
7267
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007268 sched_scan_req->dev = dev;
7269 sched_scan_req->wiphy = &rdev->wiphy;
7270
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007271 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7272 sched_scan_req->owner_nlportid = info->snd_portid;
7273
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007274 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007275
7276 nl80211_send_sched_scan(rdev, dev,
7277 NL80211_CMD_START_SCHED_SCAN);
7278 return 0;
7279
7280out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007281 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007282out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007283 return err;
7284}
7285
7286static int nl80211_stop_sched_scan(struct sk_buff *skb,
7287 struct genl_info *info)
7288{
7289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7290
7291 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7292 !rdev->ops->sched_scan_stop)
7293 return -EOPNOTSUPP;
7294
Johannes Berg5fe231e2013-05-08 21:45:15 +02007295 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007296}
7297
Simon Wunderlich04f39042013-02-08 18:16:19 +01007298static int nl80211_start_radar_detection(struct sk_buff *skb,
7299 struct genl_info *info)
7300{
7301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7302 struct net_device *dev = info->user_ptr[1];
7303 struct wireless_dev *wdev = dev->ieee80211_ptr;
7304 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007305 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007306 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007307 int err;
7308
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007309 dfs_region = reg_get_dfs_region(wdev->wiphy);
7310 if (dfs_region == NL80211_DFS_UNSET)
7311 return -EINVAL;
7312
Simon Wunderlich04f39042013-02-08 18:16:19 +01007313 err = nl80211_parse_chandef(rdev, info, &chandef);
7314 if (err)
7315 return err;
7316
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007317 if (netif_carrier_ok(dev))
7318 return -EBUSY;
7319
Amar Singhal42839af2014-03-19 18:36:58 -07007320 if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD)
7321 return -EOPNOTSUPP;
7322
Simon Wunderlich04f39042013-02-08 18:16:19 +01007323 if (wdev->cac_started)
7324 return -EBUSY;
7325
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007326 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007327 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007328 if (err < 0)
7329 return err;
7330
7331 if (err == 0)
7332 return -EINVAL;
7333
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007334 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007335 return -EINVAL;
7336
7337 if (!rdev->ops->start_radar_detection)
7338 return -EOPNOTSUPP;
7339
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007340 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7341 if (WARN_ON(!cac_time_ms))
7342 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7343
Ilan Peera1056b12015-10-22 22:27:46 +03007344 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007345 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007346 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007347 wdev->cac_started = true;
7348 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007349 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007350 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007351 return err;
7352}
7353
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007354static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7355{
7356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7357 struct net_device *dev = info->user_ptr[1];
7358 struct wireless_dev *wdev = dev->ieee80211_ptr;
7359 struct cfg80211_csa_settings params;
7360 /* csa_attrs is defined static to avoid waste of stack size - this
7361 * function is called under RTNL lock, so this should not be a problem.
7362 */
7363 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007364 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007365 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007366 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007367 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007368
7369 if (!rdev->ops->channel_switch ||
7370 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7371 return -EOPNOTSUPP;
7372
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007373 switch (dev->ieee80211_ptr->iftype) {
7374 case NL80211_IFTYPE_AP:
7375 case NL80211_IFTYPE_P2P_GO:
7376 need_new_beacon = true;
7377
7378 /* useless if AP is not running */
7379 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007380 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007381 break;
7382 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007383 if (!wdev->ssid_len)
7384 return -ENOTCONN;
7385 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007386 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007387 if (!wdev->mesh_id_len)
7388 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007389 break;
7390 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007391 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007392 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007393
7394 memset(&params, 0, sizeof(params));
7395
7396 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7397 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7398 return -EINVAL;
7399
7400 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007401 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007402 return -EINVAL;
7403
Luciano Coelho252e07c2014-10-08 09:48:34 +03007404 /* Even though the attribute is u32, the specification says
7405 * u8, so let's make sure we don't overflow.
7406 */
7407 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7408 if (cs_count > 255)
7409 return -EINVAL;
7410
7411 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007412
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007413 if (!need_new_beacon)
7414 goto skip_beacons;
7415
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007416 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7417 if (err)
7418 return err;
7419
7420 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7421 info->attrs[NL80211_ATTR_CSA_IES],
7422 nl80211_policy);
7423 if (err)
7424 return err;
7425
7426 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7427 if (err)
7428 return err;
7429
7430 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7431 return -EINVAL;
7432
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007433 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7434 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007435 return -EINVAL;
7436
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007437 params.n_counter_offsets_beacon = len / sizeof(u16);
7438 if (rdev->wiphy.max_num_csa_counters &&
7439 (params.n_counter_offsets_beacon >
7440 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007441 return -EINVAL;
7442
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007443 params.counter_offsets_beacon =
7444 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7445
7446 /* sanity checks - counters should fit and be the same */
7447 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7448 u16 offset = params.counter_offsets_beacon[i];
7449
7450 if (offset >= params.beacon_csa.tail_len)
7451 return -EINVAL;
7452
7453 if (params.beacon_csa.tail[offset] != params.count)
7454 return -EINVAL;
7455 }
7456
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007457 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007458 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7459 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007460 return -EINVAL;
7461
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007462 params.n_counter_offsets_presp = len / sizeof(u16);
7463 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007464 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007465 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007466 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007467
7468 params.counter_offsets_presp =
7469 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7470
7471 /* sanity checks - counters should fit and be the same */
7472 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7473 u16 offset = params.counter_offsets_presp[i];
7474
7475 if (offset >= params.beacon_csa.probe_resp_len)
7476 return -EINVAL;
7477
7478 if (params.beacon_csa.probe_resp[offset] !=
7479 params.count)
7480 return -EINVAL;
7481 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007482 }
7483
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007484skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007485 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7486 if (err)
7487 return err;
7488
Arik Nemtsov923b3522015-07-08 15:41:44 +03007489 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7490 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007491 return -EINVAL;
7492
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007493 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7494 &params.chandef,
7495 wdev->iftype);
7496 if (err < 0)
7497 return err;
7498
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007499 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007500 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007501
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007502 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7503 params.block_tx = true;
7504
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007505 wdev_lock(wdev);
7506 err = rdev_channel_switch(rdev, dev, &params);
7507 wdev_unlock(wdev);
7508
7509 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007510}
7511
Johannes Berg9720bb32011-06-21 09:45:33 +02007512static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7513 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007514 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007515 struct wireless_dev *wdev,
7516 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007517{
Johannes Berg48ab9052009-07-10 18:42:31 +02007518 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007519 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007520 void *hdr;
7521 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007522
7523 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007524
Eric W. Biederman15e47302012-09-07 20:12:54 +00007525 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007526 NL80211_CMD_NEW_SCAN_RESULTS);
7527 if (!hdr)
7528 return -1;
7529
Johannes Berg9720bb32011-06-21 09:45:33 +02007530 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7531
Johannes Berg97990a02013-04-19 01:02:55 +02007532 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7533 goto nla_put_failure;
7534 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007535 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7536 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007537 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7538 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007539 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007540
7541 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7542 if (!bss)
7543 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007544 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007545 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007546 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007547
7548 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007549 /* indicate whether we have probe response data or not */
7550 if (rcu_access_pointer(res->proberesp_ies) &&
7551 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7552 goto fail_unlock_rcu;
7553
7554 /* this pointer prefers to be pointed to probe response data
7555 * but is always valid
7556 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007557 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007558 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007559 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7560 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007561 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007562 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7563 ies->len, ies->data))
7564 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007565 }
Johannes Berg0e227082014-08-12 20:34:30 +02007566
7567 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007568 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007569 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007570 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7571 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007572 goto fail_unlock_rcu;
7573 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7574 ies->len, ies->data))
7575 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007576 }
7577 rcu_read_unlock();
7578
David S. Miller9360ffd2012-03-29 04:41:26 -04007579 if (res->beacon_interval &&
7580 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7581 goto nla_put_failure;
7582 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7583 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007584 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007585 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7586 jiffies_to_msecs(jiffies - intbss->ts)))
7587 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007588
Avraham Stern1d762502016-07-05 17:10:13 +03007589 if (intbss->parent_tsf &&
7590 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7591 intbss->parent_tsf, NL80211_BSS_PAD) ||
7592 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7593 intbss->parent_bssid)))
7594 goto nla_put_failure;
7595
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007596 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007597 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7598 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007599 goto nla_put_failure;
7600
Sunil Dutt0c868482017-12-13 19:51:36 +02007601 if (!nl80211_put_signal(msg, intbss->pub.chains,
7602 intbss->pub.chain_signal,
7603 NL80211_BSS_CHAIN_SIGNAL))
7604 goto nla_put_failure;
7605
Johannes Berg77965c92009-02-18 18:45:06 +01007606 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007607 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007608 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7609 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007610 break;
7611 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007612 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7613 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007614 break;
7615 default:
7616 break;
7617 }
7618
Johannes Berg48ab9052009-07-10 18:42:31 +02007619 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007620 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007621 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007622 if (intbss == wdev->current_bss &&
7623 nla_put_u32(msg, NL80211_BSS_STATUS,
7624 NL80211_BSS_STATUS_ASSOCIATED))
7625 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007626 break;
7627 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007628 if (intbss == wdev->current_bss &&
7629 nla_put_u32(msg, NL80211_BSS_STATUS,
7630 NL80211_BSS_STATUS_IBSS_JOINED))
7631 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007632 break;
7633 default:
7634 break;
7635 }
7636
Johannes Berg2a519312009-02-10 21:25:55 +01007637 nla_nest_end(msg, bss);
7638
Johannes Berg053c0952015-01-16 22:09:00 +01007639 genlmsg_end(msg, hdr);
7640 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007641
Johannes Berg8cef2c92013-02-05 16:54:31 +01007642 fail_unlock_rcu:
7643 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007644 nla_put_failure:
7645 genlmsg_cancel(msg, hdr);
7646 return -EMSGSIZE;
7647}
7648
Johannes Berg97990a02013-04-19 01:02:55 +02007649static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007650{
Johannes Berg48ab9052009-07-10 18:42:31 +02007651 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007652 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007653 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007654 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007655 int err;
7656
Johannes Berg56769e72017-03-15 14:26:04 +01007657 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007658 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg56769e72017-03-15 14:26:04 +01007659 if (err) {
7660 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007661 return err;
Johannes Berg56769e72017-03-15 14:26:04 +01007662 }
Johannes Berg2a519312009-02-10 21:25:55 +01007663
Johannes Berg48ab9052009-07-10 18:42:31 +02007664 wdev_lock(wdev);
7665 spin_lock_bh(&rdev->bss_lock);
7666 cfg80211_bss_expire(rdev);
7667
Johannes Berg9720bb32011-06-21 09:45:33 +02007668 cb->seq = rdev->bss_generation;
7669
Johannes Berg48ab9052009-07-10 18:42:31 +02007670 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007671 if (++idx <= start)
7672 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007673 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007674 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007675 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007676 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007677 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007678 }
7679 }
7680
Johannes Berg48ab9052009-07-10 18:42:31 +02007681 spin_unlock_bh(&rdev->bss_lock);
7682 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007683
Johannes Berg97990a02013-04-19 01:02:55 +02007684 cb->args[2] = idx;
Johannes Berg56769e72017-03-15 14:26:04 +01007685 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007686
Johannes Berg67748892010-10-04 21:14:06 +02007687 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007688}
7689
Eric W. Biederman15e47302012-09-07 20:12:54 +00007690static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007691 int flags, struct net_device *dev,
7692 bool allow_radio_stats,
7693 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007694{
7695 void *hdr;
7696 struct nlattr *infoattr;
7697
Johannes Berg11f78ac2014-11-14 16:43:50 +01007698 /* skip radio stats if userspace didn't request them */
7699 if (!survey->channel && !allow_radio_stats)
7700 return 0;
7701
Eric W. Biederman15e47302012-09-07 20:12:54 +00007702 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007703 NL80211_CMD_NEW_SURVEY_RESULTS);
7704 if (!hdr)
7705 return -ENOMEM;
7706
David S. Miller9360ffd2012-03-29 04:41:26 -04007707 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7708 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007709
7710 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7711 if (!infoattr)
7712 goto nla_put_failure;
7713
Johannes Berg11f78ac2014-11-14 16:43:50 +01007714 if (survey->channel &&
7715 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007716 survey->channel->center_freq))
7717 goto nla_put_failure;
7718
7719 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7720 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7721 goto nla_put_failure;
7722 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7723 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7724 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007725 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007726 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7727 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007728 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007729 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007730 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7731 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007732 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007733 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007734 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7735 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007736 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007737 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007738 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7739 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007740 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007741 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007742 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7743 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007744 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007745 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007746 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7747 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007748 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007749
7750 nla_nest_end(msg, infoattr);
7751
Johannes Berg053c0952015-01-16 22:09:00 +01007752 genlmsg_end(msg, hdr);
7753 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007754
7755 nla_put_failure:
7756 genlmsg_cancel(msg, hdr);
7757 return -EMSGSIZE;
7758}
7759
Johannes Berg11f78ac2014-11-14 16:43:50 +01007760static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007761{
7762 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007763 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007764 struct wireless_dev *wdev;
7765 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007766 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007767 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007768
Johannes Berg56769e72017-03-15 14:26:04 +01007769 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007770 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007771 if (res)
Johannes Berg56769e72017-03-15 14:26:04 +01007772 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007773
Johannes Berg11f78ac2014-11-14 16:43:50 +01007774 /* prepare_wdev_dump parsed the attributes */
7775 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7776
Johannes Berg97990a02013-04-19 01:02:55 +02007777 if (!wdev->netdev) {
7778 res = -EINVAL;
7779 goto out_err;
7780 }
7781
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007782 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007783 res = -EOPNOTSUPP;
7784 goto out_err;
7785 }
7786
7787 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007788 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007789 if (res == -ENOENT)
7790 break;
7791 if (res)
7792 goto out_err;
7793
Johannes Berg11f78ac2014-11-14 16:43:50 +01007794 /* don't send disabled channels, but do send non-channel data */
7795 if (survey.channel &&
7796 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007797 survey_idx++;
7798 continue;
7799 }
7800
Holger Schurig61fa7132009-11-11 12:25:40 +01007801 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007802 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007803 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007804 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007805 goto out;
7806 survey_idx++;
7807 }
7808
7809 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007810 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007811 res = skb->len;
7812 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01007813 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007814 return res;
7815}
7816
Samuel Ortizb23aa672009-07-01 21:26:54 +02007817static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7818{
7819 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7820 NL80211_WPA_VERSION_2));
7821}
7822
Jouni Malinen636a5d32009-03-19 13:39:22 +02007823static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7824{
Johannes Berg4c476992010-10-04 21:36:35 +02007825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7826 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007827 struct ieee80211_channel *chan;
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007828 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7829 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007830 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007831 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007832 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007833
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007834 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7835 return -EINVAL;
7836
7837 if (!info->attrs[NL80211_ATTR_MAC])
7838 return -EINVAL;
7839
Jouni Malinen17780922009-03-27 20:52:47 +02007840 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7841 return -EINVAL;
7842
Johannes Berg19957bb2009-07-02 17:20:43 +02007843 if (!info->attrs[NL80211_ATTR_SSID])
7844 return -EINVAL;
7845
7846 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7847 return -EINVAL;
7848
Johannes Bergfffd0932009-07-08 14:22:54 +02007849 err = nl80211_parse_key(info, &key);
7850 if (err)
7851 return err;
7852
7853 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007854 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7855 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007856 if (!key.p.key || !key.p.key_len)
7857 return -EINVAL;
7858 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7859 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7860 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7861 key.p.key_len != WLAN_KEY_LEN_WEP104))
7862 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007863 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007864 return -EINVAL;
7865 } else {
7866 key.p.key_len = 0;
7867 key.p.key = NULL;
7868 }
7869
Johannes Bergafea0b72010-08-10 09:46:42 +02007870 if (key.idx >= 0) {
7871 int i;
7872 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007873
Johannes Bergafea0b72010-08-10 09:46:42 +02007874 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7875 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7876 ok = true;
7877 break;
7878 }
7879 }
Johannes Berg4c476992010-10-04 21:36:35 +02007880 if (!ok)
7881 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007882 }
7883
Johannes Berg4c476992010-10-04 21:36:35 +02007884 if (!rdev->ops->auth)
7885 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007886
Johannes Berg074ac8d2010-09-16 14:58:22 +02007887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7889 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007890
Johannes Berg19957bb2009-07-02 17:20:43 +02007891 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007892 chan = nl80211_get_valid_chan(&rdev->wiphy,
7893 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7894 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007895 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007896
Johannes Berg19957bb2009-07-02 17:20:43 +02007897 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7898 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7899
7900 if (info->attrs[NL80211_ATTR_IE]) {
7901 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7902 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7903 }
7904
7905 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007906 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007907 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007908
Jouni Malinene20f90f2016-10-27 00:42:02 +03007909 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7910 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7911 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7912 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007913 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007914 return -EINVAL;
7915
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007916 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinene20f90f2016-10-27 00:42:02 +03007917 if (auth_type != NL80211_AUTHTYPE_SAE &&
7918 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7919 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7920 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007921 return -EINVAL;
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007922 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7923 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007924 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007925 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007926 return -EINVAL;
7927 }
7928
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007929 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7930
Johannes Berg95de8172012-01-20 13:55:25 +01007931 /*
7932 * Since we no longer track auth state, ignore
7933 * requests to only change local state.
7934 */
7935 if (local_state_change)
7936 return 0;
7937
Johannes Berg91bf9b22013-05-15 17:44:01 +02007938 wdev_lock(dev->ieee80211_ptr);
7939 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7940 ssid, ssid_len, ie, ie_len,
7941 key.p.key, key.p.key_len, key.idx,
Jouni Malinen3255b4a2016-10-27 00:41:58 +03007942 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007943 wdev_unlock(dev->ieee80211_ptr);
7944 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007945}
7946
Johannes Bergc0692b82010-08-27 14:26:53 +03007947static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7948 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007949 struct cfg80211_crypto_settings *settings,
7950 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007951{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007952 memset(settings, 0, sizeof(*settings));
7953
Samuel Ortizb23aa672009-07-01 21:26:54 +02007954 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7955
Johannes Bergc0692b82010-08-27 14:26:53 +03007956 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7957 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007958
Johannes Bergc0692b82010-08-27 14:26:53 +03007959 proto = nla_get_u16(
7960 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7961 settings->control_port_ethertype = cpu_to_be16(proto);
7962 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7963 proto != ETH_P_PAE)
7964 return -EINVAL;
7965 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7966 settings->control_port_no_encrypt = true;
7967 } else
7968 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7969
Samuel Ortizb23aa672009-07-01 21:26:54 +02007970 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7971 void *data;
7972 int len, i;
7973
7974 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7975 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7976 settings->n_ciphers_pairwise = len / sizeof(u32);
7977
7978 if (len % sizeof(u32))
7979 return -EINVAL;
7980
Johannes Berg3dc27d22009-07-02 21:36:37 +02007981 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007982 return -EINVAL;
7983
7984 memcpy(settings->ciphers_pairwise, data, len);
7985
7986 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007987 if (!cfg80211_supported_cipher_suite(
7988 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007989 settings->ciphers_pairwise[i]))
7990 return -EINVAL;
7991 }
7992
7993 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7994 settings->cipher_group =
7995 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007996 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7997 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007998 return -EINVAL;
7999 }
8000
8001 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
8002 settings->wpa_versions =
8003 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
8004 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
8005 return -EINVAL;
8006 }
8007
8008 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
8009 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03008010 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008011
8012 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
8013 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
8014 settings->n_akm_suites = len / sizeof(u32);
8015
8016 if (len % sizeof(u32))
8017 return -EINVAL;
8018
Jouni Malinen1b9ca022011-09-21 16:13:07 +03008019 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
8020 return -EINVAL;
8021
Samuel Ortizb23aa672009-07-01 21:26:54 +02008022 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008023 }
8024
8025 return 0;
8026}
8027
Jouni Malinen636a5d32009-03-19 13:39:22 +02008028static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
8029{
Johannes Berg4c476992010-10-04 21:36:35 +02008030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8031 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02008032 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01008033 struct cfg80211_assoc_request req = {};
8034 const u8 *bssid, *ssid;
8035 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008036
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008037 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8038 return -EINVAL;
8039
8040 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02008041 !info->attrs[NL80211_ATTR_SSID] ||
8042 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008043 return -EINVAL;
8044
Johannes Berg4c476992010-10-04 21:36:35 +02008045 if (!rdev->ops->assoc)
8046 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008047
Johannes Berg074ac8d2010-09-16 14:58:22 +02008048 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008049 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8050 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008051
Johannes Berg19957bb2009-07-02 17:20:43 +02008052 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008053
Jouni Malinen664834d2014-01-15 00:01:44 +02008054 chan = nl80211_get_valid_chan(&rdev->wiphy,
8055 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8056 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02008057 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008058
Johannes Berg19957bb2009-07-02 17:20:43 +02008059 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8060 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008061
8062 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008063 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8064 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008065 }
8066
Jouni Malinendc6382c2009-05-06 22:09:37 +03008067 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008068 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03008069 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02008070 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01008071 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02008072 else if (mfp != NL80211_MFP_NO)
8073 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03008074 }
8075
Johannes Berg3e5d7642009-07-07 14:37:26 +02008076 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008077 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008078
Ben Greear7e7c8922011-11-18 11:31:59 -08008079 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008080 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008081
8082 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008083 memcpy(&req.ht_capa_mask,
8084 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8085 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008086
8087 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008088 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008089 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008090 memcpy(&req.ht_capa,
8091 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8092 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008093 }
8094
Johannes Bergee2aca32013-02-21 17:36:01 +01008095 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008096 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008097
8098 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008099 memcpy(&req.vht_capa_mask,
8100 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8101 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008102
8103 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008104 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008105 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008106 memcpy(&req.vht_capa,
8107 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8108 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008109 }
8110
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008111 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008112 if (!((rdev->wiphy.features &
8113 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8114 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8115 !wiphy_ext_feature_isset(&rdev->wiphy,
8116 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008117 return -EINVAL;
8118 req.flags |= ASSOC_REQ_USE_RRM;
8119 }
8120
Jouni Malinenc9a63622016-10-27 00:42:03 +03008121 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8122 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8123 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8124 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8125 return -EINVAL;
8126 req.fils_nonces =
8127 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8128 }
8129
Johannes Bergf62fab72013-02-21 20:09:09 +01008130 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008131 if (!err) {
8132 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308133
Johannes Bergf62fab72013-02-21 20:09:09 +01008134 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8135 ssid, ssid_len, &req);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308136
8137 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8138 dev->ieee80211_ptr->conn_owner_nlportid =
8139 info->snd_portid;
8140 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8141 bssid, ETH_ALEN);
8142 }
8143
Johannes Berg91bf9b22013-05-15 17:44:01 +02008144 wdev_unlock(dev->ieee80211_ptr);
8145 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008146
Jouni Malinen636a5d32009-03-19 13:39:22 +02008147 return err;
8148}
8149
8150static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8151{
Johannes Berg4c476992010-10-04 21:36:35 +02008152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8153 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008154 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008155 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008156 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008157 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008158
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008159 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8160 return -EINVAL;
8161
8162 if (!info->attrs[NL80211_ATTR_MAC])
8163 return -EINVAL;
8164
8165 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8166 return -EINVAL;
8167
Johannes Berg4c476992010-10-04 21:36:35 +02008168 if (!rdev->ops->deauth)
8169 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008170
Johannes Berg074ac8d2010-09-16 14:58:22 +02008171 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008172 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8173 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008174
Johannes Berg19957bb2009-07-02 17:20:43 +02008175 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008176
Johannes Berg19957bb2009-07-02 17:20:43 +02008177 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8178 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008179 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008180 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008181 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008182
8183 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008184 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8185 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008186 }
8187
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008188 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8189
Johannes Berg91bf9b22013-05-15 17:44:01 +02008190 wdev_lock(dev->ieee80211_ptr);
8191 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8192 local_state_change);
8193 wdev_unlock(dev->ieee80211_ptr);
8194 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008195}
8196
8197static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8198{
Johannes Berg4c476992010-10-04 21:36:35 +02008199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8200 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008201 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008202 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008203 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008204 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008205
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008206 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8207 return -EINVAL;
8208
8209 if (!info->attrs[NL80211_ATTR_MAC])
8210 return -EINVAL;
8211
8212 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8213 return -EINVAL;
8214
Johannes Berg4c476992010-10-04 21:36:35 +02008215 if (!rdev->ops->disassoc)
8216 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008217
Johannes Berg074ac8d2010-09-16 14:58:22 +02008218 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008219 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8220 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008221
Johannes Berg19957bb2009-07-02 17:20:43 +02008222 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008223
Johannes Berg19957bb2009-07-02 17:20:43 +02008224 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8225 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008226 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008227 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008228 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008229
8230 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008231 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8232 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008233 }
8234
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008235 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8236
Johannes Berg91bf9b22013-05-15 17:44:01 +02008237 wdev_lock(dev->ieee80211_ptr);
8238 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8239 local_state_change);
8240 wdev_unlock(dev->ieee80211_ptr);
8241 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008242}
8243
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008244static bool
8245nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008246 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008247 int rateval)
8248{
8249 struct wiphy *wiphy = &rdev->wiphy;
8250 bool found = false;
8251 int band, i;
8252
Johannes Berg57fbcce2016-04-12 15:56:15 +02008253 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008254 struct ieee80211_supported_band *sband;
8255
8256 sband = wiphy->bands[band];
8257 if (!sband)
8258 continue;
8259
8260 for (i = 0; i < sband->n_bitrates; i++) {
8261 if (sband->bitrates[i].bitrate == rateval) {
8262 mcast_rate[band] = i + 1;
8263 found = true;
8264 break;
8265 }
8266 }
8267 }
8268
8269 return found;
8270}
8271
Johannes Berg04a773a2009-04-19 21:24:32 +02008272static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8273{
Johannes Berg4c476992010-10-04 21:36:35 +02008274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8275 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008276 struct cfg80211_ibss_params ibss;
8277 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008278 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008279 int err;
8280
Johannes Berg8e30bc52009-04-22 17:45:38 +02008281 memset(&ibss, 0, sizeof(ibss));
8282
Johannes Berg04a773a2009-04-19 21:24:32 +02008283 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8284 return -EINVAL;
8285
Johannes Berg683b6d32012-11-08 21:25:48 +01008286 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008287 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8288 return -EINVAL;
8289
Johannes Berg8e30bc52009-04-22 17:45:38 +02008290 ibss.beacon_interval = 100;
8291
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308292 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008293 ibss.beacon_interval =
8294 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308295
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05308296 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8297 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308298 if (err)
8299 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008300
Johannes Berg4c476992010-10-04 21:36:35 +02008301 if (!rdev->ops->join_ibss)
8302 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008303
Johannes Berg4c476992010-10-04 21:36:35 +02008304 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8305 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008306
Johannes Berg79c97e92009-07-07 03:56:12 +02008307 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008308
Johannes Berg39193492011-09-16 13:45:25 +02008309 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008310 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008311
8312 if (!is_valid_ether_addr(ibss.bssid))
8313 return -EINVAL;
8314 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008315 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8316 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8317
8318 if (info->attrs[NL80211_ATTR_IE]) {
8319 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8320 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8321 }
8322
Johannes Berg683b6d32012-11-08 21:25:48 +01008323 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8324 if (err)
8325 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008326
Ilan Peer174e0cd2014-02-23 09:13:01 +02008327 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8328 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008329 return -EINVAL;
8330
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008331 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008332 case NL80211_CHAN_WIDTH_5:
8333 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008334 case NL80211_CHAN_WIDTH_20_NOHT:
8335 break;
8336 case NL80211_CHAN_WIDTH_20:
8337 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008338 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8339 return -EINVAL;
8340 break;
8341 case NL80211_CHAN_WIDTH_80:
8342 case NL80211_CHAN_WIDTH_80P80:
8343 case NL80211_CHAN_WIDTH_160:
8344 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8345 return -EINVAL;
8346 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8347 NL80211_EXT_FEATURE_VHT_IBSS))
8348 return -EINVAL;
8349 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008350 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008351 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008352 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008353
Johannes Berg04a773a2009-04-19 21:24:32 +02008354 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008355 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008356
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008357 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8358 u8 *rates =
8359 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8360 int n_rates =
8361 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8362 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008363 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008364
Johannes Berg34850ab2011-07-18 18:08:35 +02008365 err = ieee80211_get_ratemask(sband, rates, n_rates,
8366 &ibss.basic_rates);
8367 if (err)
8368 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008369 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008370
Simon Wunderlich803768f2013-06-28 10:39:58 +02008371 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8372 memcpy(&ibss.ht_capa_mask,
8373 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8374 sizeof(ibss.ht_capa_mask));
8375
8376 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8377 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8378 return -EINVAL;
8379 memcpy(&ibss.ht_capa,
8380 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8381 sizeof(ibss.ht_capa));
8382 }
8383
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008384 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8385 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8386 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8387 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008388
Johannes Berg4c476992010-10-04 21:36:35 +02008389 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308390 bool no_ht = false;
8391
Johannes Berg4c476992010-10-04 21:36:35 +02008392 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308393 info->attrs[NL80211_ATTR_KEYS],
8394 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008395 if (IS_ERR(connkeys))
8396 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308397
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008398 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8399 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008400 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308401 return -EINVAL;
8402 }
Johannes Berg4c476992010-10-04 21:36:35 +02008403 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008404
Antonio Quartulli267335d2012-01-31 20:25:47 +01008405 ibss.control_port =
8406 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8407
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008408 ibss.userspace_handles_dfs =
8409 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8410
Johannes Berg4c476992010-10-04 21:36:35 +02008411 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008412 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008413 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008414 return err;
8415}
8416
8417static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8418{
Johannes Berg4c476992010-10-04 21:36:35 +02008419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8420 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008421
Johannes Berg4c476992010-10-04 21:36:35 +02008422 if (!rdev->ops->leave_ibss)
8423 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008424
Johannes Berg4c476992010-10-04 21:36:35 +02008425 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8426 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008427
Johannes Berg4c476992010-10-04 21:36:35 +02008428 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008429}
8430
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008431static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8432{
8433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8434 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008435 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008436 u32 nla_rate;
8437 int err;
8438
8439 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008440 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8441 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008442 return -EOPNOTSUPP;
8443
8444 if (!rdev->ops->set_mcast_rate)
8445 return -EOPNOTSUPP;
8446
8447 memset(mcast_rate, 0, sizeof(mcast_rate));
8448
8449 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8450 return -EINVAL;
8451
8452 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8453 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8454 return -EINVAL;
8455
Ilan Peera1056b12015-10-22 22:27:46 +03008456 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008457
8458 return err;
8459}
8460
Johannes Bergad7e7182013-11-13 13:37:47 +01008461static struct sk_buff *
8462__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008463 struct wireless_dev *wdev, int approxlen,
8464 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008465 enum nl80211_attrs attr,
8466 const struct nl80211_vendor_cmd_info *info,
8467 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008468{
8469 struct sk_buff *skb;
8470 void *hdr;
8471 struct nlattr *data;
8472
8473 skb = nlmsg_new(approxlen + 100, gfp);
8474 if (!skb)
8475 return NULL;
8476
8477 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8478 if (!hdr) {
8479 kfree_skb(skb);
8480 return NULL;
8481 }
8482
8483 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8484 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008485
8486 if (info) {
8487 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8488 info->vendor_id))
8489 goto nla_put_failure;
8490 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8491 info->subcmd))
8492 goto nla_put_failure;
8493 }
8494
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008495 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008496 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8497 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008498 goto nla_put_failure;
8499 if (wdev->netdev &&
8500 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8501 wdev->netdev->ifindex))
8502 goto nla_put_failure;
8503 }
8504
Johannes Bergad7e7182013-11-13 13:37:47 +01008505 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008506 if (!data)
8507 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008508
8509 ((void **)skb->cb)[0] = rdev;
8510 ((void **)skb->cb)[1] = hdr;
8511 ((void **)skb->cb)[2] = data;
8512
8513 return skb;
8514
8515 nla_put_failure:
8516 kfree_skb(skb);
8517 return NULL;
8518}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008519
Johannes Berge03ad6e2014-01-01 17:22:30 +01008520struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008521 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008522 enum nl80211_commands cmd,
8523 enum nl80211_attrs attr,
8524 int vendor_event_idx,
8525 int approxlen, gfp_t gfp)
8526{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008527 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008528 const struct nl80211_vendor_cmd_info *info;
8529
8530 switch (cmd) {
8531 case NL80211_CMD_TESTMODE:
8532 if (WARN_ON(vendor_event_idx != -1))
8533 return NULL;
8534 info = NULL;
8535 break;
8536 case NL80211_CMD_VENDOR:
8537 if (WARN_ON(vendor_event_idx < 0 ||
8538 vendor_event_idx >= wiphy->n_vendor_events))
8539 return NULL;
8540 info = &wiphy->vendor_events[vendor_event_idx];
8541 break;
8542 default:
8543 WARN_ON(1);
8544 return NULL;
8545 }
8546
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008547 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008548 cmd, attr, info, gfp);
8549}
8550EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8551
8552void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8553{
8554 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8555 void *hdr = ((void **)skb->cb)[1];
8556 struct nlattr *data = ((void **)skb->cb)[2];
8557 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8558
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008559 /* clear CB data for netlink core to own from now on */
8560 memset(skb->cb, 0, sizeof(skb->cb));
8561
Johannes Berge03ad6e2014-01-01 17:22:30 +01008562 nla_nest_end(skb, data);
8563 genlmsg_end(skb, hdr);
8564
8565 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8566 mcgrp = NL80211_MCGRP_VENDOR;
8567
8568 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8569 mcgrp, gfp);
8570}
8571EXPORT_SYMBOL(__cfg80211_send_event_skb);
8572
Johannes Bergaff89a92009-07-01 21:26:51 +02008573#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008574static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8575{
Johannes Berg4c476992010-10-04 21:36:35 +02008576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008577 struct wireless_dev *wdev =
8578 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008579 int err;
8580
David Spinadelfc73f112013-07-31 18:04:15 +03008581 if (!rdev->ops->testmode_cmd)
8582 return -EOPNOTSUPP;
8583
8584 if (IS_ERR(wdev)) {
8585 err = PTR_ERR(wdev);
8586 if (err != -EINVAL)
8587 return err;
8588 wdev = NULL;
8589 } else if (wdev->wiphy != &rdev->wiphy) {
8590 return -EINVAL;
8591 }
8592
Johannes Bergaff89a92009-07-01 21:26:51 +02008593 if (!info->attrs[NL80211_ATTR_TESTDATA])
8594 return -EINVAL;
8595
Johannes Bergad7e7182013-11-13 13:37:47 +01008596 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008597 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008598 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8599 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008600 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008601
Johannes Bergaff89a92009-07-01 21:26:51 +02008602 return err;
8603}
8604
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008605static int nl80211_testmode_dump(struct sk_buff *skb,
8606 struct netlink_callback *cb)
8607{
Johannes Berg00918d32011-12-13 17:22:05 +01008608 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008609 int err;
8610 long phy_idx;
8611 void *data = NULL;
8612 int data_len = 0;
8613
Johannes Berg5fe231e2013-05-08 21:45:15 +02008614 rtnl_lock();
8615
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008616 if (cb->args[0]) {
8617 /*
8618 * 0 is a valid index, but not valid for args[0],
8619 * so we need to offset by 1.
8620 */
8621 phy_idx = cb->args[0] - 1;
8622 } else {
8623 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8624 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8625 nl80211_policy);
8626 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008627 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008628
Johannes Berg2bd7e352012-06-15 14:23:16 +02008629 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8630 nl80211_fam.attrbuf);
8631 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008632 err = PTR_ERR(rdev);
8633 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008634 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008635 phy_idx = rdev->wiphy_idx;
8636 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008637
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008638 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8639 cb->args[1] =
8640 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8641 }
8642
8643 if (cb->args[1]) {
8644 data = nla_data((void *)cb->args[1]);
8645 data_len = nla_len((void *)cb->args[1]);
8646 }
8647
Johannes Berg00918d32011-12-13 17:22:05 +01008648 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8649 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008650 err = -ENOENT;
8651 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008652 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008653
Johannes Berg00918d32011-12-13 17:22:05 +01008654 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008655 err = -EOPNOTSUPP;
8656 goto out_err;
8657 }
8658
8659 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008660 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008661 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8662 NL80211_CMD_TESTMODE);
8663 struct nlattr *tmdata;
8664
Dan Carpentercb35fba2013-08-14 14:50:01 +03008665 if (!hdr)
8666 break;
8667
David S. Miller9360ffd2012-03-29 04:41:26 -04008668 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008669 genlmsg_cancel(skb, hdr);
8670 break;
8671 }
8672
8673 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8674 if (!tmdata) {
8675 genlmsg_cancel(skb, hdr);
8676 break;
8677 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008678 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008679 nla_nest_end(skb, tmdata);
8680
8681 if (err == -ENOBUFS || err == -ENOENT) {
8682 genlmsg_cancel(skb, hdr);
8683 break;
8684 } else if (err) {
8685 genlmsg_cancel(skb, hdr);
8686 goto out_err;
8687 }
8688
8689 genlmsg_end(skb, hdr);
8690 }
8691
8692 err = skb->len;
8693 /* see above */
8694 cb->args[0] = phy_idx + 1;
8695 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008696 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008697 return err;
8698}
Johannes Bergaff89a92009-07-01 21:26:51 +02008699#endif
8700
Samuel Ortizb23aa672009-07-01 21:26:54 +02008701static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8702{
Johannes Berg4c476992010-10-04 21:36:35 +02008703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8704 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008705 struct cfg80211_connect_params connect;
8706 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008707 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008708 int err;
8709
8710 memset(&connect, 0, sizeof(connect));
8711
8712 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8713 return -EINVAL;
8714
8715 if (!info->attrs[NL80211_ATTR_SSID] ||
8716 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8717 return -EINVAL;
8718
8719 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8720 connect.auth_type =
8721 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008722 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8723 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008724 return -EINVAL;
8725 } else
8726 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8727
8728 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8729
Johannes Bergc0692b82010-08-27 14:26:53 +03008730 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008731 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008732 if (err)
8733 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008734
Johannes Berg074ac8d2010-09-16 14:58:22 +02008735 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008736 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8737 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008738
Johannes Berg79c97e92009-07-07 03:56:12 +02008739 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008740
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308741 connect.bg_scan_period = -1;
8742 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8743 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8744 connect.bg_scan_period =
8745 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8746 }
8747
Samuel Ortizb23aa672009-07-01 21:26:54 +02008748 if (info->attrs[NL80211_ATTR_MAC])
8749 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008750 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8751 connect.bssid_hint =
8752 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008753 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8754 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8755
8756 if (info->attrs[NL80211_ATTR_IE]) {
8757 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8758 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8759 }
8760
Jouni Malinencee00a92013-01-15 17:15:57 +02008761 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8762 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8763 if (connect.mfp != NL80211_MFP_REQUIRED &&
8764 connect.mfp != NL80211_MFP_NO)
8765 return -EINVAL;
8766 } else {
8767 connect.mfp = NL80211_MFP_NO;
8768 }
8769
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008770 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8771 connect.prev_bssid =
8772 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8773
Samuel Ortizb23aa672009-07-01 21:26:54 +02008774 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008775 connect.channel = nl80211_get_valid_chan(
8776 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8777 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008778 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008779 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008780 connect.channel_hint = nl80211_get_valid_chan(
8781 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8782 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008783 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008784 }
8785
Johannes Bergfffd0932009-07-08 14:22:54 +02008786 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8787 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308788 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008789 if (IS_ERR(connkeys))
8790 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008791 }
8792
Ben Greear7e7c8922011-11-18 11:31:59 -08008793 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8794 connect.flags |= ASSOC_REQ_DISABLE_HT;
8795
8796 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8797 memcpy(&connect.ht_capa_mask,
8798 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8799 sizeof(connect.ht_capa_mask));
8800
8801 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008802 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008803 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008804 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008805 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008806 memcpy(&connect.ht_capa,
8807 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8808 sizeof(connect.ht_capa));
8809 }
8810
Johannes Bergee2aca32013-02-21 17:36:01 +01008811 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8812 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8813
8814 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8815 memcpy(&connect.vht_capa_mask,
8816 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8817 sizeof(connect.vht_capa_mask));
8818
8819 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8820 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008821 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008822 return -EINVAL;
8823 }
8824 memcpy(&connect.vht_capa,
8825 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8826 sizeof(connect.vht_capa));
8827 }
8828
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008829 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008830 if (!((rdev->wiphy.features &
8831 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8832 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8833 !wiphy_ext_feature_isset(&rdev->wiphy,
8834 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008835 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008836 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008837 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008838 connect.flags |= ASSOC_REQ_USE_RRM;
8839 }
8840
Lior David34d50512016-01-28 10:58:25 +02008841 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008842 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008843 kzfree(connkeys);
8844 return -EOPNOTSUPP;
8845 }
8846
Arend van Spriel38de03d2016-03-02 20:37:18 +01008847 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8848 /* bss selection makes no sense if bssid is set */
8849 if (connect.bssid) {
8850 kzfree(connkeys);
8851 return -EINVAL;
8852 }
8853
8854 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8855 wiphy, &connect.bss_select);
8856 if (err) {
8857 kzfree(connkeys);
8858 return err;
8859 }
8860 }
8861
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03008862 if (wiphy_ext_feature_isset(&rdev->wiphy,
8863 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
8864 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
8865 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
8866 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
8867 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8868 connect.fils_erp_username =
8869 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8870 connect.fils_erp_username_len =
8871 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8872 connect.fils_erp_realm =
8873 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8874 connect.fils_erp_realm_len =
8875 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8876 connect.fils_erp_next_seq_num =
8877 nla_get_u16(
8878 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
8879 connect.fils_erp_rrk =
8880 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8881 connect.fils_erp_rrk_len =
8882 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8883 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
8884 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
8885 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
8886 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8887 kzfree(connkeys);
8888 return -EINVAL;
8889 }
8890
Srinivas Dasarid041a1a2018-02-07 18:32:17 +05308891 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
8892 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8893 return -EINVAL;
8894 }
8895 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
8896 }
8897
Johannes Berg83739b02013-05-15 17:44:01 +02008898 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308899
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008900 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8901 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +02008902 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008903 kzfree(connkeys);
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +05308904
8905 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
8906 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
8907 if (connect.bssid)
8908 memcpy(dev->ieee80211_ptr->disconnect_bssid,
8909 connect.bssid, ETH_ALEN);
8910 else
8911 memset(dev->ieee80211_ptr->disconnect_bssid,
8912 0, ETH_ALEN);
8913 }
8914
8915 wdev_unlock(dev->ieee80211_ptr);
8916
Samuel Ortizb23aa672009-07-01 21:26:54 +02008917 return err;
8918}
8919
vamsi krishna30da4e82016-10-27 16:51:11 +03008920static int nl80211_update_connect_params(struct sk_buff *skb,
8921 struct genl_info *info)
8922{
8923 struct cfg80211_connect_params connect = {};
8924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8925 struct net_device *dev = info->user_ptr[1];
8926 struct wireless_dev *wdev = dev->ieee80211_ptr;
8927 u32 changed = 0;
8928 int ret;
8929
8930 if (!rdev->ops->update_connect_params)
8931 return -EOPNOTSUPP;
8932
8933 if (info->attrs[NL80211_ATTR_IE]) {
8934 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8935 return -EINVAL;
8936 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8937 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8938 changed |= UPDATE_ASSOC_IES;
8939 }
8940
Vidyullatha Kanchanapally5f5a26b2017-08-02 16:31:40 +05308941 if (wiphy_ext_feature_isset(&rdev->wiphy,
8942 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
8943 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
8944 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
8945 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
8946 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8947 connect.fils_erp_username =
8948 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8949 connect.fils_erp_username_len =
8950 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
8951 connect.fils_erp_realm =
8952 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8953 connect.fils_erp_realm_len =
8954 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
8955 connect.fils_erp_next_seq_num =
8956 nla_get_u16(
8957 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
8958 connect.fils_erp_rrk =
8959 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8960 connect.fils_erp_rrk_len =
8961 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
8962 changed |= UPDATE_FILS_ERP_INFO;
8963 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
8964 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
8965 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
8966 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
8967 return -EINVAL;
8968 }
8969
8970 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8971 u32 auth_type =
8972 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
8973 if (!nl80211_valid_auth_type(rdev, auth_type,
8974 NL80211_CMD_CONNECT))
8975 return -EINVAL;
8976 connect.auth_type = auth_type;
8977 changed |= UPDATE_AUTH_TYPE;
8978 }
8979
vamsi krishna30da4e82016-10-27 16:51:11 +03008980 wdev_lock(dev->ieee80211_ptr);
8981 if (!wdev->current_bss)
8982 ret = -ENOLINK;
8983 else
8984 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
8985 wdev_unlock(dev->ieee80211_ptr);
8986
8987 return ret;
8988}
8989
Samuel Ortizb23aa672009-07-01 21:26:54 +02008990static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8991{
Johannes Berg4c476992010-10-04 21:36:35 +02008992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8993 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008994 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008995 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008996
8997 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8998 reason = WLAN_REASON_DEAUTH_LEAVING;
8999 else
9000 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9001
9002 if (reason == 0)
9003 return -EINVAL;
9004
Johannes Berg074ac8d2010-09-16 14:58:22 +02009005 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009006 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9007 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009008
Johannes Berg83739b02013-05-15 17:44:01 +02009009 wdev_lock(dev->ieee80211_ptr);
9010 ret = cfg80211_disconnect(rdev, dev, reason, true);
9011 wdev_unlock(dev->ieee80211_ptr);
9012 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009013}
9014
Johannes Berg463d0182009-07-14 00:33:35 +02009015static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
9016{
Johannes Berg4c476992010-10-04 21:36:35 +02009017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02009018 struct net *net;
9019 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02009020
Vadim Kochan4b681c82015-01-12 16:34:05 +02009021 if (info->attrs[NL80211_ATTR_PID]) {
9022 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
9023
9024 net = get_net_ns_by_pid(pid);
9025 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
9026 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
9027
9028 net = get_net_ns_by_fd(fd);
9029 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02009030 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02009031 }
Johannes Berg463d0182009-07-14 00:33:35 +02009032
Johannes Berg4c476992010-10-04 21:36:35 +02009033 if (IS_ERR(net))
9034 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009035
9036 err = 0;
9037
9038 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02009039 if (!net_eq(wiphy_net(&rdev->wiphy), net))
9040 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02009041
Johannes Berg463d0182009-07-14 00:33:35 +02009042 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02009043 return err;
9044}
9045
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009046static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
9047{
Johannes Berg4c476992010-10-04 21:36:35 +02009048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009049 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
9050 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02009051 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009052 struct cfg80211_pmksa pmksa;
9053
9054 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
9055
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009056 if (!info->attrs[NL80211_ATTR_PMKID])
9057 return -EINVAL;
9058
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009059 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +03009060
9061 if (info->attrs[NL80211_ATTR_MAC]) {
9062 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
9063 } else if (info->attrs[NL80211_ATTR_SSID] &&
9064 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
9065 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
9066 info->attrs[NL80211_ATTR_PMK])) {
9067 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9068 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9069 pmksa.cache_id =
9070 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
9071 } else {
9072 return -EINVAL;
9073 }
9074 if (info->attrs[NL80211_ATTR_PMK]) {
9075 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9076 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
9077 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009078
Johannes Berg074ac8d2010-09-16 14:58:22 +02009079 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009080 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9081 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009082
9083 switch (info->genlhdr->cmd) {
9084 case NL80211_CMD_SET_PMKSA:
9085 rdev_ops = rdev->ops->set_pmksa;
9086 break;
9087 case NL80211_CMD_DEL_PMKSA:
9088 rdev_ops = rdev->ops->del_pmksa;
9089 break;
9090 default:
9091 WARN_ON(1);
9092 break;
9093 }
9094
Johannes Berg4c476992010-10-04 21:36:35 +02009095 if (!rdev_ops)
9096 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009097
Johannes Berg4c476992010-10-04 21:36:35 +02009098 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009099}
9100
9101static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
9102{
Johannes Berg4c476992010-10-04 21:36:35 +02009103 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9104 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009105
Johannes Berg074ac8d2010-09-16 14:58:22 +02009106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9108 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009109
Johannes Berg4c476992010-10-04 21:36:35 +02009110 if (!rdev->ops->flush_pmksa)
9111 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009112
Hila Gonene35e4d22012-06-27 17:19:42 +03009113 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009114}
9115
Arik Nemtsov109086c2011-09-28 14:12:50 +03009116static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
9117{
9118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9119 struct net_device *dev = info->user_ptr[1];
9120 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309121 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009122 u16 status_code;
9123 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009124 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03009125
9126 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9127 !rdev->ops->tdls_mgmt)
9128 return -EOPNOTSUPP;
9129
9130 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
9131 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
9132 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
9133 !info->attrs[NL80211_ATTR_IE] ||
9134 !info->attrs[NL80211_ATTR_MAC])
9135 return -EINVAL;
9136
9137 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9138 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
9139 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
9140 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009141 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309142 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
9143 peer_capability =
9144 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009145
Hila Gonene35e4d22012-06-27 17:19:42 +03009146 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05309147 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03009148 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03009149 nla_data(info->attrs[NL80211_ATTR_IE]),
9150 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03009151}
9152
9153static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
9154{
9155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9156 struct net_device *dev = info->user_ptr[1];
9157 enum nl80211_tdls_operation operation;
9158 u8 *peer;
9159
9160 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
9161 !rdev->ops->tdls_oper)
9162 return -EOPNOTSUPP;
9163
9164 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
9165 !info->attrs[NL80211_ATTR_MAC])
9166 return -EINVAL;
9167
9168 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
9169 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9170
Hila Gonene35e4d22012-06-27 17:19:42 +03009171 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03009172}
9173
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009174static int nl80211_remain_on_channel(struct sk_buff *skb,
9175 struct genl_info *info)
9176{
Johannes Berg4c476992010-10-04 21:36:35 +02009177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009178 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009179 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009180 struct sk_buff *msg;
9181 void *hdr;
9182 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01009183 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009184 int err;
9185
9186 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
9187 !info->attrs[NL80211_ATTR_DURATION])
9188 return -EINVAL;
9189
9190 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9191
Johannes Berg7c4ef712011-11-18 15:33:48 +01009192 if (!rdev->ops->remain_on_channel ||
9193 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009194 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009195
Johannes Bergebf348f2012-06-01 12:50:54 +02009196 /*
9197 * We should be on that channel for at least a minimum amount of
9198 * time (10ms) but no longer than the driver supports.
9199 */
9200 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9201 duration > rdev->wiphy.max_remain_on_channel_duration)
9202 return -EINVAL;
9203
Johannes Berg683b6d32012-11-08 21:25:48 +01009204 err = nl80211_parse_chandef(rdev, info, &chandef);
9205 if (err)
9206 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009207
9208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009209 if (!msg)
9210 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009211
Eric W. Biederman15e47302012-09-07 20:12:54 +00009212 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009213 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009214 if (!hdr) {
9215 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009216 goto free_msg;
9217 }
9218
Johannes Berg683b6d32012-11-08 21:25:48 +01009219 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9220 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009221
9222 if (err)
9223 goto free_msg;
9224
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009225 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9226 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009227 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009228
9229 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009230
9231 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009232
9233 nla_put_failure:
9234 err = -ENOBUFS;
9235 free_msg:
9236 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009237 return err;
9238}
9239
9240static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9241 struct genl_info *info)
9242{
Johannes Berg4c476992010-10-04 21:36:35 +02009243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009244 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009245 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009246
9247 if (!info->attrs[NL80211_ATTR_COOKIE])
9248 return -EINVAL;
9249
Johannes Berg4c476992010-10-04 21:36:35 +02009250 if (!rdev->ops->cancel_remain_on_channel)
9251 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009252
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009253 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9254
Hila Gonene35e4d22012-06-27 17:19:42 +03009255 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009256}
9257
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009258static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9259 struct genl_info *info)
9260{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009261 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009263 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309264 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009265
Johannes Berg4c476992010-10-04 21:36:35 +02009266 if (!rdev->ops->set_bitrate_mask)
9267 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009268
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309269 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9270 if (err)
9271 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009272
Hila Gonene35e4d22012-06-27 17:19:42 +03009273 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009274}
9275
Johannes Berg2e161f72010-08-12 15:38:38 +02009276static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009277{
Johannes Berg4c476992010-10-04 21:36:35 +02009278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009279 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009280 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009281
9282 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9283 return -EINVAL;
9284
Johannes Berg2e161f72010-08-12 15:38:38 +02009285 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9286 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009287
Johannes Berg71bbc992012-06-15 15:30:18 +02009288 switch (wdev->iftype) {
9289 case NL80211_IFTYPE_STATION:
9290 case NL80211_IFTYPE_ADHOC:
9291 case NL80211_IFTYPE_P2P_CLIENT:
9292 case NL80211_IFTYPE_AP:
9293 case NL80211_IFTYPE_AP_VLAN:
9294 case NL80211_IFTYPE_MESH_POINT:
9295 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009296 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009297 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009298 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009299 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009300 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009301 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009302
9303 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009304 if (!rdev->ops->mgmt_tx)
9305 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009306
Eric W. Biederman15e47302012-09-07 20:12:54 +00009307 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009308 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9309 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009310}
9311
Johannes Berg2e161f72010-08-12 15:38:38 +02009312static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009313{
Johannes Berg4c476992010-10-04 21:36:35 +02009314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009315 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009316 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009317 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009318 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009319 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009320 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009321 struct cfg80211_mgmt_tx_params params = {
9322 .dont_wait_for_ack =
9323 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9324 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009325
Johannes Berg683b6d32012-11-08 21:25:48 +01009326 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009327 return -EINVAL;
9328
Johannes Berg4c476992010-10-04 21:36:35 +02009329 if (!rdev->ops->mgmt_tx)
9330 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009331
Johannes Berg71bbc992012-06-15 15:30:18 +02009332 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009333 case NL80211_IFTYPE_P2P_DEVICE:
9334 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9335 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009336 case NL80211_IFTYPE_STATION:
9337 case NL80211_IFTYPE_ADHOC:
9338 case NL80211_IFTYPE_P2P_CLIENT:
9339 case NL80211_IFTYPE_AP:
9340 case NL80211_IFTYPE_AP_VLAN:
9341 case NL80211_IFTYPE_MESH_POINT:
9342 case NL80211_IFTYPE_P2P_GO:
9343 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009344 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009345 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009346 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009347 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009348
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009349 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009350 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009351 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009352 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009353
9354 /*
9355 * We should wait on the channel for at least a minimum amount
9356 * of time (10ms) but no longer than the driver supports.
9357 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009358 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9359 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009360 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009361 }
9362
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009363 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009364
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009365 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009366 return -EINVAL;
9367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009368 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309369
Antonio Quartulliea141b752013-06-11 14:20:03 +02009370 /* get the channel if any has been specified, otherwise pass NULL to
9371 * the driver. The latter will use the current one
9372 */
9373 chandef.chan = NULL;
9374 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9375 err = nl80211_parse_chandef(rdev, info, &chandef);
9376 if (err)
9377 return err;
9378 }
9379
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009380 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009381 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009382
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009383 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9384 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9385
9386 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9387 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9388 int i;
9389
9390 if (len % sizeof(u16))
9391 return -EINVAL;
9392
9393 params.n_csa_offsets = len / sizeof(u16);
9394 params.csa_offsets =
9395 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9396
9397 /* check that all the offsets fit the frame */
9398 for (i = 0; i < params.n_csa_offsets; i++) {
9399 if (params.csa_offsets[i] >= params.len)
9400 return -EINVAL;
9401 }
9402 }
9403
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009404 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009405 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9406 if (!msg)
9407 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009408
Eric W. Biederman15e47302012-09-07 20:12:54 +00009409 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009410 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009411 if (!hdr) {
9412 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009413 goto free_msg;
9414 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009415 }
Johannes Berge247bd902011-11-04 11:18:21 +01009416
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009417 params.chan = chandef.chan;
9418 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009419 if (err)
9420 goto free_msg;
9421
Johannes Berge247bd902011-11-04 11:18:21 +01009422 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009423 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9424 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009425 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009426
Johannes Berge247bd902011-11-04 11:18:21 +01009427 genlmsg_end(msg, hdr);
9428 return genlmsg_reply(msg, info);
9429 }
9430
9431 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009432
9433 nla_put_failure:
9434 err = -ENOBUFS;
9435 free_msg:
9436 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009437 return err;
9438}
9439
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009440static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9441{
9442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009443 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009444 u64 cookie;
9445
9446 if (!info->attrs[NL80211_ATTR_COOKIE])
9447 return -EINVAL;
9448
9449 if (!rdev->ops->mgmt_tx_cancel_wait)
9450 return -EOPNOTSUPP;
9451
Johannes Berg71bbc992012-06-15 15:30:18 +02009452 switch (wdev->iftype) {
9453 case NL80211_IFTYPE_STATION:
9454 case NL80211_IFTYPE_ADHOC:
9455 case NL80211_IFTYPE_P2P_CLIENT:
9456 case NL80211_IFTYPE_AP:
9457 case NL80211_IFTYPE_AP_VLAN:
9458 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009459 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009460 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009461 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009462 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009463 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009464 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009465
9466 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9467
Hila Gonene35e4d22012-06-27 17:19:42 +03009468 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009469}
9470
Kalle Valoffb9eb32010-02-17 17:58:10 +02009471static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9472{
Johannes Berg4c476992010-10-04 21:36:35 +02009473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009474 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009475 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009476 u8 ps_state;
9477 bool state;
9478 int err;
9479
Johannes Berg4c476992010-10-04 21:36:35 +02009480 if (!info->attrs[NL80211_ATTR_PS_STATE])
9481 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009482
9483 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9484
Johannes Berg4c476992010-10-04 21:36:35 +02009485 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9486 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009487
9488 wdev = dev->ieee80211_ptr;
9489
Johannes Berg4c476992010-10-04 21:36:35 +02009490 if (!rdev->ops->set_power_mgmt)
9491 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009492
9493 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9494
9495 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009496 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009497
Hila Gonene35e4d22012-06-27 17:19:42 +03009498 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009499 if (!err)
9500 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009501 return err;
9502}
9503
9504static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9505{
Johannes Berg4c476992010-10-04 21:36:35 +02009506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009507 enum nl80211_ps_state ps_state;
9508 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009509 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009510 struct sk_buff *msg;
9511 void *hdr;
9512 int err;
9513
Kalle Valoffb9eb32010-02-17 17:58:10 +02009514 wdev = dev->ieee80211_ptr;
9515
Johannes Berg4c476992010-10-04 21:36:35 +02009516 if (!rdev->ops->set_power_mgmt)
9517 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009518
9519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009520 if (!msg)
9521 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009522
Eric W. Biederman15e47302012-09-07 20:12:54 +00009523 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009524 NL80211_CMD_GET_POWER_SAVE);
9525 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009526 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009527 goto free_msg;
9528 }
9529
9530 if (wdev->ps)
9531 ps_state = NL80211_PS_ENABLED;
9532 else
9533 ps_state = NL80211_PS_DISABLED;
9534
David S. Miller9360ffd2012-03-29 04:41:26 -04009535 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9536 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009537
9538 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009539 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009540
Johannes Berg4c476992010-10-04 21:36:35 +02009541 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009542 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009543 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009544 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009545 return err;
9546}
9547
Johannes Berg94e860f2014-01-20 23:58:15 +01009548static const struct nla_policy
9549nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009550 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9551 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9552 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009553 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9554 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9555 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009556};
9557
Thomas Pedersen84f10702012-07-12 16:17:33 -07009558static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009559 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009560{
9561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009562 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009563 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009564
Johannes Bergd9d8b012012-11-26 12:51:52 +01009565 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009566 return -EINVAL;
9567
Thomas Pedersen84f10702012-07-12 16:17:33 -07009568 if (!rdev->ops->set_cqm_txe_config)
9569 return -EOPNOTSUPP;
9570
9571 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9572 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9573 return -EOPNOTSUPP;
9574
Hila Gonene35e4d22012-06-27 17:19:42 +03009575 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009576}
9577
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009578static int nl80211_set_cqm_rssi(struct genl_info *info,
9579 s32 threshold, u32 hysteresis)
9580{
Johannes Berg4c476992010-10-04 21:36:35 +02009581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009582 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009583 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009584
9585 if (threshold > 0)
9586 return -EINVAL;
9587
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009588 /* disabling - hysteresis should also be zero then */
9589 if (threshold == 0)
9590 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009591
Johannes Berg4c476992010-10-04 21:36:35 +02009592 if (!rdev->ops->set_cqm_rssi_config)
9593 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009594
Johannes Berg074ac8d2010-09-16 14:58:22 +02009595 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009596 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9597 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009598
Hila Gonene35e4d22012-06-27 17:19:42 +03009599 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009600}
9601
9602static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9603{
9604 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9605 struct nlattr *cqm;
9606 int err;
9607
9608 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009609 if (!cqm)
9610 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009611
9612 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9613 nl80211_attr_cqm_policy);
9614 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009615 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009616
9617 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9618 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009619 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9620 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009621
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009622 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9623 }
9624
9625 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9626 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9627 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9628 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9629 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9630 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9631
9632 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9633 }
9634
9635 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009636}
9637
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009638static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9639{
9640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9641 struct net_device *dev = info->user_ptr[1];
9642 struct ocb_setup setup = {};
9643 int err;
9644
9645 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9646 if (err)
9647 return err;
9648
9649 return cfg80211_join_ocb(rdev, dev, &setup);
9650}
9651
9652static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9653{
9654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9655 struct net_device *dev = info->user_ptr[1];
9656
9657 return cfg80211_leave_ocb(rdev, dev);
9658}
9659
Johannes Berg29cbe682010-12-03 09:20:44 +01009660static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9661{
9662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9663 struct net_device *dev = info->user_ptr[1];
9664 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009665 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009666 int err;
9667
9668 /* start with default */
9669 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009670 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009671
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009672 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009673 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009674 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009675 if (err)
9676 return err;
9677 }
9678
9679 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9680 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9681 return -EINVAL;
9682
Javier Cardonac80d5452010-12-16 17:37:49 -08009683 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9684 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9685
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009686 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9687 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9688 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9689 return -EINVAL;
9690
Marco Porsch9bdbf042013-01-07 16:04:51 +01009691 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9692 setup.beacon_interval =
9693 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309694
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05309695 err = cfg80211_validate_beacon_int(rdev,
9696 NL80211_IFTYPE_MESH_POINT,
9697 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309698 if (err)
9699 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009700 }
9701
9702 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9703 setup.dtim_period =
9704 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9705 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9706 return -EINVAL;
9707 }
9708
Javier Cardonac80d5452010-12-16 17:37:49 -08009709 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9710 /* parse additional setup parameters if given */
9711 err = nl80211_parse_mesh_setup(info, &setup);
9712 if (err)
9713 return err;
9714 }
9715
Thomas Pedersend37bb182013-03-04 13:06:13 -08009716 if (setup.user_mpm)
9717 cfg.auto_open_plinks = false;
9718
Johannes Bergcc1d2802012-05-16 23:50:20 +02009719 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009720 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9721 if (err)
9722 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009723 } else {
9724 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009725 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009726 }
9727
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009728 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9729 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9730 int n_rates =
9731 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9732 struct ieee80211_supported_band *sband;
9733
9734 if (!setup.chandef.chan)
9735 return -EINVAL;
9736
9737 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9738
9739 err = ieee80211_get_ratemask(sband, rates, n_rates,
9740 &setup.basic_rates);
9741 if (err)
9742 return err;
9743 }
9744
Johannes Berg8564e382016-09-19 09:44:44 +02009745 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9746 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9747 if (err)
9748 return err;
9749
Johannes Berg091eac32017-09-18 22:46:36 +02009750 if (!setup.chandef.chan)
9751 return -EINVAL;
9752
Johannes Berg8564e382016-09-19 09:44:44 +02009753 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9754 &setup.beacon_rate);
9755 if (err)
9756 return err;
9757 }
9758
Javier Cardonac80d5452010-12-16 17:37:49 -08009759 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009760}
9761
9762static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9763{
9764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9765 struct net_device *dev = info->user_ptr[1];
9766
9767 return cfg80211_leave_mesh(rdev, dev);
9768}
9769
Johannes Bergdfb89c52012-06-27 09:23:48 +02009770#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009771static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9772 struct cfg80211_registered_device *rdev)
9773{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009774 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009775 struct nlattr *nl_pats, *nl_pat;
9776 int i, pat_len;
9777
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009778 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009779 return 0;
9780
9781 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9782 if (!nl_pats)
9783 return -ENOBUFS;
9784
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009785 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009786 nl_pat = nla_nest_start(msg, i + 1);
9787 if (!nl_pat)
9788 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009789 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009790 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009791 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009792 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9793 wowlan->patterns[i].pattern) ||
9794 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009795 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009796 return -ENOBUFS;
9797 nla_nest_end(msg, nl_pat);
9798 }
9799 nla_nest_end(msg, nl_pats);
9800
9801 return 0;
9802}
9803
Johannes Berg2a0e0472013-01-23 22:57:40 +01009804static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9805 struct cfg80211_wowlan_tcp *tcp)
9806{
9807 struct nlattr *nl_tcp;
9808
9809 if (!tcp)
9810 return 0;
9811
9812 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9813 if (!nl_tcp)
9814 return -ENOBUFS;
9815
Jiri Benc930345e2015-03-29 16:59:25 +02009816 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9817 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009818 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9819 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9820 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9821 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9822 tcp->payload_len, tcp->payload) ||
9823 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9824 tcp->data_interval) ||
9825 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9826 tcp->wake_len, tcp->wake_data) ||
9827 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9828 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9829 return -ENOBUFS;
9830
9831 if (tcp->payload_seq.len &&
9832 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9833 sizeof(tcp->payload_seq), &tcp->payload_seq))
9834 return -ENOBUFS;
9835
9836 if (tcp->payload_tok.len &&
9837 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9838 sizeof(tcp->payload_tok) + tcp->tokens_size,
9839 &tcp->payload_tok))
9840 return -ENOBUFS;
9841
Johannes Berge248ad32013-05-16 10:24:28 +02009842 nla_nest_end(msg, nl_tcp);
9843
Johannes Berg2a0e0472013-01-23 22:57:40 +01009844 return 0;
9845}
9846
Luciano Coelho75453cc2015-01-09 14:06:37 +02009847static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9848 struct cfg80211_sched_scan_request *req)
9849{
Avraham Stern3b06d272015-10-12 09:51:34 +03009850 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009851 int i;
9852
9853 if (!req)
9854 return 0;
9855
9856 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9857 if (!nd)
9858 return -ENOBUFS;
9859
Avraham Stern3b06d272015-10-12 09:51:34 +03009860 if (req->n_scan_plans == 1 &&
9861 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9862 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009863 return -ENOBUFS;
9864
Luciano Coelho21fea562015-03-17 16:36:01 +02009865 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9866 return -ENOBUFS;
9867
vamsi krishnaf4f1a542017-01-13 01:12:20 +02009868 if (req->relative_rssi_set) {
9869 struct nl80211_bss_select_rssi_adjust rssi_adjust;
9870
9871 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
9872 req->relative_rssi))
9873 return -ENOBUFS;
9874
9875 rssi_adjust.band = req->rssi_adjust.band;
9876 rssi_adjust.delta = req->rssi_adjust.delta;
9877 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
9878 sizeof(rssi_adjust), &rssi_adjust))
9879 return -ENOBUFS;
9880 }
9881
Luciano Coelho75453cc2015-01-09 14:06:37 +02009882 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9883 if (!freqs)
9884 return -ENOBUFS;
9885
Johannes Berg53b18982016-09-14 09:59:21 +02009886 for (i = 0; i < req->n_channels; i++) {
9887 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9888 return -ENOBUFS;
9889 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009890
9891 nla_nest_end(msg, freqs);
9892
9893 if (req->n_match_sets) {
9894 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009895 if (!matches)
9896 return -ENOBUFS;
9897
Luciano Coelho75453cc2015-01-09 14:06:37 +02009898 for (i = 0; i < req->n_match_sets; i++) {
9899 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009900 if (!match)
9901 return -ENOBUFS;
9902
Johannes Berg53b18982016-09-14 09:59:21 +02009903 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9904 req->match_sets[i].ssid.ssid_len,
9905 req->match_sets[i].ssid.ssid))
9906 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009907 nla_nest_end(msg, match);
9908 }
9909 nla_nest_end(msg, matches);
9910 }
9911
Avraham Stern3b06d272015-10-12 09:51:34 +03009912 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9913 if (!scan_plans)
9914 return -ENOBUFS;
9915
9916 for (i = 0; i < req->n_scan_plans; i++) {
9917 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009918 if (!scan_plan)
9919 return -ENOBUFS;
9920
Avraham Stern3b06d272015-10-12 09:51:34 +03009921 if (!scan_plan ||
9922 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9923 req->scan_plans[i].interval) ||
9924 (req->scan_plans[i].iterations &&
9925 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9926 req->scan_plans[i].iterations)))
9927 return -ENOBUFS;
9928 nla_nest_end(msg, scan_plan);
9929 }
9930 nla_nest_end(msg, scan_plans);
9931
Luciano Coelho75453cc2015-01-09 14:06:37 +02009932 nla_nest_end(msg, nd);
9933
9934 return 0;
9935}
9936
Johannes Bergff1b6e62011-05-04 15:37:28 +02009937static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9938{
9939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9940 struct sk_buff *msg;
9941 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009942 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009943
Johannes Berg964dc9e2013-06-03 17:25:34 +02009944 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009945 return -EOPNOTSUPP;
9946
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009947 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009948 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009949 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9950 rdev->wiphy.wowlan_config->tcp->payload_len +
9951 rdev->wiphy.wowlan_config->tcp->wake_len +
9952 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009953 }
9954
9955 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009956 if (!msg)
9957 return -ENOMEM;
9958
Eric W. Biederman15e47302012-09-07 20:12:54 +00009959 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009960 NL80211_CMD_GET_WOWLAN);
9961 if (!hdr)
9962 goto nla_put_failure;
9963
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009964 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009965 struct nlattr *nl_wowlan;
9966
9967 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9968 if (!nl_wowlan)
9969 goto nla_put_failure;
9970
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009971 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009972 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009973 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009975 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009977 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009979 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009981 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009983 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9985 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009986
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009987 if (nl80211_send_wowlan_patterns(msg, rdev))
9988 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009989
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009990 if (nl80211_send_wowlan_tcp(msg,
9991 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009992 goto nla_put_failure;
9993
Luciano Coelho75453cc2015-01-09 14:06:37 +02009994 if (nl80211_send_wowlan_nd(
9995 msg,
9996 rdev->wiphy.wowlan_config->nd_config))
9997 goto nla_put_failure;
9998
Johannes Bergff1b6e62011-05-04 15:37:28 +02009999 nla_nest_end(msg, nl_wowlan);
10000 }
10001
10002 genlmsg_end(msg, hdr);
10003 return genlmsg_reply(msg, info);
10004
10005nla_put_failure:
10006 nlmsg_free(msg);
10007 return -ENOBUFS;
10008}
10009
Johannes Berg2a0e0472013-01-23 22:57:40 +010010010static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
10011 struct nlattr *attr,
10012 struct cfg80211_wowlan *trig)
10013{
10014 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
10015 struct cfg80211_wowlan_tcp *cfg;
10016 struct nl80211_wowlan_tcp_data_token *tok = NULL;
10017 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
10018 u32 size;
10019 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
10020 int err, port;
10021
Johannes Berg964dc9e2013-06-03 17:25:34 +020010022 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010023 return -EINVAL;
10024
10025 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
10026 nla_data(attr), nla_len(attr),
10027 nl80211_wowlan_tcp_policy);
10028 if (err)
10029 return err;
10030
10031 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
10032 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
10033 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
10034 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
10035 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
10036 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
10037 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
10038 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
10039 return -EINVAL;
10040
10041 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010042 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010043 return -EINVAL;
10044
10045 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020010046 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010010047 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010048 return -EINVAL;
10049
10050 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010051 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010052 return -EINVAL;
10053
10054 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
10055 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
10056 return -EINVAL;
10057
10058 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
10059 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10060
10061 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
10062 tokens_size = tokln - sizeof(*tok);
10063
10064 if (!tok->len || tokens_size % tok->len)
10065 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010066 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010067 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010068 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010069 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010070 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010071 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010072 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010073 return -EINVAL;
10074 if (tok->offset + tok->len > data_size)
10075 return -EINVAL;
10076 }
10077
10078 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
10079 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020010080 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010010081 return -EINVAL;
10082 if (seq->len == 0 || seq->len > 4)
10083 return -EINVAL;
10084 if (seq->len + seq->offset > data_size)
10085 return -EINVAL;
10086 }
10087
10088 size = sizeof(*cfg);
10089 size += data_size;
10090 size += wake_size + wake_mask_size;
10091 size += tokens_size;
10092
10093 cfg = kzalloc(size, GFP_KERNEL);
10094 if (!cfg)
10095 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020010096 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
10097 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010098 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
10099 ETH_ALEN);
10100 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
10101 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
10102 else
10103 port = 0;
10104#ifdef CONFIG_INET
10105 /* allocate a socket and port for it and use it */
10106 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
10107 IPPROTO_TCP, &cfg->sock, 1);
10108 if (err) {
10109 kfree(cfg);
10110 return err;
10111 }
10112 if (inet_csk_get_port(cfg->sock->sk, port)) {
10113 sock_release(cfg->sock);
10114 kfree(cfg);
10115 return -EADDRINUSE;
10116 }
10117 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
10118#else
10119 if (!port) {
10120 kfree(cfg);
10121 return -EINVAL;
10122 }
10123 cfg->src_port = port;
10124#endif
10125
10126 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
10127 cfg->payload_len = data_size;
10128 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
10129 memcpy((void *)cfg->payload,
10130 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
10131 data_size);
10132 if (seq)
10133 cfg->payload_seq = *seq;
10134 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
10135 cfg->wake_len = wake_size;
10136 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
10137 memcpy((void *)cfg->wake_data,
10138 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
10139 wake_size);
10140 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
10141 data_size + wake_size;
10142 memcpy((void *)cfg->wake_mask,
10143 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
10144 wake_mask_size);
10145 if (tok) {
10146 cfg->tokens_size = tokens_size;
10147 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
10148 }
10149
10150 trig->tcp = cfg;
10151
10152 return 0;
10153}
10154
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010155static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
10156 const struct wiphy_wowlan_support *wowlan,
10157 struct nlattr *attr,
10158 struct cfg80211_wowlan *trig)
10159{
10160 struct nlattr **tb;
10161 int err;
10162
10163 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
10164 if (!tb)
10165 return -ENOMEM;
10166
10167 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
10168 err = -EOPNOTSUPP;
10169 goto out;
10170 }
10171
10172 err = nla_parse(tb, NL80211_ATTR_MAX,
10173 nla_data(attr), nla_len(attr),
10174 nl80211_policy);
10175 if (err)
10176 goto out;
10177
Johannes Bergad2b26a2014-06-12 21:39:05 +020010178 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010179 err = PTR_ERR_OR_ZERO(trig->nd_config);
10180 if (err)
10181 trig->nd_config = NULL;
10182
10183out:
10184 kfree(tb);
10185 return err;
10186}
10187
Johannes Bergff1b6e62011-05-04 15:37:28 +020010188static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
10189{
10190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10191 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010192 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020010193 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020010194 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010195 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010196 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020010197 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010198
Johannes Berg964dc9e2013-06-03 17:25:34 +020010199 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010200 return -EOPNOTSUPP;
10201
Johannes Bergae33bd82012-07-12 16:25:02 +020010202 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
10203 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010204 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020010205 goto set_wakeup;
10206 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020010207
10208 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
10209 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
10210 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
10211 nl80211_wowlan_policy);
10212 if (err)
10213 return err;
10214
10215 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10216 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10217 return -EINVAL;
10218 new_triggers.any = true;
10219 }
10220
10221 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10222 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10223 return -EINVAL;
10224 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010225 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010226 }
10227
10228 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10229 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10230 return -EINVAL;
10231 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010232 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010233 }
10234
Johannes Berg77dbbb12011-07-13 10:48:55 +020010235 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10236 return -EINVAL;
10237
10238 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10239 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10240 return -EINVAL;
10241 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010242 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010243 }
10244
10245 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10246 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10247 return -EINVAL;
10248 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010249 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010250 }
10251
10252 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10253 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10254 return -EINVAL;
10255 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010256 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010257 }
10258
10259 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10260 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10261 return -EINVAL;
10262 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010263 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010264 }
10265
Johannes Bergff1b6e62011-05-04 15:37:28 +020010266 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10267 struct nlattr *pat;
10268 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010269 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010270 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010271
Johannes Berg98fc4382015-03-01 09:10:13 +020010272 regular = true;
10273
Johannes Bergff1b6e62011-05-04 15:37:28 +020010274 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10275 rem)
10276 n_patterns++;
10277 if (n_patterns > wowlan->n_patterns)
10278 return -EINVAL;
10279
10280 new_triggers.patterns = kcalloc(n_patterns,
10281 sizeof(new_triggers.patterns[0]),
10282 GFP_KERNEL);
10283 if (!new_triggers.patterns)
10284 return -ENOMEM;
10285
10286 new_triggers.n_patterns = n_patterns;
10287 i = 0;
10288
10289 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10290 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010291 u8 *mask_pat;
10292
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010293 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
Peng Xu4ec90fd2017-10-10 13:56:53 -070010294 nla_len(pat), nl80211_packet_pattern_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010295 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010296 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10297 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010298 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010299 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010300 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010301 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010302 goto error;
10303 if (pat_len > wowlan->pattern_max_len ||
10304 pat_len < wowlan->pattern_min_len)
10305 goto error;
10306
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010307 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010308 pkt_offset = 0;
10309 else
10310 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010311 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010312 if (pkt_offset > wowlan->max_pkt_offset)
10313 goto error;
10314 new_triggers.patterns[i].pkt_offset = pkt_offset;
10315
Johannes Berg922bd802014-05-19 17:59:50 +020010316 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10317 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010318 err = -ENOMEM;
10319 goto error;
10320 }
Johannes Berg922bd802014-05-19 17:59:50 +020010321 new_triggers.patterns[i].mask = mask_pat;
10322 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010323 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010324 mask_pat += mask_len;
10325 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010326 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010327 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010328 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010329 pat_len);
10330 i++;
10331 }
10332 }
10333
Johannes Berg2a0e0472013-01-23 22:57:40 +010010334 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010335 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010336 err = nl80211_parse_wowlan_tcp(
10337 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10338 &new_triggers);
10339 if (err)
10340 goto error;
10341 }
10342
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010343 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010344 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010345 err = nl80211_parse_wowlan_nd(
10346 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10347 &new_triggers);
10348 if (err)
10349 goto error;
10350 }
10351
Johannes Berg98fc4382015-03-01 09:10:13 +020010352 /* The 'any' trigger means the device continues operating more or less
10353 * as in its normal operation mode and wakes up the host on most of the
10354 * normal interrupts (like packet RX, ...)
10355 * It therefore makes little sense to combine with the more constrained
10356 * wakeup trigger modes.
10357 */
10358 if (new_triggers.any && regular) {
10359 err = -EINVAL;
10360 goto error;
10361 }
10362
Johannes Bergae33bd82012-07-12 16:25:02 +020010363 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10364 if (!ntrig) {
10365 err = -ENOMEM;
10366 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010367 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010368 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010369 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010370
Johannes Bergae33bd82012-07-12 16:25:02 +020010371 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010372 if (rdev->ops->set_wakeup &&
10373 prev_enabled != !!rdev->wiphy.wowlan_config)
10374 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010375
Johannes Bergff1b6e62011-05-04 15:37:28 +020010376 return 0;
10377 error:
10378 for (i = 0; i < new_triggers.n_patterns; i++)
10379 kfree(new_triggers.patterns[i].mask);
10380 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010381 if (new_triggers.tcp && new_triggers.tcp->sock)
10382 sock_release(new_triggers.tcp->sock);
10383 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010384 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010385 return err;
10386}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010387#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010388
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010389static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10390 struct cfg80211_registered_device *rdev)
10391{
10392 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10393 int i, j, pat_len;
10394 struct cfg80211_coalesce_rules *rule;
10395
10396 if (!rdev->coalesce->n_rules)
10397 return 0;
10398
10399 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10400 if (!nl_rules)
10401 return -ENOBUFS;
10402
10403 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10404 nl_rule = nla_nest_start(msg, i + 1);
10405 if (!nl_rule)
10406 return -ENOBUFS;
10407
10408 rule = &rdev->coalesce->rules[i];
10409 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10410 rule->delay))
10411 return -ENOBUFS;
10412
10413 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10414 rule->condition))
10415 return -ENOBUFS;
10416
10417 nl_pats = nla_nest_start(msg,
10418 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10419 if (!nl_pats)
10420 return -ENOBUFS;
10421
10422 for (j = 0; j < rule->n_patterns; j++) {
10423 nl_pat = nla_nest_start(msg, j + 1);
10424 if (!nl_pat)
10425 return -ENOBUFS;
10426 pat_len = rule->patterns[j].pattern_len;
10427 if (nla_put(msg, NL80211_PKTPAT_MASK,
10428 DIV_ROUND_UP(pat_len, 8),
10429 rule->patterns[j].mask) ||
10430 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10431 rule->patterns[j].pattern) ||
10432 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10433 rule->patterns[j].pkt_offset))
10434 return -ENOBUFS;
10435 nla_nest_end(msg, nl_pat);
10436 }
10437 nla_nest_end(msg, nl_pats);
10438 nla_nest_end(msg, nl_rule);
10439 }
10440 nla_nest_end(msg, nl_rules);
10441
10442 return 0;
10443}
10444
10445static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10446{
10447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10448 struct sk_buff *msg;
10449 void *hdr;
10450
10451 if (!rdev->wiphy.coalesce)
10452 return -EOPNOTSUPP;
10453
10454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10455 if (!msg)
10456 return -ENOMEM;
10457
10458 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10459 NL80211_CMD_GET_COALESCE);
10460 if (!hdr)
10461 goto nla_put_failure;
10462
10463 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10464 goto nla_put_failure;
10465
10466 genlmsg_end(msg, hdr);
10467 return genlmsg_reply(msg, info);
10468
10469nla_put_failure:
10470 nlmsg_free(msg);
10471 return -ENOBUFS;
10472}
10473
10474void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10475{
10476 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10477 int i, j;
10478 struct cfg80211_coalesce_rules *rule;
10479
10480 if (!coalesce)
10481 return;
10482
10483 for (i = 0; i < coalesce->n_rules; i++) {
10484 rule = &coalesce->rules[i];
10485 for (j = 0; j < rule->n_patterns; j++)
10486 kfree(rule->patterns[j].mask);
10487 kfree(rule->patterns);
10488 }
10489 kfree(coalesce->rules);
10490 kfree(coalesce);
10491 rdev->coalesce = NULL;
10492}
10493
10494static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10495 struct nlattr *rule,
10496 struct cfg80211_coalesce_rules *new_rule)
10497{
10498 int err, i;
10499 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10500 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10501 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10502 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10503
10504 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10505 nla_len(rule), nl80211_coalesce_policy);
10506 if (err)
10507 return err;
10508
10509 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10510 new_rule->delay =
10511 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10512 if (new_rule->delay > coalesce->max_delay)
10513 return -EINVAL;
10514
10515 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10516 new_rule->condition =
10517 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10518 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10519 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10520 return -EINVAL;
10521
10522 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10523 return -EINVAL;
10524
10525 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10526 rem)
10527 n_patterns++;
10528 if (n_patterns > coalesce->n_patterns)
10529 return -EINVAL;
10530
10531 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10532 GFP_KERNEL);
10533 if (!new_rule->patterns)
10534 return -ENOMEM;
10535
10536 new_rule->n_patterns = n_patterns;
10537 i = 0;
10538
10539 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10540 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010541 u8 *mask_pat;
10542
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010543 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
Peng Xu4ec90fd2017-10-10 13:56:53 -070010544 nla_len(pat), nl80211_packet_pattern_policy);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010545 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10546 !pat_tb[NL80211_PKTPAT_PATTERN])
10547 return -EINVAL;
10548 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10549 mask_len = DIV_ROUND_UP(pat_len, 8);
10550 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10551 return -EINVAL;
10552 if (pat_len > coalesce->pattern_max_len ||
10553 pat_len < coalesce->pattern_min_len)
10554 return -EINVAL;
10555
10556 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10557 pkt_offset = 0;
10558 else
10559 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10560 if (pkt_offset > coalesce->max_pkt_offset)
10561 return -EINVAL;
10562 new_rule->patterns[i].pkt_offset = pkt_offset;
10563
Johannes Berg922bd802014-05-19 17:59:50 +020010564 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10565 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010566 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010567
10568 new_rule->patterns[i].mask = mask_pat;
10569 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10570 mask_len);
10571
10572 mask_pat += mask_len;
10573 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010574 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010575 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10576 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010577 i++;
10578 }
10579
10580 return 0;
10581}
10582
10583static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10584{
10585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10586 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10587 struct cfg80211_coalesce new_coalesce = {};
10588 struct cfg80211_coalesce *n_coalesce;
10589 int err, rem_rule, n_rules = 0, i, j;
10590 struct nlattr *rule;
10591 struct cfg80211_coalesce_rules *tmp_rule;
10592
10593 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10594 return -EOPNOTSUPP;
10595
10596 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10597 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010598 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010599 return 0;
10600 }
10601
10602 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10603 rem_rule)
10604 n_rules++;
10605 if (n_rules > coalesce->n_rules)
10606 return -EINVAL;
10607
10608 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10609 GFP_KERNEL);
10610 if (!new_coalesce.rules)
10611 return -ENOMEM;
10612
10613 new_coalesce.n_rules = n_rules;
10614 i = 0;
10615
10616 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10617 rem_rule) {
10618 err = nl80211_parse_coalesce_rule(rdev, rule,
10619 &new_coalesce.rules[i]);
10620 if (err)
10621 goto error;
10622
10623 i++;
10624 }
10625
Ilan Peera1056b12015-10-22 22:27:46 +030010626 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010627 if (err)
10628 goto error;
10629
10630 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10631 if (!n_coalesce) {
10632 err = -ENOMEM;
10633 goto error;
10634 }
10635 cfg80211_rdev_free_coalesce(rdev);
10636 rdev->coalesce = n_coalesce;
10637
10638 return 0;
10639error:
10640 for (i = 0; i < new_coalesce.n_rules; i++) {
10641 tmp_rule = &new_coalesce.rules[i];
10642 for (j = 0; j < tmp_rule->n_patterns; j++)
10643 kfree(tmp_rule->patterns[j].mask);
10644 kfree(tmp_rule->patterns);
10645 }
10646 kfree(new_coalesce.rules);
10647
10648 return err;
10649}
10650
Johannes Berge5497d72011-07-05 16:35:40 +020010651static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10652{
10653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10654 struct net_device *dev = info->user_ptr[1];
10655 struct wireless_dev *wdev = dev->ieee80211_ptr;
10656 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10657 struct cfg80211_gtk_rekey_data rekey_data;
10658 int err;
10659
10660 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10661 return -EINVAL;
10662
10663 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10664 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10665 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10666 nl80211_rekey_policy);
10667 if (err)
10668 return err;
10669
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010670 if (!tb[NL80211_REKEY_DATA_KEK] || !tb[NL80211_REKEY_DATA_REPLAY_CTR] ||
10671 (!wiphy_ext_feature_isset(&rdev->wiphy,
10672 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10673 !wiphy_ext_feature_isset(&rdev->wiphy,
10674 NL80211_EXT_FEATURE_FILS_STA) &&
10675 !tb[NL80211_REKEY_DATA_KCK]))
10676 return -EINVAL;
10677
Johannes Berge5497d72011-07-05 16:35:40 +020010678 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10679 return -ERANGE;
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010680 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) < NL80211_KEK_LEN)
Johannes Berge5497d72011-07-05 16:35:40 +020010681 return -ERANGE;
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010682 if (tb[NL80211_REKEY_DATA_KCK] &&
10683 nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
Johannes Berge5497d72011-07-05 16:35:40 +020010684 return -ERANGE;
10685
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010686 memset(&rekey_data, 0, sizeof(rekey_data));
Johannes Berg78f686c2014-09-10 22:28:06 +030010687 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
Vidyullatha Kanchanapally84aa3ba2017-05-25 20:20:41 +053010688 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
10689 if (tb[NL80211_REKEY_DATA_KCK])
10690 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
Johannes Berg78f686c2014-09-10 22:28:06 +030010691 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010692
10693 wdev_lock(wdev);
10694 if (!wdev->current_bss) {
10695 err = -ENOTCONN;
10696 goto out;
10697 }
10698
10699 if (!rdev->ops->set_rekey_data) {
10700 err = -EOPNOTSUPP;
10701 goto out;
10702 }
10703
Hila Gonene35e4d22012-06-27 17:19:42 +030010704 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010705 out:
10706 wdev_unlock(wdev);
10707 return err;
10708}
10709
Johannes Berg28946da2011-11-04 11:18:12 +010010710static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10711 struct genl_info *info)
10712{
10713 struct net_device *dev = info->user_ptr[1];
10714 struct wireless_dev *wdev = dev->ieee80211_ptr;
10715
10716 if (wdev->iftype != NL80211_IFTYPE_AP &&
10717 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10718 return -EINVAL;
10719
Eric W. Biederman15e47302012-09-07 20:12:54 +000010720 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010721 return -EBUSY;
10722
Eric W. Biederman15e47302012-09-07 20:12:54 +000010723 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010724 return 0;
10725}
10726
Johannes Berg7f6cf312011-11-04 11:18:15 +010010727static int nl80211_probe_client(struct sk_buff *skb,
10728 struct genl_info *info)
10729{
10730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10731 struct net_device *dev = info->user_ptr[1];
10732 struct wireless_dev *wdev = dev->ieee80211_ptr;
10733 struct sk_buff *msg;
10734 void *hdr;
10735 const u8 *addr;
10736 u64 cookie;
10737 int err;
10738
10739 if (wdev->iftype != NL80211_IFTYPE_AP &&
10740 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10741 return -EOPNOTSUPP;
10742
10743 if (!info->attrs[NL80211_ATTR_MAC])
10744 return -EINVAL;
10745
10746 if (!rdev->ops->probe_client)
10747 return -EOPNOTSUPP;
10748
10749 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10750 if (!msg)
10751 return -ENOMEM;
10752
Eric W. Biederman15e47302012-09-07 20:12:54 +000010753 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010754 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010755 if (!hdr) {
10756 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010757 goto free_msg;
10758 }
10759
10760 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10761
Hila Gonene35e4d22012-06-27 17:19:42 +030010762 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010763 if (err)
10764 goto free_msg;
10765
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010766 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10767 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010768 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010769
10770 genlmsg_end(msg, hdr);
10771
10772 return genlmsg_reply(msg, info);
10773
10774 nla_put_failure:
10775 err = -ENOBUFS;
10776 free_msg:
10777 nlmsg_free(msg);
10778 return err;
10779}
10780
Johannes Berg5e7602302011-11-04 11:18:17 +010010781static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10782{
10783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010784 struct cfg80211_beacon_registration *reg, *nreg;
10785 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010786
10787 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10788 return -EOPNOTSUPP;
10789
Ben Greear37c73b52012-10-26 14:49:25 -070010790 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10791 if (!nreg)
10792 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010793
Ben Greear37c73b52012-10-26 14:49:25 -070010794 /* First, check if already registered. */
10795 spin_lock_bh(&rdev->beacon_registrations_lock);
10796 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10797 if (reg->nlportid == info->snd_portid) {
10798 rv = -EALREADY;
10799 goto out_err;
10800 }
10801 }
10802 /* Add it to the list */
10803 nreg->nlportid = info->snd_portid;
10804 list_add(&nreg->list, &rdev->beacon_registrations);
10805
10806 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010807
10808 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010809out_err:
10810 spin_unlock_bh(&rdev->beacon_registrations_lock);
10811 kfree(nreg);
10812 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010813}
10814
Johannes Berg98104fde2012-06-16 00:19:54 +020010815static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10816{
10817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10818 struct wireless_dev *wdev = info->user_ptr[1];
10819 int err;
10820
10821 if (!rdev->ops->start_p2p_device)
10822 return -EOPNOTSUPP;
10823
10824 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10825 return -EOPNOTSUPP;
10826
10827 if (wdev->p2p_started)
10828 return 0;
10829
Luciano Coelhob6a55012014-02-27 11:07:21 +020010830 if (rfkill_blocked(rdev->rfkill))
10831 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010832
Johannes Bergeeb126e2012-10-23 15:16:50 +020010833 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010834 if (err)
10835 return err;
10836
10837 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010838 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010839
10840 return 0;
10841}
10842
10843static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10844{
10845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10846 struct wireless_dev *wdev = info->user_ptr[1];
10847
10848 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10849 return -EOPNOTSUPP;
10850
10851 if (!rdev->ops->stop_p2p_device)
10852 return -EOPNOTSUPP;
10853
Johannes Bergf9f47522013-03-19 15:04:07 +010010854 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010855
10856 return 0;
10857}
10858
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010859static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10860{
10861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10862 struct wireless_dev *wdev = info->user_ptr[1];
10863 struct cfg80211_nan_conf conf = {};
10864 int err;
10865
10866 if (wdev->iftype != NL80211_IFTYPE_NAN)
10867 return -EOPNOTSUPP;
10868
10869 if (wdev->nan_started)
10870 return -EEXIST;
10871
10872 if (rfkill_blocked(rdev->rfkill))
10873 return -ERFKILL;
10874
10875 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10876 return -EINVAL;
10877
10878 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10879 return -EINVAL;
10880
10881 conf.master_pref =
10882 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10883 if (!conf.master_pref)
10884 return -EINVAL;
10885
10886 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10887
10888 err = rdev_start_nan(rdev, wdev, &conf);
10889 if (err)
10890 return err;
10891
10892 wdev->nan_started = true;
10893 rdev->opencount++;
10894
10895 return 0;
10896}
10897
10898static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10899{
10900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10901 struct wireless_dev *wdev = info->user_ptr[1];
10902
10903 if (wdev->iftype != NL80211_IFTYPE_NAN)
10904 return -EOPNOTSUPP;
10905
10906 cfg80211_stop_nan(rdev, wdev);
10907
10908 return 0;
10909}
10910
Ayala Bekera442b762016-09-20 17:31:15 +030010911static int validate_nan_filter(struct nlattr *filter_attr)
10912{
10913 struct nlattr *attr;
10914 int len = 0, n_entries = 0, rem;
10915
10916 nla_for_each_nested(attr, filter_attr, rem) {
10917 len += nla_len(attr);
10918 n_entries++;
10919 }
10920
10921 if (len >= U8_MAX)
10922 return -EINVAL;
10923
10924 return n_entries;
10925}
10926
10927static int handle_nan_filter(struct nlattr *attr_filter,
10928 struct cfg80211_nan_func *func,
10929 bool tx)
10930{
10931 struct nlattr *attr;
10932 int n_entries, rem, i;
10933 struct cfg80211_nan_func_filter *filter;
10934
10935 n_entries = validate_nan_filter(attr_filter);
10936 if (n_entries < 0)
10937 return n_entries;
10938
10939 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10940
10941 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10942 if (!filter)
10943 return -ENOMEM;
10944
10945 i = 0;
10946 nla_for_each_nested(attr, attr_filter, rem) {
10947 filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10948 GFP_KERNEL);
10949 filter[i].len = nla_len(attr);
10950 i++;
10951 }
10952 if (tx) {
10953 func->num_tx_filters = n_entries;
10954 func->tx_filters = filter;
10955 } else {
10956 func->num_rx_filters = n_entries;
10957 func->rx_filters = filter;
10958 }
10959
10960 return 0;
10961}
10962
10963static int nl80211_nan_add_func(struct sk_buff *skb,
10964 struct genl_info *info)
10965{
10966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10967 struct wireless_dev *wdev = info->user_ptr[1];
10968 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10969 struct cfg80211_nan_func *func;
10970 struct sk_buff *msg = NULL;
10971 void *hdr = NULL;
10972 int err = 0;
10973
10974 if (wdev->iftype != NL80211_IFTYPE_NAN)
10975 return -EOPNOTSUPP;
10976
10977 if (!wdev->nan_started)
10978 return -ENOTCONN;
10979
10980 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10981 return -EINVAL;
10982
10983 if (wdev->owner_nlportid &&
10984 wdev->owner_nlportid != info->snd_portid)
10985 return -ENOTCONN;
10986
10987 err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
10988 nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
10989 nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
10990 nl80211_nan_func_policy);
10991 if (err)
10992 return err;
10993
10994 func = kzalloc(sizeof(*func), GFP_KERNEL);
10995 if (!func)
10996 return -ENOMEM;
10997
10998 func->cookie = wdev->wiphy->cookie_counter++;
10999
11000 if (!tb[NL80211_NAN_FUNC_TYPE] ||
11001 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
11002 err = -EINVAL;
11003 goto out;
11004 }
11005
11006
11007 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
11008
11009 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
11010 err = -EINVAL;
11011 goto out;
11012 }
11013
11014 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
11015 sizeof(func->service_id));
11016
11017 func->close_range =
11018 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
11019
11020 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
11021 func->serv_spec_info_len =
11022 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
11023 func->serv_spec_info =
11024 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
11025 func->serv_spec_info_len,
11026 GFP_KERNEL);
11027 if (!func->serv_spec_info) {
11028 err = -ENOMEM;
11029 goto out;
11030 }
11031 }
11032
11033 if (tb[NL80211_NAN_FUNC_TTL])
11034 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
11035
11036 switch (func->type) {
11037 case NL80211_NAN_FUNC_PUBLISH:
11038 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
11039 err = -EINVAL;
11040 goto out;
11041 }
11042
11043 func->publish_type =
11044 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
11045 func->publish_bcast =
11046 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
11047
11048 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
11049 func->publish_bcast) {
11050 err = -EINVAL;
11051 goto out;
11052 }
11053 break;
11054 case NL80211_NAN_FUNC_SUBSCRIBE:
11055 func->subscribe_active =
11056 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
11057 break;
11058 case NL80211_NAN_FUNC_FOLLOW_UP:
11059 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
11060 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
11061 err = -EINVAL;
11062 goto out;
11063 }
11064
11065 func->followup_id =
11066 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
11067 func->followup_reqid =
11068 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
11069 memcpy(func->followup_dest.addr,
11070 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
11071 sizeof(func->followup_dest.addr));
11072 if (func->ttl) {
11073 err = -EINVAL;
11074 goto out;
11075 }
11076 break;
11077 default:
11078 err = -EINVAL;
11079 goto out;
11080 }
11081
11082 if (tb[NL80211_NAN_FUNC_SRF]) {
11083 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
11084
11085 err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
11086 nla_data(tb[NL80211_NAN_FUNC_SRF]),
11087 nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
11088 if (err)
11089 goto out;
11090
11091 func->srf_include =
11092 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
11093
11094 if (srf_tb[NL80211_NAN_SRF_BF]) {
11095 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
11096 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
11097 err = -EINVAL;
11098 goto out;
11099 }
11100
11101 func->srf_bf_len =
11102 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
11103 func->srf_bf =
11104 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
11105 func->srf_bf_len, GFP_KERNEL);
11106 if (!func->srf_bf) {
11107 err = -ENOMEM;
11108 goto out;
11109 }
11110
11111 func->srf_bf_idx =
11112 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
11113 } else {
11114 struct nlattr *attr, *mac_attr =
11115 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
11116 int n_entries, rem, i = 0;
11117
11118 if (!mac_attr) {
11119 err = -EINVAL;
11120 goto out;
11121 }
11122
11123 n_entries = validate_acl_mac_addrs(mac_attr);
11124 if (n_entries <= 0) {
11125 err = -EINVAL;
11126 goto out;
11127 }
11128
11129 func->srf_num_macs = n_entries;
11130 func->srf_macs =
11131 kzalloc(sizeof(*func->srf_macs) * n_entries,
11132 GFP_KERNEL);
11133 if (!func->srf_macs) {
11134 err = -ENOMEM;
11135 goto out;
11136 }
11137
11138 nla_for_each_nested(attr, mac_attr, rem)
11139 memcpy(func->srf_macs[i++].addr, nla_data(attr),
11140 sizeof(*func->srf_macs));
11141 }
11142 }
11143
11144 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
11145 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
11146 func, true);
11147 if (err)
11148 goto out;
11149 }
11150
11151 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
11152 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
11153 func, false);
11154 if (err)
11155 goto out;
11156 }
11157
11158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11159 if (!msg) {
11160 err = -ENOMEM;
11161 goto out;
11162 }
11163
11164 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11165 NL80211_CMD_ADD_NAN_FUNCTION);
11166 /* This can't really happen - we just allocated 4KB */
11167 if (WARN_ON(!hdr)) {
11168 err = -ENOMEM;
11169 goto out;
11170 }
11171
11172 err = rdev_add_nan_func(rdev, wdev, func);
11173out:
11174 if (err < 0) {
11175 cfg80211_free_nan_func(func);
11176 nlmsg_free(msg);
11177 return err;
11178 }
11179
11180 /* propagate the instance id and cookie to userspace */
11181 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
11182 NL80211_ATTR_PAD))
11183 goto nla_put_failure;
11184
11185 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11186 if (!func_attr)
11187 goto nla_put_failure;
11188
11189 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
11190 func->instance_id))
11191 goto nla_put_failure;
11192
11193 nla_nest_end(msg, func_attr);
11194
11195 genlmsg_end(msg, hdr);
11196 return genlmsg_reply(msg, info);
11197
11198nla_put_failure:
11199 nlmsg_free(msg);
11200 return -ENOBUFS;
11201}
11202
11203static int nl80211_nan_del_func(struct sk_buff *skb,
11204 struct genl_info *info)
11205{
11206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11207 struct wireless_dev *wdev = info->user_ptr[1];
11208 u64 cookie;
11209
11210 if (wdev->iftype != NL80211_IFTYPE_NAN)
11211 return -EOPNOTSUPP;
11212
11213 if (!wdev->nan_started)
11214 return -ENOTCONN;
11215
11216 if (!info->attrs[NL80211_ATTR_COOKIE])
11217 return -EINVAL;
11218
11219 if (wdev->owner_nlportid &&
11220 wdev->owner_nlportid != info->snd_portid)
11221 return -ENOTCONN;
11222
11223 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11224
11225 rdev_del_nan_func(rdev, wdev, cookie);
11226
11227 return 0;
11228}
11229
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011230static int nl80211_nan_change_config(struct sk_buff *skb,
11231 struct genl_info *info)
11232{
11233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11234 struct wireless_dev *wdev = info->user_ptr[1];
11235 struct cfg80211_nan_conf conf = {};
11236 u32 changed = 0;
11237
11238 if (wdev->iftype != NL80211_IFTYPE_NAN)
11239 return -EOPNOTSUPP;
11240
11241 if (!wdev->nan_started)
11242 return -ENOTCONN;
11243
11244 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11245 conf.master_pref =
11246 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11247 if (conf.master_pref <= 1 || conf.master_pref == 255)
11248 return -EINVAL;
11249
11250 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11251 }
11252
11253 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
11254 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
11255 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
11256 }
11257
11258 if (!changed)
11259 return -EINVAL;
11260
11261 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11262}
11263
Ayala Beker50bcd312016-09-20 17:31:17 +030011264void cfg80211_nan_match(struct wireless_dev *wdev,
11265 struct cfg80211_nan_match_params *match, gfp_t gfp)
11266{
11267 struct wiphy *wiphy = wdev->wiphy;
11268 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11269 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11270 struct sk_buff *msg;
11271 void *hdr;
11272
11273 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11274 return;
11275
11276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11277 if (!msg)
11278 return;
11279
11280 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11281 if (!hdr) {
11282 nlmsg_free(msg);
11283 return;
11284 }
11285
11286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11287 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11288 wdev->netdev->ifindex)) ||
11289 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11290 NL80211_ATTR_PAD))
11291 goto nla_put_failure;
11292
11293 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11294 NL80211_ATTR_PAD) ||
11295 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11296 goto nla_put_failure;
11297
11298 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11299 if (!match_attr)
11300 goto nla_put_failure;
11301
11302 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11303 if (!local_func_attr)
11304 goto nla_put_failure;
11305
11306 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11307 goto nla_put_failure;
11308
11309 nla_nest_end(msg, local_func_attr);
11310
11311 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11312 if (!peer_func_attr)
11313 goto nla_put_failure;
11314
11315 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11316 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11317 goto nla_put_failure;
11318
11319 if (match->info && match->info_len &&
11320 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11321 match->info))
11322 goto nla_put_failure;
11323
11324 nla_nest_end(msg, peer_func_attr);
11325 nla_nest_end(msg, match_attr);
11326 genlmsg_end(msg, hdr);
11327
11328 if (!wdev->owner_nlportid)
11329 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11330 msg, 0, NL80211_MCGRP_NAN, gfp);
11331 else
11332 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11333 wdev->owner_nlportid);
11334
11335 return;
11336
11337nla_put_failure:
11338 nlmsg_free(msg);
11339}
11340EXPORT_SYMBOL(cfg80211_nan_match);
11341
Ayala Beker368e5a72016-09-20 17:31:18 +030011342void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11343 u8 inst_id,
11344 enum nl80211_nan_func_term_reason reason,
11345 u64 cookie, gfp_t gfp)
11346{
11347 struct wiphy *wiphy = wdev->wiphy;
11348 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11349 struct sk_buff *msg;
11350 struct nlattr *func_attr;
11351 void *hdr;
11352
11353 if (WARN_ON(!inst_id))
11354 return;
11355
11356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11357 if (!msg)
11358 return;
11359
11360 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11361 if (!hdr) {
11362 nlmsg_free(msg);
11363 return;
11364 }
11365
11366 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11367 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11368 wdev->netdev->ifindex)) ||
11369 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11370 NL80211_ATTR_PAD))
11371 goto nla_put_failure;
11372
11373 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11374 NL80211_ATTR_PAD))
11375 goto nla_put_failure;
11376
11377 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11378 if (!func_attr)
11379 goto nla_put_failure;
11380
11381 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11382 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11383 goto nla_put_failure;
11384
11385 nla_nest_end(msg, func_attr);
11386 genlmsg_end(msg, hdr);
11387
11388 if (!wdev->owner_nlportid)
11389 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11390 msg, 0, NL80211_MCGRP_NAN, gfp);
11391 else
11392 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11393 wdev->owner_nlportid);
11394
11395 return;
11396
11397nla_put_failure:
11398 nlmsg_free(msg);
11399}
11400EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11401
Johannes Berg3713b4e2013-02-14 16:19:38 +010011402static int nl80211_get_protocol_features(struct sk_buff *skb,
11403 struct genl_info *info)
11404{
11405 void *hdr;
11406 struct sk_buff *msg;
11407
11408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11409 if (!msg)
11410 return -ENOMEM;
11411
11412 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11413 NL80211_CMD_GET_PROTOCOL_FEATURES);
11414 if (!hdr)
11415 goto nla_put_failure;
11416
11417 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11418 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11419 goto nla_put_failure;
11420
11421 genlmsg_end(msg, hdr);
11422 return genlmsg_reply(msg, info);
11423
11424 nla_put_failure:
11425 kfree_skb(msg);
11426 return -ENOBUFS;
11427}
11428
Jouni Malinen355199e2013-02-27 17:14:27 +020011429static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11430{
11431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11432 struct cfg80211_update_ft_ies_params ft_params;
11433 struct net_device *dev = info->user_ptr[1];
11434
11435 if (!rdev->ops->update_ft_ies)
11436 return -EOPNOTSUPP;
11437
11438 if (!info->attrs[NL80211_ATTR_MDID] ||
11439 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11440 return -EINVAL;
11441
11442 memset(&ft_params, 0, sizeof(ft_params));
11443 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11444 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11445 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11446
11447 return rdev_update_ft_ies(rdev, dev, &ft_params);
11448}
11449
Arend van Spriel5de17982013-04-18 15:49:00 +020011450static int nl80211_crit_protocol_start(struct sk_buff *skb,
11451 struct genl_info *info)
11452{
11453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11454 struct wireless_dev *wdev = info->user_ptr[1];
11455 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11456 u16 duration;
11457 int ret;
11458
11459 if (!rdev->ops->crit_proto_start)
11460 return -EOPNOTSUPP;
11461
11462 if (WARN_ON(!rdev->ops->crit_proto_stop))
11463 return -EINVAL;
11464
11465 if (rdev->crit_proto_nlportid)
11466 return -EBUSY;
11467
11468 /* determine protocol if provided */
11469 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11470 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11471
11472 if (proto >= NUM_NL80211_CRIT_PROTO)
11473 return -EINVAL;
11474
11475 /* timeout must be provided */
11476 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11477 return -EINVAL;
11478
11479 duration =
11480 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11481
11482 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11483 return -ERANGE;
11484
11485 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11486 if (!ret)
11487 rdev->crit_proto_nlportid = info->snd_portid;
11488
11489 return ret;
11490}
11491
11492static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11493 struct genl_info *info)
11494{
11495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11496 struct wireless_dev *wdev = info->user_ptr[1];
11497
11498 if (!rdev->ops->crit_proto_stop)
11499 return -EOPNOTSUPP;
11500
11501 if (rdev->crit_proto_nlportid) {
11502 rdev->crit_proto_nlportid = 0;
11503 rdev_crit_proto_stop(rdev, wdev);
11504 }
11505 return 0;
11506}
11507
Johannes Bergad7e7182013-11-13 13:37:47 +010011508static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11509{
11510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11511 struct wireless_dev *wdev =
11512 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11513 int i, err;
11514 u32 vid, subcmd;
11515
11516 if (!rdev->wiphy.vendor_commands)
11517 return -EOPNOTSUPP;
11518
11519 if (IS_ERR(wdev)) {
11520 err = PTR_ERR(wdev);
11521 if (err != -EINVAL)
11522 return err;
11523 wdev = NULL;
11524 } else if (wdev->wiphy != &rdev->wiphy) {
11525 return -EINVAL;
11526 }
11527
11528 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11529 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11530 return -EINVAL;
11531
11532 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11533 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11534 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11535 const struct wiphy_vendor_command *vcmd;
11536 void *data = NULL;
11537 int len = 0;
11538
11539 vcmd = &rdev->wiphy.vendor_commands[i];
11540
11541 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11542 continue;
11543
11544 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11545 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11546 if (!wdev)
11547 return -EINVAL;
11548 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11549 !wdev->netdev)
11550 return -EINVAL;
11551
11552 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11553 if (wdev->netdev &&
11554 !netif_running(wdev->netdev))
11555 return -ENETDOWN;
11556 if (!wdev->netdev && !wdev->p2p_started)
11557 return -ENETDOWN;
11558 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011559
11560 if (!vcmd->doit)
11561 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011562 } else {
11563 wdev = NULL;
11564 }
11565
11566 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11567 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11568 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11569 }
11570
11571 rdev->cur_cmd_info = info;
11572 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11573 data, len);
11574 rdev->cur_cmd_info = NULL;
11575 return err;
11576 }
11577
11578 return -EOPNOTSUPP;
11579}
11580
Johannes Berg7bdbe402015-08-15 22:39:49 +030011581static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11582 struct netlink_callback *cb,
11583 struct cfg80211_registered_device **rdev,
11584 struct wireless_dev **wdev)
11585{
11586 u32 vid, subcmd;
11587 unsigned int i;
11588 int vcmd_idx = -1;
11589 int err;
11590 void *data = NULL;
11591 unsigned int data_len = 0;
11592
Johannes Berg7bdbe402015-08-15 22:39:49 +030011593 if (cb->args[0]) {
11594 /* subtract the 1 again here */
11595 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11596 struct wireless_dev *tmp;
11597
Johannes Berg56769e72017-03-15 14:26:04 +010011598 if (!wiphy)
11599 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011600 *rdev = wiphy_to_rdev(wiphy);
11601 *wdev = NULL;
11602
11603 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011604 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011605 if (tmp->identifier == cb->args[1] - 1) {
11606 *wdev = tmp;
11607 break;
11608 }
11609 }
11610 }
11611
11612 /* keep rtnl locked in successful case */
11613 return 0;
11614 }
11615
11616 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
11617 nl80211_fam.attrbuf, nl80211_fam.maxattr,
11618 nl80211_policy);
11619 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011620 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011621
11622 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg56769e72017-03-15 14:26:04 +010011623 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11624 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011625
11626 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
11627 nl80211_fam.attrbuf);
11628 if (IS_ERR(*wdev))
11629 *wdev = NULL;
11630
11631 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
11632 nl80211_fam.attrbuf);
Johannes Berg56769e72017-03-15 14:26:04 +010011633 if (IS_ERR(*rdev))
11634 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011635
11636 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
11637 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11638
11639 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11640 const struct wiphy_vendor_command *vcmd;
11641
11642 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11643
11644 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11645 continue;
11646
Johannes Berg56769e72017-03-15 14:26:04 +010011647 if (!vcmd->dumpit)
11648 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011649
11650 vcmd_idx = i;
11651 break;
11652 }
11653
Johannes Berg56769e72017-03-15 14:26:04 +010011654 if (vcmd_idx < 0)
11655 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011656
11657 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11658 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11659 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11660 }
11661
11662 /* 0 is the first index - add 1 to parse only once */
11663 cb->args[0] = (*rdev)->wiphy_idx + 1;
11664 /* add 1 to know if it was NULL */
11665 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11666 cb->args[2] = vcmd_idx;
11667 cb->args[3] = (unsigned long)data;
11668 cb->args[4] = data_len;
11669
11670 /* keep rtnl locked in successful case */
11671 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011672}
11673
11674static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11675 struct netlink_callback *cb)
11676{
11677 struct cfg80211_registered_device *rdev;
11678 struct wireless_dev *wdev;
11679 unsigned int vcmd_idx;
11680 const struct wiphy_vendor_command *vcmd;
11681 void *data;
11682 int data_len;
11683 int err;
11684 struct nlattr *vendor_data;
11685
Johannes Berg56769e72017-03-15 14:26:04 +010011686 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011687 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11688 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011689 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011690
11691 vcmd_idx = cb->args[2];
11692 data = (void *)cb->args[3];
11693 data_len = cb->args[4];
11694 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11695
11696 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11697 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Berg56769e72017-03-15 14:26:04 +010011698 if (!wdev) {
11699 err = -EINVAL;
11700 goto out;
11701 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011702 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Berg56769e72017-03-15 14:26:04 +010011703 !wdev->netdev) {
11704 err = -EINVAL;
11705 goto out;
11706 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011707
11708 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11709 if (wdev->netdev &&
Johannes Berg56769e72017-03-15 14:26:04 +010011710 !netif_running(wdev->netdev)) {
11711 err = -ENETDOWN;
11712 goto out;
11713 }
11714 if (!wdev->netdev && !wdev->p2p_started) {
11715 err = -ENETDOWN;
11716 goto out;
11717 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011718 }
11719 }
11720
11721 while (1) {
11722 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11723 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11724 NL80211_CMD_VENDOR);
11725 if (!hdr)
11726 break;
11727
11728 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011729 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11730 wdev_id(wdev),
11731 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011732 genlmsg_cancel(skb, hdr);
11733 break;
11734 }
11735
11736 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11737 if (!vendor_data) {
11738 genlmsg_cancel(skb, hdr);
11739 break;
11740 }
11741
11742 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11743 (unsigned long *)&cb->args[5]);
11744 nla_nest_end(skb, vendor_data);
11745
11746 if (err == -ENOBUFS || err == -ENOENT) {
11747 genlmsg_cancel(skb, hdr);
11748 break;
11749 } else if (err) {
11750 genlmsg_cancel(skb, hdr);
11751 goto out;
11752 }
11753
11754 genlmsg_end(skb, hdr);
11755 }
11756
11757 err = skb->len;
11758 out:
11759 rtnl_unlock();
11760 return err;
11761}
11762
Johannes Bergad7e7182013-11-13 13:37:47 +010011763struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11764 enum nl80211_commands cmd,
11765 enum nl80211_attrs attr,
11766 int approxlen)
11767{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011768 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011769
11770 if (WARN_ON(!rdev->cur_cmd_info))
11771 return NULL;
11772
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011773 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011774 rdev->cur_cmd_info->snd_portid,
11775 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011776 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011777}
11778EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11779
11780int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11781{
11782 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11783 void *hdr = ((void **)skb->cb)[1];
11784 struct nlattr *data = ((void **)skb->cb)[2];
11785
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011786 /* clear CB data for netlink core to own from now on */
11787 memset(skb->cb, 0, sizeof(skb->cb));
11788
Johannes Bergad7e7182013-11-13 13:37:47 +010011789 if (WARN_ON(!rdev->cur_cmd_info)) {
11790 kfree_skb(skb);
11791 return -EINVAL;
11792 }
11793
11794 nla_nest_end(skb, data);
11795 genlmsg_end(skb, hdr);
11796 return genlmsg_reply(skb, rdev->cur_cmd_info);
11797}
11798EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11799
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011800static int nl80211_set_qos_map(struct sk_buff *skb,
11801 struct genl_info *info)
11802{
11803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11804 struct cfg80211_qos_map *qos_map = NULL;
11805 struct net_device *dev = info->user_ptr[1];
11806 u8 *pos, len, num_des, des_len, des;
11807 int ret;
11808
11809 if (!rdev->ops->set_qos_map)
11810 return -EOPNOTSUPP;
11811
11812 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11813 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11814 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11815
11816 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11817 len > IEEE80211_QOS_MAP_LEN_MAX)
11818 return -EINVAL;
11819
11820 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11821 if (!qos_map)
11822 return -ENOMEM;
11823
11824 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11825 if (num_des) {
11826 des_len = num_des *
11827 sizeof(struct cfg80211_dscp_exception);
11828 memcpy(qos_map->dscp_exception, pos, des_len);
11829 qos_map->num_des = num_des;
11830 for (des = 0; des < num_des; des++) {
11831 if (qos_map->dscp_exception[des].up > 7) {
11832 kfree(qos_map);
11833 return -EINVAL;
11834 }
11835 }
11836 pos += des_len;
11837 }
11838 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11839 }
11840
11841 wdev_lock(dev->ieee80211_ptr);
11842 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11843 if (!ret)
11844 ret = rdev_set_qos_map(rdev, dev, qos_map);
11845 wdev_unlock(dev->ieee80211_ptr);
11846
11847 kfree(qos_map);
11848 return ret;
11849}
11850
Johannes Berg960d01a2014-09-09 22:55:35 +030011851static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11852{
11853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11854 struct net_device *dev = info->user_ptr[1];
11855 struct wireless_dev *wdev = dev->ieee80211_ptr;
11856 const u8 *peer;
11857 u8 tsid, up;
11858 u16 admitted_time = 0;
11859 int err;
11860
Johannes Berg723e73a2014-10-22 09:25:06 +020011861 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011862 return -EOPNOTSUPP;
11863
11864 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11865 !info->attrs[NL80211_ATTR_USER_PRIO])
11866 return -EINVAL;
11867
11868 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11869 if (tsid >= IEEE80211_NUM_TIDS)
11870 return -EINVAL;
11871
11872 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11873 if (up >= IEEE80211_NUM_UPS)
11874 return -EINVAL;
11875
11876 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011877 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011878 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011879 * need more attributes for that (e.g. BA session requirement);
11880 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011881 */
11882 return -EINVAL;
11883 }
11884
11885 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11886
11887 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11888 admitted_time =
11889 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11890 if (!admitted_time)
11891 return -EINVAL;
11892 }
11893
11894 wdev_lock(wdev);
11895 switch (wdev->iftype) {
11896 case NL80211_IFTYPE_STATION:
11897 case NL80211_IFTYPE_P2P_CLIENT:
11898 if (wdev->current_bss)
11899 break;
11900 err = -ENOTCONN;
11901 goto out;
11902 default:
11903 err = -EOPNOTSUPP;
11904 goto out;
11905 }
11906
11907 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11908
11909 out:
11910 wdev_unlock(wdev);
11911 return err;
11912}
11913
11914static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11915{
11916 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11917 struct net_device *dev = info->user_ptr[1];
11918 struct wireless_dev *wdev = dev->ieee80211_ptr;
11919 const u8 *peer;
11920 u8 tsid;
11921 int err;
11922
11923 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11924 return -EINVAL;
11925
11926 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11927 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11928
11929 wdev_lock(wdev);
11930 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11931 wdev_unlock(wdev);
11932
11933 return err;
11934}
11935
Arik Nemtsov1057d352014-11-19 12:54:26 +020011936static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11937 struct genl_info *info)
11938{
11939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11940 struct net_device *dev = info->user_ptr[1];
11941 struct wireless_dev *wdev = dev->ieee80211_ptr;
11942 struct cfg80211_chan_def chandef = {};
11943 const u8 *addr;
11944 u8 oper_class;
11945 int err;
11946
11947 if (!rdev->ops->tdls_channel_switch ||
11948 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11949 return -EOPNOTSUPP;
11950
11951 switch (dev->ieee80211_ptr->iftype) {
11952 case NL80211_IFTYPE_STATION:
11953 case NL80211_IFTYPE_P2P_CLIENT:
11954 break;
11955 default:
11956 return -EOPNOTSUPP;
11957 }
11958
11959 if (!info->attrs[NL80211_ATTR_MAC] ||
11960 !info->attrs[NL80211_ATTR_OPER_CLASS])
11961 return -EINVAL;
11962
11963 err = nl80211_parse_chandef(rdev, info, &chandef);
11964 if (err)
11965 return err;
11966
11967 /*
11968 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11969 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11970 * specification is not defined for them.
11971 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011972 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011973 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11974 chandef.width != NL80211_CHAN_WIDTH_20)
11975 return -EINVAL;
11976
11977 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011978 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11979 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011980 return -EINVAL;
11981
11982 /* don't allow switching to DFS channels */
11983 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11984 return -EINVAL;
11985
11986 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11987 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11988
11989 wdev_lock(wdev);
11990 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11991 wdev_unlock(wdev);
11992
11993 return err;
11994}
11995
11996static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11997 struct genl_info *info)
11998{
11999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12000 struct net_device *dev = info->user_ptr[1];
12001 struct wireless_dev *wdev = dev->ieee80211_ptr;
12002 const u8 *addr;
12003
12004 if (!rdev->ops->tdls_channel_switch ||
12005 !rdev->ops->tdls_cancel_channel_switch ||
12006 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
12007 return -EOPNOTSUPP;
12008
12009 switch (dev->ieee80211_ptr->iftype) {
12010 case NL80211_IFTYPE_STATION:
12011 case NL80211_IFTYPE_P2P_CLIENT:
12012 break;
12013 default:
12014 return -EOPNOTSUPP;
12015 }
12016
12017 if (!info->attrs[NL80211_ATTR_MAC])
12018 return -EINVAL;
12019
12020 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12021
12022 wdev_lock(wdev);
12023 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
12024 wdev_unlock(wdev);
12025
12026 return 0;
12027}
12028
Michael Braund757efc2016-10-10 19:12:22 +020012029static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
12030 struct genl_info *info)
12031{
12032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12033 struct net_device *dev = info->user_ptr[1];
12034 struct wireless_dev *wdev = dev->ieee80211_ptr;
12035 const struct nlattr *nla;
12036 bool enabled;
12037
12038 if (netif_running(dev))
12039 return -EBUSY;
12040
12041 if (!rdev->ops->set_multicast_to_unicast)
12042 return -EOPNOTSUPP;
12043
12044 if (wdev->iftype != NL80211_IFTYPE_AP &&
12045 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12046 return -EOPNOTSUPP;
12047
12048 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
12049 enabled = nla_get_flag(nla);
12050
12051 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
12052}
12053
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053012054static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
12055{
12056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12057 struct net_device *dev = info->user_ptr[1];
12058 struct cfg80211_external_auth_params params;
12059
12060 if (rdev->ops->external_auth)
12061 return -EOPNOTSUPP;
12062
12063 if (!info->attrs[NL80211_ATTR_SSID])
12064 return -EINVAL;
12065
12066 if (!info->attrs[NL80211_ATTR_BSSID])
12067 return -EINVAL;
12068
12069 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
12070 return -EINVAL;
12071
12072 memset(&params, 0, sizeof(params));
12073
12074 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
12075 if (params.ssid.ssid_len == 0 ||
12076 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
12077 return -EINVAL;
12078 memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
12079 params.ssid.ssid_len);
12080
12081 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
12082 ETH_ALEN);
12083
12084 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
12085
12086 return rdev_external_auth(rdev, dev, &params);
12087}
12088
Johannes Berg4c476992010-10-04 21:36:35 +020012089#define NL80211_FLAG_NEED_WIPHY 0x01
12090#define NL80211_FLAG_NEED_NETDEV 0x02
12091#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020012092#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12093#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12094 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020012095#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020012096/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020012097#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12098 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030012099#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020012100
Johannes Bergf84f7712013-11-14 17:14:45 +010012101static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012102 struct genl_info *info)
12103{
12104 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020012105 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012106 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020012107 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
12108
12109 if (rtnl)
12110 rtnl_lock();
12111
12112 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020012113 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020012114 if (IS_ERR(rdev)) {
12115 if (rtnl)
12116 rtnl_unlock();
12117 return PTR_ERR(rdev);
12118 }
12119 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020012120 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
12121 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020012122 ASSERT_RTNL();
12123
Johannes Berg89a54e42012-06-15 14:33:17 +020012124 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
12125 info->attrs);
12126 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020012127 if (rtnl)
12128 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020012129 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020012130 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012131
Johannes Berg89a54e42012-06-15 14:33:17 +020012132 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012133 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020012134
Johannes Berg1bf614e2012-06-15 15:23:36 +020012135 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
12136 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012137 if (rtnl)
12138 rtnl_unlock();
12139 return -EINVAL;
12140 }
12141
12142 info->user_ptr[1] = dev;
12143 } else {
12144 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020012145 }
Johannes Berg89a54e42012-06-15 14:33:17 +020012146
Johannes Berg1bf614e2012-06-15 15:23:36 +020012147 if (dev) {
12148 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
12149 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020012150 if (rtnl)
12151 rtnl_unlock();
12152 return -ENETDOWN;
12153 }
12154
12155 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012156 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012157 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
12158 !wdev->p2p_started) {
12159 if (rtnl)
12160 rtnl_unlock();
12161 return -ENETDOWN;
12162 }
12163 if (wdev->iftype == NL80211_IFTYPE_NAN &&
12164 !wdev->nan_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020012165 if (rtnl)
12166 rtnl_unlock();
12167 return -ENETDOWN;
12168 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020012169 }
12170
Johannes Berg4c476992010-10-04 21:36:35 +020012171 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020012172 }
12173
12174 return 0;
12175}
12176
Johannes Bergf84f7712013-11-14 17:14:45 +010012177static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020012178 struct genl_info *info)
12179{
Johannes Berg1bf614e2012-06-15 15:23:36 +020012180 if (info->user_ptr[1]) {
12181 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
12182 struct wireless_dev *wdev = info->user_ptr[1];
12183
12184 if (wdev->netdev)
12185 dev_put(wdev->netdev);
12186 } else {
12187 dev_put(info->user_ptr[1]);
12188 }
12189 }
Johannes Berg5393b912014-09-10 15:00:16 +030012190
Johannes Berg4c476992010-10-04 21:36:35 +020012191 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
12192 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030012193
12194 /* If needed, clear the netlink message payload from the SKB
12195 * as it might contain key data that shouldn't stick around on
12196 * the heap after the SKB is freed. The netlink message header
12197 * is still needed for further processing, so leave it intact.
12198 */
12199 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
12200 struct nlmsghdr *nlh = nlmsg_hdr(skb);
12201
12202 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
12203 }
Johannes Berg4c476992010-10-04 21:36:35 +020012204}
12205
Johannes Berg4534de82013-11-14 17:14:46 +010012206static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040012207 {
12208 .cmd = NL80211_CMD_GET_WIPHY,
12209 .doit = nl80211_get_wiphy,
12210 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020012211 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040012212 .policy = nl80211_policy,
12213 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012214 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12215 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012216 },
12217 {
12218 .cmd = NL80211_CMD_SET_WIPHY,
12219 .doit = nl80211_set_wiphy,
12220 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012221 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012222 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012223 },
12224 {
12225 .cmd = NL80211_CMD_GET_INTERFACE,
12226 .doit = nl80211_get_interface,
12227 .dumpit = nl80211_dump_interface,
12228 .policy = nl80211_policy,
12229 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020012230 .internal_flags = NL80211_FLAG_NEED_WDEV |
12231 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012232 },
12233 {
12234 .cmd = NL80211_CMD_SET_INTERFACE,
12235 .doit = nl80211_set_interface,
12236 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012237 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012238 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12239 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012240 },
12241 {
12242 .cmd = NL80211_CMD_NEW_INTERFACE,
12243 .doit = nl80211_new_interface,
12244 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012245 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012246 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12247 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012248 },
12249 {
12250 .cmd = NL80211_CMD_DEL_INTERFACE,
12251 .doit = nl80211_del_interface,
12252 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012253 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020012254 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012255 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040012256 },
Johannes Berg41ade002007-12-19 02:03:29 +010012257 {
12258 .cmd = NL80211_CMD_GET_KEY,
12259 .doit = nl80211_get_key,
12260 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012261 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012263 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012264 },
12265 {
12266 .cmd = NL80211_CMD_SET_KEY,
12267 .doit = nl80211_set_key,
12268 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012269 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012270 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012271 NL80211_FLAG_NEED_RTNL |
12272 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012273 },
12274 {
12275 .cmd = NL80211_CMD_NEW_KEY,
12276 .doit = nl80211_new_key,
12277 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012278 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012280 NL80211_FLAG_NEED_RTNL |
12281 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012282 },
12283 {
12284 .cmd = NL80211_CMD_DEL_KEY,
12285 .doit = nl80211_del_key,
12286 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012287 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012289 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012290 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012291 {
12292 .cmd = NL80211_CMD_SET_BEACON,
12293 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012294 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012295 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012296 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012297 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012298 },
12299 {
Johannes Berg88600202012-02-13 15:17:18 +010012300 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012301 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012302 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012303 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012305 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012306 },
12307 {
Johannes Berg88600202012-02-13 15:17:18 +010012308 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012309 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012310 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012311 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012313 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012314 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012315 {
12316 .cmd = NL80211_CMD_GET_STATION,
12317 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012318 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012319 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012320 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12321 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012322 },
12323 {
12324 .cmd = NL80211_CMD_SET_STATION,
12325 .doit = nl80211_set_station,
12326 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012327 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012329 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012330 },
12331 {
12332 .cmd = NL80211_CMD_NEW_STATION,
12333 .doit = nl80211_new_station,
12334 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012335 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012337 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012338 },
12339 {
12340 .cmd = NL80211_CMD_DEL_STATION,
12341 .doit = nl80211_del_station,
12342 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012343 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012345 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012346 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012347 {
12348 .cmd = NL80211_CMD_GET_MPATH,
12349 .doit = nl80211_get_mpath,
12350 .dumpit = nl80211_dump_mpath,
12351 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012352 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012353 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012354 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012355 },
12356 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012357 .cmd = NL80211_CMD_GET_MPP,
12358 .doit = nl80211_get_mpp,
12359 .dumpit = nl80211_dump_mpp,
12360 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012361 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12363 NL80211_FLAG_NEED_RTNL,
12364 },
12365 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012366 .cmd = NL80211_CMD_SET_MPATH,
12367 .doit = nl80211_set_mpath,
12368 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012369 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012371 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012372 },
12373 {
12374 .cmd = NL80211_CMD_NEW_MPATH,
12375 .doit = nl80211_new_mpath,
12376 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012377 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012379 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012380 },
12381 {
12382 .cmd = NL80211_CMD_DEL_MPATH,
12383 .doit = nl80211_del_mpath,
12384 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012385 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012387 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012388 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012389 {
12390 .cmd = NL80211_CMD_SET_BSS,
12391 .doit = nl80211_set_bss,
12392 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012393 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012395 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012396 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012397 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012398 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012399 .doit = nl80211_get_reg_do,
12400 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012401 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012402 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012403 /* can be retrieved by unprivileged users */
12404 },
Johannes Bergb6863032015-10-15 09:25:18 +020012405#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012406 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012407 .cmd = NL80211_CMD_SET_REG,
12408 .doit = nl80211_set_reg,
12409 .policy = nl80211_policy,
12410 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012411 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012412 },
Johannes Bergb6863032015-10-15 09:25:18 +020012413#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012414 {
12415 .cmd = NL80211_CMD_REQ_SET_REG,
12416 .doit = nl80211_req_set_reg,
12417 .policy = nl80211_policy,
12418 .flags = GENL_ADMIN_PERM,
12419 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012420 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012421 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12422 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012423 .policy = nl80211_policy,
12424 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012426 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012427 },
12428 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012429 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12430 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012431 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012432 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012433 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012434 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012435 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012436 {
Johannes Berg2a519312009-02-10 21:25:55 +010012437 .cmd = NL80211_CMD_TRIGGER_SCAN,
12438 .doit = nl80211_trigger_scan,
12439 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012440 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012441 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012442 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012443 },
12444 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012445 .cmd = NL80211_CMD_ABORT_SCAN,
12446 .doit = nl80211_abort_scan,
12447 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012448 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012449 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12450 NL80211_FLAG_NEED_RTNL,
12451 },
12452 {
Johannes Berg2a519312009-02-10 21:25:55 +010012453 .cmd = NL80211_CMD_GET_SCAN,
12454 .policy = nl80211_policy,
12455 .dumpit = nl80211_dump_scan,
12456 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012457 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012458 .cmd = NL80211_CMD_START_SCHED_SCAN,
12459 .doit = nl80211_start_sched_scan,
12460 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012461 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12463 NL80211_FLAG_NEED_RTNL,
12464 },
12465 {
12466 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12467 .doit = nl80211_stop_sched_scan,
12468 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012469 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12471 NL80211_FLAG_NEED_RTNL,
12472 },
12473 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012474 .cmd = NL80211_CMD_AUTHENTICATE,
12475 .doit = nl80211_authenticate,
12476 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012477 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012479 NL80211_FLAG_NEED_RTNL |
12480 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012481 },
12482 {
12483 .cmd = NL80211_CMD_ASSOCIATE,
12484 .doit = nl80211_associate,
12485 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012486 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012488 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012489 },
12490 {
12491 .cmd = NL80211_CMD_DEAUTHENTICATE,
12492 .doit = nl80211_deauthenticate,
12493 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012494 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012496 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012497 },
12498 {
12499 .cmd = NL80211_CMD_DISASSOCIATE,
12500 .doit = nl80211_disassociate,
12501 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012502 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012503 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012504 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012505 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012506 {
12507 .cmd = NL80211_CMD_JOIN_IBSS,
12508 .doit = nl80211_join_ibss,
12509 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012510 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012512 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012513 },
12514 {
12515 .cmd = NL80211_CMD_LEAVE_IBSS,
12516 .doit = nl80211_leave_ibss,
12517 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012518 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012519 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012520 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012521 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012522#ifdef CONFIG_NL80211_TESTMODE
12523 {
12524 .cmd = NL80211_CMD_TESTMODE,
12525 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012526 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012527 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012528 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012529 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12530 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012531 },
12532#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012533 {
12534 .cmd = NL80211_CMD_CONNECT,
12535 .doit = nl80211_connect,
12536 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012537 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012539 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012540 },
12541 {
vamsi krishna30da4e82016-10-27 16:51:11 +030012542 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12543 .doit = nl80211_update_connect_params,
12544 .policy = nl80211_policy,
12545 .flags = GENL_ADMIN_PERM,
12546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12547 NL80211_FLAG_NEED_RTNL,
12548 },
12549 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012550 .cmd = NL80211_CMD_DISCONNECT,
12551 .doit = nl80211_disconnect,
12552 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012553 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012555 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012556 },
Johannes Berg463d0182009-07-14 00:33:35 +020012557 {
12558 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12559 .doit = nl80211_wiphy_netns,
12560 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012561 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012562 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12563 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012564 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012565 {
12566 .cmd = NL80211_CMD_GET_SURVEY,
12567 .policy = nl80211_policy,
12568 .dumpit = nl80211_dump_survey,
12569 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012570 {
12571 .cmd = NL80211_CMD_SET_PMKSA,
12572 .doit = nl80211_setdel_pmksa,
12573 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012574 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012575 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012576 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012577 },
12578 {
12579 .cmd = NL80211_CMD_DEL_PMKSA,
12580 .doit = nl80211_setdel_pmksa,
12581 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012582 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012584 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012585 },
12586 {
12587 .cmd = NL80211_CMD_FLUSH_PMKSA,
12588 .doit = nl80211_flush_pmksa,
12589 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012590 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012592 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012593 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012594 {
12595 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12596 .doit = nl80211_remain_on_channel,
12597 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012598 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012599 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012600 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012601 },
12602 {
12603 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12604 .doit = nl80211_cancel_remain_on_channel,
12605 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012606 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012607 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012608 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012609 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012610 {
12611 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12612 .doit = nl80211_set_tx_bitrate_mask,
12613 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012614 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012615 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12616 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012617 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012618 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012619 .cmd = NL80211_CMD_REGISTER_FRAME,
12620 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012621 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012622 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012623 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012624 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012625 },
12626 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012627 .cmd = NL80211_CMD_FRAME,
12628 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012629 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012630 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012631 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012632 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012633 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012634 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012635 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12636 .doit = nl80211_tx_mgmt_cancel_wait,
12637 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012638 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012639 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012640 NL80211_FLAG_NEED_RTNL,
12641 },
12642 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012643 .cmd = NL80211_CMD_SET_POWER_SAVE,
12644 .doit = nl80211_set_power_save,
12645 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012646 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012647 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12648 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012649 },
12650 {
12651 .cmd = NL80211_CMD_GET_POWER_SAVE,
12652 .doit = nl80211_get_power_save,
12653 .policy = nl80211_policy,
12654 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012655 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12656 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012657 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012658 {
12659 .cmd = NL80211_CMD_SET_CQM,
12660 .doit = nl80211_set_cqm,
12661 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012662 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012663 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12664 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012665 },
Johannes Bergf444de02010-05-05 15:25:02 +020012666 {
12667 .cmd = NL80211_CMD_SET_CHANNEL,
12668 .doit = nl80211_set_channel,
12669 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012670 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012671 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12672 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012673 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012674 {
12675 .cmd = NL80211_CMD_SET_WDS_PEER,
12676 .doit = nl80211_set_wds_peer,
12677 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012678 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012679 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12680 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012681 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012682 {
12683 .cmd = NL80211_CMD_JOIN_MESH,
12684 .doit = nl80211_join_mesh,
12685 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012686 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12688 NL80211_FLAG_NEED_RTNL,
12689 },
12690 {
12691 .cmd = NL80211_CMD_LEAVE_MESH,
12692 .doit = nl80211_leave_mesh,
12693 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012694 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012695 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12696 NL80211_FLAG_NEED_RTNL,
12697 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012698 {
12699 .cmd = NL80211_CMD_JOIN_OCB,
12700 .doit = nl80211_join_ocb,
12701 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012702 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012703 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12704 NL80211_FLAG_NEED_RTNL,
12705 },
12706 {
12707 .cmd = NL80211_CMD_LEAVE_OCB,
12708 .doit = nl80211_leave_ocb,
12709 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012710 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12712 NL80211_FLAG_NEED_RTNL,
12713 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012714#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012715 {
12716 .cmd = NL80211_CMD_GET_WOWLAN,
12717 .doit = nl80211_get_wowlan,
12718 .policy = nl80211_policy,
12719 /* can be retrieved by unprivileged users */
12720 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12721 NL80211_FLAG_NEED_RTNL,
12722 },
12723 {
12724 .cmd = NL80211_CMD_SET_WOWLAN,
12725 .doit = nl80211_set_wowlan,
12726 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012727 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012728 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12729 NL80211_FLAG_NEED_RTNL,
12730 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012731#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012732 {
12733 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12734 .doit = nl80211_set_rekey_data,
12735 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012736 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012738 NL80211_FLAG_NEED_RTNL |
12739 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012740 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012741 {
12742 .cmd = NL80211_CMD_TDLS_MGMT,
12743 .doit = nl80211_tdls_mgmt,
12744 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012745 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12747 NL80211_FLAG_NEED_RTNL,
12748 },
12749 {
12750 .cmd = NL80211_CMD_TDLS_OPER,
12751 .doit = nl80211_tdls_oper,
12752 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012753 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12755 NL80211_FLAG_NEED_RTNL,
12756 },
Johannes Berg28946da2011-11-04 11:18:12 +010012757 {
12758 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12759 .doit = nl80211_register_unexpected_frame,
12760 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012761 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012762 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12763 NL80211_FLAG_NEED_RTNL,
12764 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012765 {
12766 .cmd = NL80211_CMD_PROBE_CLIENT,
12767 .doit = nl80211_probe_client,
12768 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012769 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012770 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012771 NL80211_FLAG_NEED_RTNL,
12772 },
Johannes Berg5e7602302011-11-04 11:18:17 +010012773 {
12774 .cmd = NL80211_CMD_REGISTER_BEACONS,
12775 .doit = nl80211_register_beacons,
12776 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012777 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010012778 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12779 NL80211_FLAG_NEED_RTNL,
12780 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012781 {
12782 .cmd = NL80211_CMD_SET_NOACK_MAP,
12783 .doit = nl80211_set_noack_map,
12784 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012785 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12787 NL80211_FLAG_NEED_RTNL,
12788 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012789 {
12790 .cmd = NL80211_CMD_START_P2P_DEVICE,
12791 .doit = nl80211_start_p2p_device,
12792 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012793 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012794 .internal_flags = NL80211_FLAG_NEED_WDEV |
12795 NL80211_FLAG_NEED_RTNL,
12796 },
12797 {
12798 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12799 .doit = nl80211_stop_p2p_device,
12800 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012801 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012802 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12803 NL80211_FLAG_NEED_RTNL,
12804 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012805 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012806 .cmd = NL80211_CMD_START_NAN,
12807 .doit = nl80211_start_nan,
12808 .policy = nl80211_policy,
12809 .flags = GENL_ADMIN_PERM,
12810 .internal_flags = NL80211_FLAG_NEED_WDEV |
12811 NL80211_FLAG_NEED_RTNL,
12812 },
12813 {
12814 .cmd = NL80211_CMD_STOP_NAN,
12815 .doit = nl80211_stop_nan,
12816 .policy = nl80211_policy,
12817 .flags = GENL_ADMIN_PERM,
12818 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12819 NL80211_FLAG_NEED_RTNL,
12820 },
12821 {
Ayala Bekera442b762016-09-20 17:31:15 +030012822 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12823 .doit = nl80211_nan_add_func,
12824 .policy = nl80211_policy,
12825 .flags = GENL_ADMIN_PERM,
12826 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12827 NL80211_FLAG_NEED_RTNL,
12828 },
12829 {
12830 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12831 .doit = nl80211_nan_del_func,
12832 .policy = nl80211_policy,
12833 .flags = GENL_ADMIN_PERM,
12834 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12835 NL80211_FLAG_NEED_RTNL,
12836 },
12837 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012838 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12839 .doit = nl80211_nan_change_config,
12840 .policy = nl80211_policy,
12841 .flags = GENL_ADMIN_PERM,
12842 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12843 NL80211_FLAG_NEED_RTNL,
12844 },
12845 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012846 .cmd = NL80211_CMD_SET_MCAST_RATE,
12847 .doit = nl80211_set_mcast_rate,
12848 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012849 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012850 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12851 NL80211_FLAG_NEED_RTNL,
12852 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012853 {
12854 .cmd = NL80211_CMD_SET_MAC_ACL,
12855 .doit = nl80211_set_mac_acl,
12856 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012857 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012858 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12859 NL80211_FLAG_NEED_RTNL,
12860 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012861 {
12862 .cmd = NL80211_CMD_RADAR_DETECT,
12863 .doit = nl80211_start_radar_detection,
12864 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012865 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12867 NL80211_FLAG_NEED_RTNL,
12868 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012869 {
12870 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12871 .doit = nl80211_get_protocol_features,
12872 .policy = nl80211_policy,
12873 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012874 {
12875 .cmd = NL80211_CMD_UPDATE_FT_IES,
12876 .doit = nl80211_update_ft_ies,
12877 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012878 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12880 NL80211_FLAG_NEED_RTNL,
12881 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012882 {
12883 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12884 .doit = nl80211_crit_protocol_start,
12885 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012886 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012887 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12888 NL80211_FLAG_NEED_RTNL,
12889 },
12890 {
12891 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12892 .doit = nl80211_crit_protocol_stop,
12893 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012894 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012895 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12896 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012897 },
12898 {
12899 .cmd = NL80211_CMD_GET_COALESCE,
12900 .doit = nl80211_get_coalesce,
12901 .policy = nl80211_policy,
12902 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12903 NL80211_FLAG_NEED_RTNL,
12904 },
12905 {
12906 .cmd = NL80211_CMD_SET_COALESCE,
12907 .doit = nl80211_set_coalesce,
12908 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012909 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012910 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12911 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012912 },
12913 {
12914 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12915 .doit = nl80211_channel_switch,
12916 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012917 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012918 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12919 NL80211_FLAG_NEED_RTNL,
12920 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012921 {
12922 .cmd = NL80211_CMD_VENDOR,
12923 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012924 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012925 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012926 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012927 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12928 NL80211_FLAG_NEED_RTNL,
12929 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012930 {
12931 .cmd = NL80211_CMD_SET_QOS_MAP,
12932 .doit = nl80211_set_qos_map,
12933 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012934 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12936 NL80211_FLAG_NEED_RTNL,
12937 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012938 {
12939 .cmd = NL80211_CMD_ADD_TX_TS,
12940 .doit = nl80211_add_tx_ts,
12941 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012942 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012943 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12944 NL80211_FLAG_NEED_RTNL,
12945 },
12946 {
12947 .cmd = NL80211_CMD_DEL_TX_TS,
12948 .doit = nl80211_del_tx_ts,
12949 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012950 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12952 NL80211_FLAG_NEED_RTNL,
12953 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012954 {
12955 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12956 .doit = nl80211_tdls_channel_switch,
12957 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012958 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12960 NL80211_FLAG_NEED_RTNL,
12961 },
12962 {
12963 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12964 .doit = nl80211_tdls_cancel_channel_switch,
12965 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012966 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12968 NL80211_FLAG_NEED_RTNL,
12969 },
Michael Braund757efc2016-10-10 19:12:22 +020012970 {
12971 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
12972 .doit = nl80211_set_multicast_to_unicast,
12973 .policy = nl80211_policy,
12974 .flags = GENL_UNS_ADMIN_PERM,
12975 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12976 NL80211_FLAG_NEED_RTNL,
12977 },
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053012978 {
12979 .cmd = NL80211_CMD_EXTERNAL_AUTH,
12980 .doit = nl80211_external_auth,
12981 .policy = nl80211_policy,
12982 .flags = GENL_ADMIN_PERM,
12983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12984 NL80211_FLAG_NEED_RTNL,
12985 },
Johannes Berg55682962007-09-20 13:09:35 -040012986};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012987
Johannes Berg55682962007-09-20 13:09:35 -040012988/* notification functions */
12989
Johannes Berg3bb20552014-05-26 13:52:25 +020012990void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12991 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012992{
12993 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012994 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012995
Johannes Berg3bb20552014-05-26 13:52:25 +020012996 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12997 cmd != NL80211_CMD_DEL_WIPHY);
12998
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012999 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013000 if (!msg)
13001 return;
13002
Johannes Berg3bb20552014-05-26 13:52:25 +020013003 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040013004 nlmsg_free(msg);
13005 return;
13006 }
13007
Johannes Berg68eb5502013-11-19 15:19:38 +010013008 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013009 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040013010}
13011
Denis Kenzior896ff062016-08-03 16:58:33 -050013012void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
13013 struct wireless_dev *wdev,
13014 enum nl80211_commands cmd)
13015{
13016 struct sk_buff *msg;
13017
13018 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
13019 cmd != NL80211_CMD_DEL_INTERFACE);
13020
13021 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13022 if (!msg)
13023 return;
13024
13025 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
13026 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
13027 nlmsg_free(msg);
13028 return;
13029 }
13030
13031 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13032 NL80211_MCGRP_CONFIG, GFP_KERNEL);
13033}
13034
Johannes Berg362a4152009-05-24 16:43:15 +020013035static int nl80211_add_scan_req(struct sk_buff *msg,
13036 struct cfg80211_registered_device *rdev)
13037{
13038 struct cfg80211_scan_request *req = rdev->scan_req;
13039 struct nlattr *nest;
13040 int i;
13041
13042 if (WARN_ON(!req))
13043 return 0;
13044
13045 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
13046 if (!nest)
13047 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013048 for (i = 0; i < req->n_ssids; i++) {
13049 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
13050 goto nla_put_failure;
13051 }
Johannes Berg362a4152009-05-24 16:43:15 +020013052 nla_nest_end(msg, nest);
13053
13054 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
13055 if (!nest)
13056 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040013057 for (i = 0; i < req->n_channels; i++) {
13058 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
13059 goto nla_put_failure;
13060 }
Johannes Berg362a4152009-05-24 16:43:15 +020013061 nla_nest_end(msg, nest);
13062
David S. Miller9360ffd2012-03-29 04:41:26 -040013063 if (req->ie &&
13064 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
13065 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020013066
Johannes Bergae917c92013-10-25 11:05:22 +020013067 if (req->flags &&
13068 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
13069 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070013070
Avraham Stern1d762502016-07-05 17:10:13 +030013071 if (req->info.scan_start_tsf &&
13072 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
13073 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
13074 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
13075 req->info.tsf_bssid)))
13076 goto nla_put_failure;
13077
Johannes Berg362a4152009-05-24 16:43:15 +020013078 return 0;
13079 nla_put_failure:
13080 return -ENOBUFS;
13081}
13082
Johannes Berga538e2d2009-06-16 19:56:42 +020013083static int nl80211_send_scan_msg(struct sk_buff *msg,
13084 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013085 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013086 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020013087 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010013088{
13089 void *hdr;
13090
Eric W. Biederman15e47302012-09-07 20:12:54 +000013091 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010013092 if (!hdr)
13093 return -1;
13094
David S. Miller9360ffd2012-03-29 04:41:26 -040013095 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020013096 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13097 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013098 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13099 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013100 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010013101
Johannes Berg362a4152009-05-24 16:43:15 +020013102 /* ignore errors and send incomplete event anyway */
13103 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010013104
Johannes Berg053c0952015-01-16 22:09:00 +010013105 genlmsg_end(msg, hdr);
13106 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010013107
13108 nla_put_failure:
13109 genlmsg_cancel(msg, hdr);
13110 return -EMSGSIZE;
13111}
13112
Luciano Coelho807f8a82011-05-11 17:09:35 +030013113static int
13114nl80211_send_sched_scan_msg(struct sk_buff *msg,
13115 struct cfg80211_registered_device *rdev,
13116 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013117 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030013118{
13119 void *hdr;
13120
Eric W. Biederman15e47302012-09-07 20:12:54 +000013121 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013122 if (!hdr)
13123 return -1;
13124
David S. Miller9360ffd2012-03-29 04:41:26 -040013125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13126 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13127 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013128
Johannes Berg053c0952015-01-16 22:09:00 +010013129 genlmsg_end(msg, hdr);
13130 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030013131
13132 nla_put_failure:
13133 genlmsg_cancel(msg, hdr);
13134 return -EMSGSIZE;
13135}
13136
Johannes Berga538e2d2009-06-16 19:56:42 +020013137void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020013138 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020013139{
13140 struct sk_buff *msg;
13141
Thomas Graf58050fc2012-06-28 03:57:45 +000013142 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013143 if (!msg)
13144 return;
13145
Johannes Bergfd014282012-06-18 19:17:03 +020013146 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020013147 NL80211_CMD_TRIGGER_SCAN) < 0) {
13148 nlmsg_free(msg);
13149 return;
13150 }
13151
Johannes Berg68eb5502013-11-19 15:19:38 +010013152 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013153 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020013154}
13155
Johannes Bergf9d15d12014-01-22 11:14:19 +020013156struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
13157 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010013158{
13159 struct sk_buff *msg;
13160
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013161 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013162 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020013163 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013164
Johannes Bergfd014282012-06-18 19:17:03 +020013165 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020013166 aborted ? NL80211_CMD_SCAN_ABORTED :
13167 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010013168 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020013169 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010013170 }
13171
Johannes Bergf9d15d12014-01-22 11:14:19 +020013172 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010013173}
13174
Johannes Bergf9d15d12014-01-22 11:14:19 +020013175void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
13176 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010013177{
Johannes Berg2a519312009-02-10 21:25:55 +010013178 if (!msg)
13179 return;
13180
Johannes Berg68eb5502013-11-19 15:19:38 +010013181 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013182 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010013183}
13184
Luciano Coelho807f8a82011-05-11 17:09:35 +030013185void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
13186 struct net_device *netdev)
13187{
13188 struct sk_buff *msg;
13189
13190 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13191 if (!msg)
13192 return;
13193
13194 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
13195 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
13196 nlmsg_free(msg);
13197 return;
13198 }
13199
Johannes Berg68eb5502013-11-19 15:19:38 +010013200 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013201 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013202}
13203
13204void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
13205 struct net_device *netdev, u32 cmd)
13206{
13207 struct sk_buff *msg;
13208
Thomas Graf58050fc2012-06-28 03:57:45 +000013209 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013210 if (!msg)
13211 return;
13212
13213 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
13214 nlmsg_free(msg);
13215 return;
13216 }
13217
Johannes Berg68eb5502013-11-19 15:19:38 +010013218 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013219 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030013220}
13221
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013222static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
13223 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013224{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013225 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040013226 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
13227 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013228
David S. Miller9360ffd2012-03-29 04:41:26 -040013229 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
13230 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13231 NL80211_REGDOM_TYPE_WORLD))
13232 goto nla_put_failure;
13233 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
13234 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13235 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
13236 goto nla_put_failure;
13237 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
13238 request->intersect) {
13239 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13240 NL80211_REGDOM_TYPE_INTERSECTION))
13241 goto nla_put_failure;
13242 } else {
13243 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
13244 NL80211_REGDOM_TYPE_COUNTRY) ||
13245 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
13246 request->alpha2))
13247 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013248 }
13249
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013250 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
13251 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
13252
13253 if (wiphy &&
13254 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
13255 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020013256
13257 if (wiphy &&
13258 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
13259 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
13260 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020013261 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013262
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020013263 return true;
13264
13265nla_put_failure:
13266 return false;
13267}
13268
13269/*
13270 * This can happen on global regulatory changes or device specific settings
13271 * based on custom regulatory domains.
13272 */
13273void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13274 struct regulatory_request *request)
13275{
13276 struct sk_buff *msg;
13277 void *hdr;
13278
13279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13280 if (!msg)
13281 return;
13282
13283 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13284 if (!hdr) {
13285 nlmsg_free(msg);
13286 return;
13287 }
13288
13289 if (nl80211_reg_change_event_fill(msg, request) == false)
13290 goto nla_put_failure;
13291
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013292 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013293
Johannes Bergbc43b282009-07-25 10:54:13 +020013294 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013295 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013296 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013297 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013298
13299 return;
13300
13301nla_put_failure:
13302 genlmsg_cancel(msg, hdr);
13303 nlmsg_free(msg);
13304}
13305
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013306static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13307 struct net_device *netdev,
13308 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013309 enum nl80211_commands cmd, gfp_t gfp,
13310 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013311{
13312 struct sk_buff *msg;
13313 void *hdr;
13314
Johannes Berg14459722017-01-09 11:10:42 +010013315 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013316 if (!msg)
13317 return;
13318
13319 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13320 if (!hdr) {
13321 nlmsg_free(msg);
13322 return;
13323 }
13324
David S. Miller9360ffd2012-03-29 04:41:26 -040013325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13326 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13327 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13328 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013329
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013330 if (uapsd_queues >= 0) {
13331 struct nlattr *nla_wmm =
13332 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13333 if (!nla_wmm)
13334 goto nla_put_failure;
13335
13336 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13337 uapsd_queues))
13338 goto nla_put_failure;
13339
13340 nla_nest_end(msg, nla_wmm);
13341 }
13342
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013343 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013344
Johannes Berg68eb5502013-11-19 15:19:38 +010013345 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013346 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013347 return;
13348
13349 nla_put_failure:
13350 genlmsg_cancel(msg, hdr);
13351 nlmsg_free(msg);
13352}
13353
13354void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013355 struct net_device *netdev, const u8 *buf,
13356 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013357{
13358 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013359 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013360}
13361
13362void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13363 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013364 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013365{
Johannes Berge6d6e342009-07-01 21:26:47 +020013366 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013367 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013368}
13369
Jouni Malinen53b46b82009-03-27 20:53:56 +020013370void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013371 struct net_device *netdev, const u8 *buf,
13372 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013373{
13374 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013375 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013376}
13377
Jouni Malinen53b46b82009-03-27 20:53:56 +020013378void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13379 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013380 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013381{
13382 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013383 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013384}
13385
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013386void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13387 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013388{
Johannes Berg947add32013-02-22 22:05:20 +010013389 struct wireless_dev *wdev = dev->ieee80211_ptr;
13390 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013391 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013392 const struct ieee80211_mgmt *mgmt = (void *)buf;
13393 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013394
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013395 if (WARN_ON(len < 2))
13396 return;
13397
13398 if (ieee80211_is_deauth(mgmt->frame_control))
13399 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13400 else
13401 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13402
13403 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013404 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013405}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013406EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013407
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013408static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13409 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013410 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013411{
13412 struct sk_buff *msg;
13413 void *hdr;
13414
Johannes Berge6d6e342009-07-01 21:26:47 +020013415 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013416 if (!msg)
13417 return;
13418
13419 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13420 if (!hdr) {
13421 nlmsg_free(msg);
13422 return;
13423 }
13424
David S. Miller9360ffd2012-03-29 04:41:26 -040013425 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13426 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13427 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13428 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13429 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013430
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013431 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013432
Johannes Berg68eb5502013-11-19 15:19:38 +010013433 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013434 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013435 return;
13436
13437 nla_put_failure:
13438 genlmsg_cancel(msg, hdr);
13439 nlmsg_free(msg);
13440}
13441
13442void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013443 struct net_device *netdev, const u8 *addr,
13444 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013445{
13446 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013447 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013448}
13449
13450void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013451 struct net_device *netdev, const u8 *addr,
13452 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013453{
Johannes Berge6d6e342009-07-01 21:26:47 +020013454 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13455 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013456}
13457
Samuel Ortizb23aa672009-07-01 21:26:54 +020013458void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013459 struct net_device *netdev,
13460 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwahadf935062017-01-13 01:12:21 +020013461 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013462{
13463 struct sk_buff *msg;
13464 void *hdr;
13465
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +030013466 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
13467 cr->fils_kek_len + cr->pmk_len +
13468 (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013469 if (!msg)
13470 return;
13471
13472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13473 if (!hdr) {
13474 nlmsg_free(msg);
13475 return;
13476 }
13477
David S. Miller9360ffd2012-03-29 04:41:26 -040013478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013480 (cr->bssid &&
13481 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013482 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013483 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13484 cr->status) ||
13485 (cr->status < 0 &&
Purushottam Kushwahadf935062017-01-13 01:12:21 +020013486 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally3f1905b2017-03-31 00:22:33 +030013487 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
13488 cr->timeout_reason))) ||
13489 (cr->req_ie &&
13490 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
13491 (cr->resp_ie &&
13492 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapally36eabf62017-03-31 00:22:34 +030013493 cr->resp_ie)) ||
13494 (cr->update_erp_next_seq_num &&
13495 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
13496 cr->fils_erp_next_seq_num)) ||
13497 (cr->status == WLAN_STATUS_SUCCESS &&
13498 ((cr->fils_kek &&
13499 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
13500 cr->fils_kek)) ||
13501 (cr->pmk &&
13502 nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
13503 (cr->pmkid &&
13504 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040013505 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013506
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013507 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013508
Johannes Berg68eb5502013-11-19 15:19:38 +010013509 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013510 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013511 return;
13512
13513 nla_put_failure:
13514 genlmsg_cancel(msg, hdr);
13515 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013516}
13517
13518void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern9e841a62017-04-26 10:58:49 +030013519 struct net_device *netdev,
13520 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013521{
13522 struct sk_buff *msg;
13523 void *hdr;
Avraham Stern9e841a62017-04-26 10:58:49 +030013524 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013525
Avraham Stern9e841a62017-04-26 10:58:49 +030013526 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013527 if (!msg)
13528 return;
13529
13530 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13531 if (!hdr) {
13532 nlmsg_free(msg);
13533 return;
13534 }
13535
David S. Miller9360ffd2012-03-29 04:41:26 -040013536 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13537 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13538 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern9e841a62017-04-26 10:58:49 +030013539 (info->req_ie &&
13540 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
13541 info->req_ie)) ||
13542 (info->resp_ie &&
13543 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Avraham Stern562be6e2017-06-09 13:08:45 +010013544 info->resp_ie)) ||
13545 (info->authorized &&
13546 nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013547 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013548
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013549 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013550
Johannes Berg68eb5502013-11-19 15:19:38 +010013551 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013552 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013553 return;
13554
13555 nla_put_failure:
13556 genlmsg_cancel(msg, hdr);
13557 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013558}
13559
13560void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13561 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020013562 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013563{
13564 struct sk_buff *msg;
13565 void *hdr;
13566
Johannes Berg14459722017-01-09 11:10:42 +010013567 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013568 if (!msg)
13569 return;
13570
13571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13572 if (!hdr) {
13573 nlmsg_free(msg);
13574 return;
13575 }
13576
David S. Miller9360ffd2012-03-29 04:41:26 -040013577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13578 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13579 (from_ap && reason &&
13580 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13581 (from_ap &&
13582 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13583 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13584 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013585
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013586 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013587
Johannes Berg68eb5502013-11-19 15:19:38 +010013588 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013589 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013590 return;
13591
13592 nla_put_failure:
13593 genlmsg_cancel(msg, hdr);
13594 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013595}
13596
Johannes Berg04a773a2009-04-19 21:24:32 +020013597void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13598 struct net_device *netdev, const u8 *bssid,
13599 gfp_t gfp)
13600{
13601 struct sk_buff *msg;
13602 void *hdr;
13603
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013605 if (!msg)
13606 return;
13607
13608 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13609 if (!hdr) {
13610 nlmsg_free(msg);
13611 return;
13612 }
13613
David S. Miller9360ffd2012-03-29 04:41:26 -040013614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13616 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13617 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013618
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013619 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013620
Johannes Berg68eb5502013-11-19 15:19:38 +010013621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013622 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013623 return;
13624
13625 nla_put_failure:
13626 genlmsg_cancel(msg, hdr);
13627 nlmsg_free(msg);
13628}
13629
Johannes Berg947add32013-02-22 22:05:20 +010013630void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13631 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013632{
Johannes Berg947add32013-02-22 22:05:20 +010013633 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013634 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013635 struct sk_buff *msg;
13636 void *hdr;
13637
Johannes Berg947add32013-02-22 22:05:20 +010013638 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13639 return;
13640
13641 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13642
Johannes Berg14459722017-01-09 11:10:42 +010013643 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013644 if (!msg)
13645 return;
13646
13647 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13648 if (!hdr) {
13649 nlmsg_free(msg);
13650 return;
13651 }
13652
David S. Miller9360ffd2012-03-29 04:41:26 -040013653 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013654 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13655 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013656 (ie_len && ie &&
13657 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13658 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013659
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013660 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013661
Johannes Berg68eb5502013-11-19 15:19:38 +010013662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013663 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013664 return;
13665
13666 nla_put_failure:
13667 genlmsg_cancel(msg, hdr);
13668 nlmsg_free(msg);
13669}
Johannes Berg947add32013-02-22 22:05:20 +010013670EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013671
Jouni Malinena3b8b052009-03-27 21:59:49 +020013672void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13673 struct net_device *netdev, const u8 *addr,
13674 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013675 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013676{
13677 struct sk_buff *msg;
13678 void *hdr;
13679
Johannes Berge6d6e342009-07-01 21:26:47 +020013680 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013681 if (!msg)
13682 return;
13683
13684 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13685 if (!hdr) {
13686 nlmsg_free(msg);
13687 return;
13688 }
13689
David S. Miller9360ffd2012-03-29 04:41:26 -040013690 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13692 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13693 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13694 (key_id != -1 &&
13695 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13696 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13697 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013698
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013699 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013700
Johannes Berg68eb5502013-11-19 15:19:38 +010013701 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013702 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013703 return;
13704
13705 nla_put_failure:
13706 genlmsg_cancel(msg, hdr);
13707 nlmsg_free(msg);
13708}
13709
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013710void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13711 struct ieee80211_channel *channel_before,
13712 struct ieee80211_channel *channel_after)
13713{
13714 struct sk_buff *msg;
13715 void *hdr;
13716 struct nlattr *nl_freq;
13717
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013718 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013719 if (!msg)
13720 return;
13721
13722 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13723 if (!hdr) {
13724 nlmsg_free(msg);
13725 return;
13726 }
13727
13728 /*
13729 * Since we are applying the beacon hint to a wiphy we know its
13730 * wiphy_idx is valid
13731 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13733 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013734
13735 /* Before */
13736 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13737 if (!nl_freq)
13738 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013739 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013740 goto nla_put_failure;
13741 nla_nest_end(msg, nl_freq);
13742
13743 /* After */
13744 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13745 if (!nl_freq)
13746 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013747 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013748 goto nla_put_failure;
13749 nla_nest_end(msg, nl_freq);
13750
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013751 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013752
Johannes Berg463d0182009-07-14 00:33:35 +020013753 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013754 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013755 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013756 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013757
13758 return;
13759
13760nla_put_failure:
13761 genlmsg_cancel(msg, hdr);
13762 nlmsg_free(msg);
13763}
13764
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013765static void nl80211_send_remain_on_chan_event(
13766 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013767 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013768 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013769 unsigned int duration, gfp_t gfp)
13770{
13771 struct sk_buff *msg;
13772 void *hdr;
13773
13774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13775 if (!msg)
13776 return;
13777
13778 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13779 if (!hdr) {
13780 nlmsg_free(msg);
13781 return;
13782 }
13783
David S. Miller9360ffd2012-03-29 04:41:26 -040013784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013785 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13786 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013787 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13788 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013789 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013790 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13791 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013792 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13793 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013794 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013795
David S. Miller9360ffd2012-03-29 04:41:26 -040013796 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13797 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13798 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013799
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013800 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013801
Johannes Berg68eb5502013-11-19 15:19:38 +010013802 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013803 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013804 return;
13805
13806 nla_put_failure:
13807 genlmsg_cancel(msg, hdr);
13808 nlmsg_free(msg);
13809}
13810
Johannes Berg947add32013-02-22 22:05:20 +010013811void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13812 struct ieee80211_channel *chan,
13813 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013814{
Johannes Berg947add32013-02-22 22:05:20 +010013815 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013816 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013817
13818 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013819 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013820 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013821 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013822}
Johannes Berg947add32013-02-22 22:05:20 +010013823EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013824
Johannes Berg947add32013-02-22 22:05:20 +010013825void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13826 struct ieee80211_channel *chan,
13827 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013828{
Johannes Berg947add32013-02-22 22:05:20 +010013829 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013830 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013831
13832 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013833 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013834 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013835}
Johannes Berg947add32013-02-22 22:05:20 +010013836EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013837
Johannes Berg947add32013-02-22 22:05:20 +010013838void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13839 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013840{
Johannes Berg947add32013-02-22 22:05:20 +010013841 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013842 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013843 struct sk_buff *msg;
13844
Johannes Berg947add32013-02-22 22:05:20 +010013845 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13846
Thomas Graf58050fc2012-06-28 03:57:45 +000013847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013848 if (!msg)
13849 return;
13850
Johannes Bergcf5ead82014-11-14 17:14:00 +010013851 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013852 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013853 nlmsg_free(msg);
13854 return;
13855 }
13856
Johannes Berg68eb5502013-11-19 15:19:38 +010013857 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013858 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013859}
Johannes Berg947add32013-02-22 22:05:20 +010013860EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013861
Johannes Bergcf5ead82014-11-14 17:14:00 +010013862void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13863 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013864{
Johannes Berg947add32013-02-22 22:05:20 +010013865 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013866 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013867 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013868 struct station_info empty_sinfo = {};
13869
13870 if (!sinfo)
13871 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013872
Johannes Berg947add32013-02-22 22:05:20 +010013873 trace_cfg80211_del_sta(dev, mac_addr);
13874
Thomas Graf58050fc2012-06-28 03:57:45 +000013875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013876 if (!msg)
13877 return;
13878
Johannes Bergcf5ead82014-11-14 17:14:00 +010013879 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013880 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013881 nlmsg_free(msg);
13882 return;
13883 }
13884
Johannes Berg68eb5502013-11-19 15:19:38 +010013885 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013886 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013887}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013888EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013889
Johannes Berg947add32013-02-22 22:05:20 +010013890void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13891 enum nl80211_connect_failed_reason reason,
13892 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013893{
Johannes Berg947add32013-02-22 22:05:20 +010013894 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013895 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013896 struct sk_buff *msg;
13897 void *hdr;
13898
13899 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13900 if (!msg)
13901 return;
13902
13903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13904 if (!hdr) {
13905 nlmsg_free(msg);
13906 return;
13907 }
13908
13909 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13910 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13911 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13912 goto nla_put_failure;
13913
13914 genlmsg_end(msg, hdr);
13915
Johannes Berg68eb5502013-11-19 15:19:38 +010013916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013917 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013918 return;
13919
13920 nla_put_failure:
13921 genlmsg_cancel(msg, hdr);
13922 nlmsg_free(msg);
13923}
Johannes Berg947add32013-02-22 22:05:20 +010013924EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013925
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013926static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13927 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013928{
13929 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013930 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013931 struct sk_buff *msg;
13932 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013933 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013934
Eric W. Biederman15e47302012-09-07 20:12:54 +000013935 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013936 return false;
13937
13938 msg = nlmsg_new(100, gfp);
13939 if (!msg)
13940 return true;
13941
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013942 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013943 if (!hdr) {
13944 nlmsg_free(msg);
13945 return true;
13946 }
13947
David S. Miller9360ffd2012-03-29 04:41:26 -040013948 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13949 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13950 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13951 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013952
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013953 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013954 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013955 return true;
13956
13957 nla_put_failure:
13958 genlmsg_cancel(msg, hdr);
13959 nlmsg_free(msg);
13960 return true;
13961}
13962
Johannes Berg947add32013-02-22 22:05:20 +010013963bool cfg80211_rx_spurious_frame(struct net_device *dev,
13964 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013965{
Johannes Berg947add32013-02-22 22:05:20 +010013966 struct wireless_dev *wdev = dev->ieee80211_ptr;
13967 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013968
Johannes Berg947add32013-02-22 22:05:20 +010013969 trace_cfg80211_rx_spurious_frame(dev, addr);
13970
13971 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13972 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13973 trace_cfg80211_return_bool(false);
13974 return false;
13975 }
13976 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13977 addr, gfp);
13978 trace_cfg80211_return_bool(ret);
13979 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013980}
Johannes Berg947add32013-02-22 22:05:20 +010013981EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13982
13983bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13984 const u8 *addr, gfp_t gfp)
13985{
13986 struct wireless_dev *wdev = dev->ieee80211_ptr;
13987 bool ret;
13988
13989 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13990
13991 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13992 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13993 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13994 trace_cfg80211_return_bool(false);
13995 return false;
13996 }
13997 ret = __nl80211_unexpected_frame(dev,
13998 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13999 addr, gfp);
14000 trace_cfg80211_return_bool(ret);
14001 return ret;
14002}
14003EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010014004
Johannes Berg2e161f72010-08-12 15:38:38 +020014005int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000014006 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010014007 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014008 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014009{
Johannes Berg71bbc992012-06-15 15:30:18 +020014010 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014011 struct sk_buff *msg;
14012 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020014013
Johannes Berg14459722017-01-09 11:10:42 +010014014 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014015 if (!msg)
14016 return -ENOMEM;
14017
Johannes Berg2e161f72010-08-12 15:38:38 +020014018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020014019 if (!hdr) {
14020 nlmsg_free(msg);
14021 return -ENOMEM;
14022 }
14023
David S. Miller9360ffd2012-03-29 04:41:26 -040014024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014025 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14026 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014027 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14028 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014029 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
14030 (sig_dbm &&
14031 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030014032 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
14033 (flags &&
14034 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040014035 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014036
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014037 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014038
Eric W. Biederman15e47302012-09-07 20:12:54 +000014039 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020014040
14041 nla_put_failure:
14042 genlmsg_cancel(msg, hdr);
14043 nlmsg_free(msg);
14044 return -ENOBUFS;
14045}
14046
Johannes Berg947add32013-02-22 22:05:20 +010014047void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
14048 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020014049{
Johannes Berg947add32013-02-22 22:05:20 +010014050 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014051 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020014052 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020014053 struct sk_buff *msg;
14054 void *hdr;
14055
Johannes Berg947add32013-02-22 22:05:20 +010014056 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
14057
Johannes Berg14459722017-01-09 11:10:42 +010014058 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014059 if (!msg)
14060 return;
14061
Johannes Berg2e161f72010-08-12 15:38:38 +020014062 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020014063 if (!hdr) {
14064 nlmsg_free(msg);
14065 return;
14066 }
14067
David S. Miller9360ffd2012-03-29 04:41:26 -040014068 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020014069 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14070 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014071 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14072 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014073 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014074 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14075 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014076 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
14077 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020014078
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014079 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020014080
Johannes Berg68eb5502013-11-19 15:19:38 +010014081 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014082 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020014083 return;
14084
14085 nla_put_failure:
14086 genlmsg_cancel(msg, hdr);
14087 nlmsg_free(msg);
14088}
Johannes Berg947add32013-02-22 22:05:20 +010014089EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020014090
Johannes Berg5b97f492014-11-26 12:37:43 +010014091static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
14092 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014093{
Johannes Berg947add32013-02-22 22:05:20 +010014094 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010014095 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14096 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14097 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014098
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014099 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010014100 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014101
Johannes Berg5b97f492014-11-26 12:37:43 +010014102 cb = (void **)msg->cb;
14103
14104 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
14105 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014106 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010014107 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014108 }
14109
David S. Miller9360ffd2012-03-29 04:41:26 -040014110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010014111 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040014112 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014113
Johannes Berg5b97f492014-11-26 12:37:43 +010014114 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014115 goto nla_put_failure;
14116
Johannes Berg5b97f492014-11-26 12:37:43 +010014117 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
14118 if (!cb[1])
14119 goto nla_put_failure;
14120
14121 cb[2] = rdev;
14122
14123 return msg;
14124 nla_put_failure:
14125 nlmsg_free(msg);
14126 return NULL;
14127}
14128
14129static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
14130{
14131 void **cb = (void **)msg->cb;
14132 struct cfg80211_registered_device *rdev = cb[2];
14133
14134 nla_nest_end(msg, cb[1]);
14135 genlmsg_end(msg, cb[0]);
14136
14137 memset(msg->cb, 0, sizeof(msg->cb));
14138
14139 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
14140 NL80211_MCGRP_MLME, gfp);
14141}
14142
14143void cfg80211_cqm_rssi_notify(struct net_device *dev,
14144 enum nl80211_cqm_rssi_threshold_event rssi_event,
14145 gfp_t gfp)
14146{
14147 struct sk_buff *msg;
14148
14149 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
14150
Johannes Berg98f03342014-11-26 12:42:02 +010014151 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
14152 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
14153 return;
14154
Johannes Berg5b97f492014-11-26 12:37:43 +010014155 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14156 if (!msg)
14157 return;
14158
David S. Miller9360ffd2012-03-29 04:41:26 -040014159 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
14160 rssi_event))
14161 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014162
Johannes Berg5b97f492014-11-26 12:37:43 +010014163 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014164
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014165 return;
14166
14167 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014168 nlmsg_free(msg);
14169}
Johannes Berg947add32013-02-22 22:05:20 +010014170EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014171
Johannes Berg5b97f492014-11-26 12:37:43 +010014172void cfg80211_cqm_txe_notify(struct net_device *dev,
14173 const u8 *peer, u32 num_packets,
14174 u32 rate, u32 intvl, gfp_t gfp)
14175{
14176 struct sk_buff *msg;
14177
14178 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14179 if (!msg)
14180 return;
14181
14182 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
14183 goto nla_put_failure;
14184
14185 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
14186 goto nla_put_failure;
14187
14188 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
14189 goto nla_put_failure;
14190
14191 cfg80211_send_cqm(msg, gfp);
14192 return;
14193
14194 nla_put_failure:
14195 nlmsg_free(msg);
14196}
14197EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
14198
14199void cfg80211_cqm_pktloss_notify(struct net_device *dev,
14200 const u8 *peer, u32 num_packets, gfp_t gfp)
14201{
14202 struct sk_buff *msg;
14203
14204 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
14205
14206 msg = cfg80211_prepare_cqm(dev, peer, gfp);
14207 if (!msg)
14208 return;
14209
14210 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
14211 goto nla_put_failure;
14212
14213 cfg80211_send_cqm(msg, gfp);
14214 return;
14215
14216 nla_put_failure:
14217 nlmsg_free(msg);
14218}
14219EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
14220
Johannes Berg98f03342014-11-26 12:42:02 +010014221void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
14222{
14223 struct sk_buff *msg;
14224
14225 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
14226 if (!msg)
14227 return;
14228
14229 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
14230 goto nla_put_failure;
14231
14232 cfg80211_send_cqm(msg, gfp);
14233 return;
14234
14235 nla_put_failure:
14236 nlmsg_free(msg);
14237}
14238EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
14239
Johannes Berg947add32013-02-22 22:05:20 +010014240static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
14241 struct net_device *netdev, const u8 *bssid,
14242 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020014243{
14244 struct sk_buff *msg;
14245 struct nlattr *rekey_attr;
14246 void *hdr;
14247
Thomas Graf58050fc2012-06-28 03:57:45 +000014248 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014249 if (!msg)
14250 return;
14251
14252 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
14253 if (!hdr) {
14254 nlmsg_free(msg);
14255 return;
14256 }
14257
David S. Miller9360ffd2012-03-29 04:41:26 -040014258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14259 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14260 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
14261 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014262
14263 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
14264 if (!rekey_attr)
14265 goto nla_put_failure;
14266
David S. Miller9360ffd2012-03-29 04:41:26 -040014267 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
14268 NL80211_REPLAY_CTR_LEN, replay_ctr))
14269 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020014270
14271 nla_nest_end(msg, rekey_attr);
14272
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014273 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020014274
Johannes Berg68eb5502013-11-19 15:19:38 +010014275 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014276 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020014277 return;
14278
14279 nla_put_failure:
14280 genlmsg_cancel(msg, hdr);
14281 nlmsg_free(msg);
14282}
14283
Johannes Berg947add32013-02-22 22:05:20 +010014284void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
14285 const u8 *replay_ctr, gfp_t gfp)
14286{
14287 struct wireless_dev *wdev = dev->ieee80211_ptr;
14288 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014289 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014290
14291 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14292 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14293}
14294EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14295
14296static void
14297nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14298 struct net_device *netdev, int index,
14299 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014300{
14301 struct sk_buff *msg;
14302 struct nlattr *attr;
14303 void *hdr;
14304
Thomas Graf58050fc2012-06-28 03:57:45 +000014305 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014306 if (!msg)
14307 return;
14308
14309 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14310 if (!hdr) {
14311 nlmsg_free(msg);
14312 return;
14313 }
14314
David S. Miller9360ffd2012-03-29 04:41:26 -040014315 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14316 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14317 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014318
14319 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14320 if (!attr)
14321 goto nla_put_failure;
14322
David S. Miller9360ffd2012-03-29 04:41:26 -040014323 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14324 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14325 (preauth &&
14326 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14327 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014328
14329 nla_nest_end(msg, attr);
14330
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014331 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014332
Johannes Berg68eb5502013-11-19 15:19:38 +010014333 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014334 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014335 return;
14336
14337 nla_put_failure:
14338 genlmsg_cancel(msg, hdr);
14339 nlmsg_free(msg);
14340}
14341
Johannes Berg947add32013-02-22 22:05:20 +010014342void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14343 const u8 *bssid, bool preauth, gfp_t gfp)
14344{
14345 struct wireless_dev *wdev = dev->ieee80211_ptr;
14346 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014347 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014348
14349 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14350 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14351}
14352EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14353
14354static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14355 struct net_device *netdev,
14356 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014357 gfp_t gfp,
14358 enum nl80211_commands notif,
14359 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014360{
14361 struct sk_buff *msg;
14362 void *hdr;
14363
Thomas Graf58050fc2012-06-28 03:57:45 +000014364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014365 if (!msg)
14366 return;
14367
Luciano Coelhof8d75522014-11-07 14:31:35 +020014368 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014369 if (!hdr) {
14370 nlmsg_free(msg);
14371 return;
14372 }
14373
Johannes Berg683b6d32012-11-08 21:25:48 +010014374 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14375 goto nla_put_failure;
14376
14377 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014378 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014379
Luciano Coelhof8d75522014-11-07 14:31:35 +020014380 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14381 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14382 goto nla_put_failure;
14383
Thomas Pedersen53145262012-04-06 13:35:47 -070014384 genlmsg_end(msg, hdr);
14385
Johannes Berg68eb5502013-11-19 15:19:38 +010014386 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014387 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014388 return;
14389
14390 nla_put_failure:
14391 genlmsg_cancel(msg, hdr);
14392 nlmsg_free(msg);
14393}
14394
Johannes Berg947add32013-02-22 22:05:20 +010014395void cfg80211_ch_switch_notify(struct net_device *dev,
14396 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014397{
Johannes Berg947add32013-02-22 22:05:20 +010014398 struct wireless_dev *wdev = dev->ieee80211_ptr;
14399 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014400 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014401
Simon Wunderliche487eae2013-11-21 18:19:51 +010014402 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014403
Simon Wunderliche487eae2013-11-21 18:19:51 +010014404 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014405
Michal Kazior9e0e2962014-01-29 14:22:27 +010014406 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014407 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014408 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14409 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014410}
14411EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14412
Luciano Coelhof8d75522014-11-07 14:31:35 +020014413void cfg80211_ch_switch_started_notify(struct net_device *dev,
14414 struct cfg80211_chan_def *chandef,
14415 u8 count)
14416{
14417 struct wireless_dev *wdev = dev->ieee80211_ptr;
14418 struct wiphy *wiphy = wdev->wiphy;
14419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14420
14421 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14422
14423 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14424 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14425}
14426EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14427
Thomas Pedersen84f10702012-07-12 16:17:33 -070014428void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014429nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014430 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014431 enum nl80211_radar_event event,
14432 struct net_device *netdev, gfp_t gfp)
14433{
14434 struct sk_buff *msg;
14435 void *hdr;
14436
14437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14438 if (!msg)
14439 return;
14440
14441 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14442 if (!hdr) {
14443 nlmsg_free(msg);
14444 return;
14445 }
14446
14447 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14448 goto nla_put_failure;
14449
14450 /* NOP and radar events don't need a netdev parameter */
14451 if (netdev) {
14452 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14453
14454 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014455 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14456 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014457 goto nla_put_failure;
14458 }
14459
14460 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14461 goto nla_put_failure;
14462
14463 if (nl80211_send_chandef(msg, chandef))
14464 goto nla_put_failure;
14465
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014466 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014467
Johannes Berg68eb5502013-11-19 15:19:38 +010014468 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014469 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014470 return;
14471
14472 nla_put_failure:
14473 genlmsg_cancel(msg, hdr);
14474 nlmsg_free(msg);
14475}
14476
Johannes Berg7f6cf312011-11-04 11:18:15 +010014477void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14478 u64 cookie, bool acked, gfp_t gfp)
14479{
14480 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014481 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014482 struct sk_buff *msg;
14483 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014484
Beni Lev4ee3e062012-08-27 12:49:39 +030014485 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14486
Thomas Graf58050fc2012-06-28 03:57:45 +000014487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014488
Johannes Berg7f6cf312011-11-04 11:18:15 +010014489 if (!msg)
14490 return;
14491
14492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14493 if (!hdr) {
14494 nlmsg_free(msg);
14495 return;
14496 }
14497
David S. Miller9360ffd2012-03-29 04:41:26 -040014498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14499 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14500 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014501 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14502 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014503 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14504 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014505
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014506 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014507
Johannes Berg68eb5502013-11-19 15:19:38 +010014508 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014509 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014510 return;
14511
14512 nla_put_failure:
14513 genlmsg_cancel(msg, hdr);
14514 nlmsg_free(msg);
14515}
14516EXPORT_SYMBOL(cfg80211_probe_status);
14517
Johannes Berg5e7602302011-11-04 11:18:17 +010014518void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14519 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014520 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010014521{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014522 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010014523 struct sk_buff *msg;
14524 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014525 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010014526
Beni Lev4ee3e062012-08-27 12:49:39 +030014527 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14528
Ben Greear37c73b52012-10-26 14:49:25 -070014529 spin_lock_bh(&rdev->beacon_registrations_lock);
14530 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14531 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14532 if (!msg) {
14533 spin_unlock_bh(&rdev->beacon_registrations_lock);
14534 return;
14535 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014536
Ben Greear37c73b52012-10-26 14:49:25 -070014537 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14538 if (!hdr)
14539 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010014540
Ben Greear37c73b52012-10-26 14:49:25 -070014541 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14542 (freq &&
14543 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14544 (sig_dbm &&
14545 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14546 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14547 goto nla_put_failure;
14548
14549 genlmsg_end(msg, hdr);
14550
14551 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010014552 }
Ben Greear37c73b52012-10-26 14:49:25 -070014553 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010014554 return;
14555
14556 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014557 spin_unlock_bh(&rdev->beacon_registrations_lock);
14558 if (hdr)
14559 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010014560 nlmsg_free(msg);
14561}
14562EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14563
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014564#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014565static int cfg80211_net_detect_results(struct sk_buff *msg,
14566 struct cfg80211_wowlan_wakeup *wakeup)
14567{
14568 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14569 struct nlattr *nl_results, *nl_match, *nl_freqs;
14570 int i, j;
14571
14572 nl_results = nla_nest_start(
14573 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14574 if (!nl_results)
14575 return -EMSGSIZE;
14576
14577 for (i = 0; i < nd->n_matches; i++) {
14578 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14579
14580 nl_match = nla_nest_start(msg, i);
14581 if (!nl_match)
14582 break;
14583
14584 /* The SSID attribute is optional in nl80211, but for
14585 * simplicity reasons it's always present in the
14586 * cfg80211 structure. If a driver can't pass the
14587 * SSID, that needs to be changed. A zero length SSID
14588 * is still a valid SSID (wildcard), so it cannot be
14589 * used for this purpose.
14590 */
14591 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14592 match->ssid.ssid)) {
14593 nla_nest_cancel(msg, nl_match);
14594 goto out;
14595 }
14596
14597 if (match->n_channels) {
14598 nl_freqs = nla_nest_start(
14599 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14600 if (!nl_freqs) {
14601 nla_nest_cancel(msg, nl_match);
14602 goto out;
14603 }
14604
14605 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014606 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014607 nla_nest_cancel(msg, nl_freqs);
14608 nla_nest_cancel(msg, nl_match);
14609 goto out;
14610 }
14611 }
14612
14613 nla_nest_end(msg, nl_freqs);
14614 }
14615
14616 nla_nest_end(msg, nl_match);
14617 }
14618
14619out:
14620 nla_nest_end(msg, nl_results);
14621 return 0;
14622}
14623
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014624void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14625 struct cfg80211_wowlan_wakeup *wakeup,
14626 gfp_t gfp)
14627{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014628 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014629 struct sk_buff *msg;
14630 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014631 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014632
14633 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14634
14635 if (wakeup)
14636 size += wakeup->packet_present_len;
14637
14638 msg = nlmsg_new(size, gfp);
14639 if (!msg)
14640 return;
14641
14642 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14643 if (!hdr)
14644 goto free_msg;
14645
14646 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014647 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14648 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014649 goto free_msg;
14650
14651 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14652 wdev->netdev->ifindex))
14653 goto free_msg;
14654
14655 if (wakeup) {
14656 struct nlattr *reasons;
14657
14658 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014659 if (!reasons)
14660 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014661
14662 if (wakeup->disconnect &&
14663 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14664 goto free_msg;
14665 if (wakeup->magic_pkt &&
14666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14667 goto free_msg;
14668 if (wakeup->gtk_rekey_failure &&
14669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14670 goto free_msg;
14671 if (wakeup->eap_identity_req &&
14672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14673 goto free_msg;
14674 if (wakeup->four_way_handshake &&
14675 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14676 goto free_msg;
14677 if (wakeup->rfkill_release &&
14678 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14679 goto free_msg;
14680
14681 if (wakeup->pattern_idx >= 0 &&
14682 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14683 wakeup->pattern_idx))
14684 goto free_msg;
14685
Johannes Bergae917c92013-10-25 11:05:22 +020014686 if (wakeup->tcp_match &&
14687 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14688 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014689
Johannes Bergae917c92013-10-25 11:05:22 +020014690 if (wakeup->tcp_connlost &&
14691 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14692 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014693
Johannes Bergae917c92013-10-25 11:05:22 +020014694 if (wakeup->tcp_nomoretokens &&
14695 nla_put_flag(msg,
14696 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14697 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014698
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014699 if (wakeup->packet) {
14700 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14701 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14702
14703 if (!wakeup->packet_80211) {
14704 pkt_attr =
14705 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14706 len_attr =
14707 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14708 }
14709
14710 if (wakeup->packet_len &&
14711 nla_put_u32(msg, len_attr, wakeup->packet_len))
14712 goto free_msg;
14713
14714 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14715 wakeup->packet))
14716 goto free_msg;
14717 }
14718
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014719 if (wakeup->net_detect &&
14720 cfg80211_net_detect_results(msg, wakeup))
14721 goto free_msg;
14722
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014723 nla_nest_end(msg, reasons);
14724 }
14725
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014726 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014727
Johannes Berg68eb5502013-11-19 15:19:38 +010014728 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014729 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014730 return;
14731
14732 free_msg:
14733 nlmsg_free(msg);
14734}
14735EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14736#endif
14737
Jouni Malinen3475b092012-11-16 22:49:57 +020014738void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14739 enum nl80211_tdls_operation oper,
14740 u16 reason_code, gfp_t gfp)
14741{
14742 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014743 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014744 struct sk_buff *msg;
14745 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014746
14747 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14748 reason_code);
14749
14750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14751 if (!msg)
14752 return;
14753
14754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14755 if (!hdr) {
14756 nlmsg_free(msg);
14757 return;
14758 }
14759
14760 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14762 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14763 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14764 (reason_code > 0 &&
14765 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14766 goto nla_put_failure;
14767
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014768 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014769
Johannes Berg68eb5502013-11-19 15:19:38 +010014770 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014771 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014772 return;
14773
14774 nla_put_failure:
14775 genlmsg_cancel(msg, hdr);
14776 nlmsg_free(msg);
14777}
14778EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14779
Jouni Malinen026331c2010-02-15 12:53:10 +020014780static int nl80211_netlink_notify(struct notifier_block * nb,
14781 unsigned long state,
14782 void *_notify)
14783{
14784 struct netlink_notify *notify = _notify;
14785 struct cfg80211_registered_device *rdev;
14786 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014787 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014788
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014789 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014790 return NOTIFY_DONE;
14791
14792 rcu_read_lock();
14793
Johannes Berg5e7602302011-11-04 11:18:17 +010014794 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014795 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014796 struct cfg80211_sched_scan_request *sched_scan_req =
14797 rcu_dereference(rdev->sched_scan_req);
14798
14799 if (sched_scan_req && notify->portid &&
Johannes Berg0a28f532017-01-05 10:57:14 +010014800 sched_scan_req->owner_nlportid == notify->portid) {
14801 sched_scan_req->owner_nlportid = 0;
14802
14803 if (rdev->ops->sched_scan_stop &&
14804 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14805 schedule_work(&rdev->sched_scan_stop_wk);
14806 }
Johannes Berg78f22b62014-03-24 17:57:27 +010014807
Johannes Berg53873f12016-05-03 16:52:04 +030014808 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014809 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014810
Johannes Berg78f22b62014-03-24 17:57:27 +010014811 if (wdev->owner_nlportid == notify->portid)
14812 schedule_destroy_work = true;
Andrzej Zaborowski5f3f4d32018-02-04 21:57:28 +053014813 else if (wdev->conn_owner_nlportid == notify->portid)
14814 schedule_work(&wdev->disconnect_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014815 }
14816
Ben Greear37c73b52012-10-26 14:49:25 -070014817 spin_lock_bh(&rdev->beacon_registrations_lock);
14818 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14819 list) {
14820 if (reg->nlportid == notify->portid) {
14821 list_del(&reg->list);
14822 kfree(reg);
14823 break;
14824 }
14825 }
14826 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014827
14828 if (schedule_destroy_work) {
14829 struct cfg80211_iface_destroy *destroy;
14830
14831 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14832 if (destroy) {
14833 destroy->nlportid = notify->portid;
14834 spin_lock(&rdev->destroy_list_lock);
14835 list_add(&destroy->list, &rdev->destroy_list);
14836 spin_unlock(&rdev->destroy_list_lock);
14837 schedule_work(&rdev->destroy_work);
14838 }
14839 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014840 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014841
14842 rcu_read_unlock();
14843
Ilan peer05050752015-03-04 00:32:06 -050014844 /*
14845 * It is possible that the user space process that is controlling the
14846 * indoor setting disappeared, so notify the regulatory core.
14847 */
14848 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014849 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014850}
14851
14852static struct notifier_block nl80211_netlink_notifier = {
14853 .notifier_call = nl80211_netlink_notify,
14854};
14855
Jouni Malinen355199e2013-02-27 17:14:27 +020014856void cfg80211_ft_event(struct net_device *netdev,
14857 struct cfg80211_ft_event_params *ft_event)
14858{
14859 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014860 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014861 struct sk_buff *msg;
14862 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014863
14864 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14865
14866 if (!ft_event->target_ap)
14867 return;
14868
Johannes Berg14459722017-01-09 11:10:42 +010014869 msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020014870 if (!msg)
14871 return;
14872
14873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014874 if (!hdr)
14875 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014876
Johannes Bergae917c92013-10-25 11:05:22 +020014877 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14878 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14879 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14880 goto out;
14881
14882 if (ft_event->ies &&
14883 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14884 goto out;
14885 if (ft_event->ric_ies &&
14886 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14887 ft_event->ric_ies))
14888 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014889
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014890 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014891
Johannes Berg68eb5502013-11-19 15:19:38 +010014892 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014893 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014894 return;
14895 out:
14896 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014897}
14898EXPORT_SYMBOL(cfg80211_ft_event);
14899
Arend van Spriel5de17982013-04-18 15:49:00 +020014900void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14901{
14902 struct cfg80211_registered_device *rdev;
14903 struct sk_buff *msg;
14904 void *hdr;
14905 u32 nlportid;
14906
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014907 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014908 if (!rdev->crit_proto_nlportid)
14909 return;
14910
14911 nlportid = rdev->crit_proto_nlportid;
14912 rdev->crit_proto_nlportid = 0;
14913
14914 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14915 if (!msg)
14916 return;
14917
14918 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14919 if (!hdr)
14920 goto nla_put_failure;
14921
14922 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014923 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14924 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014925 goto nla_put_failure;
14926
14927 genlmsg_end(msg, hdr);
14928
14929 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14930 return;
14931
14932 nla_put_failure:
14933 if (hdr)
14934 genlmsg_cancel(msg, hdr);
14935 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014936}
14937EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14938
Sameer Thalappilfaa4c4a2013-07-05 14:58:32 -070014939void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
14940{
14941 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14942 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14943
14944 nl80211_send_mlme_event(rdev, netdev, NULL, 0,
14945 NL80211_CMD_STOP_AP, gfp, -1);
14946}
14947EXPORT_SYMBOL(cfg80211_ap_stopped);
14948
Johannes Berg348baf02014-01-24 14:06:29 +010014949void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14950{
14951 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014952 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014953 struct sk_buff *msg;
14954 void *hdr;
14955
14956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14957 if (!msg)
14958 return;
14959
14960 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14961 if (!hdr)
14962 goto out;
14963
14964 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14965 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014966 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14967 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014968 goto out;
14969
14970 genlmsg_end(msg, hdr);
14971
14972 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14973 NL80211_MCGRP_MLME, GFP_KERNEL);
14974 return;
14975 out:
14976 nlmsg_free(msg);
14977}
14978
Srinivas Dasarid041a1a2018-02-07 18:32:17 +053014979int cfg80211_external_auth_request(struct net_device *dev,
14980 struct cfg80211_external_auth_params *params,
14981 gfp_t gfp)
14982{
14983 struct wireless_dev *wdev = dev->ieee80211_ptr;
14984 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14985 struct sk_buff *msg;
14986 void *hdr;
14987
14988 if (!wdev->conn_owner_nlportid)
14989 return -EINVAL;
14990
14991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14992 if (!msg)
14993 return -ENOMEM;
14994
14995 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
14996 if (!hdr)
14997 goto nla_put_failure;
14998
14999 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15000 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15001 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
15002 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
15003 params->action) ||
15004 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
15005 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
15006 params->ssid.ssid))
15007 goto nla_put_failure;
15008
15009 genlmsg_end(msg, hdr);
15010 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
15011 wdev->conn_owner_nlportid);
15012 return 0;
15013
15014 nla_put_failure:
15015 nlmsg_free(msg);
15016 return -ENOBUFS;
15017}
15018EXPORT_SYMBOL(cfg80211_external_auth_request);
15019
Johannes Berg55682962007-09-20 13:09:35 -040015020/* initialisation/exit functions */
15021
15022int nl80211_init(void)
15023{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000015024 int err;
Johannes Berg55682962007-09-20 13:09:35 -040015025
Johannes Berg2a94fe42013-11-19 15:19:39 +010015026 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
15027 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040015028 if (err)
15029 return err;
15030
Jouni Malinen026331c2010-02-15 12:53:10 +020015031 err = netlink_register_notifier(&nl80211_netlink_notifier);
15032 if (err)
15033 goto err_out;
15034
Johannes Berg55682962007-09-20 13:09:35 -040015035 return 0;
15036 err_out:
15037 genl_unregister_family(&nl80211_fam);
15038 return err;
15039}
15040
15041void nl80211_exit(void)
15042{
Jouni Malinen026331c2010-02-15 12:53:10 +020015043 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040015044 genl_unregister_family(&nl80211_fam);
15045}