blob: 3df85a751a85285f609c5583e7ad864c7c822560 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Berg55682962007-09-20 13:09:35 -040035/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020036static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040037
Johannes Berg2a94fe42013-11-19 15:19:39 +010038/* multicast groups */
39enum nl80211_multicast_groups {
40 NL80211_MCGRP_CONFIG,
41 NL80211_MCGRP_SCAN,
42 NL80211_MCGRP_REGULATORY,
43 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010044 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030045 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010046 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
47};
48
49static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010050 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
51 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
52 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
53 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
54 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030055 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010056#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010057 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010058#endif
59};
60
Johannes Berg89a54e42012-06-15 14:33:17 +020061/* returns ERR_PTR values */
62static struct wireless_dev *
63__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040064{
Johannes Berg89a54e42012-06-15 14:33:17 +020065 struct cfg80211_registered_device *rdev;
66 struct wireless_dev *result = NULL;
67 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
68 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
69 u64 wdev_id;
70 int wiphy_idx = -1;
71 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040072
Johannes Berg5fe231e2013-05-08 21:45:15 +020073 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040074
Johannes Berg89a54e42012-06-15 14:33:17 +020075 if (!have_ifidx && !have_wdev_id)
76 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (have_ifidx)
79 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
80 if (have_wdev_id) {
81 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
82 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040083 }
84
Johannes Berg89a54e42012-06-15 14:33:17 +020085 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
86 struct wireless_dev *wdev;
87
88 if (wiphy_net(&rdev->wiphy) != netns)
89 continue;
90
91 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
92 continue;
93
Johannes Berg53873f12016-05-03 16:52:04 +030094 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020095 if (have_ifidx && wdev->netdev &&
96 wdev->netdev->ifindex == ifidx) {
97 result = wdev;
98 break;
99 }
100 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
101 result = wdev;
102 break;
103 }
104 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200105
106 if (result)
107 break;
108 }
109
110 if (result)
111 return result;
112 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400113}
114
Johannes Berga9455402012-06-15 13:32:49 +0200115static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200116__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200117{
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 struct cfg80211_registered_device *rdev = NULL, *tmp;
119 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg5fe231e2013-05-08 21:45:15 +0200121 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200122
Johannes Berg878d9ec2012-06-15 14:18:32 +0200123 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200124 !attrs[NL80211_ATTR_IFINDEX] &&
125 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 return ERR_PTR(-EINVAL);
127
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 if (attrs[NL80211_ATTR_WDEV]) {
133 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
134 struct wireless_dev *wdev;
135 bool found = false;
136
137 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
138 if (tmp) {
139 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300140 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200141 if (wdev->identifier != (u32)wdev_id)
142 continue;
143 found = true;
144 break;
145 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200146
147 if (!found)
148 tmp = NULL;
149
150 if (rdev && tmp != rdev)
151 return ERR_PTR(-EINVAL);
152 rdev = tmp;
153 }
154 }
155
Johannes Berg878d9ec2012-06-15 14:18:32 +0200156 if (attrs[NL80211_ATTR_IFINDEX]) {
157 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700158
Ying Xue7f2b8562014-01-15 10:23:45 +0800159 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200160 if (netdev) {
161 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800162 tmp = wiphy_to_rdev(
163 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200164 else
165 tmp = NULL;
166
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 /* not wireless device -- return error */
168 if (!tmp)
169 return ERR_PTR(-EINVAL);
170
171 /* mismatch -- return error */
172 if (rdev && tmp != rdev)
173 return ERR_PTR(-EINVAL);
174
175 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200176 }
Johannes Berga9455402012-06-15 13:32:49 +0200177 }
178
Johannes Berg4f7eff12012-06-15 14:14:22 +0200179 if (!rdev)
180 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (netns != wiphy_net(&rdev->wiphy))
183 return ERR_PTR(-ENODEV);
184
185 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200186}
187
188/*
189 * This function returns a pointer to the driver
190 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200191 *
192 * The result of this can be a PTR_ERR and hence must
193 * be checked with IS_ERR() for errors.
194 */
195static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200197{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200198 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200199}
200
Johannes Berg55682962007-09-20 13:09:35 -0400201/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300202static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400203 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
204 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700205 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200206 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100207
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200208 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530209 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100210 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
211 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
212 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200214 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
215 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
216 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
217 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100218 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200219 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400220
221 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
222 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
223 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100224
Eliad Pellere007b852011-11-24 18:13:56 +0200225 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
226 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100227
Johannes Bergb9454e82009-07-08 13:29:08 +0200228 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100229 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
230 .len = WLAN_MAX_KEY_LEN },
231 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
232 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
233 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200234 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200235 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100236
237 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
238 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
239 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
240 .len = IEEE80211_MAX_DATA_LEN },
241 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
242 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100243 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
244 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
245 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
246 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
247 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100248 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100249 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200250 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100251 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800252 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100253 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300254
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700255 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
256 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
257
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300258 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
259 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
260 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200261 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
262 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100263 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300264
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800265 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700266 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700267
Johannes Berg6c739412011-11-03 09:27:01 +0100268 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200269
270 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
271 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
272 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100273 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
274 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200275
276 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
277 .len = IEEE80211_MAX_SSID_LEN },
278 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
279 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200280 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300281 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300282 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300283 [NL80211_ATTR_STA_FLAGS2] = {
284 .len = sizeof(struct nl80211_sta_flag_update),
285 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300286 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300287 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
288 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200289 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
290 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
291 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200292 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100293 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100294 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
295 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100296 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
297 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200298 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200299 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
300 .len = IEEE80211_MAX_DATA_LEN },
301 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200302 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200303 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300304 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200305 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300306 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
307 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200308 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900309 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
310 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100311 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100312 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100313 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200314 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700315 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300316 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200317 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200318 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300319 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300320 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
321 .len = IEEE80211_MAX_DATA_LEN },
322 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530324 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300325 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530326 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300327 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
328 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
329 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
330 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
331 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300332 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100333 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200334 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700336 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800337 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
338 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
339 .len = NL80211_HT_CAPABILITY_LEN
340 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100341 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530342 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530343 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200344 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700345 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300346 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000347 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700348 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100349 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
350 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530351 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
352 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200353 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
354 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100355 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100356 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
357 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
358 .len = NL80211_VHT_CAPABILITY_LEN,
359 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200360 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
361 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
362 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300363 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200364 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
365 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
366 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300367 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
368 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530369 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
370 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200371 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100372 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100373 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
374 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
375 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800376 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
377 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200378 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
379 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530380 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200381 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300382 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300383 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300384 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
385 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
386 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300387 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200388 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200389 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200390 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200391 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500392 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200393 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100394 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200395 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300396 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
397 .len = VHT_MUMIMO_GROUPS_DATA_LEN
398 },
399 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300400 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
401 [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
Ayala Bekera442b762016-09-20 17:31:15 +0300402 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300403 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
404 .len = FILS_MAX_KEK_LEN },
405 [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
Michael Braunce0ce132016-10-10 19:12:22 +0200406 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Vamsi Krishna2fa436b2016-12-02 23:59:08 +0200407 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
Johannes Berg55682962007-09-20 13:09:35 -0400408};
409
Johannes Berge31b8212010-10-05 19:39:30 +0200410/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000411static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200412 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200413 [NL80211_KEY_IDX] = { .type = NLA_U8 },
414 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200415 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200416 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
417 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200418 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100419 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
420};
421
422/* policy for the key default flags */
423static const struct nla_policy
424nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
425 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
426 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200427};
428
Johannes Bergf83ace32016-10-17 08:04:07 +0200429#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200430/* policy for WoWLAN attributes */
431static const struct nla_policy
432nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
433 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
435 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
436 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200437 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
438 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
439 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
440 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100441 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300442 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100443};
444
445static const struct nla_policy
446nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
447 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
448 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
449 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
450 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
451 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
452 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
453 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
454 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
455 },
456 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
457 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
458 },
459 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
460 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
461 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200462};
Johannes Bergf83ace32016-10-17 08:04:07 +0200463#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200464
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700465/* policy for coalesce rule attributes */
466static const struct nla_policy
467nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
468 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
469 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
470 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
471};
472
Johannes Berge5497d72011-07-05 16:35:40 +0200473/* policy for GTK rekey offload attributes */
474static const struct nla_policy
475nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
476 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
477 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
478 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
479};
480
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300481static const struct nla_policy
482nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200483 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300484 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700485 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300486};
487
Avraham Stern3b06d272015-10-12 09:51:34 +0300488static const struct nla_policy
489nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
490 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
491 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
492};
493
Arend van Spriel38de03d2016-03-02 20:37:18 +0100494static const struct nla_policy
495nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
496 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
497 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
498 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
499 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
500 },
501};
502
Ayala Bekera442b762016-09-20 17:31:15 +0300503/* policy for NAN function attributes */
504static const struct nla_policy
505nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
506 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
507 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
508 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
509 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
510 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
511 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
512 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
513 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
514 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
515 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
516 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
517 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
518 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
519 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
520 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
521 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
522 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
523 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
524};
525
526/* policy for Service Response Filter attributes */
527static const struct nla_policy
528nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
529 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
530 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
531 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
532 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
533 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
534};
535
Johannes Berg97990a02013-04-19 01:02:55 +0200536static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
537 struct netlink_callback *cb,
538 struct cfg80211_registered_device **rdev,
539 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100540{
Johannes Berg67748892010-10-04 21:14:06 +0200541 int err;
542
Johannes Berg67748892010-10-04 21:14:06 +0200543 rtnl_lock();
544
Johannes Berg97990a02013-04-19 01:02:55 +0200545 if (!cb->args[0]) {
546 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +0200547 genl_family_attrbuf(&nl80211_fam),
548 nl80211_fam.maxattr, nl80211_policy);
Johannes Berg97990a02013-04-19 01:02:55 +0200549 if (err)
550 goto out_unlock;
551
Johannes Bergc90c39d2016-10-24 14:40:01 +0200552 *wdev = __cfg80211_wdev_from_attrs(
553 sock_net(skb->sk),
554 genl_family_attrbuf(&nl80211_fam));
Johannes Berg97990a02013-04-19 01:02:55 +0200555 if (IS_ERR(*wdev)) {
556 err = PTR_ERR(*wdev);
557 goto out_unlock;
558 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800559 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200560 /* 0 is the first index - add 1 to parse only once */
561 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200562 cb->args[1] = (*wdev)->identifier;
563 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200564 /* subtract the 1 again here */
565 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200566 struct wireless_dev *tmp;
567
568 if (!wiphy) {
569 err = -ENODEV;
570 goto out_unlock;
571 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800572 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200573 *wdev = NULL;
574
Johannes Berg53873f12016-05-03 16:52:04 +0300575 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200576 if (tmp->identifier == cb->args[1]) {
577 *wdev = tmp;
578 break;
579 }
580 }
Johannes Berg97990a02013-04-19 01:02:55 +0200581
582 if (!*wdev) {
583 err = -ENODEV;
584 goto out_unlock;
585 }
Johannes Berg67748892010-10-04 21:14:06 +0200586 }
587
Johannes Berg67748892010-10-04 21:14:06 +0200588 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200589 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200590 rtnl_unlock();
591 return err;
592}
593
Johannes Berg97990a02013-04-19 01:02:55 +0200594static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200595{
Johannes Berg67748892010-10-04 21:14:06 +0200596 rtnl_unlock();
597}
598
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100599/* IE validation */
600static bool is_valid_ie_attr(const struct nlattr *attr)
601{
602 const u8 *pos;
603 int len;
604
605 if (!attr)
606 return true;
607
608 pos = nla_data(attr);
609 len = nla_len(attr);
610
611 while (len) {
612 u8 elemlen;
613
614 if (len < 2)
615 return false;
616 len -= 2;
617
618 elemlen = pos[1];
619 if (elemlen > len)
620 return false;
621
622 len -= elemlen;
623 pos += 2 + elemlen;
624 }
625
626 return true;
627}
628
Johannes Berg55682962007-09-20 13:09:35 -0400629/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000630static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400631 int flags, u8 cmd)
632{
633 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000634 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400635}
636
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400637static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100638 struct ieee80211_channel *chan,
639 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400640{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200641 /* Some channels must be completely excluded from the
642 * list to protect old user-space tools from breaking
643 */
644 if (!large && chan->flags &
645 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
646 return 0;
647
David S. Miller9360ffd2012-03-29 04:41:26 -0400648 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
649 chan->center_freq))
650 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400651
David S. Miller9360ffd2012-03-29 04:41:26 -0400652 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
654 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200655 if (chan->flags & IEEE80211_CHAN_NO_IR) {
656 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
657 goto nla_put_failure;
658 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
659 goto nla_put_failure;
660 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100661 if (chan->flags & IEEE80211_CHAN_RADAR) {
662 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
663 goto nla_put_failure;
664 if (large) {
665 u32 time;
666
667 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
668
669 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
670 chan->dfs_state))
671 goto nla_put_failure;
672 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
673 time))
674 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100675 if (nla_put_u32(msg,
676 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
677 chan->dfs_cac_ms))
678 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100679 }
680 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400681
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100682 if (large) {
683 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
684 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
685 goto nla_put_failure;
686 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
687 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
688 goto nla_put_failure;
689 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
690 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
691 goto nla_put_failure;
692 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
693 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
694 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200695 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
696 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
697 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300698 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
699 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200700 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200701 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
702 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
703 goto nla_put_failure;
704 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
705 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
706 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100707 }
708
David S. Miller9360ffd2012-03-29 04:41:26 -0400709 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
710 DBM_TO_MBM(chan->max_power)))
711 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400712
713 return 0;
714
715 nla_put_failure:
716 return -ENOBUFS;
717}
718
Johannes Berg55682962007-09-20 13:09:35 -0400719/* netlink command implementations */
720
Johannes Bergb9454e82009-07-08 13:29:08 +0200721struct key_parse {
722 struct key_params p;
723 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200724 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100726 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200727};
728
729static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
730{
731 struct nlattr *tb[NL80211_KEY_MAX + 1];
732 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
733 nl80211_key_policy);
734 if (err)
735 return err;
736
737 k->def = !!tb[NL80211_KEY_DEFAULT];
738 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
739
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100740 if (k->def) {
741 k->def_uni = true;
742 k->def_multi = true;
743 }
744 if (k->defmgmt)
745 k->def_multi = true;
746
Johannes Bergb9454e82009-07-08 13:29:08 +0200747 if (tb[NL80211_KEY_IDX])
748 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
749
750 if (tb[NL80211_KEY_DATA]) {
751 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
752 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
753 }
754
755 if (tb[NL80211_KEY_SEQ]) {
756 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
757 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
758 }
759
760 if (tb[NL80211_KEY_CIPHER])
761 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
762
Johannes Berge31b8212010-10-05 19:39:30 +0200763 if (tb[NL80211_KEY_TYPE]) {
764 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
765 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
766 return -EINVAL;
767 }
768
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100769 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
770 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700771
Johannes Berg2da8f412012-01-20 13:52:37 +0100772 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
773 tb[NL80211_KEY_DEFAULT_TYPES],
774 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100775 if (err)
776 return err;
777
778 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
779 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
780 }
781
Johannes Bergb9454e82009-07-08 13:29:08 +0200782 return 0;
783}
784
785static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
786{
787 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
788 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
789 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
790 }
791
792 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
793 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
794 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
795 }
796
797 if (info->attrs[NL80211_ATTR_KEY_IDX])
798 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
799
800 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
801 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
802
803 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
804 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
805
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100806 if (k->def) {
807 k->def_uni = true;
808 k->def_multi = true;
809 }
810 if (k->defmgmt)
811 k->def_multi = true;
812
Johannes Berge31b8212010-10-05 19:39:30 +0200813 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
814 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
815 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
816 return -EINVAL;
817 }
818
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100819 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
820 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
821 int err = nla_parse_nested(
822 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
823 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
824 nl80211_key_default_policy);
825 if (err)
826 return err;
827
828 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
829 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
830 }
831
Johannes Bergb9454e82009-07-08 13:29:08 +0200832 return 0;
833}
834
835static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
836{
837 int err;
838
839 memset(k, 0, sizeof(*k));
840 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200841 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200842
843 if (info->attrs[NL80211_ATTR_KEY])
844 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
845 else
846 err = nl80211_parse_key_old(info, k);
847
848 if (err)
849 return err;
850
851 if (k->def && k->defmgmt)
852 return -EINVAL;
853
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100854 if (k->defmgmt) {
855 if (k->def_uni || !k->def_multi)
856 return -EINVAL;
857 }
858
Johannes Bergb9454e82009-07-08 13:29:08 +0200859 if (k->idx != -1) {
860 if (k->defmgmt) {
861 if (k->idx < 4 || k->idx > 5)
862 return -EINVAL;
863 } else if (k->def) {
864 if (k->idx < 0 || k->idx > 3)
865 return -EINVAL;
866 } else {
867 if (k->idx < 0 || k->idx > 5)
868 return -EINVAL;
869 }
870 }
871
872 return 0;
873}
874
Johannes Bergfffd0932009-07-08 14:22:54 +0200875static struct cfg80211_cached_keys *
876nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530877 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200878{
879 struct key_parse parse;
880 struct nlattr *key;
881 struct cfg80211_cached_keys *result;
882 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200883 bool have_key = false;
884
885 nla_for_each_nested(key, keys, rem) {
886 have_key = true;
887 break;
888 }
889
890 if (!have_key)
891 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200892
893 result = kzalloc(sizeof(*result), GFP_KERNEL);
894 if (!result)
895 return ERR_PTR(-ENOMEM);
896
897 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200898
899 nla_for_each_nested(key, keys, rem) {
900 memset(&parse, 0, sizeof(parse));
901 parse.idx = -1;
902
903 err = nl80211_parse_key_new(key, &parse);
904 if (err)
905 goto error;
906 err = -EINVAL;
907 if (!parse.p.key)
908 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200909 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200910 goto error;
911 if (parse.def) {
912 if (def)
913 goto error;
914 def = 1;
915 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100916 if (!parse.def_uni || !parse.def_multi)
917 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 } else if (parse.defmgmt)
919 goto error;
920 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200921 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200922 if (err)
923 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200924 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
925 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
926 err = -EINVAL;
927 goto error;
928 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200929 result->params[parse.idx].cipher = parse.p.cipher;
930 result->params[parse.idx].key_len = parse.p.key_len;
931 result->params[parse.idx].key = result->data[parse.idx];
932 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530933
Johannes Berg386b1f22016-09-13 16:10:02 +0200934 /* must be WEP key if we got here */
935 if (no_ht)
936 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200937 }
938
Johannes Bergf1c1f172016-09-13 17:08:23 +0200939 if (result->def < 0) {
940 err = -EINVAL;
941 goto error;
942 }
943
Johannes Bergfffd0932009-07-08 14:22:54 +0200944 return result;
945 error:
946 kfree(result);
947 return ERR_PTR(err);
948}
949
950static int nl80211_key_allowed(struct wireless_dev *wdev)
951{
952 ASSERT_WDEV_LOCK(wdev);
953
Johannes Bergfffd0932009-07-08 14:22:54 +0200954 switch (wdev->iftype) {
955 case NL80211_IFTYPE_AP:
956 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200957 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700958 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200959 break;
960 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200961 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200962 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200963 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200964 return -ENOLINK;
965 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100966 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100967 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100968 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300969 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100970 case NL80211_IFTYPE_P2P_DEVICE:
971 case NL80211_IFTYPE_WDS:
972 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200973 return -EINVAL;
974 }
975
976 return 0;
977}
978
Jouni Malinen664834d2014-01-15 00:01:44 +0200979static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
980 struct nlattr *tb)
981{
982 struct ieee80211_channel *chan;
983
984 if (tb == NULL)
985 return NULL;
986 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
987 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
988 return NULL;
989 return chan;
990}
991
Johannes Berg7527a782011-05-13 10:58:57 +0200992static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
993{
994 struct nlattr *nl_modes = nla_nest_start(msg, attr);
995 int i;
996
997 if (!nl_modes)
998 goto nla_put_failure;
999
1000 i = 0;
1001 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001002 if ((ifmodes & 1) && nla_put_flag(msg, i))
1003 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001004 ifmodes >>= 1;
1005 i++;
1006 }
1007
1008 nla_nest_end(msg, nl_modes);
1009 return 0;
1010
1011nla_put_failure:
1012 return -ENOBUFS;
1013}
1014
1015static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001016 struct sk_buff *msg,
1017 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001018{
1019 struct nlattr *nl_combis;
1020 int i, j;
1021
1022 nl_combis = nla_nest_start(msg,
1023 NL80211_ATTR_INTERFACE_COMBINATIONS);
1024 if (!nl_combis)
1025 goto nla_put_failure;
1026
1027 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1028 const struct ieee80211_iface_combination *c;
1029 struct nlattr *nl_combi, *nl_limits;
1030
1031 c = &wiphy->iface_combinations[i];
1032
1033 nl_combi = nla_nest_start(msg, i + 1);
1034 if (!nl_combi)
1035 goto nla_put_failure;
1036
1037 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1038 if (!nl_limits)
1039 goto nla_put_failure;
1040
1041 for (j = 0; j < c->n_limits; j++) {
1042 struct nlattr *nl_limit;
1043
1044 nl_limit = nla_nest_start(msg, j + 1);
1045 if (!nl_limit)
1046 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001047 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1048 c->limits[j].max))
1049 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001050 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1051 c->limits[j].types))
1052 goto nla_put_failure;
1053 nla_nest_end(msg, nl_limit);
1054 }
1055
1056 nla_nest_end(msg, nl_limits);
1057
David S. Miller9360ffd2012-03-29 04:41:26 -04001058 if (c->beacon_int_infra_match &&
1059 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1060 goto nla_put_failure;
1061 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1062 c->num_different_channels) ||
1063 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1064 c->max_interfaces))
1065 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001066 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001067 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1068 c->radar_detect_widths) ||
1069 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1070 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001071 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301072 if (c->beacon_int_min_gcd &&
1073 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1074 c->beacon_int_min_gcd))
1075 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001076
1077 nla_nest_end(msg, nl_combi);
1078 }
1079
1080 nla_nest_end(msg, nl_combis);
1081
1082 return 0;
1083nla_put_failure:
1084 return -ENOBUFS;
1085}
1086
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001088static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1089 struct sk_buff *msg)
1090{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001091 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001092 struct nlattr *nl_tcp;
1093
1094 if (!tcp)
1095 return 0;
1096
1097 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1098 if (!nl_tcp)
1099 return -ENOBUFS;
1100
1101 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1102 tcp->data_payload_max))
1103 return -ENOBUFS;
1104
1105 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1106 tcp->data_payload_max))
1107 return -ENOBUFS;
1108
1109 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1110 return -ENOBUFS;
1111
1112 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1113 sizeof(*tcp->tok), tcp->tok))
1114 return -ENOBUFS;
1115
1116 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1117 tcp->data_interval_max))
1118 return -ENOBUFS;
1119
1120 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1121 tcp->wake_payload_max))
1122 return -ENOBUFS;
1123
1124 nla_nest_end(msg, nl_tcp);
1125 return 0;
1126}
1127
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001129 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001130 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131{
1132 struct nlattr *nl_wowlan;
1133
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001135 return 0;
1136
1137 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1138 if (!nl_wowlan)
1139 return -ENOBUFS;
1140
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001141 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001142 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001143 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001144 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001145 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001147 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001148 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001149 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001151 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001153 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001155 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001156 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1157 return -ENOBUFS;
1158
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001159 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001160 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001161 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1162 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1163 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1164 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001165 };
1166
1167 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1168 sizeof(pat), &pat))
1169 return -ENOBUFS;
1170 }
1171
Luciano Coelho75453cc2015-01-09 14:06:37 +02001172 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1173 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1174 rdev->wiphy.wowlan->max_nd_match_sets))
1175 return -ENOBUFS;
1176
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001177 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001178 return -ENOBUFS;
1179
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 nla_nest_end(msg, nl_wowlan);
1181
1182 return 0;
1183}
1184#endif
1185
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001186static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001187 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001188{
1189 struct nl80211_coalesce_rule_support rule;
1190
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001191 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001192 return 0;
1193
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001194 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1195 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1196 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1197 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1198 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1199 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001200
1201 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1202 return -ENOBUFS;
1203
1204 return 0;
1205}
1206
Johannes Berg3713b4e2013-02-14 16:19:38 +01001207static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1208 struct ieee80211_supported_band *sband)
1209{
1210 struct nlattr *nl_rates, *nl_rate;
1211 struct ieee80211_rate *rate;
1212 int i;
1213
1214 /* add HT info */
1215 if (sband->ht_cap.ht_supported &&
1216 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1217 sizeof(sband->ht_cap.mcs),
1218 &sband->ht_cap.mcs) ||
1219 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1220 sband->ht_cap.cap) ||
1221 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1222 sband->ht_cap.ampdu_factor) ||
1223 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1224 sband->ht_cap.ampdu_density)))
1225 return -ENOBUFS;
1226
1227 /* add VHT info */
1228 if (sband->vht_cap.vht_supported &&
1229 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1230 sizeof(sband->vht_cap.vht_mcs),
1231 &sband->vht_cap.vht_mcs) ||
1232 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1233 sband->vht_cap.cap)))
1234 return -ENOBUFS;
1235
1236 /* add bitrates */
1237 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1238 if (!nl_rates)
1239 return -ENOBUFS;
1240
1241 for (i = 0; i < sband->n_bitrates; i++) {
1242 nl_rate = nla_nest_start(msg, i);
1243 if (!nl_rate)
1244 return -ENOBUFS;
1245
1246 rate = &sband->bitrates[i];
1247 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1248 rate->bitrate))
1249 return -ENOBUFS;
1250 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1251 nla_put_flag(msg,
1252 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1253 return -ENOBUFS;
1254
1255 nla_nest_end(msg, nl_rate);
1256 }
1257
1258 nla_nest_end(msg, nl_rates);
1259
1260 return 0;
1261}
1262
1263static int
1264nl80211_send_mgmt_stypes(struct sk_buff *msg,
1265 const struct ieee80211_txrx_stypes *mgmt_stypes)
1266{
1267 u16 stypes;
1268 struct nlattr *nl_ftypes, *nl_ifs;
1269 enum nl80211_iftype ift;
1270 int i;
1271
1272 if (!mgmt_stypes)
1273 return 0;
1274
1275 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1276 if (!nl_ifs)
1277 return -ENOBUFS;
1278
1279 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1280 nl_ftypes = nla_nest_start(msg, ift);
1281 if (!nl_ftypes)
1282 return -ENOBUFS;
1283 i = 0;
1284 stypes = mgmt_stypes[ift].tx;
1285 while (stypes) {
1286 if ((stypes & 1) &&
1287 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1288 (i << 4) | IEEE80211_FTYPE_MGMT))
1289 return -ENOBUFS;
1290 stypes >>= 1;
1291 i++;
1292 }
1293 nla_nest_end(msg, nl_ftypes);
1294 }
1295
1296 nla_nest_end(msg, nl_ifs);
1297
1298 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1299 if (!nl_ifs)
1300 return -ENOBUFS;
1301
1302 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1303 nl_ftypes = nla_nest_start(msg, ift);
1304 if (!nl_ftypes)
1305 return -ENOBUFS;
1306 i = 0;
1307 stypes = mgmt_stypes[ift].rx;
1308 while (stypes) {
1309 if ((stypes & 1) &&
1310 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1311 (i << 4) | IEEE80211_FTYPE_MGMT))
1312 return -ENOBUFS;
1313 stypes >>= 1;
1314 i++;
1315 }
1316 nla_nest_end(msg, nl_ftypes);
1317 }
1318 nla_nest_end(msg, nl_ifs);
1319
1320 return 0;
1321}
1322
Johannes Berg17948992016-10-26 11:42:04 +02001323#define CMD(op, n) \
1324 do { \
1325 if (rdev->ops->op) { \
1326 i++; \
1327 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1328 goto nla_put_failure; \
1329 } \
1330 } while (0)
1331
1332static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1333 struct sk_buff *msg)
1334{
1335 int i = 0;
1336
1337 /*
1338 * do *NOT* add anything into this function, new things need to be
1339 * advertised only to new versions of userspace that can deal with
1340 * the split (and they can't possibly care about new features...
1341 */
1342 CMD(add_virtual_intf, NEW_INTERFACE);
1343 CMD(change_virtual_intf, SET_INTERFACE);
1344 CMD(add_key, NEW_KEY);
1345 CMD(start_ap, START_AP);
1346 CMD(add_station, NEW_STATION);
1347 CMD(add_mpath, NEW_MPATH);
1348 CMD(update_mesh_config, SET_MESH_CONFIG);
1349 CMD(change_bss, SET_BSS);
1350 CMD(auth, AUTHENTICATE);
1351 CMD(assoc, ASSOCIATE);
1352 CMD(deauth, DEAUTHENTICATE);
1353 CMD(disassoc, DISASSOCIATE);
1354 CMD(join_ibss, JOIN_IBSS);
1355 CMD(join_mesh, JOIN_MESH);
1356 CMD(set_pmksa, SET_PMKSA);
1357 CMD(del_pmksa, DEL_PMKSA);
1358 CMD(flush_pmksa, FLUSH_PMKSA);
1359 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1360 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1361 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1362 CMD(mgmt_tx, FRAME);
1363 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1364 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1365 i++;
1366 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1367 goto nla_put_failure;
1368 }
1369 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1370 rdev->ops->join_mesh) {
1371 i++;
1372 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1373 goto nla_put_failure;
1374 }
1375 CMD(set_wds_peer, SET_WDS_PEER);
1376 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1377 CMD(tdls_mgmt, TDLS_MGMT);
1378 CMD(tdls_oper, TDLS_OPER);
1379 }
1380 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1381 CMD(sched_scan_start, START_SCHED_SCAN);
1382 CMD(probe_client, PROBE_CLIENT);
1383 CMD(set_noack_map, SET_NOACK_MAP);
1384 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1385 i++;
1386 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1387 goto nla_put_failure;
1388 }
1389 CMD(start_p2p_device, START_P2P_DEVICE);
1390 CMD(set_mcast_rate, SET_MCAST_RATE);
1391#ifdef CONFIG_NL80211_TESTMODE
1392 CMD(testmode_cmd, TESTMODE);
1393#endif
1394
1395 if (rdev->ops->connect || rdev->ops->auth) {
1396 i++;
1397 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1398 goto nla_put_failure;
1399 }
1400
1401 if (rdev->ops->disconnect || rdev->ops->deauth) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1404 goto nla_put_failure;
1405 }
1406
1407 return i;
1408 nla_put_failure:
1409 return -ENOBUFS;
1410}
1411
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412struct nl80211_dump_wiphy_state {
1413 s64 filter_wiphy;
1414 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301415 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001416 bool split;
1417};
1418
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001419static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001420 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001423{
1424 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001425 struct nlattr *nl_bands, *nl_band;
1426 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001427 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001428 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001429 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001430 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001432 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001433 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001434
Johannes Berg3bb20552014-05-26 13:52:25 +02001435 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001436 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 return -ENOBUFS;
1438
Johannes Berg86e8cf92013-06-19 10:57:22 +02001439 if (WARN_ON(!state))
1440 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001441
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001442 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001444 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001445 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001447 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001448
Johannes Berg3bb20552014-05-26 13:52:25 +02001449 if (cmd != NL80211_CMD_NEW_WIPHY)
1450 goto finish;
1451
Johannes Berg86e8cf92013-06-19 10:57:22 +02001452 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 case 0:
1454 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001455 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001457 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001459 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001460 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001463 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001465 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001467 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001469 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001473 rdev->wiphy.max_match_sets) ||
1474 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1475 rdev->wiphy.max_sched_scan_plans) ||
1476 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1477 rdev->wiphy.max_sched_scan_plan_interval) ||
1478 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1479 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001480 goto nla_put_failure;
1481
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1484 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001485 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1487 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001488 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1490 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1493 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1496 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001499 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001500 state->split_start++;
1501 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 break;
1503 case 1:
1504 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001505 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1506 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001507 goto nla_put_failure;
1508
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001511 goto nla_put_failure;
1512
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1515 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001516
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001518 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001522
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001525 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001527
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001528 if ((rdev->wiphy.available_antennas_tx ||
1529 rdev->wiphy.available_antennas_rx) &&
1530 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 u32 tx_ant = 0, rx_ant = 0;
1532 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001533
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 if (!res) {
1536 if (nla_put_u32(msg,
1537 NL80211_ATTR_WIPHY_ANTENNA_TX,
1538 tx_ant) ||
1539 nla_put_u32(msg,
1540 NL80211_ATTR_WIPHY_ANTENNA_RX,
1541 rx_ant))
1542 goto nla_put_failure;
1543 }
Johannes Bergee688b002008-01-24 19:38:39 +01001544 }
1545
Johannes Berg86e8cf92013-06-19 10:57:22 +02001546 state->split_start++;
1547 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 break;
1549 case 2:
1550 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001551 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001553 state->split_start++;
1554 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 break;
1556 case 3:
1557 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1558 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001559 goto nla_put_failure;
1560
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001562 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 struct ieee80211_supported_band *sband;
1564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566
1567 if (!sband)
1568 continue;
1569
1570 nl_band = nla_nest_start(msg, band);
1571 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001572 goto nla_put_failure;
1573
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575 case 0:
1576 if (nl80211_send_band_rateinfo(msg, sband))
1577 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->chan_start++;
1579 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 break;
1581 default:
1582 /* add frequencies */
1583 nl_freqs = nla_nest_start(
1584 msg, NL80211_BAND_ATTR_FREQS);
1585 if (!nl_freqs)
1586 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001587
Johannes Berg86e8cf92013-06-19 10:57:22 +02001588 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 i < sband->n_channels;
1590 i++) {
1591 nl_freq = nla_nest_start(msg, i);
1592 if (!nl_freq)
1593 goto nla_put_failure;
1594
1595 chan = &sband->channels[i];
1596
Johannes Berg86e8cf92013-06-19 10:57:22 +02001597 if (nl80211_msg_put_channel(
1598 msg, chan,
1599 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 goto nla_put_failure;
1601
1602 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001603 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 break;
1605 }
1606 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 nla_nest_end(msg, nl_freqs);
1611 }
1612
1613 nla_nest_end(msg, nl_band);
1614
Johannes Berg86e8cf92013-06-19 10:57:22 +02001615 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 band--;
1619 break;
1620 }
Johannes Bergee688b002008-01-24 19:38:39 +01001621 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001623
Johannes Berg57fbcce2016-04-12 15:56:15 +02001624 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001627 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001628
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001630 if (state->band_start == 0 && state->chan_start == 0)
1631 state->split_start++;
1632 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001633 break;
1634 case 4:
1635 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1636 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001637 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638
Johannes Berg17948992016-10-26 11:42:04 +02001639 i = nl80211_add_commands_unsplit(rdev, msg);
1640 if (i < 0)
1641 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001642 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001643 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1644 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001645 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001646 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001647 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001648 if (rdev->wiphy.features &
1649 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001650 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02001651 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03001652 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001653 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001654#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001655
Johannes Berg3713b4e2013-02-14 16:19:38 +01001656 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001657 state->split_start++;
1658 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 break;
1660 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 if (rdev->ops->remain_on_channel &&
1662 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001663 nla_put_u32(msg,
1664 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001666 goto nla_put_failure;
1667
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001668 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001669 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1670 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001671
Johannes Berg3713b4e2013-02-14 16:19:38 +01001672 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1673 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001674 state->split_start++;
1675 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001676 break;
1677 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001678#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001680 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001681 state->split_start++;
1682 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683 break;
1684#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686#endif
1687 case 7:
1688 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001690 goto nla_put_failure;
1691
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001692 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001693 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001694 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001695
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696 state->split_start++;
1697 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001698 break;
1699 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001700 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001701 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001702 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 goto nla_put_failure;
1704
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001705 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001706 /*
1707 * We can only add the per-channel limit information if the
1708 * dump is split, otherwise it makes it too big. Therefore
1709 * only advertise it in that case.
1710 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001711 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001712 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1713 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001714 goto nla_put_failure;
1715
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001716 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001717 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001718 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1719 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 goto nla_put_failure;
1721
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001722 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1723 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001724 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001725 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001726 goto nla_put_failure;
1727
1728 /*
1729 * Any information below this point is only available to
1730 * applications that can deal with it being split. This
1731 * helps ensure that newly added capabilities don't break
1732 * older tools by overrunning their buffers.
1733 *
1734 * We still increment split_start so that in the split
1735 * case we'll continue with more data in the next round,
1736 * but break unconditionally so unsplit data stops here.
1737 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001739 break;
1740 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001741 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001742 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001743 rdev->wiphy.extended_capabilities_len,
1744 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001745 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001746 rdev->wiphy.extended_capabilities_len,
1747 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001748 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001749
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001750 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001751 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001752 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1753 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001754 goto nla_put_failure;
1755
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001756 state->split_start++;
1757 break;
1758 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001759 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001760 goto nla_put_failure;
1761
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001762 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001763 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1764 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1765 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001766
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001767 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001768 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001769 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001770 goto nla_put_failure;
1771
Johannes Bergad7e7182013-11-13 13:37:47 +01001772 state->split_start++;
1773 break;
1774 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001775 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001776 const struct nl80211_vendor_cmd_info *info;
1777 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001778
Johannes Berg567ffc32013-12-18 14:43:31 +01001779 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1780 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001781 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001782
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001783 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1784 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001785 if (nla_put(msg, i + 1, sizeof(*info), info))
1786 goto nla_put_failure;
1787 }
1788 nla_nest_end(msg, nested);
1789 }
1790
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001791 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001792 const struct nl80211_vendor_cmd_info *info;
1793 struct nlattr *nested;
1794
1795 nested = nla_nest_start(msg,
1796 NL80211_ATTR_VENDOR_EVENTS);
1797 if (!nested)
1798 goto nla_put_failure;
1799
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001800 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1801 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001802 if (nla_put(msg, i + 1, sizeof(*info), info))
1803 goto nla_put_failure;
1804 }
1805 nla_nest_end(msg, nested);
1806 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001807 state->split_start++;
1808 break;
1809 case 12:
1810 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1811 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1812 rdev->wiphy.max_num_csa_counters))
1813 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001814
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001815 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1816 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1817 goto nla_put_failure;
1818
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001819 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1820 sizeof(rdev->wiphy.ext_features),
1821 rdev->wiphy.ext_features))
1822 goto nla_put_failure;
1823
Arend van Spriel38de03d2016-03-02 20:37:18 +01001824 if (rdev->wiphy.bss_select_support) {
1825 struct nlattr *nested;
1826 u32 bss_select_support = rdev->wiphy.bss_select_support;
1827
1828 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1829 if (!nested)
1830 goto nla_put_failure;
1831
1832 i = 0;
1833 while (bss_select_support) {
1834 if ((bss_select_support & 1) &&
1835 nla_put_flag(msg, i))
1836 goto nla_put_failure;
1837 i++;
1838 bss_select_support >>= 1;
1839 }
1840 nla_nest_end(msg, nested);
1841 }
1842
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301843 state->split_start++;
1844 break;
1845 case 13:
1846 if (rdev->wiphy.num_iftype_ext_capab &&
1847 rdev->wiphy.iftype_ext_capab) {
1848 struct nlattr *nested_ext_capab, *nested;
1849
1850 nested = nla_nest_start(msg,
1851 NL80211_ATTR_IFTYPE_EXT_CAPA);
1852 if (!nested)
1853 goto nla_put_failure;
1854
1855 for (i = state->capa_start;
1856 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1857 const struct wiphy_iftype_ext_capab *capab;
1858
1859 capab = &rdev->wiphy.iftype_ext_capab[i];
1860
1861 nested_ext_capab = nla_nest_start(msg, i);
1862 if (!nested_ext_capab ||
1863 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1864 capab->iftype) ||
1865 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1866 capab->extended_capabilities_len,
1867 capab->extended_capabilities) ||
1868 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1869 capab->extended_capabilities_len,
1870 capab->extended_capabilities_mask))
1871 goto nla_put_failure;
1872
1873 nla_nest_end(msg, nested_ext_capab);
1874 if (state->split)
1875 break;
1876 }
1877 nla_nest_end(msg, nested);
1878 if (i < rdev->wiphy.num_iftype_ext_capab) {
1879 state->capa_start = i + 1;
1880 break;
1881 }
1882 }
1883
Johannes Berg3713b4e2013-02-14 16:19:38 +01001884 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001885 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001886 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001887 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001888 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001889 genlmsg_end(msg, hdr);
1890 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001891
1892 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001893 genlmsg_cancel(msg, hdr);
1894 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001895}
1896
Johannes Berg86e8cf92013-06-19 10:57:22 +02001897static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1898 struct netlink_callback *cb,
1899 struct nl80211_dump_wiphy_state *state)
1900{
Johannes Bergc90c39d2016-10-24 14:40:01 +02001901 struct nlattr **tb = genl_family_attrbuf(&nl80211_fam);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001902 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1903 tb, nl80211_fam.maxattr, nl80211_policy);
1904 /* ignore parse errors for backward compatibility */
1905 if (ret)
1906 return 0;
1907
1908 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1909 if (tb[NL80211_ATTR_WIPHY])
1910 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1911 if (tb[NL80211_ATTR_WDEV])
1912 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1913 if (tb[NL80211_ATTR_IFINDEX]) {
1914 struct net_device *netdev;
1915 struct cfg80211_registered_device *rdev;
1916 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1917
Ying Xue7f2b8562014-01-15 10:23:45 +08001918 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001919 if (!netdev)
1920 return -ENODEV;
1921 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001922 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001923 netdev->ieee80211_ptr->wiphy);
1924 state->filter_wiphy = rdev->wiphy_idx;
1925 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001926 }
1927
1928 return 0;
1929}
1930
Johannes Berg55682962007-09-20 13:09:35 -04001931static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1932{
Johannes Berg645e77d2013-03-01 14:03:49 +01001933 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001934 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001935 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001936
Johannes Berg5fe231e2013-05-08 21:45:15 +02001937 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001938 if (!state) {
1939 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001940 if (!state) {
1941 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001942 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001943 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 state->filter_wiphy = -1;
1945 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1946 if (ret) {
1947 kfree(state);
1948 rtnl_unlock();
1949 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001950 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001951 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001952 }
1953
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001954 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1955 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001956 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001957 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001958 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001959 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001960 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001961 continue;
1962 /* attempt to fit multiple wiphy data chunks into the skb */
1963 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001964 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1965 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001966 NETLINK_CB(cb->skb).portid,
1967 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001968 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001969 if (ret < 0) {
1970 /*
1971 * If sending the wiphy data didn't fit (ENOBUFS
1972 * or EMSGSIZE returned), this SKB is still
1973 * empty (so it's not too big because another
1974 * wiphy dataset is already in the skb) and
1975 * we've not tried to adjust the dump allocation
1976 * yet ... then adjust the alloc size to be
1977 * bigger, and return 1 but with the empty skb.
1978 * This results in an empty message being RX'ed
1979 * in userspace, but that is ignored.
1980 *
1981 * We can then retry with the larger buffer.
1982 */
1983 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001984 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001985 cb->min_dump_alloc < 4096) {
1986 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001987 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001988 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001989 return 1;
1990 }
1991 idx--;
1992 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001993 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001994 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001995 break;
Johannes Berg55682962007-09-20 13:09:35 -04001996 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001997 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001998
Johannes Berg86e8cf92013-06-19 10:57:22 +02001999 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002000
2001 return skb->len;
2002}
2003
Johannes Berg86e8cf92013-06-19 10:57:22 +02002004static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2005{
2006 kfree((void *)cb->args[0]);
2007 return 0;
2008}
2009
Johannes Berg55682962007-09-20 13:09:35 -04002010static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2011{
2012 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002014 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002015
Johannes Berg645e77d2013-03-01 14:03:49 +01002016 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002017 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002018 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002019
Johannes Berg3bb20552014-05-26 13:52:25 +02002020 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2021 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002022 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002023 nlmsg_free(msg);
2024 return -ENOBUFS;
2025 }
Johannes Berg55682962007-09-20 13:09:35 -04002026
Johannes Berg134e6372009-07-10 09:51:34 +00002027 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002028}
2029
Jouni Malinen31888482008-10-30 16:59:24 +02002030static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2031 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2032 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2033 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2034 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2035 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2036};
2037
2038static int parse_txq_params(struct nlattr *tb[],
2039 struct ieee80211_txq_params *txq_params)
2040{
Johannes Berga3304b02012-03-28 11:04:24 +02002041 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002042 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2043 !tb[NL80211_TXQ_ATTR_AIFS])
2044 return -EINVAL;
2045
Johannes Berga3304b02012-03-28 11:04:24 +02002046 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002047 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2048 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2049 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2050 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2051
Johannes Berga3304b02012-03-28 11:04:24 +02002052 if (txq_params->ac >= NL80211_NUM_ACS)
2053 return -EINVAL;
2054
Jouni Malinen31888482008-10-30 16:59:24 +02002055 return 0;
2056}
2057
Johannes Bergf444de02010-05-05 15:25:02 +02002058static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2059{
2060 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002061 * You can only set the channel explicitly for WDS interfaces,
2062 * all others have their channel managed via their respective
2063 * "establish a connection" command (connect, join, ...)
2064 *
2065 * For AP/GO and mesh mode, the channel can be set with the
2066 * channel userspace API, but is only stored and passed to the
2067 * low-level driver when the AP starts or the mesh is joined.
2068 * This is for backward compatibility, userspace can also give
2069 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002070 *
2071 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002072 * whatever else is going on, so they have their own special
2073 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002074 */
2075 return !wdev ||
2076 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002077 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002078 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2079 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002080}
2081
Johannes Berg683b6d32012-11-08 21:25:48 +01002082static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2083 struct genl_info *info,
2084 struct cfg80211_chan_def *chandef)
2085{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302086 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002087
2088 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2089 return -EINVAL;
2090
2091 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2092
2093 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002094 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2095 chandef->center_freq1 = control_freq;
2096 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002097
2098 /* Primary channel not allowed */
2099 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2100 return -EINVAL;
2101
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002102 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2103 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002104
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002105 chantype = nla_get_u32(
2106 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2107
2108 switch (chantype) {
2109 case NL80211_CHAN_NO_HT:
2110 case NL80211_CHAN_HT20:
2111 case NL80211_CHAN_HT40PLUS:
2112 case NL80211_CHAN_HT40MINUS:
2113 cfg80211_chandef_create(chandef, chandef->chan,
2114 chantype);
2115 break;
2116 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002117 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002118 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002119 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2120 chandef->width =
2121 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2122 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2123 chandef->center_freq1 =
2124 nla_get_u32(
2125 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2126 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2127 chandef->center_freq2 =
2128 nla_get_u32(
2129 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2130 }
2131
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002132 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002133 return -EINVAL;
2134
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002135 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2136 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002137 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002138
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002139 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2140 chandef->width == NL80211_CHAN_WIDTH_10) &&
2141 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2142 return -EINVAL;
2143
Johannes Berg683b6d32012-11-08 21:25:48 +01002144 return 0;
2145}
2146
Johannes Bergf444de02010-05-05 15:25:02 +02002147static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002148 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002149 struct genl_info *info)
2150{
Johannes Berg683b6d32012-11-08 21:25:48 +01002151 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002152 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002153 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002154 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002155
Jouni Malinene16821b2014-04-28 11:22:08 +03002156 if (dev)
2157 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002158 if (!nl80211_can_set_dev_channel(wdev))
2159 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002160 if (wdev)
2161 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002162
Johannes Berg683b6d32012-11-08 21:25:48 +01002163 result = nl80211_parse_chandef(rdev, info, &chandef);
2164 if (result)
2165 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002166
Johannes Berge8c9bd52012-06-06 08:18:22 +02002167 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002168 case NL80211_IFTYPE_AP:
2169 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002170 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2171 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002172 result = -EINVAL;
2173 break;
2174 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002175 if (wdev->beacon_interval) {
2176 if (!dev || !rdev->ops->set_ap_chanwidth ||
2177 !(rdev->wiphy.features &
2178 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2179 result = -EBUSY;
2180 break;
2181 }
2182
2183 /* Only allow dynamic channel width changes */
2184 if (chandef.chan != wdev->preset_chandef.chan) {
2185 result = -EBUSY;
2186 break;
2187 }
2188 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2189 if (result)
2190 break;
2191 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002192 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002193 result = 0;
2194 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002195 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002196 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002197 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002198 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002199 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002200 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002201 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002202 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002203 }
Johannes Bergf444de02010-05-05 15:25:02 +02002204
2205 return result;
2206}
2207
2208static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2209{
Johannes Berg4c476992010-10-04 21:36:35 +02002210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2211 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002212
Jouni Malinene16821b2014-04-28 11:22:08 +03002213 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002214}
2215
Bill Jordane8347eb2010-10-01 13:54:28 -04002216static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2217{
Johannes Berg43b19952010-10-07 13:10:30 +02002218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2219 struct net_device *dev = info->user_ptr[1];
2220 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002221 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002222
2223 if (!info->attrs[NL80211_ATTR_MAC])
2224 return -EINVAL;
2225
Johannes Berg43b19952010-10-07 13:10:30 +02002226 if (netif_running(dev))
2227 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002228
Johannes Berg43b19952010-10-07 13:10:30 +02002229 if (!rdev->ops->set_wds_peer)
2230 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002231
Johannes Berg43b19952010-10-07 13:10:30 +02002232 if (wdev->iftype != NL80211_IFTYPE_WDS)
2233 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002234
2235 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002236 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002237}
2238
Johannes Berg55682962007-09-20 13:09:35 -04002239static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2240{
2241 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002242 struct net_device *netdev = NULL;
2243 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002244 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002245 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002246 u32 changed;
2247 u8 retry_short = 0, retry_long = 0;
2248 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002249 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002250
Johannes Berg5fe231e2013-05-08 21:45:15 +02002251 ASSERT_RTNL();
2252
Johannes Bergf444de02010-05-05 15:25:02 +02002253 /*
2254 * Try to find the wiphy and netdev. Normally this
2255 * function shouldn't need the netdev, but this is
2256 * done for backward compatibility -- previously
2257 * setting the channel was done per wiphy, but now
2258 * it is per netdev. Previous userland like hostapd
2259 * also passed a netdev to set_wiphy, so that it is
2260 * possible to let that go to the right netdev!
2261 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002262
Johannes Bergf444de02010-05-05 15:25:02 +02002263 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2264 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2265
Ying Xue7f2b8562014-01-15 10:23:45 +08002266 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002267 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002268 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002269 else
Johannes Bergf444de02010-05-05 15:25:02 +02002270 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002271 }
2272
Johannes Bergf444de02010-05-05 15:25:02 +02002273 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002274 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2275 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002276 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002277 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002278 wdev = NULL;
2279 netdev = NULL;
2280 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002281 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002282 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002283
2284 /*
2285 * end workaround code, by now the rdev is available
2286 * and locked, and wdev may or may not be NULL.
2287 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002288
2289 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002290 result = cfg80211_dev_rename(
2291 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002292
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002293 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002294 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002295
Jouni Malinen31888482008-10-30 16:59:24 +02002296 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2297 struct ieee80211_txq_params txq_params;
2298 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2299
Ying Xue7f2b8562014-01-15 10:23:45 +08002300 if (!rdev->ops->set_txq_params)
2301 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002302
Ying Xue7f2b8562014-01-15 10:23:45 +08002303 if (!netdev)
2304 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002305
Johannes Berg133a3ff2011-11-03 14:50:13 +01002306 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002307 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2308 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002309
Ying Xue7f2b8562014-01-15 10:23:45 +08002310 if (!netif_running(netdev))
2311 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002312
Jouni Malinen31888482008-10-30 16:59:24 +02002313 nla_for_each_nested(nl_txq_params,
2314 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2315 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002316 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2317 nl_txq_params,
2318 txq_params_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01002319 if (result)
2320 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002321 result = parse_txq_params(tb, &txq_params);
2322 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002323 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002324
Hila Gonene35e4d22012-06-27 17:19:42 +03002325 result = rdev_set_txq_params(rdev, netdev,
2326 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002327 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002328 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002329 }
2330 }
2331
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002332 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002333 result = __nl80211_set_channel(
2334 rdev,
2335 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2336 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002337 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002338 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002339 }
2340
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002341 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002342 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002343 enum nl80211_tx_power_setting type;
2344 int idx, mbm = 0;
2345
Johannes Bergc8442112012-10-24 10:17:18 +02002346 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2347 txp_wdev = NULL;
2348
Ying Xue7f2b8562014-01-15 10:23:45 +08002349 if (!rdev->ops->set_tx_power)
2350 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002351
2352 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2353 type = nla_get_u32(info->attrs[idx]);
2354
2355 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002356 (type != NL80211_TX_POWER_AUTOMATIC))
2357 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002358
2359 if (type != NL80211_TX_POWER_AUTOMATIC) {
2360 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2361 mbm = nla_get_u32(info->attrs[idx]);
2362 }
2363
Johannes Bergc8442112012-10-24 10:17:18 +02002364 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002365 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002366 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002367 }
2368
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002369 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2370 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2371 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002372
Bruno Randolf7f531e02010-12-16 11:30:22 +09002373 if ((!rdev->wiphy.available_antennas_tx &&
2374 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002375 !rdev->ops->set_antenna)
2376 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002377
2378 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2379 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2380
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002381 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002382 * available antenna masks, except for the "all" mask */
2383 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002384 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2385 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002386
Bruno Randolf7f531e02010-12-16 11:30:22 +09002387 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2388 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002389
Hila Gonene35e4d22012-06-27 17:19:42 +03002390 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002391 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002392 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002393 }
2394
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002395 changed = 0;
2396
2397 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2398 retry_short = nla_get_u8(
2399 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002400 if (retry_short == 0)
2401 return -EINVAL;
2402
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002403 changed |= WIPHY_PARAM_RETRY_SHORT;
2404 }
2405
2406 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2407 retry_long = nla_get_u8(
2408 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002409 if (retry_long == 0)
2410 return -EINVAL;
2411
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002412 changed |= WIPHY_PARAM_RETRY_LONG;
2413 }
2414
2415 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2416 frag_threshold = nla_get_u32(
2417 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002418 if (frag_threshold < 256)
2419 return -EINVAL;
2420
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002421 if (frag_threshold != (u32) -1) {
2422 /*
2423 * Fragments (apart from the last one) are required to
2424 * have even length. Make the fragmentation code
2425 * simpler by stripping LSB should someone try to use
2426 * odd threshold value.
2427 */
2428 frag_threshold &= ~0x1;
2429 }
2430 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2431 }
2432
2433 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2434 rts_threshold = nla_get_u32(
2435 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2436 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2437 }
2438
Lukáš Turek81077e82009-12-21 22:50:47 +01002439 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002440 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2441 return -EINVAL;
2442
Lukáš Turek81077e82009-12-21 22:50:47 +01002443 coverage_class = nla_get_u8(
2444 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2445 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2446 }
2447
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002448 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2449 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2450 return -EOPNOTSUPP;
2451
2452 changed |= WIPHY_PARAM_DYN_ACK;
2453 }
2454
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002455 if (changed) {
2456 u8 old_retry_short, old_retry_long;
2457 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002458 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002459
Ying Xue7f2b8562014-01-15 10:23:45 +08002460 if (!rdev->ops->set_wiphy_params)
2461 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002462
2463 old_retry_short = rdev->wiphy.retry_short;
2464 old_retry_long = rdev->wiphy.retry_long;
2465 old_frag_threshold = rdev->wiphy.frag_threshold;
2466 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002467 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002468
2469 if (changed & WIPHY_PARAM_RETRY_SHORT)
2470 rdev->wiphy.retry_short = retry_short;
2471 if (changed & WIPHY_PARAM_RETRY_LONG)
2472 rdev->wiphy.retry_long = retry_long;
2473 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2474 rdev->wiphy.frag_threshold = frag_threshold;
2475 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2476 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002477 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2478 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002479
Hila Gonene35e4d22012-06-27 17:19:42 +03002480 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002481 if (result) {
2482 rdev->wiphy.retry_short = old_retry_short;
2483 rdev->wiphy.retry_long = old_retry_long;
2484 rdev->wiphy.frag_threshold = old_frag_threshold;
2485 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002486 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002487 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002488 }
2489 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002490 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002491}
2492
Johannes Berg71bbc992012-06-15 15:30:18 +02002493static inline u64 wdev_id(struct wireless_dev *wdev)
2494{
2495 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002496 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002497}
Johannes Berg55682962007-09-20 13:09:35 -04002498
Johannes Berg683b6d32012-11-08 21:25:48 +01002499static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002500 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002501{
Johannes Berg601555c2014-11-27 17:26:56 +01002502 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2503 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002504
Johannes Berg683b6d32012-11-08 21:25:48 +01002505 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2506 chandef->chan->center_freq))
2507 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002508 switch (chandef->width) {
2509 case NL80211_CHAN_WIDTH_20_NOHT:
2510 case NL80211_CHAN_WIDTH_20:
2511 case NL80211_CHAN_WIDTH_40:
2512 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2513 cfg80211_get_chandef_type(chandef)))
2514 return -ENOBUFS;
2515 break;
2516 default:
2517 break;
2518 }
2519 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2520 return -ENOBUFS;
2521 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2522 return -ENOBUFS;
2523 if (chandef->center_freq2 &&
2524 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002525 return -ENOBUFS;
2526 return 0;
2527}
2528
Eric W. Biederman15e47302012-09-07 20:12:54 +00002529static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002530 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002531 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002532{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002533 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002534 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002535 void *hdr;
2536
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002537 if (removal)
2538 cmd = NL80211_CMD_DEL_INTERFACE;
2539
2540 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002541 if (!hdr)
2542 return -1;
2543
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002544 if (dev &&
2545 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002546 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002547 goto nla_put_failure;
2548
2549 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2550 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002551 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2552 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002553 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002554 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2555 rdev->devlist_generation ^
2556 (cfg80211_rdev_list_generation << 2)))
2557 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002558
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002559 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002560 int ret;
2561 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002562
Johannes Berg683b6d32012-11-08 21:25:48 +01002563 ret = rdev_get_channel(rdev, wdev, &chandef);
2564 if (ret == 0) {
2565 if (nl80211_send_chandef(msg, &chandef))
2566 goto nla_put_failure;
2567 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002568 }
2569
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002570 if (rdev->ops->get_tx_power) {
2571 int dbm, ret;
2572
2573 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2574 if (ret == 0 &&
2575 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2576 DBM_TO_MBM(dbm)))
2577 goto nla_put_failure;
2578 }
2579
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002580 if (wdev->ssid_len) {
2581 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2582 goto nla_put_failure;
2583 }
2584
Johannes Berg053c0952015-01-16 22:09:00 +01002585 genlmsg_end(msg, hdr);
2586 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002587
2588 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002589 genlmsg_cancel(msg, hdr);
2590 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002591}
2592
2593static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2594{
2595 int wp_idx = 0;
2596 int if_idx = 0;
2597 int wp_start = cb->args[0];
2598 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002599 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002600 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002601 struct wireless_dev *wdev;
2602
Johannes Berg5fe231e2013-05-08 21:45:15 +02002603 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002604 if (!cb->args[2]) {
2605 struct nl80211_dump_wiphy_state state = {
2606 .filter_wiphy = -1,
2607 };
2608 int ret;
2609
2610 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2611 if (ret)
2612 return ret;
2613
2614 filter_wiphy = state.filter_wiphy;
2615
2616 /*
2617 * if filtering, set cb->args[2] to +1 since 0 is the default
2618 * value needed to determine that parsing is necessary.
2619 */
2620 if (filter_wiphy >= 0)
2621 cb->args[2] = filter_wiphy + 1;
2622 else
2623 cb->args[2] = -1;
2624 } else if (cb->args[2] > 0) {
2625 filter_wiphy = cb->args[2] - 1;
2626 }
2627
Johannes Bergf5ea9122009-08-07 16:17:38 +02002628 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2629 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002630 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002631 if (wp_idx < wp_start) {
2632 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002633 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002634 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002635
2636 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2637 continue;
2638
Johannes Berg55682962007-09-20 13:09:35 -04002639 if_idx = 0;
2640
Johannes Berg53873f12016-05-03 16:52:04 +03002641 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002642 if (if_idx < if_start) {
2643 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002644 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002645 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002646 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002647 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002648 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002649 goto out;
2650 }
2651 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002652 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002653
2654 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002655 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002656 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002657 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002658
2659 cb->args[0] = wp_idx;
2660 cb->args[1] = if_idx;
2661
2662 return skb->len;
2663}
2664
2665static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2666{
2667 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002668 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002669 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002670
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002672 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002673 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002674
Eric W. Biederman15e47302012-09-07 20:12:54 +00002675 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002676 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002677 nlmsg_free(msg);
2678 return -ENOBUFS;
2679 }
Johannes Berg55682962007-09-20 13:09:35 -04002680
Johannes Berg134e6372009-07-10 09:51:34 +00002681 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002682}
2683
Michael Wu66f7ac52008-01-31 19:48:22 +01002684static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2685 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2686 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2687 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2688 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2689 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002690 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002691};
2692
2693static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2694{
2695 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2696 int flag;
2697
2698 *mntrflags = 0;
2699
2700 if (!nla)
2701 return -EINVAL;
2702
2703 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2704 nla, mntr_flags_policy))
2705 return -EINVAL;
2706
2707 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2708 if (flags[flag])
2709 *mntrflags |= (1<<flag);
2710
2711 return 0;
2712}
2713
Johannes Berg9bc383d2009-11-19 11:55:19 +01002714static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002715 struct net_device *netdev, u8 use_4addr,
2716 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002717{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002718 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002719 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002720 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002721 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002722 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002723
2724 switch (iftype) {
2725 case NL80211_IFTYPE_AP_VLAN:
2726 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2727 return 0;
2728 break;
2729 case NL80211_IFTYPE_STATION:
2730 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2731 return 0;
2732 break;
2733 default:
2734 break;
2735 }
2736
2737 return -EOPNOTSUPP;
2738}
2739
Johannes Berg55682962007-09-20 13:09:35 -04002740static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2741{
Johannes Berg4c476992010-10-04 21:36:35 +02002742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002743 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002744 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002745 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002746 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002747 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002748 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002749
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002750 memset(&params, 0, sizeof(params));
2751
Johannes Berg04a773a2009-04-19 21:24:32 +02002752 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002753
Johannes Berg723b0382008-09-16 20:22:09 +02002754 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002755 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002756 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002757 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002758 if (ntype > NL80211_IFTYPE_MAX)
2759 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002760 }
2761
Johannes Berg92ffe052008-09-16 20:39:36 +02002762 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002763 struct wireless_dev *wdev = dev->ieee80211_ptr;
2764
Johannes Berg4c476992010-10-04 21:36:35 +02002765 if (ntype != NL80211_IFTYPE_MESH_POINT)
2766 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002767 if (netif_running(dev))
2768 return -EBUSY;
2769
2770 wdev_lock(wdev);
2771 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2772 IEEE80211_MAX_MESH_ID_LEN);
2773 wdev->mesh_id_up_len =
2774 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2775 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2776 wdev->mesh_id_up_len);
2777 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002778 }
2779
Felix Fietkau8b787642009-11-10 18:53:10 +01002780 if (info->attrs[NL80211_ATTR_4ADDR]) {
2781 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2782 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002783 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002784 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002785 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002786 } else {
2787 params.use_4addr = -1;
2788 }
2789
Johannes Berg92ffe052008-09-16 20:39:36 +02002790 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002791 if (ntype != NL80211_IFTYPE_MONITOR)
2792 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002793 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2794 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002795 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002796 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002797
2798 flags = &_flags;
2799 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002800 }
Johannes Berg3b858752009-03-12 09:55:09 +01002801
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002802 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2803 const u8 *mumimo_groups;
2804 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2805
2806 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2807 return -EOPNOTSUPP;
2808
2809 mumimo_groups =
2810 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2811
2812 /* bits 0 and 63 are reserved and must be zero */
2813 if ((mumimo_groups[0] & BIT(7)) ||
2814 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2815 return -EINVAL;
2816
2817 memcpy(params.vht_mumimo_groups, mumimo_groups,
2818 VHT_MUMIMO_GROUPS_DATA_LEN);
2819 change = true;
2820 }
2821
2822 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2823 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2824
2825 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2826 return -EOPNOTSUPP;
2827
2828 nla_memcpy(params.macaddr,
2829 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2830 ETH_ALEN);
2831 change = true;
2832 }
2833
Luciano Coelho18003292013-08-29 13:26:57 +03002834 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002835 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2836 return -EOPNOTSUPP;
2837
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002838 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002839 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002840 else
2841 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002842
Johannes Berg9bc383d2009-11-19 11:55:19 +01002843 if (!err && params.use_4addr != -1)
2844 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2845
Johannes Berg55682962007-09-20 13:09:35 -04002846 return err;
2847}
2848
2849static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2850{
Johannes Berg4c476992010-10-04 21:36:35 +02002851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002852 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002853 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002854 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002855 int err;
2856 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002857 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002858
Johannes Berg78f22b62014-03-24 17:57:27 +01002859 /* to avoid failing a new interface creation due to pending removal */
2860 cfg80211_destroy_ifaces(rdev);
2861
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002862 memset(&params, 0, sizeof(params));
2863
Johannes Berg55682962007-09-20 13:09:35 -04002864 if (!info->attrs[NL80211_ATTR_IFNAME])
2865 return -EINVAL;
2866
2867 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2868 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2869 if (type > NL80211_IFTYPE_MAX)
2870 return -EINVAL;
2871 }
2872
Johannes Berg79c97e92009-07-07 03:56:12 +02002873 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002874 !(rdev->wiphy.interface_modes & (1 << type)))
2875 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002876
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002877 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002878 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2879 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002880 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2881 ETH_ALEN);
2882 if (!is_valid_ether_addr(params.macaddr))
2883 return -EADDRNOTAVAIL;
2884 }
2885
Johannes Berg9bc383d2009-11-19 11:55:19 +01002886 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002887 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002888 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002889 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002890 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002891 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002892
Michael Wu66f7ac52008-01-31 19:48:22 +01002893 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2894 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2895 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002896
Luciano Coelho18003292013-08-29 13:26:57 +03002897 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002898 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2899 return -EOPNOTSUPP;
2900
Johannes Berga18c7192015-02-24 10:56:42 +01002901 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2902 if (!msg)
2903 return -ENOMEM;
2904
Hila Gonene35e4d22012-06-27 17:19:42 +03002905 wdev = rdev_add_virtual_intf(rdev,
2906 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002907 NET_NAME_USER, type, err ? NULL : &flags,
2908 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002909 if (WARN_ON(!wdev)) {
2910 nlmsg_free(msg);
2911 return -EPROTO;
2912 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002913 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002914 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002915 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002916
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002917 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002918 wdev->owner_nlportid = info->snd_portid;
2919
Johannes Berg98104fde2012-06-16 00:19:54 +02002920 switch (type) {
2921 case NL80211_IFTYPE_MESH_POINT:
2922 if (!info->attrs[NL80211_ATTR_MESH_ID])
2923 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002924 wdev_lock(wdev);
2925 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2926 IEEE80211_MAX_MESH_ID_LEN);
2927 wdev->mesh_id_up_len =
2928 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2929 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2930 wdev->mesh_id_up_len);
2931 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002932 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002933 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002934 case NL80211_IFTYPE_P2P_DEVICE:
2935 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002936 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002937 * through the netdev notifier and must be added here
2938 */
2939 mutex_init(&wdev->mtx);
2940 INIT_LIST_HEAD(&wdev->event_list);
2941 spin_lock_init(&wdev->event_lock);
2942 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2943 spin_lock_init(&wdev->mgmt_registrations_lock);
2944
Johannes Berg98104fde2012-06-16 00:19:54 +02002945 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002946 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002947 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002948 break;
2949 default:
2950 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002951 }
2952
Eric W. Biederman15e47302012-09-07 20:12:54 +00002953 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002954 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002955 nlmsg_free(msg);
2956 return -ENOBUFS;
2957 }
2958
Denis Kenzior896ff062016-08-03 16:58:33 -05002959 /*
2960 * For wdevs which have no associated netdev object (e.g. of type
2961 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2962 * For all other types, the event will be generated from the
2963 * netdev notifier
2964 */
2965 if (!wdev->netdev)
2966 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002967
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002968 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002969}
2970
2971static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2972{
Johannes Berg4c476992010-10-04 21:36:35 +02002973 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002974 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002975
Johannes Berg4c476992010-10-04 21:36:35 +02002976 if (!rdev->ops->del_virtual_intf)
2977 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002978
Johannes Berg84efbb82012-06-16 00:00:26 +02002979 /*
2980 * If we remove a wireless device without a netdev then clear
2981 * user_ptr[1] so that nl80211_post_doit won't dereference it
2982 * to check if it needs to do dev_put(). Otherwise it crashes
2983 * since the wdev has been freed, unlike with a netdev where
2984 * we need the dev_put() for the netdev to really be freed.
2985 */
2986 if (!wdev->netdev)
2987 info->user_ptr[1] = NULL;
2988
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002989 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002990}
2991
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002992static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2993{
2994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2995 struct net_device *dev = info->user_ptr[1];
2996 u16 noack_map;
2997
2998 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2999 return -EINVAL;
3000
3001 if (!rdev->ops->set_noack_map)
3002 return -EOPNOTSUPP;
3003
3004 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3005
Hila Gonene35e4d22012-06-27 17:19:42 +03003006 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003007}
3008
Johannes Berg41ade002007-12-19 02:03:29 +01003009struct get_key_cookie {
3010 struct sk_buff *msg;
3011 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003012 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003013};
3014
3015static void get_key_callback(void *c, struct key_params *params)
3016{
Johannes Bergb9454e82009-07-08 13:29:08 +02003017 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003018 struct get_key_cookie *cookie = c;
3019
David S. Miller9360ffd2012-03-29 04:41:26 -04003020 if ((params->key &&
3021 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3022 params->key_len, params->key)) ||
3023 (params->seq &&
3024 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3025 params->seq_len, params->seq)) ||
3026 (params->cipher &&
3027 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3028 params->cipher)))
3029 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003030
Johannes Bergb9454e82009-07-08 13:29:08 +02003031 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3032 if (!key)
3033 goto nla_put_failure;
3034
David S. Miller9360ffd2012-03-29 04:41:26 -04003035 if ((params->key &&
3036 nla_put(cookie->msg, NL80211_KEY_DATA,
3037 params->key_len, params->key)) ||
3038 (params->seq &&
3039 nla_put(cookie->msg, NL80211_KEY_SEQ,
3040 params->seq_len, params->seq)) ||
3041 (params->cipher &&
3042 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3043 params->cipher)))
3044 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003045
David S. Miller9360ffd2012-03-29 04:41:26 -04003046 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3047 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003048
3049 nla_nest_end(cookie->msg, key);
3050
Johannes Berg41ade002007-12-19 02:03:29 +01003051 return;
3052 nla_put_failure:
3053 cookie->error = 1;
3054}
3055
3056static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3057{
Johannes Berg4c476992010-10-04 21:36:35 +02003058 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003059 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003060 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003061 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003062 const u8 *mac_addr = NULL;
3063 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003064 struct get_key_cookie cookie = {
3065 .error = 0,
3066 };
3067 void *hdr;
3068 struct sk_buff *msg;
3069
3070 if (info->attrs[NL80211_ATTR_KEY_IDX])
3071 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3072
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003073 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003074 return -EINVAL;
3075
3076 if (info->attrs[NL80211_ATTR_MAC])
3077 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3078
Johannes Berge31b8212010-10-05 19:39:30 +02003079 pairwise = !!mac_addr;
3080 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3081 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003082
Johannes Berge31b8212010-10-05 19:39:30 +02003083 if (kt >= NUM_NL80211_KEYTYPES)
3084 return -EINVAL;
3085 if (kt != NL80211_KEYTYPE_GROUP &&
3086 kt != NL80211_KEYTYPE_PAIRWISE)
3087 return -EINVAL;
3088 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3089 }
3090
Johannes Berg4c476992010-10-04 21:36:35 +02003091 if (!rdev->ops->get_key)
3092 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003093
Johannes Berg0fa7b392015-01-23 11:10:12 +01003094 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3095 return -ENOENT;
3096
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003097 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003098 if (!msg)
3099 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003100
Eric W. Biederman15e47302012-09-07 20:12:54 +00003101 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003102 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003103 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003104 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003105
3106 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003107 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003108
David S. Miller9360ffd2012-03-29 04:41:26 -04003109 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3110 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3111 goto nla_put_failure;
3112 if (mac_addr &&
3113 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3114 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003115
Hila Gonene35e4d22012-06-27 17:19:42 +03003116 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3117 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003118
3119 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003120 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003121
3122 if (cookie.error)
3123 goto nla_put_failure;
3124
3125 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003126 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003127
3128 nla_put_failure:
3129 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003130 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003131 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003132 return err;
3133}
3134
3135static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3136{
Johannes Berg4c476992010-10-04 21:36:35 +02003137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003138 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003139 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003140 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003141
Johannes Bergb9454e82009-07-08 13:29:08 +02003142 err = nl80211_parse_key(info, &key);
3143 if (err)
3144 return err;
3145
3146 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003147 return -EINVAL;
3148
Johannes Bergb9454e82009-07-08 13:29:08 +02003149 /* only support setting default key */
3150 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003151 return -EINVAL;
3152
Johannes Bergfffd0932009-07-08 14:22:54 +02003153 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003154
3155 if (key.def) {
3156 if (!rdev->ops->set_default_key) {
3157 err = -EOPNOTSUPP;
3158 goto out;
3159 }
3160
3161 err = nl80211_key_allowed(dev->ieee80211_ptr);
3162 if (err)
3163 goto out;
3164
Hila Gonene35e4d22012-06-27 17:19:42 +03003165 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003166 key.def_uni, key.def_multi);
3167
3168 if (err)
3169 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003170
Johannes Berg3d23e342009-09-29 23:27:28 +02003171#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003172 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003173#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003174 } else {
3175 if (key.def_uni || !key.def_multi) {
3176 err = -EINVAL;
3177 goto out;
3178 }
3179
3180 if (!rdev->ops->set_default_mgmt_key) {
3181 err = -EOPNOTSUPP;
3182 goto out;
3183 }
3184
3185 err = nl80211_key_allowed(dev->ieee80211_ptr);
3186 if (err)
3187 goto out;
3188
Hila Gonene35e4d22012-06-27 17:19:42 +03003189 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003190 if (err)
3191 goto out;
3192
3193#ifdef CONFIG_CFG80211_WEXT
3194 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3195#endif
3196 }
3197
3198 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003199 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003200
Johannes Berg41ade002007-12-19 02:03:29 +01003201 return err;
3202}
3203
3204static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3205{
Johannes Berg4c476992010-10-04 21:36:35 +02003206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003207 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003208 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003209 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003210 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003211
Johannes Bergb9454e82009-07-08 13:29:08 +02003212 err = nl80211_parse_key(info, &key);
3213 if (err)
3214 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003215
Johannes Bergb9454e82009-07-08 13:29:08 +02003216 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003217 return -EINVAL;
3218
Johannes Berg41ade002007-12-19 02:03:29 +01003219 if (info->attrs[NL80211_ATTR_MAC])
3220 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3221
Johannes Berge31b8212010-10-05 19:39:30 +02003222 if (key.type == -1) {
3223 if (mac_addr)
3224 key.type = NL80211_KEYTYPE_PAIRWISE;
3225 else
3226 key.type = NL80211_KEYTYPE_GROUP;
3227 }
3228
3229 /* for now */
3230 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3231 key.type != NL80211_KEYTYPE_GROUP)
3232 return -EINVAL;
3233
Johannes Berg4c476992010-10-04 21:36:35 +02003234 if (!rdev->ops->add_key)
3235 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003236
Johannes Berge31b8212010-10-05 19:39:30 +02003237 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3238 key.type == NL80211_KEYTYPE_PAIRWISE,
3239 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003240 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003241
3242 wdev_lock(dev->ieee80211_ptr);
3243 err = nl80211_key_allowed(dev->ieee80211_ptr);
3244 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003245 err = rdev_add_key(rdev, dev, key.idx,
3246 key.type == NL80211_KEYTYPE_PAIRWISE,
3247 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003248 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003249
Johannes Berg41ade002007-12-19 02:03:29 +01003250 return err;
3251}
3252
3253static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3254{
Johannes Berg4c476992010-10-04 21:36:35 +02003255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003256 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003257 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003258 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003259 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003260
Johannes Bergb9454e82009-07-08 13:29:08 +02003261 err = nl80211_parse_key(info, &key);
3262 if (err)
3263 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003264
3265 if (info->attrs[NL80211_ATTR_MAC])
3266 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3267
Johannes Berge31b8212010-10-05 19:39:30 +02003268 if (key.type == -1) {
3269 if (mac_addr)
3270 key.type = NL80211_KEYTYPE_PAIRWISE;
3271 else
3272 key.type = NL80211_KEYTYPE_GROUP;
3273 }
3274
3275 /* for now */
3276 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3277 key.type != NL80211_KEYTYPE_GROUP)
3278 return -EINVAL;
3279
Johannes Berg4c476992010-10-04 21:36:35 +02003280 if (!rdev->ops->del_key)
3281 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003282
Johannes Bergfffd0932009-07-08 14:22:54 +02003283 wdev_lock(dev->ieee80211_ptr);
3284 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003285
Johannes Berg0fa7b392015-01-23 11:10:12 +01003286 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003287 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3288 err = -ENOENT;
3289
Johannes Bergfffd0932009-07-08 14:22:54 +02003290 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003291 err = rdev_del_key(rdev, dev, key.idx,
3292 key.type == NL80211_KEYTYPE_PAIRWISE,
3293 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003294
Johannes Berg3d23e342009-09-29 23:27:28 +02003295#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003296 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003297 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003298 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003299 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003300 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3301 }
3302#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003303 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003304
Johannes Berg41ade002007-12-19 02:03:29 +01003305 return err;
3306}
3307
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303308/* This function returns an error or the number of nested attributes */
3309static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3310{
3311 struct nlattr *attr;
3312 int n_entries = 0, tmp;
3313
3314 nla_for_each_nested(attr, nl_attr, tmp) {
3315 if (nla_len(attr) != ETH_ALEN)
3316 return -EINVAL;
3317
3318 n_entries++;
3319 }
3320
3321 return n_entries;
3322}
3323
3324/*
3325 * This function parses ACL information and allocates memory for ACL data.
3326 * On successful return, the calling function is responsible to free the
3327 * ACL buffer returned by this function.
3328 */
3329static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3330 struct genl_info *info)
3331{
3332 enum nl80211_acl_policy acl_policy;
3333 struct nlattr *attr;
3334 struct cfg80211_acl_data *acl;
3335 int i = 0, n_entries, tmp;
3336
3337 if (!wiphy->max_acl_mac_addrs)
3338 return ERR_PTR(-EOPNOTSUPP);
3339
3340 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3341 return ERR_PTR(-EINVAL);
3342
3343 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3344 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3345 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3346 return ERR_PTR(-EINVAL);
3347
3348 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3349 return ERR_PTR(-EINVAL);
3350
3351 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3352 if (n_entries < 0)
3353 return ERR_PTR(n_entries);
3354
3355 if (n_entries > wiphy->max_acl_mac_addrs)
3356 return ERR_PTR(-ENOTSUPP);
3357
3358 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3359 GFP_KERNEL);
3360 if (!acl)
3361 return ERR_PTR(-ENOMEM);
3362
3363 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3364 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3365 i++;
3366 }
3367
3368 acl->n_acl_entries = n_entries;
3369 acl->acl_policy = acl_policy;
3370
3371 return acl;
3372}
3373
3374static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3375{
3376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3377 struct net_device *dev = info->user_ptr[1];
3378 struct cfg80211_acl_data *acl;
3379 int err;
3380
3381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3382 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3383 return -EOPNOTSUPP;
3384
3385 if (!dev->ieee80211_ptr->beacon_interval)
3386 return -EINVAL;
3387
3388 acl = parse_acl_data(&rdev->wiphy, info);
3389 if (IS_ERR(acl))
3390 return PTR_ERR(acl);
3391
3392 err = rdev_set_mac_acl(rdev, dev, acl);
3393
3394 kfree(acl);
3395
3396 return err;
3397}
3398
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303399static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3400 u8 *rates, u8 rates_len)
3401{
3402 u8 i;
3403 u32 mask = 0;
3404
3405 for (i = 0; i < rates_len; i++) {
3406 int rate = (rates[i] & 0x7f) * 5;
3407 int ridx;
3408
3409 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3410 struct ieee80211_rate *srate =
3411 &sband->bitrates[ridx];
3412 if (rate == srate->bitrate) {
3413 mask |= 1 << ridx;
3414 break;
3415 }
3416 }
3417 if (ridx == sband->n_bitrates)
3418 return 0; /* rate not found */
3419 }
3420
3421 return mask;
3422}
3423
3424static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3425 u8 *rates, u8 rates_len,
3426 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3427{
3428 u8 i;
3429
3430 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3431
3432 for (i = 0; i < rates_len; i++) {
3433 int ridx, rbit;
3434
3435 ridx = rates[i] / 8;
3436 rbit = BIT(rates[i] % 8);
3437
3438 /* check validity */
3439 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3440 return false;
3441
3442 /* check availability */
3443 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3444 mcs[ridx] |= rbit;
3445 else
3446 return false;
3447 }
3448
3449 return true;
3450}
3451
3452static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3453{
3454 u16 mcs_mask = 0;
3455
3456 switch (vht_mcs_map) {
3457 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3458 break;
3459 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3460 mcs_mask = 0x00FF;
3461 break;
3462 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3463 mcs_mask = 0x01FF;
3464 break;
3465 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3466 mcs_mask = 0x03FF;
3467 break;
3468 default:
3469 break;
3470 }
3471
3472 return mcs_mask;
3473}
3474
3475static void vht_build_mcs_mask(u16 vht_mcs_map,
3476 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3477{
3478 u8 nss;
3479
3480 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3481 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3482 vht_mcs_map >>= 2;
3483 }
3484}
3485
3486static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3487 struct nl80211_txrate_vht *txrate,
3488 u16 mcs[NL80211_VHT_NSS_MAX])
3489{
3490 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3491 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3492 u8 i;
3493
3494 if (!sband->vht_cap.vht_supported)
3495 return false;
3496
3497 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3498
3499 /* Build vht_mcs_mask from VHT capabilities */
3500 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3501
3502 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3503 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3504 mcs[i] = txrate->mcs[i];
3505 else
3506 return false;
3507 }
3508
3509 return true;
3510}
3511
3512static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3513 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3514 .len = NL80211_MAX_SUPP_RATES },
3515 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3516 .len = NL80211_MAX_SUPP_HT_RATES },
3517 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3518 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3519};
3520
3521static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3522 struct cfg80211_bitrate_mask *mask)
3523{
3524 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3526 int rem, i;
3527 struct nlattr *tx_rates;
3528 struct ieee80211_supported_band *sband;
3529 u16 vht_tx_mcs_map;
3530
3531 memset(mask, 0, sizeof(*mask));
3532 /* Default to all rates enabled */
3533 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3534 sband = rdev->wiphy.bands[i];
3535
3536 if (!sband)
3537 continue;
3538
3539 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3540 memcpy(mask->control[i].ht_mcs,
3541 sband->ht_cap.mcs.rx_mask,
3542 sizeof(mask->control[i].ht_mcs));
3543
3544 if (!sband->vht_cap.vht_supported)
3545 continue;
3546
3547 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3548 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3549 }
3550
3551 /* if no rates are given set it back to the defaults */
3552 if (!info->attrs[NL80211_ATTR_TX_RATES])
3553 goto out;
3554
3555 /* The nested attribute uses enum nl80211_band as the index. This maps
3556 * directly to the enum nl80211_band values used in cfg80211.
3557 */
3558 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3559 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3560 enum nl80211_band band = nla_type(tx_rates);
3561 int err;
3562
3563 if (band < 0 || band >= NUM_NL80211_BANDS)
3564 return -EINVAL;
3565 sband = rdev->wiphy.bands[band];
3566 if (sband == NULL)
3567 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003568 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
3569 nl80211_txattr_policy);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303570 if (err)
3571 return err;
3572 if (tb[NL80211_TXRATE_LEGACY]) {
3573 mask->control[band].legacy = rateset_to_mask(
3574 sband,
3575 nla_data(tb[NL80211_TXRATE_LEGACY]),
3576 nla_len(tb[NL80211_TXRATE_LEGACY]));
3577 if ((mask->control[band].legacy == 0) &&
3578 nla_len(tb[NL80211_TXRATE_LEGACY]))
3579 return -EINVAL;
3580 }
3581 if (tb[NL80211_TXRATE_HT]) {
3582 if (!ht_rateset_to_mask(
3583 sband,
3584 nla_data(tb[NL80211_TXRATE_HT]),
3585 nla_len(tb[NL80211_TXRATE_HT]),
3586 mask->control[band].ht_mcs))
3587 return -EINVAL;
3588 }
3589 if (tb[NL80211_TXRATE_VHT]) {
3590 if (!vht_set_mcs_mask(
3591 sband,
3592 nla_data(tb[NL80211_TXRATE_VHT]),
3593 mask->control[band].vht_mcs))
3594 return -EINVAL;
3595 }
3596 if (tb[NL80211_TXRATE_GI]) {
3597 mask->control[band].gi =
3598 nla_get_u8(tb[NL80211_TXRATE_GI]);
3599 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3600 return -EINVAL;
3601 }
3602
3603 if (mask->control[band].legacy == 0) {
3604 /* don't allow empty legacy rates if HT or VHT
3605 * are not even supported.
3606 */
3607 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3608 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3609 return -EINVAL;
3610
3611 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3612 if (mask->control[band].ht_mcs[i])
3613 goto out;
3614
3615 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3616 if (mask->control[band].vht_mcs[i])
3617 goto out;
3618
3619 /* legacy and mcs rates may not be both empty */
3620 return -EINVAL;
3621 }
3622 }
3623
3624out:
3625 return 0;
3626}
3627
Johannes Berg8564e382016-09-19 09:44:44 +02003628static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3629 enum nl80211_band band,
3630 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303631{
Johannes Berg8564e382016-09-19 09:44:44 +02003632 u32 count_ht, count_vht, i;
3633 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303634
3635 /* Allow only one rate */
3636 if (hweight32(rate) > 1)
3637 return -EINVAL;
3638
3639 count_ht = 0;
3640 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003641 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303642 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003643 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303644 count_ht++;
3645 if (count_ht > 1)
3646 return -EINVAL;
3647 }
3648 if (count_ht && rate)
3649 return -EINVAL;
3650 }
3651
3652 count_vht = 0;
3653 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003654 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303655 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003656 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303657 count_vht++;
3658 if (count_vht > 1)
3659 return -EINVAL;
3660 }
3661 if (count_vht && rate)
3662 return -EINVAL;
3663 }
3664
3665 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3666 return -EINVAL;
3667
Johannes Berg8564e382016-09-19 09:44:44 +02003668 if (rate &&
3669 !wiphy_ext_feature_isset(&rdev->wiphy,
3670 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3671 return -EINVAL;
3672 if (count_ht &&
3673 !wiphy_ext_feature_isset(&rdev->wiphy,
3674 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3675 return -EINVAL;
3676 if (count_vht &&
3677 !wiphy_ext_feature_isset(&rdev->wiphy,
3678 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3679 return -EINVAL;
3680
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303681 return 0;
3682}
3683
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003684static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003685 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003686{
Johannes Berg88600202012-02-13 15:17:18 +01003687 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003688
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003689 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3690 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3691 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3692 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003693 return -EINVAL;
3694
Johannes Berg88600202012-02-13 15:17:18 +01003695 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003696
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003697 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3698 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3699 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003700 if (!bcn->head_len)
3701 return -EINVAL;
3702 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003703 }
3704
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003705 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3706 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3707 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003708 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003709 }
3710
Johannes Berg4c476992010-10-04 21:36:35 +02003711 if (!haveinfo)
3712 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003713
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003714 if (attrs[NL80211_ATTR_IE]) {
3715 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3716 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003717 }
3718
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003719 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003720 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003721 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003722 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003723 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003724 }
3725
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003726 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003727 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003728 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003729 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003730 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003731 }
3732
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003733 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3734 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3735 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003736 }
3737
Johannes Berg88600202012-02-13 15:17:18 +01003738 return 0;
3739}
3740
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003741static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3742 struct cfg80211_ap_settings *params)
3743{
3744 struct wireless_dev *wdev;
3745 bool ret = false;
3746
Johannes Berg53873f12016-05-03 16:52:04 +03003747 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003748 if (wdev->iftype != NL80211_IFTYPE_AP &&
3749 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3750 continue;
3751
Johannes Berg683b6d32012-11-08 21:25:48 +01003752 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003753 continue;
3754
Johannes Berg683b6d32012-11-08 21:25:48 +01003755 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003756 ret = true;
3757 break;
3758 }
3759
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003760 return ret;
3761}
3762
Jouni Malinene39e5b52012-09-30 19:29:39 +03003763static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3764 enum nl80211_auth_type auth_type,
3765 enum nl80211_commands cmd)
3766{
3767 if (auth_type > NL80211_AUTHTYPE_MAX)
3768 return false;
3769
3770 switch (cmd) {
3771 case NL80211_CMD_AUTHENTICATE:
3772 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3773 auth_type == NL80211_AUTHTYPE_SAE)
3774 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003775 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3776 NL80211_EXT_FEATURE_FILS_STA) &&
3777 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3778 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3779 auth_type == NL80211_AUTHTYPE_FILS_PK))
3780 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003781 return true;
3782 case NL80211_CMD_CONNECT:
3783 case NL80211_CMD_START_AP:
3784 /* SAE not supported yet */
3785 if (auth_type == NL80211_AUTHTYPE_SAE)
3786 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003787 /* FILS not supported yet */
3788 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3789 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3790 auth_type == NL80211_AUTHTYPE_FILS_PK)
3791 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003792 return true;
3793 default:
3794 return false;
3795 }
3796}
3797
Johannes Berg88600202012-02-13 15:17:18 +01003798static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3799{
3800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3801 struct net_device *dev = info->user_ptr[1];
3802 struct wireless_dev *wdev = dev->ieee80211_ptr;
3803 struct cfg80211_ap_settings params;
3804 int err;
3805
3806 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3807 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3808 return -EOPNOTSUPP;
3809
3810 if (!rdev->ops->start_ap)
3811 return -EOPNOTSUPP;
3812
3813 if (wdev->beacon_interval)
3814 return -EALREADY;
3815
3816 memset(&params, 0, sizeof(params));
3817
3818 /* these are required for START_AP */
3819 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3820 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3821 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3822 return -EINVAL;
3823
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003824 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003825 if (err)
3826 return err;
3827
3828 params.beacon_interval =
3829 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3830 params.dtim_period =
3831 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3832
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303833 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3834 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003835 if (err)
3836 return err;
3837
3838 /*
3839 * In theory, some of these attributes should be required here
3840 * but since they were not used when the command was originally
3841 * added, keep them optional for old user space programs to let
3842 * them continue to work with drivers that do not need the
3843 * additional information -- drivers must check!
3844 */
3845 if (info->attrs[NL80211_ATTR_SSID]) {
3846 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3847 params.ssid_len =
3848 nla_len(info->attrs[NL80211_ATTR_SSID]);
3849 if (params.ssid_len == 0 ||
3850 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3851 return -EINVAL;
3852 }
3853
3854 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3855 params.hidden_ssid = nla_get_u32(
3856 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3857 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3858 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3859 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3860 return -EINVAL;
3861 }
3862
3863 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3864
3865 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3866 params.auth_type = nla_get_u32(
3867 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003868 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3869 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003870 return -EINVAL;
3871 } else
3872 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3873
3874 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3875 NL80211_MAX_NR_CIPHER_SUITES);
3876 if (err)
3877 return err;
3878
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303879 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3880 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3881 return -EOPNOTSUPP;
3882 params.inactivity_timeout = nla_get_u16(
3883 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3884 }
3885
Johannes Berg53cabad2012-11-14 15:17:28 +01003886 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3888 return -EINVAL;
3889 params.p2p_ctwindow =
3890 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3891 if (params.p2p_ctwindow > 127)
3892 return -EINVAL;
3893 if (params.p2p_ctwindow != 0 &&
3894 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3895 return -EINVAL;
3896 }
3897
3898 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3899 u8 tmp;
3900
3901 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3902 return -EINVAL;
3903 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3904 if (tmp > 1)
3905 return -EINVAL;
3906 params.p2p_opp_ps = tmp;
3907 if (params.p2p_opp_ps != 0 &&
3908 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3909 return -EINVAL;
3910 }
3911
Johannes Bergaa430da2012-05-16 23:50:18 +02003912 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003913 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3914 if (err)
3915 return err;
3916 } else if (wdev->preset_chandef.chan) {
3917 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003918 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003919 return -EINVAL;
3920
Arik Nemtsov923b3522015-07-08 15:41:44 +03003921 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3922 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003923 return -EINVAL;
3924
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303925 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3926 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3927 if (err)
3928 return err;
3929
Johannes Berg8564e382016-09-19 09:44:44 +02003930 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3931 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303932 if (err)
3933 return err;
3934 }
3935
Eliad Peller18998c32014-09-10 14:07:34 +03003936 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3937 params.smps_mode =
3938 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3939 switch (params.smps_mode) {
3940 case NL80211_SMPS_OFF:
3941 break;
3942 case NL80211_SMPS_STATIC:
3943 if (!(rdev->wiphy.features &
3944 NL80211_FEATURE_STATIC_SMPS))
3945 return -EINVAL;
3946 break;
3947 case NL80211_SMPS_DYNAMIC:
3948 if (!(rdev->wiphy.features &
3949 NL80211_FEATURE_DYNAMIC_SMPS))
3950 return -EINVAL;
3951 break;
3952 default:
3953 return -EINVAL;
3954 }
3955 } else {
3956 params.smps_mode = NL80211_SMPS_OFF;
3957 }
3958
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303959 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3960 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3961 return -EOPNOTSUPP;
3962
Ola Olsson4baf6be2015-10-29 07:04:58 +01003963 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3964 params.acl = parse_acl_data(&rdev->wiphy, info);
3965 if (IS_ERR(params.acl))
3966 return PTR_ERR(params.acl);
3967 }
3968
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003969 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003970 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003971 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003972 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003973 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003974 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003975 wdev->ssid_len = params.ssid_len;
3976 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003977 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003978 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303979
3980 kfree(params.acl);
3981
Johannes Berg56d18932011-05-09 18:41:15 +02003982 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003983}
3984
Johannes Berg88600202012-02-13 15:17:18 +01003985static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3986{
3987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3988 struct net_device *dev = info->user_ptr[1];
3989 struct wireless_dev *wdev = dev->ieee80211_ptr;
3990 struct cfg80211_beacon_data params;
3991 int err;
3992
3993 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3994 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3995 return -EOPNOTSUPP;
3996
3997 if (!rdev->ops->change_beacon)
3998 return -EOPNOTSUPP;
3999
4000 if (!wdev->beacon_interval)
4001 return -EINVAL;
4002
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004003 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004004 if (err)
4005 return err;
4006
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004007 wdev_lock(wdev);
4008 err = rdev_change_beacon(rdev, dev, &params);
4009 wdev_unlock(wdev);
4010
4011 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004012}
4013
4014static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004015{
Johannes Berg4c476992010-10-04 21:36:35 +02004016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4017 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004018
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004019 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004020}
4021
Johannes Berg5727ef12007-12-19 02:03:34 +01004022static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4023 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4024 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4025 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004026 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004027 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004028 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004029};
4030
Johannes Bergeccb8e82009-05-11 21:57:56 +03004031static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004032 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004033 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004034{
4035 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004036 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004037 int flag;
4038
Johannes Bergeccb8e82009-05-11 21:57:56 +03004039 /*
4040 * Try parsing the new attribute first so userspace
4041 * can specify both for older kernels.
4042 */
4043 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4044 if (nla) {
4045 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004046
Johannes Bergeccb8e82009-05-11 21:57:56 +03004047 sta_flags = nla_data(nla);
4048 params->sta_flags_mask = sta_flags->mask;
4049 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004050 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004051 if ((params->sta_flags_mask |
4052 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4053 return -EINVAL;
4054 return 0;
4055 }
4056
4057 /* if present, parse the old attribute */
4058
4059 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004060 if (!nla)
4061 return 0;
4062
4063 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4064 nla, sta_flags_policy))
4065 return -EINVAL;
4066
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004067 /*
4068 * Only allow certain flags for interface types so that
4069 * other attributes are silently ignored. Remember that
4070 * this is backward compatibility code with old userspace
4071 * and shouldn't be hit in other cases anyway.
4072 */
4073 switch (iftype) {
4074 case NL80211_IFTYPE_AP:
4075 case NL80211_IFTYPE_AP_VLAN:
4076 case NL80211_IFTYPE_P2P_GO:
4077 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4078 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4079 BIT(NL80211_STA_FLAG_WME) |
4080 BIT(NL80211_STA_FLAG_MFP);
4081 break;
4082 case NL80211_IFTYPE_P2P_CLIENT:
4083 case NL80211_IFTYPE_STATION:
4084 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4085 BIT(NL80211_STA_FLAG_TDLS_PEER);
4086 break;
4087 case NL80211_IFTYPE_MESH_POINT:
4088 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4089 BIT(NL80211_STA_FLAG_MFP) |
4090 BIT(NL80211_STA_FLAG_AUTHORIZED);
4091 default:
4092 return -EINVAL;
4093 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004094
Johannes Berg3383b5a2012-05-10 20:14:43 +02004095 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4096 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004097 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004098
Johannes Berg3383b5a2012-05-10 20:14:43 +02004099 /* no longer support new API additions in old API */
4100 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4101 return -EINVAL;
4102 }
4103 }
4104
Johannes Berg5727ef12007-12-19 02:03:34 +01004105 return 0;
4106}
4107
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004108static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4109 int attr)
4110{
4111 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004112 u32 bitrate;
4113 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004114 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004115
4116 rate = nla_nest_start(msg, attr);
4117 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004118 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004119
4120 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4121 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004122 /* report 16-bit bitrate only if we can */
4123 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004124 if (bitrate > 0 &&
4125 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4126 return false;
4127 if (bitrate_compat > 0 &&
4128 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4129 return false;
4130
Johannes Bergb51f3be2015-01-15 16:14:02 +01004131 switch (info->bw) {
4132 case RATE_INFO_BW_5:
4133 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4134 break;
4135 case RATE_INFO_BW_10:
4136 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4137 break;
4138 default:
4139 WARN_ON(1);
4140 /* fall through */
4141 case RATE_INFO_BW_20:
4142 rate_flg = 0;
4143 break;
4144 case RATE_INFO_BW_40:
4145 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4146 break;
4147 case RATE_INFO_BW_80:
4148 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4149 break;
4150 case RATE_INFO_BW_160:
4151 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4152 break;
4153 }
4154
4155 if (rate_flg && nla_put_flag(msg, rate_flg))
4156 return false;
4157
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004158 if (info->flags & RATE_INFO_FLAGS_MCS) {
4159 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4160 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004161 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4162 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4163 return false;
4164 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4165 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4166 return false;
4167 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4168 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004169 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4170 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4171 return false;
4172 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004173
4174 nla_nest_end(msg, rate);
4175 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004176}
4177
Felix Fietkau119363c2013-04-22 16:29:30 +02004178static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4179 int id)
4180{
4181 void *attr;
4182 int i = 0;
4183
4184 if (!mask)
4185 return true;
4186
4187 attr = nla_nest_start(msg, id);
4188 if (!attr)
4189 return false;
4190
4191 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4192 if (!(mask & BIT(i)))
4193 continue;
4194
4195 if (nla_put_u8(msg, i, signal[i]))
4196 return false;
4197 }
4198
4199 nla_nest_end(msg, attr);
4200
4201 return true;
4202}
4203
Johannes Bergcf5ead82014-11-14 17:14:00 +01004204static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4205 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004206 struct cfg80211_registered_device *rdev,
4207 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004208 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004209{
4210 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004211 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004212
Johannes Bergcf5ead82014-11-14 17:14:00 +01004213 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004214 if (!hdr)
4215 return -1;
4216
David S. Miller9360ffd2012-03-29 04:41:26 -04004217 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4218 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4219 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4220 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004221
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004222 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4223 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004224 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004225
4226#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004227 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304228 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004229 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4230 sinfo->memb)) \
4231 goto nla_put_failure; \
4232 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004233#define PUT_SINFO_U64(attr, memb) do { \
4234 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4235 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4236 sinfo->memb, NL80211_STA_INFO_PAD)) \
4237 goto nla_put_failure; \
4238 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004239
4240 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4241 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4242
4243 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4244 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004245 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004246 (u32)sinfo->rx_bytes))
4247 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004248
4249 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4250 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004251 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4252 (u32)sinfo->tx_bytes))
4253 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004254
Johannes Bergd686b922016-04-26 09:54:11 +02004255 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4256 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004257 PUT_SINFO(LLID, llid, u16);
4258 PUT_SINFO(PLID, plid, u16);
4259 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004260 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004261
John W. Linville66266b32012-03-15 13:25:41 -04004262 switch (rdev->wiphy.signal_type) {
4263 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004264 PUT_SINFO(SIGNAL, signal, u8);
4265 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004266 break;
4267 default:
4268 break;
4269 }
Johannes Berg319090b2014-11-17 14:08:11 +01004270 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004271 if (!nl80211_put_signal(msg, sinfo->chains,
4272 sinfo->chain_signal,
4273 NL80211_STA_INFO_CHAIN_SIGNAL))
4274 goto nla_put_failure;
4275 }
Johannes Berg319090b2014-11-17 14:08:11 +01004276 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004277 if (!nl80211_put_signal(msg, sinfo->chains,
4278 sinfo->chain_signal_avg,
4279 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4280 goto nla_put_failure;
4281 }
Johannes Berg319090b2014-11-17 14:08:11 +01004282 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004283 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4284 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004285 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004286 }
Johannes Berg319090b2014-11-17 14:08:11 +01004287 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004288 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4289 NL80211_STA_INFO_RX_BITRATE))
4290 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004291 }
Johannes Berg319090b2014-11-17 14:08:11 +01004292
4293 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4294 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4295 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4296 PUT_SINFO(TX_FAILED, tx_failed, u32);
4297 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4298 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4299 PUT_SINFO(LOCAL_PM, local_pm, u32);
4300 PUT_SINFO(PEER_PM, peer_pm, u32);
4301 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4302
4303 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004304 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4305 if (!bss_param)
4306 goto nla_put_failure;
4307
David S. Miller9360ffd2012-03-29 04:41:26 -04004308 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4309 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4310 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4311 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4312 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4313 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4314 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4315 sinfo->bss_param.dtim_period) ||
4316 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4317 sinfo->bss_param.beacon_interval))
4318 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004319
4320 nla_nest_end(msg, bss_param);
4321 }
Johannes Berg319090b2014-11-17 14:08:11 +01004322 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004323 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4324 sizeof(struct nl80211_sta_flag_update),
4325 &sinfo->sta_flags))
4326 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004327
Johannes Bergd686b922016-04-26 09:54:11 +02004328 PUT_SINFO_U64(T_OFFSET, t_offset);
4329 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4330 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004331 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004332
4333#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004334#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004335
4336 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4337 struct nlattr *tidsattr;
4338 int tid;
4339
4340 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4341 if (!tidsattr)
4342 goto nla_put_failure;
4343
4344 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4345 struct cfg80211_tid_stats *tidstats;
4346 struct nlattr *tidattr;
4347
4348 tidstats = &sinfo->pertid[tid];
4349
4350 if (!tidstats->filled)
4351 continue;
4352
4353 tidattr = nla_nest_start(msg, tid + 1);
4354 if (!tidattr)
4355 goto nla_put_failure;
4356
Johannes Bergd686b922016-04-26 09:54:11 +02004357#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004358 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004359 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4360 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004361 goto nla_put_failure; \
4362 } while (0)
4363
Johannes Bergd686b922016-04-26 09:54:11 +02004364 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4365 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4366 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4367 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004368
Johannes Bergd686b922016-04-26 09:54:11 +02004369#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004370 nla_nest_end(msg, tidattr);
4371 }
4372
4373 nla_nest_end(msg, tidsattr);
4374 }
4375
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004377
Johannes Berg319090b2014-11-17 14:08:11 +01004378 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004379 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4380 sinfo->assoc_req_ies))
4381 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004382
Johannes Berg053c0952015-01-16 22:09:00 +01004383 genlmsg_end(msg, hdr);
4384 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004385
4386 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004387 genlmsg_cancel(msg, hdr);
4388 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004389}
4390
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004392 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004393{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004394 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004395 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004396 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004398 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004399 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004401 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004402 if (err)
4403 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004404
Johannes Berg97990a02013-04-19 01:02:55 +02004405 if (!wdev->netdev) {
4406 err = -EINVAL;
4407 goto out_err;
4408 }
4409
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004410 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004411 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004412 goto out_err;
4413 }
4414
Johannes Bergbba95fe2008-07-29 13:22:51 +02004415 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004416 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004417 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004418 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004419 if (err == -ENOENT)
4420 break;
4421 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004422 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004423
Johannes Bergcf5ead82014-11-14 17:14:00 +01004424 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004425 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004426 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004427 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004428 &sinfo) < 0)
4429 goto out;
4430
4431 sta_idx++;
4432 }
4433
Johannes Bergbba95fe2008-07-29 13:22:51 +02004434 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004435 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004436 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004437 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004438 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004439
4440 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004441}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004442
Johannes Berg5727ef12007-12-19 02:03:34 +01004443static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4444{
Johannes Berg4c476992010-10-04 21:36:35 +02004445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4446 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004448 struct sk_buff *msg;
4449 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004450 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004451
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004452 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004453
4454 if (!info->attrs[NL80211_ATTR_MAC])
4455 return -EINVAL;
4456
4457 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4458
Johannes Berg4c476992010-10-04 21:36:35 +02004459 if (!rdev->ops->get_station)
4460 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004461
Hila Gonene35e4d22012-06-27 17:19:42 +03004462 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004463 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004464 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004465
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004467 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004468 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004469
Johannes Bergcf5ead82014-11-14 17:14:00 +01004470 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4471 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004472 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004473 nlmsg_free(msg);
4474 return -ENOBUFS;
4475 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004476
Johannes Berg4c476992010-10-04 21:36:35 +02004477 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004478}
4479
Johannes Berg77ee7c82013-02-15 00:48:33 +01004480int cfg80211_check_station_change(struct wiphy *wiphy,
4481 struct station_parameters *params,
4482 enum cfg80211_station_type statype)
4483{
Ayala Bekere4208422015-10-23 11:20:06 +03004484 if (params->listen_interval != -1 &&
4485 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004486 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004487
Ayala Beker17b94242016-03-17 15:41:38 +02004488 if (params->support_p2p_ps != -1 &&
4489 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4490 return -EINVAL;
4491
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004492 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004493 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4494 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004495 return -EINVAL;
4496
4497 /* When you run into this, adjust the code below for the new flag */
4498 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4499
4500 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004501 case CFG80211_STA_MESH_PEER_KERNEL:
4502 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004503 /*
4504 * No ignoring the TDLS flag here -- the userspace mesh
4505 * code doesn't have the bug of including TDLS in the
4506 * mask everywhere.
4507 */
4508 if (params->sta_flags_mask &
4509 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4510 BIT(NL80211_STA_FLAG_MFP) |
4511 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4512 return -EINVAL;
4513 break;
4514 case CFG80211_STA_TDLS_PEER_SETUP:
4515 case CFG80211_STA_TDLS_PEER_ACTIVE:
4516 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4517 return -EINVAL;
4518 /* ignore since it can't change */
4519 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4520 break;
4521 default:
4522 /* disallow mesh-specific things */
4523 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4524 return -EINVAL;
4525 if (params->local_pm)
4526 return -EINVAL;
4527 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4528 return -EINVAL;
4529 }
4530
4531 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4532 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4533 /* TDLS can't be set, ... */
4534 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4535 return -EINVAL;
4536 /*
4537 * ... but don't bother the driver with it. This works around
4538 * a hostapd/wpa_supplicant issue -- it always includes the
4539 * TLDS_PEER flag in the mask even for AP mode.
4540 */
4541 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4542 }
4543
Ayala Beker47edb112015-09-21 15:49:53 +03004544 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4545 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004546 /* reject other things that can't change */
4547 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4548 return -EINVAL;
4549 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4550 return -EINVAL;
4551 if (params->supported_rates)
4552 return -EINVAL;
4553 if (params->ext_capab || params->ht_capa || params->vht_capa)
4554 return -EINVAL;
4555 }
4556
Ayala Beker47edb112015-09-21 15:49:53 +03004557 if (statype != CFG80211_STA_AP_CLIENT &&
4558 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004559 if (params->vlan)
4560 return -EINVAL;
4561 }
4562
4563 switch (statype) {
4564 case CFG80211_STA_AP_MLME_CLIENT:
4565 /* Use this only for authorizing/unauthorizing a station */
4566 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4567 return -EOPNOTSUPP;
4568 break;
4569 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004570 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004571 /* accept only the listed bits */
4572 if (params->sta_flags_mask &
4573 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4574 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4575 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4576 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4577 BIT(NL80211_STA_FLAG_WME) |
4578 BIT(NL80211_STA_FLAG_MFP)))
4579 return -EINVAL;
4580
4581 /* but authenticated/associated only if driver handles it */
4582 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4583 params->sta_flags_mask &
4584 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4585 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4586 return -EINVAL;
4587 break;
4588 case CFG80211_STA_IBSS:
4589 case CFG80211_STA_AP_STA:
4590 /* reject any changes other than AUTHORIZED */
4591 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4592 return -EINVAL;
4593 break;
4594 case CFG80211_STA_TDLS_PEER_SETUP:
4595 /* reject any changes other than AUTHORIZED or WME */
4596 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4597 BIT(NL80211_STA_FLAG_WME)))
4598 return -EINVAL;
4599 /* force (at least) rates when authorizing */
4600 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4601 !params->supported_rates)
4602 return -EINVAL;
4603 break;
4604 case CFG80211_STA_TDLS_PEER_ACTIVE:
4605 /* reject any changes */
4606 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004607 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004608 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4609 return -EINVAL;
4610 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004611 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004612 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4613 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004614 return -EINVAL;
4615 break;
4616 }
4617
4618 return 0;
4619}
4620EXPORT_SYMBOL(cfg80211_check_station_change);
4621
Johannes Berg5727ef12007-12-19 02:03:34 +01004622/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004623 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004624 */
Johannes Berg80b99892011-11-18 16:23:01 +01004625static struct net_device *get_vlan(struct genl_info *info,
4626 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004627{
Johannes Berg463d0182009-07-14 00:33:35 +02004628 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004629 struct net_device *v;
4630 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004631
Johannes Berg80b99892011-11-18 16:23:01 +01004632 if (!vlanattr)
4633 return NULL;
4634
4635 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4636 if (!v)
4637 return ERR_PTR(-ENODEV);
4638
4639 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4640 ret = -EINVAL;
4641 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004642 }
Johannes Berg80b99892011-11-18 16:23:01 +01004643
Johannes Berg77ee7c82013-02-15 00:48:33 +01004644 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4645 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4646 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4647 ret = -EINVAL;
4648 goto error;
4649 }
4650
Johannes Berg80b99892011-11-18 16:23:01 +01004651 if (!netif_running(v)) {
4652 ret = -ENETDOWN;
4653 goto error;
4654 }
4655
4656 return v;
4657 error:
4658 dev_put(v);
4659 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004660}
4661
Johannes Berg94e860f2014-01-20 23:58:15 +01004662static const struct nla_policy
4663nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004664 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4665 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4666};
4667
Johannes Bergff276692013-02-15 00:09:01 +01004668static int nl80211_parse_sta_wme(struct genl_info *info,
4669 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004670{
Jouni Malinendf881292013-02-14 21:10:54 +02004671 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4672 struct nlattr *nla;
4673 int err;
4674
Jouni Malinendf881292013-02-14 21:10:54 +02004675 /* parse WME attributes if present */
4676 if (!info->attrs[NL80211_ATTR_STA_WME])
4677 return 0;
4678
4679 nla = info->attrs[NL80211_ATTR_STA_WME];
4680 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4681 nl80211_sta_wme_policy);
4682 if (err)
4683 return err;
4684
4685 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4686 params->uapsd_queues = nla_get_u8(
4687 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4688 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4689 return -EINVAL;
4690
4691 if (tb[NL80211_STA_WME_MAX_SP])
4692 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4693
4694 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4695 return -EINVAL;
4696
4697 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4698
4699 return 0;
4700}
4701
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304702static int nl80211_parse_sta_channel_info(struct genl_info *info,
4703 struct station_parameters *params)
4704{
4705 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4706 params->supported_channels =
4707 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4708 params->supported_channels_len =
4709 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4710 /*
4711 * Need to include at least one (first channel, number of
4712 * channels) tuple for each subband, and must have proper
4713 * tuples for the rest of the data as well.
4714 */
4715 if (params->supported_channels_len < 2)
4716 return -EINVAL;
4717 if (params->supported_channels_len % 2)
4718 return -EINVAL;
4719 }
4720
4721 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4722 params->supported_oper_classes =
4723 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4724 params->supported_oper_classes_len =
4725 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4726 /*
4727 * The value of the Length field of the Supported Operating
4728 * Classes element is between 2 and 253.
4729 */
4730 if (params->supported_oper_classes_len < 2 ||
4731 params->supported_oper_classes_len > 253)
4732 return -EINVAL;
4733 }
4734 return 0;
4735}
4736
Johannes Bergff276692013-02-15 00:09:01 +01004737static int nl80211_set_station_tdls(struct genl_info *info,
4738 struct station_parameters *params)
4739{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304740 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004741 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004742 if (info->attrs[NL80211_ATTR_PEER_AID])
4743 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004744 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4745 params->ht_capa =
4746 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4747 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4748 params->vht_capa =
4749 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4750
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304751 err = nl80211_parse_sta_channel_info(info, params);
4752 if (err)
4753 return err;
4754
Johannes Bergff276692013-02-15 00:09:01 +01004755 return nl80211_parse_sta_wme(info, params);
4756}
4757
Johannes Berg5727ef12007-12-19 02:03:34 +01004758static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4759{
Johannes Berg4c476992010-10-04 21:36:35 +02004760 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004761 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004762 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004763 u8 *mac_addr;
4764 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004765
4766 memset(&params, 0, sizeof(params));
4767
Johannes Berg77ee7c82013-02-15 00:48:33 +01004768 if (!rdev->ops->change_station)
4769 return -EOPNOTSUPP;
4770
Ayala Bekere4208422015-10-23 11:20:06 +03004771 /*
4772 * AID and listen_interval properties can be set only for unassociated
4773 * station. Include these parameters here and will check them in
4774 * cfg80211_check_station_change().
4775 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004776 if (info->attrs[NL80211_ATTR_STA_AID])
4777 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004778
4779 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4780 params.listen_interval =
4781 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4782 else
4783 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004784
Ayala Beker17b94242016-03-17 15:41:38 +02004785 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4786 u8 tmp;
4787
4788 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4789 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4790 return -EINVAL;
4791
4792 params.support_p2p_ps = tmp;
4793 } else {
4794 params.support_p2p_ps = -1;
4795 }
4796
Johannes Berg5727ef12007-12-19 02:03:34 +01004797 if (!info->attrs[NL80211_ATTR_MAC])
4798 return -EINVAL;
4799
4800 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4801
4802 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4803 params.supported_rates =
4804 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4805 params.supported_rates_len =
4806 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4807 }
4808
Jouni Malinen9d62a982013-02-14 21:10:13 +02004809 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4810 params.capability =
4811 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4812 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4813 }
4814
4815 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4816 params.ext_capab =
4817 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4818 params.ext_capab_len =
4819 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4820 }
4821
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004822 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004823 return -EINVAL;
4824
Johannes Bergf8bacc22013-02-14 23:27:01 +01004825 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004826 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004827 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4828 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4829 return -EINVAL;
4830 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004831
Johannes Bergf8bacc22013-02-14 23:27:01 +01004832 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004833 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004834 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4835 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4836 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004837 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4838 params.peer_aid = nla_get_u16(
4839 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4840 if (params.peer_aid > IEEE80211_MAX_AID)
4841 return -EINVAL;
4842 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004843 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4844 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004845
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004846 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4847 enum nl80211_mesh_power_mode pm = nla_get_u32(
4848 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4849
4850 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4851 pm > NL80211_MESH_POWER_MAX)
4852 return -EINVAL;
4853
4854 params.local_pm = pm;
4855 }
4856
Johannes Berg77ee7c82013-02-15 00:48:33 +01004857 /* Include parameters for TDLS peer (will check later) */
4858 err = nl80211_set_station_tdls(info, &params);
4859 if (err)
4860 return err;
4861
4862 params.vlan = get_vlan(info, rdev);
4863 if (IS_ERR(params.vlan))
4864 return PTR_ERR(params.vlan);
4865
Johannes Berga97f4422009-06-18 17:23:43 +02004866 switch (dev->ieee80211_ptr->iftype) {
4867 case NL80211_IFTYPE_AP:
4868 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004869 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004870 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004871 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004872 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004873 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004874 break;
4875 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004876 err = -EOPNOTSUPP;
4877 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004878 }
4879
Johannes Berg77ee7c82013-02-15 00:48:33 +01004880 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004881 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004882
Johannes Berg77ee7c82013-02-15 00:48:33 +01004883 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004884 if (params.vlan)
4885 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004886
Johannes Berg5727ef12007-12-19 02:03:34 +01004887 return err;
4888}
4889
4890static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4891{
Johannes Berg4c476992010-10-04 21:36:35 +02004892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004893 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004894 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004895 struct station_parameters params;
4896 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004897 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4898 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004899
4900 memset(&params, 0, sizeof(params));
4901
Johannes Berg984c3112013-02-14 23:43:25 +01004902 if (!rdev->ops->add_station)
4903 return -EOPNOTSUPP;
4904
Johannes Berg5727ef12007-12-19 02:03:34 +01004905 if (!info->attrs[NL80211_ATTR_MAC])
4906 return -EINVAL;
4907
Johannes Berg5727ef12007-12-19 02:03:34 +01004908 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4909 return -EINVAL;
4910
4911 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4912 return -EINVAL;
4913
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004914 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4915 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004916 return -EINVAL;
4917
Johannes Berg5727ef12007-12-19 02:03:34 +01004918 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4919 params.supported_rates =
4920 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4921 params.supported_rates_len =
4922 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4923 params.listen_interval =
4924 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004925
Ayala Beker17b94242016-03-17 15:41:38 +02004926 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4927 u8 tmp;
4928
4929 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4930 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4931 return -EINVAL;
4932
4933 params.support_p2p_ps = tmp;
4934 } else {
4935 /*
4936 * if not specified, assume it's supported for P2P GO interface,
4937 * and is NOT supported for AP interface
4938 */
4939 params.support_p2p_ps =
4940 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4941 }
4942
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004943 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004944 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004945 else
4946 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004947 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4948 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004949
Jouni Malinen9d62a982013-02-14 21:10:13 +02004950 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4951 params.capability =
4952 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4953 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4954 }
4955
4956 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4957 params.ext_capab =
4958 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4959 params.ext_capab_len =
4960 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4961 }
4962
Jouni Malinen36aedc92008-08-25 11:58:58 +03004963 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4964 params.ht_capa =
4965 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004966
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004967 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4968 params.vht_capa =
4969 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4970
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004971 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4972 params.opmode_notif_used = true;
4973 params.opmode_notif =
4974 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4975 }
4976
Johannes Bergf8bacc22013-02-14 23:27:01 +01004977 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004978 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004979 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4980 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4981 return -EINVAL;
4982 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004983
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304984 err = nl80211_parse_sta_channel_info(info, &params);
4985 if (err)
4986 return err;
4987
Johannes Bergff276692013-02-15 00:09:01 +01004988 err = nl80211_parse_sta_wme(info, &params);
4989 if (err)
4990 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004991
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004992 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004993 return -EINVAL;
4994
Johannes Berg496fcc22015-03-12 08:53:27 +02004995 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4996 * as userspace might just pass through the capabilities from the IEs
4997 * directly, rather than enforcing this restriction and returning an
4998 * error in this case.
4999 */
5000 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5001 params.ht_capa = NULL;
5002 params.vht_capa = NULL;
5003 }
5004
Johannes Berg77ee7c82013-02-15 00:48:33 +01005005 /* When you run into this, adjust the code below for the new flag */
5006 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5007
Johannes Bergbdd90d52011-12-14 12:20:27 +01005008 switch (dev->ieee80211_ptr->iftype) {
5009 case NL80211_IFTYPE_AP:
5010 case NL80211_IFTYPE_AP_VLAN:
5011 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005012 /* ignore WME attributes if iface/sta is not capable */
5013 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5014 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5015 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005016
Johannes Bergbdd90d52011-12-14 12:20:27 +01005017 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005018 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5019 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005020 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005021 /* but don't bother the driver with it */
5022 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005023
Johannes Bergd582cff2012-10-26 17:53:44 +02005024 /* allow authenticated/associated only if driver handles it */
5025 if (!(rdev->wiphy.features &
5026 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005027 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005028 return -EINVAL;
5029
Johannes Bergbda95eb2015-11-26 16:26:13 +01005030 /* Older userspace, or userspace wanting to be compatible with
5031 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5032 * and assoc flags in the mask, but assumes the station will be
5033 * added as associated anyway since this was the required driver
5034 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5035 * introduced.
5036 * In order to not bother drivers with this quirk in the API
5037 * set the flags in both the mask and set for new stations in
5038 * this case.
5039 */
5040 if (!(params.sta_flags_mask & auth_assoc)) {
5041 params.sta_flags_mask |= auth_assoc;
5042 params.sta_flags_set |= auth_assoc;
5043 }
5044
Johannes Bergbdd90d52011-12-14 12:20:27 +01005045 /* must be last in here for error handling */
5046 params.vlan = get_vlan(info, rdev);
5047 if (IS_ERR(params.vlan))
5048 return PTR_ERR(params.vlan);
5049 break;
5050 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005051 /* ignore uAPSD data */
5052 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5053
Johannes Bergd582cff2012-10-26 17:53:44 +02005054 /* associated is disallowed */
5055 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5056 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005057 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005058 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5059 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005060 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005061 break;
5062 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005063 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005064 /* ignore uAPSD data */
5065 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5066
Johannes Berg77ee7c82013-02-15 00:48:33 +01005067 /* these are disallowed */
5068 if (params.sta_flags_mask &
5069 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5070 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005071 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005072 /* Only TDLS peers can be added */
5073 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5074 return -EINVAL;
5075 /* Can only add if TDLS ... */
5076 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5077 return -EOPNOTSUPP;
5078 /* ... with external setup is supported */
5079 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5080 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005081 /*
5082 * Older wpa_supplicant versions always mark the TDLS peer
5083 * as authorized, but it shouldn't yet be.
5084 */
5085 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005086 break;
5087 default:
5088 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005089 }
5090
Johannes Bergbdd90d52011-12-14 12:20:27 +01005091 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005092
Hila Gonene35e4d22012-06-27 17:19:42 +03005093 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005094
Johannes Berg5727ef12007-12-19 02:03:34 +01005095 if (params.vlan)
5096 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005097 return err;
5098}
5099
5100static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5101{
Johannes Berg4c476992010-10-04 21:36:35 +02005102 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5103 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005104 struct station_del_parameters params;
5105
5106 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005107
5108 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005109 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005110
Johannes Berge80cf852009-05-11 14:43:13 +02005111 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005112 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005113 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005114 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5115 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005116
Johannes Berg4c476992010-10-04 21:36:35 +02005117 if (!rdev->ops->del_station)
5118 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005119
Jouni Malinen98856862014-10-20 13:20:45 +03005120 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5121 params.subtype =
5122 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5123 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5124 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5125 return -EINVAL;
5126 } else {
5127 /* Default to Deauthentication frame */
5128 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5129 }
5130
5131 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5132 params.reason_code =
5133 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5134 if (params.reason_code == 0)
5135 return -EINVAL; /* 0 is reserved */
5136 } else {
5137 /* Default to reason code 2 */
5138 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5139 }
5140
Jouni Malinen89c771e2014-10-10 20:52:40 +03005141 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005142}
5143
Eric W. Biederman15e47302012-09-07 20:12:54 +00005144static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005145 int flags, struct net_device *dev,
5146 u8 *dst, u8 *next_hop,
5147 struct mpath_info *pinfo)
5148{
5149 void *hdr;
5150 struct nlattr *pinfoattr;
5151
Henning Rogge1ef4c852014-11-04 16:14:58 +01005152 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005153 if (!hdr)
5154 return -1;
5155
David S. Miller9360ffd2012-03-29 04:41:26 -04005156 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5157 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5158 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5159 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5160 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005161
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005162 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5163 if (!pinfoattr)
5164 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005165 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5166 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5167 pinfo->frame_qlen))
5168 goto nla_put_failure;
5169 if (((pinfo->filled & MPATH_INFO_SN) &&
5170 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5171 ((pinfo->filled & MPATH_INFO_METRIC) &&
5172 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5173 pinfo->metric)) ||
5174 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5175 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5176 pinfo->exptime)) ||
5177 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5178 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5179 pinfo->flags)) ||
5180 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5181 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5182 pinfo->discovery_timeout)) ||
5183 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5184 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5185 pinfo->discovery_retries)))
5186 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005187
5188 nla_nest_end(msg, pinfoattr);
5189
Johannes Berg053c0952015-01-16 22:09:00 +01005190 genlmsg_end(msg, hdr);
5191 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005192
5193 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005194 genlmsg_cancel(msg, hdr);
5195 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005196}
5197
5198static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005199 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005200{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005201 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005202 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005203 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005204 u8 dst[ETH_ALEN];
5205 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005206 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005207 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005208
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005209 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005210 if (err)
5211 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005212
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005213 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005214 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005215 goto out_err;
5216 }
5217
Johannes Berg97990a02013-04-19 01:02:55 +02005218 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005219 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005220 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005221 }
5222
Johannes Bergbba95fe2008-07-29 13:22:51 +02005223 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005224 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005225 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005226 if (err == -ENOENT)
5227 break;
5228 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005229 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005230
Eric W. Biederman15e47302012-09-07 20:12:54 +00005231 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005232 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005233 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005234 &pinfo) < 0)
5235 goto out;
5236
5237 path_idx++;
5238 }
5239
Johannes Bergbba95fe2008-07-29 13:22:51 +02005240 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005241 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005242 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005243 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005244 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005245 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005246}
5247
5248static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5249{
Johannes Berg4c476992010-10-04 21:36:35 +02005250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005251 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005252 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005253 struct mpath_info pinfo;
5254 struct sk_buff *msg;
5255 u8 *dst = NULL;
5256 u8 next_hop[ETH_ALEN];
5257
5258 memset(&pinfo, 0, sizeof(pinfo));
5259
5260 if (!info->attrs[NL80211_ATTR_MAC])
5261 return -EINVAL;
5262
5263 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5264
Johannes Berg4c476992010-10-04 21:36:35 +02005265 if (!rdev->ops->get_mpath)
5266 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005267
Johannes Berg4c476992010-10-04 21:36:35 +02005268 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5269 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005270
Hila Gonene35e4d22012-06-27 17:19:42 +03005271 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005272 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005273 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005274
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005276 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005277 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005278
Eric W. Biederman15e47302012-09-07 20:12:54 +00005279 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005280 dev, dst, next_hop, &pinfo) < 0) {
5281 nlmsg_free(msg);
5282 return -ENOBUFS;
5283 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005284
Johannes Berg4c476992010-10-04 21:36:35 +02005285 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005286}
5287
5288static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5289{
Johannes Berg4c476992010-10-04 21:36:35 +02005290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5291 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005292 u8 *dst = NULL;
5293 u8 *next_hop = NULL;
5294
5295 if (!info->attrs[NL80211_ATTR_MAC])
5296 return -EINVAL;
5297
5298 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5299 return -EINVAL;
5300
5301 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5302 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5303
Johannes Berg4c476992010-10-04 21:36:35 +02005304 if (!rdev->ops->change_mpath)
5305 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005306
Johannes Berg4c476992010-10-04 21:36:35 +02005307 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5308 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005309
Hila Gonene35e4d22012-06-27 17:19:42 +03005310 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005311}
Johannes Berg4c476992010-10-04 21:36:35 +02005312
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005313static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5314{
Johannes Berg4c476992010-10-04 21:36:35 +02005315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5316 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005317 u8 *dst = NULL;
5318 u8 *next_hop = NULL;
5319
5320 if (!info->attrs[NL80211_ATTR_MAC])
5321 return -EINVAL;
5322
5323 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5324 return -EINVAL;
5325
5326 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5327 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5328
Johannes Berg4c476992010-10-04 21:36:35 +02005329 if (!rdev->ops->add_mpath)
5330 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005331
Johannes Berg4c476992010-10-04 21:36:35 +02005332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5333 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005334
Hila Gonene35e4d22012-06-27 17:19:42 +03005335 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005336}
5337
5338static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5339{
Johannes Berg4c476992010-10-04 21:36:35 +02005340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5341 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005342 u8 *dst = NULL;
5343
5344 if (info->attrs[NL80211_ATTR_MAC])
5345 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5346
Johannes Berg4c476992010-10-04 21:36:35 +02005347 if (!rdev->ops->del_mpath)
5348 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005349
Hila Gonene35e4d22012-06-27 17:19:42 +03005350 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005351}
5352
Henning Rogge66be7d22014-09-12 08:58:49 +02005353static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5354{
5355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5356 int err;
5357 struct net_device *dev = info->user_ptr[1];
5358 struct mpath_info pinfo;
5359 struct sk_buff *msg;
5360 u8 *dst = NULL;
5361 u8 mpp[ETH_ALEN];
5362
5363 memset(&pinfo, 0, sizeof(pinfo));
5364
5365 if (!info->attrs[NL80211_ATTR_MAC])
5366 return -EINVAL;
5367
5368 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5369
5370 if (!rdev->ops->get_mpp)
5371 return -EOPNOTSUPP;
5372
5373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5374 return -EOPNOTSUPP;
5375
5376 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5377 if (err)
5378 return err;
5379
5380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5381 if (!msg)
5382 return -ENOMEM;
5383
5384 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5385 dev, dst, mpp, &pinfo) < 0) {
5386 nlmsg_free(msg);
5387 return -ENOBUFS;
5388 }
5389
5390 return genlmsg_reply(msg, info);
5391}
5392
5393static int nl80211_dump_mpp(struct sk_buff *skb,
5394 struct netlink_callback *cb)
5395{
5396 struct mpath_info pinfo;
5397 struct cfg80211_registered_device *rdev;
5398 struct wireless_dev *wdev;
5399 u8 dst[ETH_ALEN];
5400 u8 mpp[ETH_ALEN];
5401 int path_idx = cb->args[2];
5402 int err;
5403
5404 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5405 if (err)
5406 return err;
5407
5408 if (!rdev->ops->dump_mpp) {
5409 err = -EOPNOTSUPP;
5410 goto out_err;
5411 }
5412
5413 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5414 err = -EOPNOTSUPP;
5415 goto out_err;
5416 }
5417
5418 while (1) {
5419 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5420 mpp, &pinfo);
5421 if (err == -ENOENT)
5422 break;
5423 if (err)
5424 goto out_err;
5425
5426 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5427 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5428 wdev->netdev, dst, mpp,
5429 &pinfo) < 0)
5430 goto out;
5431
5432 path_idx++;
5433 }
5434
5435 out:
5436 cb->args[2] = path_idx;
5437 err = skb->len;
5438 out_err:
5439 nl80211_finish_wdev_dump(rdev);
5440 return err;
5441}
5442
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005443static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5444{
Johannes Berg4c476992010-10-04 21:36:35 +02005445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5446 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005447 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005448 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005449 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005450
5451 memset(&params, 0, sizeof(params));
5452 /* default to not changing parameters */
5453 params.use_cts_prot = -1;
5454 params.use_short_preamble = -1;
5455 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005456 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005457 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005458 params.p2p_ctwindow = -1;
5459 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005460
5461 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5462 params.use_cts_prot =
5463 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5464 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5465 params.use_short_preamble =
5466 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5467 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5468 params.use_short_slot_time =
5469 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005470 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5471 params.basic_rates =
5472 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5473 params.basic_rates_len =
5474 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5475 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005476 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5477 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005478 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5479 params.ht_opmode =
5480 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005481
Johannes Berg53cabad2012-11-14 15:17:28 +01005482 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5483 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5484 return -EINVAL;
5485 params.p2p_ctwindow =
5486 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5487 if (params.p2p_ctwindow < 0)
5488 return -EINVAL;
5489 if (params.p2p_ctwindow != 0 &&
5490 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5491 return -EINVAL;
5492 }
5493
5494 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5495 u8 tmp;
5496
5497 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5498 return -EINVAL;
5499 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5500 if (tmp > 1)
5501 return -EINVAL;
5502 params.p2p_opp_ps = tmp;
5503 if (params.p2p_opp_ps &&
5504 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5505 return -EINVAL;
5506 }
5507
Johannes Berg4c476992010-10-04 21:36:35 +02005508 if (!rdev->ops->change_bss)
5509 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005510
Johannes Berg074ac8d2010-09-16 14:58:22 +02005511 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005512 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5513 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005514
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005515 wdev_lock(wdev);
5516 err = rdev_change_bss(rdev, dev, &params);
5517 wdev_unlock(wdev);
5518
5519 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005520}
5521
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005522static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5523{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005524 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005525 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005526 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005527 u32 owner_nlportid;
5528
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005529 /*
5530 * You should only get this when cfg80211 hasn't yet initialized
5531 * completely when built-in to the kernel right between the time
5532 * window between nl80211_init() and regulatory_init(), if that is
5533 * even possible.
5534 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005535 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005536 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005537
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005538 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5539 user_reg_hint_type =
5540 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5541 else
5542 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5543
5544 switch (user_reg_hint_type) {
5545 case NL80211_USER_REG_HINT_USER:
5546 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005547 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5548 return -EINVAL;
5549
5550 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5551 return regulatory_hint_user(data, user_reg_hint_type);
5552 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005553 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5554 owner_nlportid = info->snd_portid;
5555 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5556 } else {
5557 owner_nlportid = 0;
5558 is_indoor = true;
5559 }
5560
5561 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005562 default:
5563 return -EINVAL;
5564 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005565}
5566
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005567static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005568 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005569{
Johannes Berg4c476992010-10-04 21:36:35 +02005570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005571 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005572 struct wireless_dev *wdev = dev->ieee80211_ptr;
5573 struct mesh_config cur_params;
5574 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005575 void *hdr;
5576 struct nlattr *pinfoattr;
5577 struct sk_buff *msg;
5578
Johannes Berg29cbe682010-12-03 09:20:44 +01005579 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5580 return -EOPNOTSUPP;
5581
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005582 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005583 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005584
Johannes Berg29cbe682010-12-03 09:20:44 +01005585 wdev_lock(wdev);
5586 /* If not connected, get default parameters */
5587 if (!wdev->mesh_id_len)
5588 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5589 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005590 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005591 wdev_unlock(wdev);
5592
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005593 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005594 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005595
5596 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005598 if (!msg)
5599 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005600 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005601 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005602 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005603 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005604 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005605 if (!pinfoattr)
5606 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005607 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5608 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5609 cur_params.dot11MeshRetryTimeout) ||
5610 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5611 cur_params.dot11MeshConfirmTimeout) ||
5612 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5613 cur_params.dot11MeshHoldingTimeout) ||
5614 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5615 cur_params.dot11MeshMaxPeerLinks) ||
5616 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5617 cur_params.dot11MeshMaxRetries) ||
5618 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5619 cur_params.dot11MeshTTL) ||
5620 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5621 cur_params.element_ttl) ||
5622 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5623 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005624 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5625 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005626 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5627 cur_params.dot11MeshHWMPmaxPREQretries) ||
5628 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5629 cur_params.path_refresh_time) ||
5630 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5631 cur_params.min_discovery_timeout) ||
5632 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5633 cur_params.dot11MeshHWMPactivePathTimeout) ||
5634 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5635 cur_params.dot11MeshHWMPpreqMinInterval) ||
5636 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5637 cur_params.dot11MeshHWMPperrMinInterval) ||
5638 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5639 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5640 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5641 cur_params.dot11MeshHWMPRootMode) ||
5642 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5643 cur_params.dot11MeshHWMPRannInterval) ||
5644 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5645 cur_params.dot11MeshGateAnnouncementProtocol) ||
5646 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5647 cur_params.dot11MeshForwarding) ||
5648 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005649 cur_params.rssi_threshold) ||
5650 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005651 cur_params.ht_opmode) ||
5652 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5653 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5654 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005655 cur_params.dot11MeshHWMProotInterval) ||
5656 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005657 cur_params.dot11MeshHWMPconfirmationInterval) ||
5658 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5659 cur_params.power_mode) ||
5660 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005661 cur_params.dot11MeshAwakeWindowDuration) ||
5662 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5663 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005664 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005665 nla_nest_end(msg, pinfoattr);
5666 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005667 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005668
Johannes Berg3b858752009-03-12 09:55:09 +01005669 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005670 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005671 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005672 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005673 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005674}
5675
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005676static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005677 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5678 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5679 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5680 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5681 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5682 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005683 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005684 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005685 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005686 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5687 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5688 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5689 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5690 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005691 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005692 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005693 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005694 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005695 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005696 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005697 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5698 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005699 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5700 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005701 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005702 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5703 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005704 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005705};
5706
Javier Cardonac80d5452010-12-16 17:37:49 -08005707static const struct nla_policy
5708 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005709 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005710 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5711 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005712 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005713 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005714 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005715 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005716 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005717 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005718};
5719
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005720static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5721{
5722 u8 val = nla_get_u8(nla);
5723 if (val < min || val > max)
5724 return -EINVAL;
5725 *out = val;
5726 return 0;
5727}
5728
5729static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5730{
5731 u8 val = nla_get_u8(nla);
5732 if (val < min || val > max)
5733 return -EINVAL;
5734 *out = val;
5735 return 0;
5736}
5737
5738static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5739{
5740 u16 val = nla_get_u16(nla);
5741 if (val < min || val > max)
5742 return -EINVAL;
5743 *out = val;
5744 return 0;
5745}
5746
5747static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5748{
5749 u32 val = nla_get_u32(nla);
5750 if (val < min || val > max)
5751 return -EINVAL;
5752 *out = val;
5753 return 0;
5754}
5755
5756static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5757{
5758 s32 val = nla_get_s32(nla);
5759 if (val < min || val > max)
5760 return -EINVAL;
5761 *out = val;
5762 return 0;
5763}
5764
Johannes Bergff9a71a2016-08-11 14:59:53 +02005765static int nl80211_check_power_mode(const struct nlattr *nla,
5766 enum nl80211_mesh_power_mode min,
5767 enum nl80211_mesh_power_mode max,
5768 enum nl80211_mesh_power_mode *out)
5769{
5770 u32 val = nla_get_u32(nla);
5771 if (val < min || val > max)
5772 return -EINVAL;
5773 *out = val;
5774 return 0;
5775}
5776
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005777static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005778 struct mesh_config *cfg,
5779 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005780{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005781 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005782 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005783 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005784
Marco Porschea54fba2013-01-07 16:04:48 +01005785#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5786do { \
5787 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005788 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005789 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005790 mask |= (1 << (attr - 1)); \
5791 } \
5792} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005793
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005794 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005795 return -EINVAL;
5796 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005797 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005798 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005799 return -EINVAL;
5800
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005801 /* This makes sure that there aren't more than 32 mesh config
5802 * parameters (otherwise our bitfield scheme would not work.) */
5803 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5804
5805 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005807 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005808 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005809 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005810 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005811 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005813 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005814 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005815 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005816 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005817 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005819 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005820 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005822 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005823 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005824 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005825 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005827 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005828 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5830 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005831 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005832 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005834 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005835 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005836 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005837 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005838 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005840 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
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, dot11MeshHWMPactivePathTimeout,
5843 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005844 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005845 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005847 1, 65535, mask,
5848 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005849 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005851 1, 65535, mask,
5852 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005853 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005855 dot11MeshHWMPnetDiameterTraversalTime,
5856 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005857 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005858 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005859 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5860 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005861 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005862 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5863 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005864 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005865 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005866 dot11MeshGateAnnouncementProtocol, 0, 1,
5867 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005868 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005870 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005871 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005872 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005873 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005874 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005875 /*
5876 * Check HT operation mode based on
5877 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5878 */
5879 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5880 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5881
5882 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5883 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5884 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5885 return -EINVAL;
5886
5887 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5888 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5889 return -EINVAL;
5890
5891 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5892 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5893 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5894 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5895 return -EINVAL;
5896 break;
5897 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5898 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5899 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5900 return -EINVAL;
5901 break;
5902 }
5903 cfg->ht_opmode = ht_opmode;
5904 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005905 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005906 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005907 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005908 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005909 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005910 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005911 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005912 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005913 dot11MeshHWMPconfirmationInterval,
5914 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005915 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005916 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5918 NL80211_MESH_POWER_ACTIVE,
5919 NL80211_MESH_POWER_MAX,
5920 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005921 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005922 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5923 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005924 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005925 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005926 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005927 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005928 if (mask_out)
5929 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005930
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005931 return 0;
5932
5933#undef FILL_IN_MESH_PARAM_IF_SET
5934}
5935
Javier Cardonac80d5452010-12-16 17:37:49 -08005936static int nl80211_parse_mesh_setup(struct genl_info *info,
5937 struct mesh_setup *setup)
5938{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005940 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5941
5942 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5943 return -EINVAL;
5944 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5945 info->attrs[NL80211_ATTR_MESH_SETUP],
5946 nl80211_mesh_setup_params_policy))
5947 return -EINVAL;
5948
Javier Cardonad299a1f2012-03-31 11:31:33 -07005949 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5950 setup->sync_method =
5951 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5952 IEEE80211_SYNC_METHOD_VENDOR :
5953 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5954
Javier Cardonac80d5452010-12-16 17:37:49 -08005955 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5956 setup->path_sel_proto =
5957 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5958 IEEE80211_PATH_PROTOCOL_VENDOR :
5959 IEEE80211_PATH_PROTOCOL_HWMP;
5960
5961 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5962 setup->path_metric =
5963 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5964 IEEE80211_PATH_METRIC_VENDOR :
5965 IEEE80211_PATH_METRIC_AIRTIME;
5966
Javier Cardona581a8b02011-04-07 15:08:27 -07005967 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005968 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005969 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005970 if (!is_valid_ie_attr(ieattr))
5971 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005972 setup->ie = nla_data(ieattr);
5973 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005974 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005975 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5976 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5977 return -EINVAL;
5978 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005979 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5980 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005981 if (setup->is_secure)
5982 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005983
Colleen Twitty6e16d902013-05-08 11:45:59 -07005984 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5985 if (!setup->user_mpm)
5986 return -EINVAL;
5987 setup->auth_id =
5988 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5989 }
5990
Javier Cardonac80d5452010-12-16 17:37:49 -08005991 return 0;
5992}
5993
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005994static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005995 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005996{
5997 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5998 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005999 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006000 struct mesh_config cfg;
6001 u32 mask;
6002 int err;
6003
Johannes Berg29cbe682010-12-03 09:20:44 +01006004 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6005 return -EOPNOTSUPP;
6006
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006007 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006008 return -EOPNOTSUPP;
6009
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006010 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006011 if (err)
6012 return err;
6013
Johannes Berg29cbe682010-12-03 09:20:44 +01006014 wdev_lock(wdev);
6015 if (!wdev->mesh_id_len)
6016 err = -ENOLINK;
6017
6018 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006019 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006020
6021 wdev_unlock(wdev);
6022
6023 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006024}
6025
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006026static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6027 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006028{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006029 struct nlattr *nl_reg_rules;
6030 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006031
Johannes Berg458f4f92012-12-06 15:47:38 +01006032 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6033 (regdom->dfs_region &&
6034 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006035 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006036
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006037 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6038 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006039 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006040
Johannes Berg458f4f92012-12-06 15:47:38 +01006041 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006042 struct nlattr *nl_reg_rule;
6043 const struct ieee80211_reg_rule *reg_rule;
6044 const struct ieee80211_freq_range *freq_range;
6045 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006046 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006047
Johannes Berg458f4f92012-12-06 15:47:38 +01006048 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006049 freq_range = &reg_rule->freq_range;
6050 power_rule = &reg_rule->power_rule;
6051
6052 nl_reg_rule = nla_nest_start(msg, i);
6053 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006054 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006055
Janusz Dziedzic97524822014-01-30 09:52:20 +01006056 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6057 if (!max_bandwidth_khz)
6058 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6059 reg_rule);
6060
David S. Miller9360ffd2012-03-29 04:41:26 -04006061 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6062 reg_rule->flags) ||
6063 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6064 freq_range->start_freq_khz) ||
6065 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6066 freq_range->end_freq_khz) ||
6067 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006068 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006069 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6070 power_rule->max_antenna_gain) ||
6071 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006072 power_rule->max_eirp) ||
6073 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6074 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006075 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006076
6077 nla_nest_end(msg, nl_reg_rule);
6078 }
6079
6080 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006081 return 0;
6082
6083nla_put_failure:
6084 return -EMSGSIZE;
6085}
6086
6087static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6088{
6089 const struct ieee80211_regdomain *regdom = NULL;
6090 struct cfg80211_registered_device *rdev;
6091 struct wiphy *wiphy = NULL;
6092 struct sk_buff *msg;
6093 void *hdr;
6094
6095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6096 if (!msg)
6097 return -ENOBUFS;
6098
6099 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6100 NL80211_CMD_GET_REG);
6101 if (!hdr)
6102 goto put_failure;
6103
6104 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006105 bool self_managed;
6106
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006107 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6108 if (IS_ERR(rdev)) {
6109 nlmsg_free(msg);
6110 return PTR_ERR(rdev);
6111 }
6112
6113 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006114 self_managed = wiphy->regulatory_flags &
6115 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006116 regdom = get_wiphy_regdom(wiphy);
6117
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006118 /* a self-managed-reg device must have a private regdom */
6119 if (WARN_ON(!regdom && self_managed)) {
6120 nlmsg_free(msg);
6121 return -EINVAL;
6122 }
6123
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006124 if (regdom &&
6125 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6126 goto nla_put_failure;
6127 }
6128
6129 if (!wiphy && reg_last_request_cell_base() &&
6130 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6131 NL80211_USER_REG_HINT_CELL_BASE))
6132 goto nla_put_failure;
6133
6134 rcu_read_lock();
6135
6136 if (!regdom)
6137 regdom = rcu_dereference(cfg80211_regdomain);
6138
6139 if (nl80211_put_regdom(regdom, msg))
6140 goto nla_put_failure_rcu;
6141
6142 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006143
6144 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006145 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006146
Johannes Berg458f4f92012-12-06 15:47:38 +01006147nla_put_failure_rcu:
6148 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006149nla_put_failure:
6150 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006151put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006152 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006153 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006154}
6155
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006156static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6157 u32 seq, int flags, struct wiphy *wiphy,
6158 const struct ieee80211_regdomain *regdom)
6159{
6160 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6161 NL80211_CMD_GET_REG);
6162
6163 if (!hdr)
6164 return -1;
6165
6166 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6167
6168 if (nl80211_put_regdom(regdom, msg))
6169 goto nla_put_failure;
6170
6171 if (!wiphy && reg_last_request_cell_base() &&
6172 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6173 NL80211_USER_REG_HINT_CELL_BASE))
6174 goto nla_put_failure;
6175
6176 if (wiphy &&
6177 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6178 goto nla_put_failure;
6179
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006180 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6181 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6182 goto nla_put_failure;
6183
Johannes Berg053c0952015-01-16 22:09:00 +01006184 genlmsg_end(msg, hdr);
6185 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006186
6187nla_put_failure:
6188 genlmsg_cancel(msg, hdr);
6189 return -EMSGSIZE;
6190}
6191
6192static int nl80211_get_reg_dump(struct sk_buff *skb,
6193 struct netlink_callback *cb)
6194{
6195 const struct ieee80211_regdomain *regdom = NULL;
6196 struct cfg80211_registered_device *rdev;
6197 int err, reg_idx, start = cb->args[2];
6198
6199 rtnl_lock();
6200
6201 if (cfg80211_regdomain && start == 0) {
6202 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6203 NLM_F_MULTI, NULL,
6204 rtnl_dereference(cfg80211_regdomain));
6205 if (err < 0)
6206 goto out_err;
6207 }
6208
6209 /* the global regdom is idx 0 */
6210 reg_idx = 1;
6211 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6212 regdom = get_wiphy_regdom(&rdev->wiphy);
6213 if (!regdom)
6214 continue;
6215
6216 if (++reg_idx <= start)
6217 continue;
6218
6219 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6220 NLM_F_MULTI, &rdev->wiphy, regdom);
6221 if (err < 0) {
6222 reg_idx--;
6223 break;
6224 }
6225 }
6226
6227 cb->args[2] = reg_idx;
6228 err = skb->len;
6229out_err:
6230 rtnl_unlock();
6231 return err;
6232}
6233
Johannes Bergb6863032015-10-15 09:25:18 +02006234#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6235static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6236 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6237 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6238 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6239 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6240 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6241 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6242 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6243};
6244
6245static int parse_reg_rule(struct nlattr *tb[],
6246 struct ieee80211_reg_rule *reg_rule)
6247{
6248 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6249 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6250
6251 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6252 return -EINVAL;
6253 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6254 return -EINVAL;
6255 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6256 return -EINVAL;
6257 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6258 return -EINVAL;
6259 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6260 return -EINVAL;
6261
6262 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6263
6264 freq_range->start_freq_khz =
6265 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6266 freq_range->end_freq_khz =
6267 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6268 freq_range->max_bandwidth_khz =
6269 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6270
6271 power_rule->max_eirp =
6272 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6273
6274 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6275 power_rule->max_antenna_gain =
6276 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6277
6278 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6279 reg_rule->dfs_cac_ms =
6280 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6281
6282 return 0;
6283}
6284
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006285static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6286{
6287 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6288 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006289 char *alpha2;
6290 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006291 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006292 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006293 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006294
6295 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6296 return -EINVAL;
6297
6298 if (!info->attrs[NL80211_ATTR_REG_RULES])
6299 return -EINVAL;
6300
6301 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6302
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006303 if (info->attrs[NL80211_ATTR_DFS_REGION])
6304 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6305
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006306 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006307 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006308 num_rules++;
6309 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006310 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006311 }
6312
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006313 if (!reg_is_valid_request(alpha2))
6314 return -EINVAL;
6315
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006316 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006317 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006318
6319 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006320 if (!rd)
6321 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006322
6323 rd->n_reg_rules = num_rules;
6324 rd->alpha2[0] = alpha2[0];
6325 rd->alpha2[1] = alpha2[1];
6326
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006327 /*
6328 * Disable DFS master mode if the DFS region was
6329 * not supported or known on this kernel.
6330 */
6331 if (reg_supported_dfs_region(dfs_region))
6332 rd->dfs_region = dfs_region;
6333
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006334 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006335 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006336 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
6337 nl_reg_rule, reg_rule_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01006338 if (r)
6339 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006340 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6341 if (r)
6342 goto bad_reg;
6343
6344 rule_idx++;
6345
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006346 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6347 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006348 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006349 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006350 }
6351
Johannes Berg06627992016-06-09 10:40:09 +02006352 /* set_regdom takes ownership of rd */
6353 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006354 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006355 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006356 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006357}
Johannes Bergb6863032015-10-15 09:25:18 +02006358#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006359
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006360static int validate_scan_freqs(struct nlattr *freqs)
6361{
6362 struct nlattr *attr1, *attr2;
6363 int n_channels = 0, tmp1, tmp2;
6364
6365 nla_for_each_nested(attr1, freqs, tmp1) {
6366 n_channels++;
6367 /*
6368 * Some hardware has a limited channel list for
6369 * scanning, and it is pretty much nonsensical
6370 * to scan for a channel twice, so disallow that
6371 * and don't require drivers to check that the
6372 * channel list they get isn't longer than what
6373 * they can scan, as long as they can scan all
6374 * the channels they registered at once.
6375 */
6376 nla_for_each_nested(attr2, freqs, tmp2)
6377 if (attr1 != attr2 &&
6378 nla_get_u32(attr1) == nla_get_u32(attr2))
6379 return 0;
6380 }
6381
6382 return n_channels;
6383}
6384
Johannes Berg57fbcce2016-04-12 15:56:15 +02006385static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006386{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006387 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006388}
6389
6390static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6391 struct cfg80211_bss_selection *bss_select)
6392{
6393 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6394 struct nlattr *nest;
6395 int err;
6396 bool found = false;
6397 int i;
6398
6399 /* only process one nested attribute */
6400 nest = nla_data(nla);
6401 if (!nla_ok(nest, nla_len(nest)))
6402 return -EINVAL;
6403
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006404 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
6405 nl80211_bss_select_policy);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006406 if (err)
6407 return err;
6408
6409 /* only one attribute may be given */
6410 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6411 if (attr[i]) {
6412 if (found)
6413 return -EINVAL;
6414 found = true;
6415 }
6416 }
6417
6418 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6419
6420 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6421 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6422
6423 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6424 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6425 bss_select->param.band_pref =
6426 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6427 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6428 return -EINVAL;
6429 }
6430
6431 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6432 struct nl80211_bss_select_rssi_adjust *adj_param;
6433
6434 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6435 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6436 bss_select->param.adjust.band = adj_param->band;
6437 bss_select->param.adjust.delta = adj_param->delta;
6438 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6439 return -EINVAL;
6440 }
6441
6442 /* user-space did not provide behaviour attribute */
6443 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6444 return -EINVAL;
6445
6446 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6447 return -EINVAL;
6448
6449 return 0;
6450}
6451
Johannes Bergad2b26a2014-06-12 21:39:05 +02006452static int nl80211_parse_random_mac(struct nlattr **attrs,
6453 u8 *mac_addr, u8 *mac_addr_mask)
6454{
6455 int i;
6456
6457 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006458 eth_zero_addr(mac_addr);
6459 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006460 mac_addr[0] = 0x2;
6461 mac_addr_mask[0] = 0x3;
6462
6463 return 0;
6464 }
6465
6466 /* need both or none */
6467 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6468 return -EINVAL;
6469
6470 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6471 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6472
6473 /* don't allow or configure an mcast address */
6474 if (!is_multicast_ether_addr(mac_addr_mask) ||
6475 is_multicast_ether_addr(mac_addr))
6476 return -EINVAL;
6477
6478 /*
6479 * allow users to pass a MAC address that has bits set outside
6480 * of the mask, but don't bother drivers with having to deal
6481 * with such bits
6482 */
6483 for (i = 0; i < ETH_ALEN; i++)
6484 mac_addr[i] &= mac_addr_mask[i];
6485
6486 return 0;
6487}
6488
Johannes Berg2a519312009-02-10 21:25:55 +01006489static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6490{
Johannes Berg4c476992010-10-04 21:36:35 +02006491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006492 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006493 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006494 struct nlattr *attr;
6495 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006496 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006497 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006498
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006499 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6500 return -EINVAL;
6501
Johannes Berg79c97e92009-07-07 03:56:12 +02006502 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006503
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006504 if (wdev->iftype == NL80211_IFTYPE_NAN)
6505 return -EOPNOTSUPP;
6506
Johannes Berg4c476992010-10-04 21:36:35 +02006507 if (!rdev->ops->scan)
6508 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006509
Johannes Bergf9d15d12014-01-22 11:14:19 +02006510 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006511 err = -EBUSY;
6512 goto unlock;
6513 }
Johannes Berg2a519312009-02-10 21:25:55 +01006514
6515 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006516 n_channels = validate_scan_freqs(
6517 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006518 if (!n_channels) {
6519 err = -EINVAL;
6520 goto unlock;
6521 }
Johannes Berg2a519312009-02-10 21:25:55 +01006522 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006523 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006524 }
6525
6526 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6527 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6528 n_ssids++;
6529
Johannes Bergf9f47522013-03-19 15:04:07 +01006530 if (n_ssids > wiphy->max_scan_ssids) {
6531 err = -EINVAL;
6532 goto unlock;
6533 }
Johannes Berg2a519312009-02-10 21:25:55 +01006534
Jouni Malinen70692ad2009-02-16 19:39:13 +02006535 if (info->attrs[NL80211_ATTR_IE])
6536 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6537 else
6538 ie_len = 0;
6539
Johannes Bergf9f47522013-03-19 15:04:07 +01006540 if (ie_len > wiphy->max_scan_ie_len) {
6541 err = -EINVAL;
6542 goto unlock;
6543 }
Johannes Berg18a83652009-03-31 12:12:05 +02006544
Johannes Berg2a519312009-02-10 21:25:55 +01006545 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006546 + sizeof(*request->ssids) * n_ssids
6547 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006548 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006549 if (!request) {
6550 err = -ENOMEM;
6551 goto unlock;
6552 }
Johannes Berg2a519312009-02-10 21:25:55 +01006553
Johannes Berg2a519312009-02-10 21:25:55 +01006554 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006555 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006556 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006557 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006558 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006559 request->ie = (void *)(request->ssids + n_ssids);
6560 else
6561 request->ie = (void *)(request->channels + n_channels);
6562 }
Johannes Berg2a519312009-02-10 21:25:55 +01006563
Johannes Berg584991d2009-11-02 13:32:03 +01006564 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006565 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6566 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006567 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006568 struct ieee80211_channel *chan;
6569
6570 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6571
6572 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006573 err = -EINVAL;
6574 goto out_free;
6575 }
Johannes Berg584991d2009-11-02 13:32:03 +01006576
6577 /* ignore disabled channels */
6578 if (chan->flags & IEEE80211_CHAN_DISABLED)
6579 continue;
6580
6581 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006582 i++;
6583 }
6584 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006585 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006586
Johannes Berg2a519312009-02-10 21:25:55 +01006587 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006588 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006589 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006590
Johannes Berg2a519312009-02-10 21:25:55 +01006591 if (!wiphy->bands[band])
6592 continue;
6593 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006594 struct ieee80211_channel *chan;
6595
6596 chan = &wiphy->bands[band]->channels[j];
6597
6598 if (chan->flags & IEEE80211_CHAN_DISABLED)
6599 continue;
6600
6601 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006602 i++;
6603 }
6604 }
6605 }
6606
Johannes Berg584991d2009-11-02 13:32:03 +01006607 if (!i) {
6608 err = -EINVAL;
6609 goto out_free;
6610 }
6611
6612 request->n_channels = i;
6613
Johannes Berg2a519312009-02-10 21:25:55 +01006614 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006615 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006616 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006617 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006618 err = -EINVAL;
6619 goto out_free;
6620 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006621 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006622 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006623 i++;
6624 }
6625 }
6626
Jouni Malinen70692ad2009-02-16 19:39:13 +02006627 if (info->attrs[NL80211_ATTR_IE]) {
6628 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006629 memcpy((void *)request->ie,
6630 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006631 request->ie_len);
6632 }
6633
Johannes Berg57fbcce2016-04-12 15:56:15 +02006634 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006635 if (wiphy->bands[i])
6636 request->rates[i] =
6637 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006638
6639 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6640 nla_for_each_nested(attr,
6641 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6642 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006643 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006644
Johannes Berg57fbcce2016-04-12 15:56:15 +02006645 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006646 err = -EINVAL;
6647 goto out_free;
6648 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006649
6650 if (!wiphy->bands[band])
6651 continue;
6652
Johannes Berg34850ab2011-07-18 18:08:35 +02006653 err = ieee80211_get_ratemask(wiphy->bands[band],
6654 nla_data(attr),
6655 nla_len(attr),
6656 &request->rates[band]);
6657 if (err)
6658 goto out_free;
6659 }
6660 }
6661
Avraham Stern1d762502016-07-05 17:10:13 +03006662 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6663 if (!wiphy_ext_feature_isset(wiphy,
6664 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6665 err = -EOPNOTSUPP;
6666 goto out_free;
6667 }
6668
6669 request->duration =
6670 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6671 request->duration_mandatory =
6672 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6673 }
6674
Sam Leffler46856bb2012-10-11 21:03:32 -07006675 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006676 request->flags = nla_get_u32(
6677 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006678 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6679 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006680 err = -EOPNOTSUPP;
6681 goto out_free;
6682 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006683
6684 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6685 if (!(wiphy->features &
6686 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6687 err = -EOPNOTSUPP;
6688 goto out_free;
6689 }
6690
6691 if (wdev->current_bss) {
6692 err = -EOPNOTSUPP;
6693 goto out_free;
6694 }
6695
6696 err = nl80211_parse_random_mac(info->attrs,
6697 request->mac_addr,
6698 request->mac_addr_mask);
6699 if (err)
6700 goto out_free;
6701 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006702 }
Sam Lefflered4737712012-10-11 21:03:31 -07006703
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306704 request->no_cck =
6705 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6706
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02006707 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6708 * BSSID to scan for. This was problematic because that same attribute
6709 * was already used for another purpose (local random MAC address). The
6710 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6711 * compatibility with older userspace components, also use the
6712 * NL80211_ATTR_MAC value here if it can be determined to be used for
6713 * the specific BSSID use case instead of the random MAC address
6714 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6715 */
6716 if (info->attrs[NL80211_ATTR_BSSID])
6717 memcpy(request->bssid,
6718 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6719 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6720 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006721 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6722 ETH_ALEN);
6723 else
6724 eth_broadcast_addr(request->bssid);
6725
Johannes Bergfd014282012-06-18 19:17:03 +02006726 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006727 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006728 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006729
Johannes Berg79c97e92009-07-07 03:56:12 +02006730 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006731 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006732
Johannes Berg463d0182009-07-14 00:33:35 +02006733 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006734 nl80211_send_scan_start(rdev, wdev);
6735 if (wdev->netdev)
6736 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006737 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006738 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006739 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006740 kfree(request);
6741 }
Johannes Berg3b858752009-03-12 09:55:09 +01006742
Johannes Bergf9f47522013-03-19 15:04:07 +01006743 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006744 return err;
6745}
6746
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306747static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6748{
6749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6750 struct wireless_dev *wdev = info->user_ptr[1];
6751
6752 if (!rdev->ops->abort_scan)
6753 return -EOPNOTSUPP;
6754
6755 if (rdev->scan_msg)
6756 return 0;
6757
6758 if (!rdev->scan_req)
6759 return -ENOENT;
6760
6761 rdev_abort_scan(rdev, wdev);
6762 return 0;
6763}
6764
Avraham Stern3b06d272015-10-12 09:51:34 +03006765static int
6766nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6767 struct cfg80211_sched_scan_request *request,
6768 struct nlattr **attrs)
6769{
6770 int tmp, err, i = 0;
6771 struct nlattr *attr;
6772
6773 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6774 u32 interval;
6775
6776 /*
6777 * If scan plans are not specified,
6778 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6779 * case one scan plan will be set with the specified scan
6780 * interval and infinite number of iterations.
6781 */
6782 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6783 return -EINVAL;
6784
6785 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6786 if (!interval)
6787 return -EINVAL;
6788
6789 request->scan_plans[0].interval =
6790 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6791 if (!request->scan_plans[0].interval)
6792 return -EINVAL;
6793
6794 if (request->scan_plans[0].interval >
6795 wiphy->max_sched_scan_plan_interval)
6796 request->scan_plans[0].interval =
6797 wiphy->max_sched_scan_plan_interval;
6798
6799 return 0;
6800 }
6801
6802 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6803 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6804
6805 if (WARN_ON(i >= n_plans))
6806 return -EINVAL;
6807
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006808 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6809 attr, nl80211_plan_policy);
Avraham Stern3b06d272015-10-12 09:51:34 +03006810 if (err)
6811 return err;
6812
6813 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6814 return -EINVAL;
6815
6816 request->scan_plans[i].interval =
6817 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6818 if (!request->scan_plans[i].interval ||
6819 request->scan_plans[i].interval >
6820 wiphy->max_sched_scan_plan_interval)
6821 return -EINVAL;
6822
6823 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6824 request->scan_plans[i].iterations =
6825 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6826 if (!request->scan_plans[i].iterations ||
6827 (request->scan_plans[i].iterations >
6828 wiphy->max_sched_scan_plan_iterations))
6829 return -EINVAL;
6830 } else if (i < n_plans - 1) {
6831 /*
6832 * All scan plans but the last one must specify
6833 * a finite number of iterations
6834 */
6835 return -EINVAL;
6836 }
6837
6838 i++;
6839 }
6840
6841 /*
6842 * The last scan plan must not specify the number of
6843 * iterations, it is supposed to run infinitely
6844 */
6845 if (request->scan_plans[n_plans - 1].iterations)
6846 return -EINVAL;
6847
6848 return 0;
6849}
6850
Luciano Coelho256da022014-11-10 16:13:46 +02006851static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006852nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006853 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006854{
6855 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006856 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006857 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006858 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006859 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006860 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006861 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006862
Luciano Coelho256da022014-11-10 16:13:46 +02006863 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6864 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006865
Luciano Coelho256da022014-11-10 16:13:46 +02006866 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006867 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006868 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006869 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006870 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006871 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006872 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006873 }
6874
Luciano Coelho256da022014-11-10 16:13:46 +02006875 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6876 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006877 tmp)
6878 n_ssids++;
6879
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006880 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006881 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006882
Johannes Bergea73cbc2014-01-24 10:53:53 +01006883 /*
6884 * First, count the number of 'real' matchsets. Due to an issue with
6885 * the old implementation, matchsets containing only the RSSI attribute
6886 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6887 * RSSI for all matchsets, rather than their own matchset for reporting
6888 * all APs with a strong RSSI. This is needed to be compatible with
6889 * older userspace that treated a matchset with only the RSSI as the
6890 * global RSSI for all other matchsets - if there are other matchsets.
6891 */
Luciano Coelho256da022014-11-10 16:13:46 +02006892 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006893 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006894 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006895 tmp) {
6896 struct nlattr *rssi;
6897
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006898 err = nla_parse_nested(tb,
6899 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6900 attr, nl80211_match_policy);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006901 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006902 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006903 /* add other standalone attributes here */
6904 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6905 n_match_sets++;
6906 continue;
6907 }
6908 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6909 if (rssi)
6910 default_match_rssi = nla_get_s32(rssi);
6911 }
6912 }
6913
6914 /* However, if there's no other matchset, add the RSSI one */
6915 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6916 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006917
6918 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006919 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006920
Luciano Coelho256da022014-11-10 16:13:46 +02006921 if (attrs[NL80211_ATTR_IE])
6922 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006923 else
6924 ie_len = 0;
6925
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006926 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006927 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006928
Avraham Stern3b06d272015-10-12 09:51:34 +03006929 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6930 /*
6931 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6932 * each scan plan already specifies its own interval
6933 */
6934 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6935 return ERR_PTR(-EINVAL);
6936
6937 nla_for_each_nested(attr,
6938 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6939 n_plans++;
6940 } else {
6941 /*
6942 * The scan interval attribute is kept for backward
6943 * compatibility. If no scan plans are specified and sched scan
6944 * interval is specified, one scan plan will be set with this
6945 * scan interval and infinite number of iterations.
6946 */
6947 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6948 return ERR_PTR(-EINVAL);
6949
6950 n_plans = 1;
6951 }
6952
6953 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6954 return ERR_PTR(-EINVAL);
6955
Luciano Coelho807f8a82011-05-11 17:09:35 +03006956 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006957 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006958 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006959 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006960 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006961 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006962 if (!request)
6963 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006964
6965 if (n_ssids)
6966 request->ssids = (void *)&request->channels[n_channels];
6967 request->n_ssids = n_ssids;
6968 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006969 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006970 request->ie = (void *)(request->ssids + n_ssids);
6971 else
6972 request->ie = (void *)(request->channels + n_channels);
6973 }
6974
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006975 if (n_match_sets) {
6976 if (request->ie)
6977 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006978 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006979 request->match_sets =
6980 (void *)(request->ssids + n_ssids);
6981 else
6982 request->match_sets =
6983 (void *)(request->channels + n_channels);
6984 }
6985 request->n_match_sets = n_match_sets;
6986
Avraham Stern3b06d272015-10-12 09:51:34 +03006987 if (n_match_sets)
6988 request->scan_plans = (void *)(request->match_sets +
6989 n_match_sets);
6990 else if (request->ie)
6991 request->scan_plans = (void *)(request->ie + ie_len);
6992 else if (n_ssids)
6993 request->scan_plans = (void *)(request->ssids + n_ssids);
6994 else
6995 request->scan_plans = (void *)(request->channels + n_channels);
6996
6997 request->n_scan_plans = n_plans;
6998
Luciano Coelho807f8a82011-05-11 17:09:35 +03006999 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007000 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007001 /* user specified, bail out if channel not found */
7002 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007003 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007004 tmp) {
7005 struct ieee80211_channel *chan;
7006
7007 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7008
7009 if (!chan) {
7010 err = -EINVAL;
7011 goto out_free;
7012 }
7013
7014 /* ignore disabled channels */
7015 if (chan->flags & IEEE80211_CHAN_DISABLED)
7016 continue;
7017
7018 request->channels[i] = chan;
7019 i++;
7020 }
7021 } else {
7022 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007023 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007024 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007025
Luciano Coelho807f8a82011-05-11 17:09:35 +03007026 if (!wiphy->bands[band])
7027 continue;
7028 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7029 struct ieee80211_channel *chan;
7030
7031 chan = &wiphy->bands[band]->channels[j];
7032
7033 if (chan->flags & IEEE80211_CHAN_DISABLED)
7034 continue;
7035
7036 request->channels[i] = chan;
7037 i++;
7038 }
7039 }
7040 }
7041
7042 if (!i) {
7043 err = -EINVAL;
7044 goto out_free;
7045 }
7046
7047 request->n_channels = i;
7048
7049 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007050 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007051 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007052 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007053 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007054 err = -EINVAL;
7055 goto out_free;
7056 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007057 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007058 memcpy(request->ssids[i].ssid, nla_data(attr),
7059 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007060 i++;
7061 }
7062 }
7063
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007064 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007065 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007066 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007067 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007068 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007069 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007070
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007071 err = nla_parse_nested(tb,
7072 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7073 attr, nl80211_match_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01007074 if (err)
7075 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007076 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007077 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007078 if (WARN_ON(i >= n_match_sets)) {
7079 /* this indicates a programming error,
7080 * the loop above should have verified
7081 * things properly
7082 */
7083 err = -EINVAL;
7084 goto out_free;
7085 }
7086
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007087 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7088 err = -EINVAL;
7089 goto out_free;
7090 }
7091 memcpy(request->match_sets[i].ssid.ssid,
7092 nla_data(ssid), nla_len(ssid));
7093 request->match_sets[i].ssid.ssid_len =
7094 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007095 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007096 request->match_sets[i].rssi_thold =
7097 default_match_rssi;
7098 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7099 if (rssi)
7100 request->match_sets[i].rssi_thold =
7101 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007102 }
7103 i++;
7104 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007105
7106 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007107 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007108 request->match_sets[0].rssi_thold = default_match_rssi;
7109
7110 request->min_rssi_thold = INT_MAX;
7111 for (i = 0; i < n_match_sets; i++)
7112 request->min_rssi_thold =
7113 min(request->match_sets[i].rssi_thold,
7114 request->min_rssi_thold);
7115 } else {
7116 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007117 }
7118
Johannes Berg9900e482014-02-04 21:01:25 +01007119 if (ie_len) {
7120 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007121 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007122 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007123 request->ie_len);
7124 }
7125
Luciano Coelho256da022014-11-10 16:13:46 +02007126 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007127 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007128 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007129 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7130 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007131 err = -EOPNOTSUPP;
7132 goto out_free;
7133 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007134
7135 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7136 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7137
7138 if (!wdev) /* must be net-detect */
7139 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7140
7141 if (!(wiphy->features & flg)) {
7142 err = -EOPNOTSUPP;
7143 goto out_free;
7144 }
7145
7146 if (wdev && wdev->current_bss) {
7147 err = -EOPNOTSUPP;
7148 goto out_free;
7149 }
7150
7151 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7152 request->mac_addr_mask);
7153 if (err)
7154 goto out_free;
7155 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007156 }
Sam Lefflered4737712012-10-11 21:03:31 -07007157
Luciano Coelho9c748932015-01-16 16:04:09 +02007158 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7159 request->delay =
7160 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7161
Avraham Stern3b06d272015-10-12 09:51:34 +03007162 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7163 if (err)
7164 goto out_free;
7165
Sam Leffler15d60302012-10-11 21:03:34 -07007166 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007167
Luciano Coelho256da022014-11-10 16:13:46 +02007168 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007169
7170out_free:
7171 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007172 return ERR_PTR(err);
7173}
7174
7175static int nl80211_start_sched_scan(struct sk_buff *skb,
7176 struct genl_info *info)
7177{
7178 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7179 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007180 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007181 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007182 int err;
7183
7184 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7185 !rdev->ops->sched_scan_start)
7186 return -EOPNOTSUPP;
7187
7188 if (rdev->sched_scan_req)
7189 return -EINPROGRESS;
7190
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007191 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7192 info->attrs);
7193
7194 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007195 if (err)
7196 goto out_err;
7197
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007198 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007199 if (err)
7200 goto out_free;
7201
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007202 sched_scan_req->dev = dev;
7203 sched_scan_req->wiphy = &rdev->wiphy;
7204
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007205 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7206 sched_scan_req->owner_nlportid = info->snd_portid;
7207
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007208 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007209
7210 nl80211_send_sched_scan(rdev, dev,
7211 NL80211_CMD_START_SCHED_SCAN);
7212 return 0;
7213
7214out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007215 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007216out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007217 return err;
7218}
7219
7220static int nl80211_stop_sched_scan(struct sk_buff *skb,
7221 struct genl_info *info)
7222{
7223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7224
7225 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7226 !rdev->ops->sched_scan_stop)
7227 return -EOPNOTSUPP;
7228
Johannes Berg5fe231e2013-05-08 21:45:15 +02007229 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007230}
7231
Simon Wunderlich04f39042013-02-08 18:16:19 +01007232static int nl80211_start_radar_detection(struct sk_buff *skb,
7233 struct genl_info *info)
7234{
7235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7236 struct net_device *dev = info->user_ptr[1];
7237 struct wireless_dev *wdev = dev->ieee80211_ptr;
7238 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007239 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007240 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007241 int err;
7242
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007243 dfs_region = reg_get_dfs_region(wdev->wiphy);
7244 if (dfs_region == NL80211_DFS_UNSET)
7245 return -EINVAL;
7246
Simon Wunderlich04f39042013-02-08 18:16:19 +01007247 err = nl80211_parse_chandef(rdev, info, &chandef);
7248 if (err)
7249 return err;
7250
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007251 if (netif_carrier_ok(dev))
7252 return -EBUSY;
7253
Simon Wunderlich04f39042013-02-08 18:16:19 +01007254 if (wdev->cac_started)
7255 return -EBUSY;
7256
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007257 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007258 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007259 if (err < 0)
7260 return err;
7261
7262 if (err == 0)
7263 return -EINVAL;
7264
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007265 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007266 return -EINVAL;
7267
7268 if (!rdev->ops->start_radar_detection)
7269 return -EOPNOTSUPP;
7270
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007271 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7272 if (WARN_ON(!cac_time_ms))
7273 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7274
Ilan Peera1056b1b2015-10-22 22:27:46 +03007275 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007276 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007277 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007278 wdev->cac_started = true;
7279 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007280 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007281 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007282 return err;
7283}
7284
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007285static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7286{
7287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7288 struct net_device *dev = info->user_ptr[1];
7289 struct wireless_dev *wdev = dev->ieee80211_ptr;
7290 struct cfg80211_csa_settings params;
7291 /* csa_attrs is defined static to avoid waste of stack size - this
7292 * function is called under RTNL lock, so this should not be a problem.
7293 */
7294 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007295 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007296 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007297 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007298 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007299
7300 if (!rdev->ops->channel_switch ||
7301 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7302 return -EOPNOTSUPP;
7303
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007304 switch (dev->ieee80211_ptr->iftype) {
7305 case NL80211_IFTYPE_AP:
7306 case NL80211_IFTYPE_P2P_GO:
7307 need_new_beacon = true;
7308
7309 /* useless if AP is not running */
7310 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007311 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007312 break;
7313 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007314 if (!wdev->ssid_len)
7315 return -ENOTCONN;
7316 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007317 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007318 if (!wdev->mesh_id_len)
7319 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007320 break;
7321 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007322 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007323 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007324
7325 memset(&params, 0, sizeof(params));
7326
7327 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7328 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7329 return -EINVAL;
7330
7331 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007332 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007333 return -EINVAL;
7334
Luciano Coelho252e07c2014-10-08 09:48:34 +03007335 /* Even though the attribute is u32, the specification says
7336 * u8, so let's make sure we don't overflow.
7337 */
7338 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7339 if (cs_count > 255)
7340 return -EINVAL;
7341
7342 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007343
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007344 if (!need_new_beacon)
7345 goto skip_beacons;
7346
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007347 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7348 if (err)
7349 return err;
7350
7351 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7352 info->attrs[NL80211_ATTR_CSA_IES],
7353 nl80211_policy);
7354 if (err)
7355 return err;
7356
7357 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7358 if (err)
7359 return err;
7360
7361 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7362 return -EINVAL;
7363
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007364 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7365 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007366 return -EINVAL;
7367
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007368 params.n_counter_offsets_beacon = len / sizeof(u16);
7369 if (rdev->wiphy.max_num_csa_counters &&
7370 (params.n_counter_offsets_beacon >
7371 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007372 return -EINVAL;
7373
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007374 params.counter_offsets_beacon =
7375 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7376
7377 /* sanity checks - counters should fit and be the same */
7378 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7379 u16 offset = params.counter_offsets_beacon[i];
7380
7381 if (offset >= params.beacon_csa.tail_len)
7382 return -EINVAL;
7383
7384 if (params.beacon_csa.tail[offset] != params.count)
7385 return -EINVAL;
7386 }
7387
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007388 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007389 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7390 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007391 return -EINVAL;
7392
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007393 params.n_counter_offsets_presp = len / sizeof(u16);
7394 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007395 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007396 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007397 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007398
7399 params.counter_offsets_presp =
7400 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7401
7402 /* sanity checks - counters should fit and be the same */
7403 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7404 u16 offset = params.counter_offsets_presp[i];
7405
7406 if (offset >= params.beacon_csa.probe_resp_len)
7407 return -EINVAL;
7408
7409 if (params.beacon_csa.probe_resp[offset] !=
7410 params.count)
7411 return -EINVAL;
7412 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007413 }
7414
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007415skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007416 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7417 if (err)
7418 return err;
7419
Arik Nemtsov923b3522015-07-08 15:41:44 +03007420 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7421 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007422 return -EINVAL;
7423
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007424 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7425 &params.chandef,
7426 wdev->iftype);
7427 if (err < 0)
7428 return err;
7429
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007430 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007431 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007432
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007433 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7434 params.block_tx = true;
7435
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007436 wdev_lock(wdev);
7437 err = rdev_channel_switch(rdev, dev, &params);
7438 wdev_unlock(wdev);
7439
7440 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007441}
7442
Johannes Berg9720bb32011-06-21 09:45:33 +02007443static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7444 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007445 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007446 struct wireless_dev *wdev,
7447 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007448{
Johannes Berg48ab9052009-07-10 18:42:31 +02007449 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007450 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007451 void *hdr;
7452 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007453
7454 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007455
Eric W. Biederman15e47302012-09-07 20:12:54 +00007456 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007457 NL80211_CMD_NEW_SCAN_RESULTS);
7458 if (!hdr)
7459 return -1;
7460
Johannes Berg9720bb32011-06-21 09:45:33 +02007461 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7462
Johannes Berg97990a02013-04-19 01:02:55 +02007463 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7464 goto nla_put_failure;
7465 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7467 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007468 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7469 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007470 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007471
7472 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7473 if (!bss)
7474 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007475 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007476 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007477 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007478
7479 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007480 /* indicate whether we have probe response data or not */
7481 if (rcu_access_pointer(res->proberesp_ies) &&
7482 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7483 goto fail_unlock_rcu;
7484
7485 /* this pointer prefers to be pointed to probe response data
7486 * but is always valid
7487 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007488 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007489 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007490 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7491 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007492 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007493 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7494 ies->len, ies->data))
7495 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007496 }
Johannes Berg0e227082014-08-12 20:34:30 +02007497
7498 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007499 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007500 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007501 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7502 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007503 goto fail_unlock_rcu;
7504 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7505 ies->len, ies->data))
7506 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007507 }
7508 rcu_read_unlock();
7509
David S. Miller9360ffd2012-03-29 04:41:26 -04007510 if (res->beacon_interval &&
7511 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7512 goto nla_put_failure;
7513 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7514 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007515 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007516 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7517 jiffies_to_msecs(jiffies - intbss->ts)))
7518 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007519
Avraham Stern1d762502016-07-05 17:10:13 +03007520 if (intbss->parent_tsf &&
7521 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7522 intbss->parent_tsf, NL80211_BSS_PAD) ||
7523 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7524 intbss->parent_bssid)))
7525 goto nla_put_failure;
7526
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007527 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007528 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7529 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007530 goto nla_put_failure;
7531
Johannes Berg77965c92009-02-18 18:45:06 +01007532 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007533 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007534 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7535 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007536 break;
7537 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007538 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7539 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007540 break;
7541 default:
7542 break;
7543 }
7544
Johannes Berg48ab9052009-07-10 18:42:31 +02007545 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007546 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007547 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007548 if (intbss == wdev->current_bss &&
7549 nla_put_u32(msg, NL80211_BSS_STATUS,
7550 NL80211_BSS_STATUS_ASSOCIATED))
7551 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007552 break;
7553 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007554 if (intbss == wdev->current_bss &&
7555 nla_put_u32(msg, NL80211_BSS_STATUS,
7556 NL80211_BSS_STATUS_IBSS_JOINED))
7557 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007558 break;
7559 default:
7560 break;
7561 }
7562
Johannes Berg2a519312009-02-10 21:25:55 +01007563 nla_nest_end(msg, bss);
7564
Johannes Berg053c0952015-01-16 22:09:00 +01007565 genlmsg_end(msg, hdr);
7566 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007567
Johannes Berg8cef2c92013-02-05 16:54:31 +01007568 fail_unlock_rcu:
7569 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007570 nla_put_failure:
7571 genlmsg_cancel(msg, hdr);
7572 return -EMSGSIZE;
7573}
7574
Johannes Berg97990a02013-04-19 01:02:55 +02007575static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007576{
Johannes Berg48ab9052009-07-10 18:42:31 +02007577 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007578 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007579 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007580 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007581 int err;
7582
Johannes Berg97990a02013-04-19 01:02:55 +02007583 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007584 if (err)
7585 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007586
Johannes Berg48ab9052009-07-10 18:42:31 +02007587 wdev_lock(wdev);
7588 spin_lock_bh(&rdev->bss_lock);
7589 cfg80211_bss_expire(rdev);
7590
Johannes Berg9720bb32011-06-21 09:45:33 +02007591 cb->seq = rdev->bss_generation;
7592
Johannes Berg48ab9052009-07-10 18:42:31 +02007593 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007594 if (++idx <= start)
7595 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007596 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007597 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007598 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007599 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007600 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007601 }
7602 }
7603
Johannes Berg48ab9052009-07-10 18:42:31 +02007604 spin_unlock_bh(&rdev->bss_lock);
7605 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007606
Johannes Berg97990a02013-04-19 01:02:55 +02007607 cb->args[2] = idx;
7608 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007609
Johannes Berg67748892010-10-04 21:14:06 +02007610 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007611}
7612
Eric W. Biederman15e47302012-09-07 20:12:54 +00007613static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007614 int flags, struct net_device *dev,
7615 bool allow_radio_stats,
7616 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007617{
7618 void *hdr;
7619 struct nlattr *infoattr;
7620
Johannes Berg11f78ac2014-11-14 16:43:50 +01007621 /* skip radio stats if userspace didn't request them */
7622 if (!survey->channel && !allow_radio_stats)
7623 return 0;
7624
Eric W. Biederman15e47302012-09-07 20:12:54 +00007625 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007626 NL80211_CMD_NEW_SURVEY_RESULTS);
7627 if (!hdr)
7628 return -ENOMEM;
7629
David S. Miller9360ffd2012-03-29 04:41:26 -04007630 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7631 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007632
7633 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7634 if (!infoattr)
7635 goto nla_put_failure;
7636
Johannes Berg11f78ac2014-11-14 16:43:50 +01007637 if (survey->channel &&
7638 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007639 survey->channel->center_freq))
7640 goto nla_put_failure;
7641
7642 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7643 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7644 goto nla_put_failure;
7645 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7646 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7647 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007648 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007649 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7650 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007651 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007652 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007653 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7654 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007655 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007656 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007657 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7658 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007659 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007660 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007661 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7662 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007663 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007664 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007665 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7666 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007667 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007668 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007669 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7670 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007671 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007672
7673 nla_nest_end(msg, infoattr);
7674
Johannes Berg053c0952015-01-16 22:09:00 +01007675 genlmsg_end(msg, hdr);
7676 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007677
7678 nla_put_failure:
7679 genlmsg_cancel(msg, hdr);
7680 return -EMSGSIZE;
7681}
7682
Johannes Berg11f78ac2014-11-14 16:43:50 +01007683static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007684{
Johannes Bergc90c39d2016-10-24 14:40:01 +02007685 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Holger Schurig61fa7132009-11-11 12:25:40 +01007686 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007687 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007688 struct wireless_dev *wdev;
7689 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007690 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007691 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007692
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007693 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007694 if (res)
7695 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007696
Johannes Berg11f78ac2014-11-14 16:43:50 +01007697 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02007698 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01007699
Johannes Berg97990a02013-04-19 01:02:55 +02007700 if (!wdev->netdev) {
7701 res = -EINVAL;
7702 goto out_err;
7703 }
7704
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007705 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007706 res = -EOPNOTSUPP;
7707 goto out_err;
7708 }
7709
7710 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007711 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007712 if (res == -ENOENT)
7713 break;
7714 if (res)
7715 goto out_err;
7716
Johannes Berg11f78ac2014-11-14 16:43:50 +01007717 /* don't send disabled channels, but do send non-channel data */
7718 if (survey.channel &&
7719 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007720 survey_idx++;
7721 continue;
7722 }
7723
Holger Schurig61fa7132009-11-11 12:25:40 +01007724 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007725 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007727 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007728 goto out;
7729 survey_idx++;
7730 }
7731
7732 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007733 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007734 res = skb->len;
7735 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007736 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007737 return res;
7738}
7739
Samuel Ortizb23aa672009-07-01 21:26:54 +02007740static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7741{
7742 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7743 NL80211_WPA_VERSION_2));
7744}
7745
Jouni Malinen636a5d32009-03-19 13:39:22 +02007746static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7747{
Johannes Berg4c476992010-10-04 21:36:35 +02007748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7749 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007750 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007751 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7752 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007753 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007754 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007755 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007756
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007757 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7758 return -EINVAL;
7759
7760 if (!info->attrs[NL80211_ATTR_MAC])
7761 return -EINVAL;
7762
Jouni Malinen17780922009-03-27 20:52:47 +02007763 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7764 return -EINVAL;
7765
Johannes Berg19957bb2009-07-02 17:20:43 +02007766 if (!info->attrs[NL80211_ATTR_SSID])
7767 return -EINVAL;
7768
7769 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7770 return -EINVAL;
7771
Johannes Bergfffd0932009-07-08 14:22:54 +02007772 err = nl80211_parse_key(info, &key);
7773 if (err)
7774 return err;
7775
7776 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007777 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7778 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007779 if (!key.p.key || !key.p.key_len)
7780 return -EINVAL;
7781 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7782 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7783 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7784 key.p.key_len != WLAN_KEY_LEN_WEP104))
7785 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007786 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007787 return -EINVAL;
7788 } else {
7789 key.p.key_len = 0;
7790 key.p.key = NULL;
7791 }
7792
Johannes Bergafea0b72010-08-10 09:46:42 +02007793 if (key.idx >= 0) {
7794 int i;
7795 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007796
Johannes Bergafea0b72010-08-10 09:46:42 +02007797 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7798 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7799 ok = true;
7800 break;
7801 }
7802 }
Johannes Berg4c476992010-10-04 21:36:35 +02007803 if (!ok)
7804 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007805 }
7806
Johannes Berg4c476992010-10-04 21:36:35 +02007807 if (!rdev->ops->auth)
7808 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007809
Johannes Berg074ac8d2010-09-16 14:58:22 +02007810 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007811 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7812 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007813
Johannes Berg19957bb2009-07-02 17:20:43 +02007814 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007815 chan = nl80211_get_valid_chan(&rdev->wiphy,
7816 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7817 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007818 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007819
Johannes Berg19957bb2009-07-02 17:20:43 +02007820 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7821 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7822
7823 if (info->attrs[NL80211_ATTR_IE]) {
7824 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7825 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7826 }
7827
7828 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007829 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007830 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007831
Jouni Malinen63181062016-10-27 00:42:02 +03007832 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7833 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7834 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7835 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007836 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007837 return -EINVAL;
7838
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007839 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03007840 if (auth_type != NL80211_AUTHTYPE_SAE &&
7841 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7842 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7843 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007844 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007845 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7846 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007847 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007848 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007849 return -EINVAL;
7850 }
7851
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007852 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7853
Johannes Berg95de8172012-01-20 13:55:25 +01007854 /*
7855 * Since we no longer track auth state, ignore
7856 * requests to only change local state.
7857 */
7858 if (local_state_change)
7859 return 0;
7860
Johannes Berg91bf9b22013-05-15 17:44:01 +02007861 wdev_lock(dev->ieee80211_ptr);
7862 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7863 ssid, ssid_len, ie, ie_len,
7864 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007865 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007866 wdev_unlock(dev->ieee80211_ptr);
7867 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007868}
7869
Johannes Bergc0692b82010-08-27 14:26:53 +03007870static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7871 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007872 struct cfg80211_crypto_settings *settings,
7873 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007874{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007875 memset(settings, 0, sizeof(*settings));
7876
Samuel Ortizb23aa672009-07-01 21:26:54 +02007877 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7878
Johannes Bergc0692b82010-08-27 14:26:53 +03007879 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7880 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007881
Johannes Bergc0692b82010-08-27 14:26:53 +03007882 proto = nla_get_u16(
7883 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7884 settings->control_port_ethertype = cpu_to_be16(proto);
7885 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7886 proto != ETH_P_PAE)
7887 return -EINVAL;
7888 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7889 settings->control_port_no_encrypt = true;
7890 } else
7891 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7892
Samuel Ortizb23aa672009-07-01 21:26:54 +02007893 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7894 void *data;
7895 int len, i;
7896
7897 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7898 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7899 settings->n_ciphers_pairwise = len / sizeof(u32);
7900
7901 if (len % sizeof(u32))
7902 return -EINVAL;
7903
Johannes Berg3dc27d22009-07-02 21:36:37 +02007904 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007905 return -EINVAL;
7906
7907 memcpy(settings->ciphers_pairwise, data, len);
7908
7909 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007910 if (!cfg80211_supported_cipher_suite(
7911 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007912 settings->ciphers_pairwise[i]))
7913 return -EINVAL;
7914 }
7915
7916 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7917 settings->cipher_group =
7918 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007919 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7920 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007921 return -EINVAL;
7922 }
7923
7924 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7925 settings->wpa_versions =
7926 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7927 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7928 return -EINVAL;
7929 }
7930
7931 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7932 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007933 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007934
7935 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7936 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7937 settings->n_akm_suites = len / sizeof(u32);
7938
7939 if (len % sizeof(u32))
7940 return -EINVAL;
7941
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007942 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7943 return -EINVAL;
7944
Samuel Ortizb23aa672009-07-01 21:26:54 +02007945 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007946 }
7947
7948 return 0;
7949}
7950
Jouni Malinen636a5d32009-03-19 13:39:22 +02007951static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7952{
Johannes Berg4c476992010-10-04 21:36:35 +02007953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7954 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007955 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007956 struct cfg80211_assoc_request req = {};
7957 const u8 *bssid, *ssid;
7958 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007959
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007960 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7961 return -EINVAL;
7962
7963 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007964 !info->attrs[NL80211_ATTR_SSID] ||
7965 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007966 return -EINVAL;
7967
Johannes Berg4c476992010-10-04 21:36:35 +02007968 if (!rdev->ops->assoc)
7969 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007970
Johannes Berg074ac8d2010-09-16 14:58:22 +02007971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7973 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007974
Johannes Berg19957bb2009-07-02 17:20:43 +02007975 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007976
Jouni Malinen664834d2014-01-15 00:01:44 +02007977 chan = nl80211_get_valid_chan(&rdev->wiphy,
7978 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7979 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007980 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007981
Johannes Berg19957bb2009-07-02 17:20:43 +02007982 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7983 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007984
7985 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007986 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7987 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007988 }
7989
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007990 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007991 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007992 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007993 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007994 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007995 else if (mfp != NL80211_MFP_NO)
7996 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007997 }
7998
Johannes Berg3e5d7642009-07-07 14:37:26 +02007999 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01008000 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02008001
Ben Greear7e7c8922011-11-18 11:31:59 -08008002 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008003 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08008004
8005 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008006 memcpy(&req.ht_capa_mask,
8007 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8008 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008009
8010 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008011 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008012 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008013 memcpy(&req.ht_capa,
8014 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8015 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008016 }
8017
Johannes Bergee2aca32013-02-21 17:36:01 +01008018 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008019 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008020
8021 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008022 memcpy(&req.vht_capa_mask,
8023 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8024 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008025
8026 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008027 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008028 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008029 memcpy(&req.vht_capa,
8030 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8031 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008032 }
8033
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008034 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008035 if (!((rdev->wiphy.features &
8036 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8037 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8038 !wiphy_ext_feature_isset(&rdev->wiphy,
8039 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008040 return -EINVAL;
8041 req.flags |= ASSOC_REQ_USE_RRM;
8042 }
8043
Jouni Malinen348bd452016-10-27 00:42:03 +03008044 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
8045 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
8046 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
8047 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
8048 return -EINVAL;
8049 req.fils_nonces =
8050 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
8051 }
8052
Johannes Bergf62fab72013-02-21 20:09:09 +01008053 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008054 if (!err) {
8055 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01008056 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8057 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008058 wdev_unlock(dev->ieee80211_ptr);
8059 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008060
Jouni Malinen636a5d32009-03-19 13:39:22 +02008061 return err;
8062}
8063
8064static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8065{
Johannes Berg4c476992010-10-04 21:36:35 +02008066 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8067 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008068 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008069 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008070 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008071 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008072
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008073 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8074 return -EINVAL;
8075
8076 if (!info->attrs[NL80211_ATTR_MAC])
8077 return -EINVAL;
8078
8079 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8080 return -EINVAL;
8081
Johannes Berg4c476992010-10-04 21:36:35 +02008082 if (!rdev->ops->deauth)
8083 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008084
Johannes Berg074ac8d2010-09-16 14:58:22 +02008085 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008086 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8087 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008088
Johannes Berg19957bb2009-07-02 17:20:43 +02008089 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008090
Johannes Berg19957bb2009-07-02 17:20:43 +02008091 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8092 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008093 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008094 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008095 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008096
8097 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008098 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8099 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008100 }
8101
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008102 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8103
Johannes Berg91bf9b22013-05-15 17:44:01 +02008104 wdev_lock(dev->ieee80211_ptr);
8105 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8106 local_state_change);
8107 wdev_unlock(dev->ieee80211_ptr);
8108 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008109}
8110
8111static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8112{
Johannes Berg4c476992010-10-04 21:36:35 +02008113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8114 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008115 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008116 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008117 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008118 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008119
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008120 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8121 return -EINVAL;
8122
8123 if (!info->attrs[NL80211_ATTR_MAC])
8124 return -EINVAL;
8125
8126 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8127 return -EINVAL;
8128
Johannes Berg4c476992010-10-04 21:36:35 +02008129 if (!rdev->ops->disassoc)
8130 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008131
Johannes Berg074ac8d2010-09-16 14:58:22 +02008132 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008133 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8134 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008135
Johannes Berg19957bb2009-07-02 17:20:43 +02008136 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008137
Johannes Berg19957bb2009-07-02 17:20:43 +02008138 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8139 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008140 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008141 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008142 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008143
8144 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008145 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8146 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008147 }
8148
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008149 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8150
Johannes Berg91bf9b22013-05-15 17:44:01 +02008151 wdev_lock(dev->ieee80211_ptr);
8152 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8153 local_state_change);
8154 wdev_unlock(dev->ieee80211_ptr);
8155 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008156}
8157
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008158static bool
8159nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008160 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008161 int rateval)
8162{
8163 struct wiphy *wiphy = &rdev->wiphy;
8164 bool found = false;
8165 int band, i;
8166
Johannes Berg57fbcce2016-04-12 15:56:15 +02008167 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008168 struct ieee80211_supported_band *sband;
8169
8170 sband = wiphy->bands[band];
8171 if (!sband)
8172 continue;
8173
8174 for (i = 0; i < sband->n_bitrates; i++) {
8175 if (sband->bitrates[i].bitrate == rateval) {
8176 mcast_rate[band] = i + 1;
8177 found = true;
8178 break;
8179 }
8180 }
8181 }
8182
8183 return found;
8184}
8185
Johannes Berg04a773a2009-04-19 21:24:32 +02008186static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8187{
Johannes Berg4c476992010-10-04 21:36:35 +02008188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8189 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008190 struct cfg80211_ibss_params ibss;
8191 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008192 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008193 int err;
8194
Johannes Berg8e30bc52009-04-22 17:45:38 +02008195 memset(&ibss, 0, sizeof(ibss));
8196
Johannes Berg04a773a2009-04-19 21:24:32 +02008197 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8198 return -EINVAL;
8199
Johannes Berg683b6d32012-11-08 21:25:48 +01008200 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008201 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8202 return -EINVAL;
8203
Johannes Berg8e30bc52009-04-22 17:45:38 +02008204 ibss.beacon_interval = 100;
8205
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308206 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008207 ibss.beacon_interval =
8208 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308209
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308210 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8211 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308212 if (err)
8213 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008214
Johannes Berg4c476992010-10-04 21:36:35 +02008215 if (!rdev->ops->join_ibss)
8216 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008217
Johannes Berg4c476992010-10-04 21:36:35 +02008218 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8219 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008220
Johannes Berg79c97e92009-07-07 03:56:12 +02008221 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008222
Johannes Berg39193492011-09-16 13:45:25 +02008223 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008224 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008225
8226 if (!is_valid_ether_addr(ibss.bssid))
8227 return -EINVAL;
8228 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008229 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8230 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8231
8232 if (info->attrs[NL80211_ATTR_IE]) {
8233 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8234 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8235 }
8236
Johannes Berg683b6d32012-11-08 21:25:48 +01008237 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8238 if (err)
8239 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008240
Ilan Peer174e0cd2014-02-23 09:13:01 +02008241 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8242 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008243 return -EINVAL;
8244
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008245 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008246 case NL80211_CHAN_WIDTH_5:
8247 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008248 case NL80211_CHAN_WIDTH_20_NOHT:
8249 break;
8250 case NL80211_CHAN_WIDTH_20:
8251 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008252 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8253 return -EINVAL;
8254 break;
8255 case NL80211_CHAN_WIDTH_80:
8256 case NL80211_CHAN_WIDTH_80P80:
8257 case NL80211_CHAN_WIDTH_160:
8258 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8259 return -EINVAL;
8260 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8261 NL80211_EXT_FEATURE_VHT_IBSS))
8262 return -EINVAL;
8263 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008264 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008265 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008266 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008267
Johannes Berg04a773a2009-04-19 21:24:32 +02008268 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008269 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008270
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008271 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8272 u8 *rates =
8273 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8274 int n_rates =
8275 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8276 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008277 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008278
Johannes Berg34850ab2011-07-18 18:08:35 +02008279 err = ieee80211_get_ratemask(sband, rates, n_rates,
8280 &ibss.basic_rates);
8281 if (err)
8282 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008283 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008284
Simon Wunderlich803768f2013-06-28 10:39:58 +02008285 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8286 memcpy(&ibss.ht_capa_mask,
8287 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8288 sizeof(ibss.ht_capa_mask));
8289
8290 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8291 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8292 return -EINVAL;
8293 memcpy(&ibss.ht_capa,
8294 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8295 sizeof(ibss.ht_capa));
8296 }
8297
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008298 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8299 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8300 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8301 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008302
Johannes Berg4c476992010-10-04 21:36:35 +02008303 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308304 bool no_ht = false;
8305
Johannes Berg4c476992010-10-04 21:36:35 +02008306 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308307 info->attrs[NL80211_ATTR_KEYS],
8308 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008309 if (IS_ERR(connkeys))
8310 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308311
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008312 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8313 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008314 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308315 return -EINVAL;
8316 }
Johannes Berg4c476992010-10-04 21:36:35 +02008317 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008318
Antonio Quartulli267335d2012-01-31 20:25:47 +01008319 ibss.control_port =
8320 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8321
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008322 ibss.userspace_handles_dfs =
8323 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8324
Johannes Berg4c476992010-10-04 21:36:35 +02008325 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008326 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008327 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008328 return err;
8329}
8330
8331static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8332{
Johannes Berg4c476992010-10-04 21:36:35 +02008333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8334 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008335
Johannes Berg4c476992010-10-04 21:36:35 +02008336 if (!rdev->ops->leave_ibss)
8337 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008338
Johannes Berg4c476992010-10-04 21:36:35 +02008339 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8340 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008341
Johannes Berg4c476992010-10-04 21:36:35 +02008342 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008343}
8344
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008345static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8346{
8347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8348 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008349 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008350 u32 nla_rate;
8351 int err;
8352
8353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008354 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8355 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008356 return -EOPNOTSUPP;
8357
8358 if (!rdev->ops->set_mcast_rate)
8359 return -EOPNOTSUPP;
8360
8361 memset(mcast_rate, 0, sizeof(mcast_rate));
8362
8363 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8364 return -EINVAL;
8365
8366 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8367 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8368 return -EINVAL;
8369
Ilan Peera1056b1b2015-10-22 22:27:46 +03008370 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008371
8372 return err;
8373}
8374
Johannes Bergad7e7182013-11-13 13:37:47 +01008375static struct sk_buff *
8376__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008377 struct wireless_dev *wdev, int approxlen,
8378 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008379 enum nl80211_attrs attr,
8380 const struct nl80211_vendor_cmd_info *info,
8381 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008382{
8383 struct sk_buff *skb;
8384 void *hdr;
8385 struct nlattr *data;
8386
8387 skb = nlmsg_new(approxlen + 100, gfp);
8388 if (!skb)
8389 return NULL;
8390
8391 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8392 if (!hdr) {
8393 kfree_skb(skb);
8394 return NULL;
8395 }
8396
8397 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8398 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008399
8400 if (info) {
8401 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8402 info->vendor_id))
8403 goto nla_put_failure;
8404 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8405 info->subcmd))
8406 goto nla_put_failure;
8407 }
8408
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008409 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008410 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8411 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008412 goto nla_put_failure;
8413 if (wdev->netdev &&
8414 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8415 wdev->netdev->ifindex))
8416 goto nla_put_failure;
8417 }
8418
Johannes Bergad7e7182013-11-13 13:37:47 +01008419 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008420 if (!data)
8421 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008422
8423 ((void **)skb->cb)[0] = rdev;
8424 ((void **)skb->cb)[1] = hdr;
8425 ((void **)skb->cb)[2] = data;
8426
8427 return skb;
8428
8429 nla_put_failure:
8430 kfree_skb(skb);
8431 return NULL;
8432}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008433
Johannes Berge03ad6e2014-01-01 17:22:30 +01008434struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008435 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008436 enum nl80211_commands cmd,
8437 enum nl80211_attrs attr,
8438 int vendor_event_idx,
8439 int approxlen, gfp_t gfp)
8440{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008441 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008442 const struct nl80211_vendor_cmd_info *info;
8443
8444 switch (cmd) {
8445 case NL80211_CMD_TESTMODE:
8446 if (WARN_ON(vendor_event_idx != -1))
8447 return NULL;
8448 info = NULL;
8449 break;
8450 case NL80211_CMD_VENDOR:
8451 if (WARN_ON(vendor_event_idx < 0 ||
8452 vendor_event_idx >= wiphy->n_vendor_events))
8453 return NULL;
8454 info = &wiphy->vendor_events[vendor_event_idx];
8455 break;
8456 default:
8457 WARN_ON(1);
8458 return NULL;
8459 }
8460
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008461 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008462 cmd, attr, info, gfp);
8463}
8464EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8465
8466void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8467{
8468 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8469 void *hdr = ((void **)skb->cb)[1];
8470 struct nlattr *data = ((void **)skb->cb)[2];
8471 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8472
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008473 /* clear CB data for netlink core to own from now on */
8474 memset(skb->cb, 0, sizeof(skb->cb));
8475
Johannes Berge03ad6e2014-01-01 17:22:30 +01008476 nla_nest_end(skb, data);
8477 genlmsg_end(skb, hdr);
8478
8479 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8480 mcgrp = NL80211_MCGRP_VENDOR;
8481
8482 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8483 mcgrp, gfp);
8484}
8485EXPORT_SYMBOL(__cfg80211_send_event_skb);
8486
Johannes Bergaff89a92009-07-01 21:26:51 +02008487#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008488static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8489{
Johannes Berg4c476992010-10-04 21:36:35 +02008490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008491 struct wireless_dev *wdev =
8492 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008493 int err;
8494
David Spinadelfc73f112013-07-31 18:04:15 +03008495 if (!rdev->ops->testmode_cmd)
8496 return -EOPNOTSUPP;
8497
8498 if (IS_ERR(wdev)) {
8499 err = PTR_ERR(wdev);
8500 if (err != -EINVAL)
8501 return err;
8502 wdev = NULL;
8503 } else if (wdev->wiphy != &rdev->wiphy) {
8504 return -EINVAL;
8505 }
8506
Johannes Bergaff89a92009-07-01 21:26:51 +02008507 if (!info->attrs[NL80211_ATTR_TESTDATA])
8508 return -EINVAL;
8509
Johannes Bergad7e7182013-11-13 13:37:47 +01008510 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008511 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008512 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8513 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008514 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008515
Johannes Bergaff89a92009-07-01 21:26:51 +02008516 return err;
8517}
8518
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008519static int nl80211_testmode_dump(struct sk_buff *skb,
8520 struct netlink_callback *cb)
8521{
Johannes Berg00918d32011-12-13 17:22:05 +01008522 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008523 int err;
8524 long phy_idx;
8525 void *data = NULL;
8526 int data_len = 0;
8527
Johannes Berg5fe231e2013-05-08 21:45:15 +02008528 rtnl_lock();
8529
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008530 if (cb->args[0]) {
8531 /*
8532 * 0 is a valid index, but not valid for args[0],
8533 * so we need to offset by 1.
8534 */
8535 phy_idx = cb->args[0] - 1;
8536 } else {
Johannes Bergc90c39d2016-10-24 14:40:01 +02008537 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
8538
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008539 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +02008540 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008541 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008542 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008543
Johannes Bergc90c39d2016-10-24 14:40:01 +02008544 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +02008545 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008546 err = PTR_ERR(rdev);
8547 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008548 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008549 phy_idx = rdev->wiphy_idx;
8550 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008551
Johannes Bergc90c39d2016-10-24 14:40:01 +02008552 if (attrbuf[NL80211_ATTR_TESTDATA])
8553 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008554 }
8555
8556 if (cb->args[1]) {
8557 data = nla_data((void *)cb->args[1]);
8558 data_len = nla_len((void *)cb->args[1]);
8559 }
8560
Johannes Berg00918d32011-12-13 17:22:05 +01008561 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8562 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008563 err = -ENOENT;
8564 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008565 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008566
Johannes Berg00918d32011-12-13 17:22:05 +01008567 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008568 err = -EOPNOTSUPP;
8569 goto out_err;
8570 }
8571
8572 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008573 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008574 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8575 NL80211_CMD_TESTMODE);
8576 struct nlattr *tmdata;
8577
Dan Carpentercb35fba2013-08-14 14:50:01 +03008578 if (!hdr)
8579 break;
8580
David S. Miller9360ffd2012-03-29 04:41:26 -04008581 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008582 genlmsg_cancel(skb, hdr);
8583 break;
8584 }
8585
8586 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8587 if (!tmdata) {
8588 genlmsg_cancel(skb, hdr);
8589 break;
8590 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008591 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008592 nla_nest_end(skb, tmdata);
8593
8594 if (err == -ENOBUFS || err == -ENOENT) {
8595 genlmsg_cancel(skb, hdr);
8596 break;
8597 } else if (err) {
8598 genlmsg_cancel(skb, hdr);
8599 goto out_err;
8600 }
8601
8602 genlmsg_end(skb, hdr);
8603 }
8604
8605 err = skb->len;
8606 /* see above */
8607 cb->args[0] = phy_idx + 1;
8608 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008609 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008610 return err;
8611}
Johannes Bergaff89a92009-07-01 21:26:51 +02008612#endif
8613
Samuel Ortizb23aa672009-07-01 21:26:54 +02008614static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8615{
Johannes Berg4c476992010-10-04 21:36:35 +02008616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8617 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008618 struct cfg80211_connect_params connect;
8619 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008620 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008621 int err;
8622
8623 memset(&connect, 0, sizeof(connect));
8624
8625 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8626 return -EINVAL;
8627
8628 if (!info->attrs[NL80211_ATTR_SSID] ||
8629 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8630 return -EINVAL;
8631
8632 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8633 connect.auth_type =
8634 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008635 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8636 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008637 return -EINVAL;
8638 } else
8639 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8640
8641 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8642
Johannes Bergc0692b82010-08-27 14:26:53 +03008643 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008644 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008645 if (err)
8646 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008647
Johannes Berg074ac8d2010-09-16 14:58:22 +02008648 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008649 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8650 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008651
Johannes Berg79c97e92009-07-07 03:56:12 +02008652 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008653
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308654 connect.bg_scan_period = -1;
8655 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8656 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8657 connect.bg_scan_period =
8658 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8659 }
8660
Samuel Ortizb23aa672009-07-01 21:26:54 +02008661 if (info->attrs[NL80211_ATTR_MAC])
8662 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008663 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8664 connect.bssid_hint =
8665 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008666 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8667 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8668
8669 if (info->attrs[NL80211_ATTR_IE]) {
8670 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8671 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8672 }
8673
Jouni Malinencee00a92013-01-15 17:15:57 +02008674 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8675 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8676 if (connect.mfp != NL80211_MFP_REQUIRED &&
8677 connect.mfp != NL80211_MFP_NO)
8678 return -EINVAL;
8679 } else {
8680 connect.mfp = NL80211_MFP_NO;
8681 }
8682
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008683 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8684 connect.prev_bssid =
8685 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8686
Samuel Ortizb23aa672009-07-01 21:26:54 +02008687 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008688 connect.channel = nl80211_get_valid_chan(
8689 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8690 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008691 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008692 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008693 connect.channel_hint = nl80211_get_valid_chan(
8694 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8695 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008696 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008697 }
8698
Johannes Bergfffd0932009-07-08 14:22:54 +02008699 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8700 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308701 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008702 if (IS_ERR(connkeys))
8703 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008704 }
8705
Ben Greear7e7c8922011-11-18 11:31:59 -08008706 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8707 connect.flags |= ASSOC_REQ_DISABLE_HT;
8708
8709 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8710 memcpy(&connect.ht_capa_mask,
8711 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8712 sizeof(connect.ht_capa_mask));
8713
8714 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008715 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008716 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008717 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008718 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008719 memcpy(&connect.ht_capa,
8720 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8721 sizeof(connect.ht_capa));
8722 }
8723
Johannes Bergee2aca32013-02-21 17:36:01 +01008724 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8725 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8726
8727 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8728 memcpy(&connect.vht_capa_mask,
8729 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8730 sizeof(connect.vht_capa_mask));
8731
8732 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8733 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008734 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008735 return -EINVAL;
8736 }
8737 memcpy(&connect.vht_capa,
8738 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8739 sizeof(connect.vht_capa));
8740 }
8741
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008742 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008743 if (!((rdev->wiphy.features &
8744 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8745 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8746 !wiphy_ext_feature_isset(&rdev->wiphy,
8747 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008748 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008749 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008750 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008751 connect.flags |= ASSOC_REQ_USE_RRM;
8752 }
8753
Lior David34d50512016-01-28 10:58:25 +02008754 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008755 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008756 kzfree(connkeys);
8757 return -EOPNOTSUPP;
8758 }
8759
Arend van Spriel38de03d2016-03-02 20:37:18 +01008760 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8761 /* bss selection makes no sense if bssid is set */
8762 if (connect.bssid) {
8763 kzfree(connkeys);
8764 return -EINVAL;
8765 }
8766
8767 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8768 wiphy, &connect.bss_select);
8769 if (err) {
8770 kzfree(connkeys);
8771 return err;
8772 }
8773 }
8774
Johannes Berg83739b02013-05-15 17:44:01 +02008775 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd9c42016-03-29 13:53:28 +03008776 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8777 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008778 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008779 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008780 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008781 return err;
8782}
8783
vamsi krishna088e8df2016-10-27 16:51:11 +03008784static int nl80211_update_connect_params(struct sk_buff *skb,
8785 struct genl_info *info)
8786{
8787 struct cfg80211_connect_params connect = {};
8788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8789 struct net_device *dev = info->user_ptr[1];
8790 struct wireless_dev *wdev = dev->ieee80211_ptr;
8791 u32 changed = 0;
8792 int ret;
8793
8794 if (!rdev->ops->update_connect_params)
8795 return -EOPNOTSUPP;
8796
8797 if (info->attrs[NL80211_ATTR_IE]) {
8798 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8799 return -EINVAL;
8800 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8801 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8802 changed |= UPDATE_ASSOC_IES;
8803 }
8804
8805 wdev_lock(dev->ieee80211_ptr);
8806 if (!wdev->current_bss)
8807 ret = -ENOLINK;
8808 else
8809 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
8810 wdev_unlock(dev->ieee80211_ptr);
8811
8812 return ret;
8813}
8814
Samuel Ortizb23aa672009-07-01 21:26:54 +02008815static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8816{
Johannes Berg4c476992010-10-04 21:36:35 +02008817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8818 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008819 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008820 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008821
8822 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8823 reason = WLAN_REASON_DEAUTH_LEAVING;
8824 else
8825 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8826
8827 if (reason == 0)
8828 return -EINVAL;
8829
Johannes Berg074ac8d2010-09-16 14:58:22 +02008830 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008831 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8832 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008833
Johannes Berg83739b02013-05-15 17:44:01 +02008834 wdev_lock(dev->ieee80211_ptr);
8835 ret = cfg80211_disconnect(rdev, dev, reason, true);
8836 wdev_unlock(dev->ieee80211_ptr);
8837 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008838}
8839
Johannes Berg463d0182009-07-14 00:33:35 +02008840static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8841{
Johannes Berg4c476992010-10-04 21:36:35 +02008842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008843 struct net *net;
8844 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008845
Vadim Kochan4b681c82015-01-12 16:34:05 +02008846 if (info->attrs[NL80211_ATTR_PID]) {
8847 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8848
8849 net = get_net_ns_by_pid(pid);
8850 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8851 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8852
8853 net = get_net_ns_by_fd(fd);
8854 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008855 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008856 }
Johannes Berg463d0182009-07-14 00:33:35 +02008857
Johannes Berg4c476992010-10-04 21:36:35 +02008858 if (IS_ERR(net))
8859 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008860
8861 err = 0;
8862
8863 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008864 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8865 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008866
Johannes Berg463d0182009-07-14 00:33:35 +02008867 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008868 return err;
8869}
8870
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008871static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8872{
Johannes Berg4c476992010-10-04 21:36:35 +02008873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008874 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8875 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008876 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008877 struct cfg80211_pmksa pmksa;
8878
8879 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8880
8881 if (!info->attrs[NL80211_ATTR_MAC])
8882 return -EINVAL;
8883
8884 if (!info->attrs[NL80211_ATTR_PMKID])
8885 return -EINVAL;
8886
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008887 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8888 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8889
Johannes Berg074ac8d2010-09-16 14:58:22 +02008890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8892 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008893
8894 switch (info->genlhdr->cmd) {
8895 case NL80211_CMD_SET_PMKSA:
8896 rdev_ops = rdev->ops->set_pmksa;
8897 break;
8898 case NL80211_CMD_DEL_PMKSA:
8899 rdev_ops = rdev->ops->del_pmksa;
8900 break;
8901 default:
8902 WARN_ON(1);
8903 break;
8904 }
8905
Johannes Berg4c476992010-10-04 21:36:35 +02008906 if (!rdev_ops)
8907 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008908
Johannes Berg4c476992010-10-04 21:36:35 +02008909 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008910}
8911
8912static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8913{
Johannes Berg4c476992010-10-04 21:36:35 +02008914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8915 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008916
Johannes Berg074ac8d2010-09-16 14:58:22 +02008917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8919 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008920
Johannes Berg4c476992010-10-04 21:36:35 +02008921 if (!rdev->ops->flush_pmksa)
8922 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008923
Hila Gonene35e4d22012-06-27 17:19:42 +03008924 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008925}
8926
Arik Nemtsov109086c2011-09-28 14:12:50 +03008927static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8928{
8929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8930 struct net_device *dev = info->user_ptr[1];
8931 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308932 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008933 u16 status_code;
8934 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008935 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008936
8937 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8938 !rdev->ops->tdls_mgmt)
8939 return -EOPNOTSUPP;
8940
8941 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8942 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8943 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8944 !info->attrs[NL80211_ATTR_IE] ||
8945 !info->attrs[NL80211_ATTR_MAC])
8946 return -EINVAL;
8947
8948 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8949 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8950 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8951 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008952 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308953 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8954 peer_capability =
8955 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008956
Hila Gonene35e4d22012-06-27 17:19:42 +03008957 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308958 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008959 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008960 nla_data(info->attrs[NL80211_ATTR_IE]),
8961 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008962}
8963
8964static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8965{
8966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8967 struct net_device *dev = info->user_ptr[1];
8968 enum nl80211_tdls_operation operation;
8969 u8 *peer;
8970
8971 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8972 !rdev->ops->tdls_oper)
8973 return -EOPNOTSUPP;
8974
8975 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8976 !info->attrs[NL80211_ATTR_MAC])
8977 return -EINVAL;
8978
8979 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8980 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8981
Hila Gonene35e4d22012-06-27 17:19:42 +03008982 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008983}
8984
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008985static int nl80211_remain_on_channel(struct sk_buff *skb,
8986 struct genl_info *info)
8987{
Johannes Berg4c476992010-10-04 21:36:35 +02008988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008989 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008990 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008991 struct sk_buff *msg;
8992 void *hdr;
8993 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008994 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008995 int err;
8996
8997 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8998 !info->attrs[NL80211_ATTR_DURATION])
8999 return -EINVAL;
9000
9001 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
9002
Johannes Berg7c4ef712011-11-18 15:33:48 +01009003 if (!rdev->ops->remain_on_channel ||
9004 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02009005 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009006
Johannes Bergebf348f2012-06-01 12:50:54 +02009007 /*
9008 * We should be on that channel for at least a minimum amount of
9009 * time (10ms) but no longer than the driver supports.
9010 */
9011 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9012 duration > rdev->wiphy.max_remain_on_channel_duration)
9013 return -EINVAL;
9014
Johannes Berg683b6d32012-11-08 21:25:48 +01009015 err = nl80211_parse_chandef(rdev, info, &chandef);
9016 if (err)
9017 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009018
9019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009020 if (!msg)
9021 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009022
Eric W. Biederman15e47302012-09-07 20:12:54 +00009023 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009024 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009025 if (!hdr) {
9026 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009027 goto free_msg;
9028 }
9029
Johannes Berg683b6d32012-11-08 21:25:48 +01009030 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
9031 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009032
9033 if (err)
9034 goto free_msg;
9035
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009036 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9037 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009038 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009039
9040 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009041
9042 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009043
9044 nla_put_failure:
9045 err = -ENOBUFS;
9046 free_msg:
9047 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009048 return err;
9049}
9050
9051static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9052 struct genl_info *info)
9053{
Johannes Berg4c476992010-10-04 21:36:35 +02009054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009055 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009056 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009057
9058 if (!info->attrs[NL80211_ATTR_COOKIE])
9059 return -EINVAL;
9060
Johannes Berg4c476992010-10-04 21:36:35 +02009061 if (!rdev->ops->cancel_remain_on_channel)
9062 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009063
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009064 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9065
Hila Gonene35e4d22012-06-27 17:19:42 +03009066 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009067}
9068
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009069static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9070 struct genl_info *info)
9071{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009072 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309073 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009074 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309075 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009076
Johannes Berg4c476992010-10-04 21:36:35 +02009077 if (!rdev->ops->set_bitrate_mask)
9078 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009079
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309080 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9081 if (err)
9082 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009083
Hila Gonene35e4d22012-06-27 17:19:42 +03009084 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009085}
9086
Johannes Berg2e161f72010-08-12 15:38:38 +02009087static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009088{
Johannes Berg4c476992010-10-04 21:36:35 +02009089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009090 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009091 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009092
9093 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9094 return -EINVAL;
9095
Johannes Berg2e161f72010-08-12 15:38:38 +02009096 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9097 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009098
Johannes Berg71bbc992012-06-15 15:30:18 +02009099 switch (wdev->iftype) {
9100 case NL80211_IFTYPE_STATION:
9101 case NL80211_IFTYPE_ADHOC:
9102 case NL80211_IFTYPE_P2P_CLIENT:
9103 case NL80211_IFTYPE_AP:
9104 case NL80211_IFTYPE_AP_VLAN:
9105 case NL80211_IFTYPE_MESH_POINT:
9106 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009107 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009108 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009109 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009110 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009111 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009112 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009113
9114 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009115 if (!rdev->ops->mgmt_tx)
9116 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009117
Eric W. Biederman15e47302012-09-07 20:12:54 +00009118 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009119 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9120 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009121}
9122
Johannes Berg2e161f72010-08-12 15:38:38 +02009123static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009124{
Johannes Berg4c476992010-10-04 21:36:35 +02009125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009126 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009127 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009128 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009129 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009130 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009131 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009132 struct cfg80211_mgmt_tx_params params = {
9133 .dont_wait_for_ack =
9134 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9135 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009136
Johannes Berg683b6d32012-11-08 21:25:48 +01009137 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009138 return -EINVAL;
9139
Johannes Berg4c476992010-10-04 21:36:35 +02009140 if (!rdev->ops->mgmt_tx)
9141 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009142
Johannes Berg71bbc992012-06-15 15:30:18 +02009143 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009144 case NL80211_IFTYPE_P2P_DEVICE:
9145 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9146 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009147 case NL80211_IFTYPE_STATION:
9148 case NL80211_IFTYPE_ADHOC:
9149 case NL80211_IFTYPE_P2P_CLIENT:
9150 case NL80211_IFTYPE_AP:
9151 case NL80211_IFTYPE_AP_VLAN:
9152 case NL80211_IFTYPE_MESH_POINT:
9153 case NL80211_IFTYPE_P2P_GO:
9154 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009155 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009156 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009157 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009158 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009159
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009160 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009161 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009162 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009163 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009164
9165 /*
9166 * We should wait on the channel for at least a minimum amount
9167 * of time (10ms) but no longer than the driver supports.
9168 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009169 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9170 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009171 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009172 }
9173
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009174 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009175
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009176 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009177 return -EINVAL;
9178
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009179 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309180
Antonio Quartulliea141b752013-06-11 14:20:03 +02009181 /* get the channel if any has been specified, otherwise pass NULL to
9182 * the driver. The latter will use the current one
9183 */
9184 chandef.chan = NULL;
9185 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9186 err = nl80211_parse_chandef(rdev, info, &chandef);
9187 if (err)
9188 return err;
9189 }
9190
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009191 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009192 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009193
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009194 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9195 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9196
9197 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9198 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9199 int i;
9200
9201 if (len % sizeof(u16))
9202 return -EINVAL;
9203
9204 params.n_csa_offsets = len / sizeof(u16);
9205 params.csa_offsets =
9206 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9207
9208 /* check that all the offsets fit the frame */
9209 for (i = 0; i < params.n_csa_offsets; i++) {
9210 if (params.csa_offsets[i] >= params.len)
9211 return -EINVAL;
9212 }
9213 }
9214
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009215 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009216 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9217 if (!msg)
9218 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009219
Eric W. Biederman15e47302012-09-07 20:12:54 +00009220 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009221 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009222 if (!hdr) {
9223 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009224 goto free_msg;
9225 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009226 }
Johannes Berge247bd902011-11-04 11:18:21 +01009227
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009228 params.chan = chandef.chan;
9229 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009230 if (err)
9231 goto free_msg;
9232
Johannes Berge247bd902011-11-04 11:18:21 +01009233 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009234 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9235 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009236 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009237
Johannes Berge247bd902011-11-04 11:18:21 +01009238 genlmsg_end(msg, hdr);
9239 return genlmsg_reply(msg, info);
9240 }
9241
9242 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009243
9244 nla_put_failure:
9245 err = -ENOBUFS;
9246 free_msg:
9247 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009248 return err;
9249}
9250
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009251static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9252{
9253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009254 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009255 u64 cookie;
9256
9257 if (!info->attrs[NL80211_ATTR_COOKIE])
9258 return -EINVAL;
9259
9260 if (!rdev->ops->mgmt_tx_cancel_wait)
9261 return -EOPNOTSUPP;
9262
Johannes Berg71bbc992012-06-15 15:30:18 +02009263 switch (wdev->iftype) {
9264 case NL80211_IFTYPE_STATION:
9265 case NL80211_IFTYPE_ADHOC:
9266 case NL80211_IFTYPE_P2P_CLIENT:
9267 case NL80211_IFTYPE_AP:
9268 case NL80211_IFTYPE_AP_VLAN:
9269 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009270 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009271 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009272 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009273 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009274 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009275 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009276
9277 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9278
Hila Gonene35e4d22012-06-27 17:19:42 +03009279 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009280}
9281
Kalle Valoffb9eb32010-02-17 17:58:10 +02009282static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9283{
Johannes Berg4c476992010-10-04 21:36:35 +02009284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009285 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009286 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009287 u8 ps_state;
9288 bool state;
9289 int err;
9290
Johannes Berg4c476992010-10-04 21:36:35 +02009291 if (!info->attrs[NL80211_ATTR_PS_STATE])
9292 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009293
9294 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9295
Johannes Berg4c476992010-10-04 21:36:35 +02009296 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9297 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009298
9299 wdev = dev->ieee80211_ptr;
9300
Johannes Berg4c476992010-10-04 21:36:35 +02009301 if (!rdev->ops->set_power_mgmt)
9302 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009303
9304 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9305
9306 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009307 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009308
Hila Gonene35e4d22012-06-27 17:19:42 +03009309 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009310 if (!err)
9311 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009312 return err;
9313}
9314
9315static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9316{
Johannes Berg4c476992010-10-04 21:36:35 +02009317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009318 enum nl80211_ps_state ps_state;
9319 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009320 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009321 struct sk_buff *msg;
9322 void *hdr;
9323 int err;
9324
Kalle Valoffb9eb32010-02-17 17:58:10 +02009325 wdev = dev->ieee80211_ptr;
9326
Johannes Berg4c476992010-10-04 21:36:35 +02009327 if (!rdev->ops->set_power_mgmt)
9328 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009329
9330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009331 if (!msg)
9332 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009333
Eric W. Biederman15e47302012-09-07 20:12:54 +00009334 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009335 NL80211_CMD_GET_POWER_SAVE);
9336 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009337 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009338 goto free_msg;
9339 }
9340
9341 if (wdev->ps)
9342 ps_state = NL80211_PS_ENABLED;
9343 else
9344 ps_state = NL80211_PS_DISABLED;
9345
David S. Miller9360ffd2012-03-29 04:41:26 -04009346 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9347 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009348
9349 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009350 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009351
Johannes Berg4c476992010-10-04 21:36:35 +02009352 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009353 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009354 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009355 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009356 return err;
9357}
9358
Johannes Berg94e860f2014-01-20 23:58:15 +01009359static const struct nla_policy
9360nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009361 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9362 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9363 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009364 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9365 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9366 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009367};
9368
Thomas Pedersen84f10702012-07-12 16:17:33 -07009369static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009370 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009371{
9372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009373 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009374 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009375
Johannes Bergd9d8b012012-11-26 12:51:52 +01009376 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009377 return -EINVAL;
9378
Thomas Pedersen84f10702012-07-12 16:17:33 -07009379 if (!rdev->ops->set_cqm_txe_config)
9380 return -EOPNOTSUPP;
9381
9382 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9383 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9384 return -EOPNOTSUPP;
9385
Hila Gonene35e4d22012-06-27 17:19:42 +03009386 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009387}
9388
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009389static int nl80211_set_cqm_rssi(struct genl_info *info,
9390 s32 threshold, u32 hysteresis)
9391{
Johannes Berg4c476992010-10-04 21:36:35 +02009392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009393 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009394 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009395
9396 if (threshold > 0)
9397 return -EINVAL;
9398
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009399 /* disabling - hysteresis should also be zero then */
9400 if (threshold == 0)
9401 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009402
Johannes Berg4c476992010-10-04 21:36:35 +02009403 if (!rdev->ops->set_cqm_rssi_config)
9404 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009405
Johannes Berg074ac8d2010-09-16 14:58:22 +02009406 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009407 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9408 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009409
Hila Gonene35e4d22012-06-27 17:19:42 +03009410 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009411}
9412
9413static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9414{
9415 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9416 struct nlattr *cqm;
9417 int err;
9418
9419 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009420 if (!cqm)
9421 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009422
9423 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9424 nl80211_attr_cqm_policy);
9425 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009426 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009427
9428 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9429 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009430 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9431 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009432
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009433 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9434 }
9435
9436 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9437 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9438 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9439 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9440 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9441 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9442
9443 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9444 }
9445
9446 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009447}
9448
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009449static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9450{
9451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9452 struct net_device *dev = info->user_ptr[1];
9453 struct ocb_setup setup = {};
9454 int err;
9455
9456 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9457 if (err)
9458 return err;
9459
9460 return cfg80211_join_ocb(rdev, dev, &setup);
9461}
9462
9463static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9464{
9465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9466 struct net_device *dev = info->user_ptr[1];
9467
9468 return cfg80211_leave_ocb(rdev, dev);
9469}
9470
Johannes Berg29cbe682010-12-03 09:20:44 +01009471static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9472{
9473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9474 struct net_device *dev = info->user_ptr[1];
9475 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009476 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009477 int err;
9478
9479 /* start with default */
9480 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009481 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009482
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009483 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009484 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009485 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009486 if (err)
9487 return err;
9488 }
9489
9490 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9491 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9492 return -EINVAL;
9493
Javier Cardonac80d5452010-12-16 17:37:49 -08009494 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9495 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9496
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009497 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9498 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9499 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9500 return -EINVAL;
9501
Marco Porsch9bdbf042013-01-07 16:04:51 +01009502 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9503 setup.beacon_interval =
9504 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309505
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309506 err = cfg80211_validate_beacon_int(rdev,
9507 NL80211_IFTYPE_MESH_POINT,
9508 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309509 if (err)
9510 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009511 }
9512
9513 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9514 setup.dtim_period =
9515 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9516 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9517 return -EINVAL;
9518 }
9519
Javier Cardonac80d5452010-12-16 17:37:49 -08009520 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9521 /* parse additional setup parameters if given */
9522 err = nl80211_parse_mesh_setup(info, &setup);
9523 if (err)
9524 return err;
9525 }
9526
Thomas Pedersend37bb182013-03-04 13:06:13 -08009527 if (setup.user_mpm)
9528 cfg.auto_open_plinks = false;
9529
Johannes Bergcc1d2802012-05-16 23:50:20 +02009530 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009531 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9532 if (err)
9533 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009534 } else {
9535 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009536 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009537 }
9538
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009539 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9540 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9541 int n_rates =
9542 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9543 struct ieee80211_supported_band *sband;
9544
9545 if (!setup.chandef.chan)
9546 return -EINVAL;
9547
9548 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9549
9550 err = ieee80211_get_ratemask(sband, rates, n_rates,
9551 &setup.basic_rates);
9552 if (err)
9553 return err;
9554 }
9555
Johannes Berg8564e382016-09-19 09:44:44 +02009556 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9557 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9558 if (err)
9559 return err;
9560
9561 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9562 &setup.beacon_rate);
9563 if (err)
9564 return err;
9565 }
9566
Javier Cardonac80d5452010-12-16 17:37:49 -08009567 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009568}
9569
9570static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9571{
9572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9573 struct net_device *dev = info->user_ptr[1];
9574
9575 return cfg80211_leave_mesh(rdev, dev);
9576}
9577
Johannes Bergdfb89c52012-06-27 09:23:48 +02009578#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009579static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9580 struct cfg80211_registered_device *rdev)
9581{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009582 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009583 struct nlattr *nl_pats, *nl_pat;
9584 int i, pat_len;
9585
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009586 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009587 return 0;
9588
9589 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9590 if (!nl_pats)
9591 return -ENOBUFS;
9592
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009593 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009594 nl_pat = nla_nest_start(msg, i + 1);
9595 if (!nl_pat)
9596 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009597 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009598 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009599 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009600 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9601 wowlan->patterns[i].pattern) ||
9602 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009603 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009604 return -ENOBUFS;
9605 nla_nest_end(msg, nl_pat);
9606 }
9607 nla_nest_end(msg, nl_pats);
9608
9609 return 0;
9610}
9611
Johannes Berg2a0e0472013-01-23 22:57:40 +01009612static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9613 struct cfg80211_wowlan_tcp *tcp)
9614{
9615 struct nlattr *nl_tcp;
9616
9617 if (!tcp)
9618 return 0;
9619
9620 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9621 if (!nl_tcp)
9622 return -ENOBUFS;
9623
Jiri Benc930345e2015-03-29 16:59:25 +02009624 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9625 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009626 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9627 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9628 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9629 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9630 tcp->payload_len, tcp->payload) ||
9631 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9632 tcp->data_interval) ||
9633 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9634 tcp->wake_len, tcp->wake_data) ||
9635 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9636 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9637 return -ENOBUFS;
9638
9639 if (tcp->payload_seq.len &&
9640 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9641 sizeof(tcp->payload_seq), &tcp->payload_seq))
9642 return -ENOBUFS;
9643
9644 if (tcp->payload_tok.len &&
9645 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9646 sizeof(tcp->payload_tok) + tcp->tokens_size,
9647 &tcp->payload_tok))
9648 return -ENOBUFS;
9649
Johannes Berge248ad32013-05-16 10:24:28 +02009650 nla_nest_end(msg, nl_tcp);
9651
Johannes Berg2a0e0472013-01-23 22:57:40 +01009652 return 0;
9653}
9654
Luciano Coelho75453cc2015-01-09 14:06:37 +02009655static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9656 struct cfg80211_sched_scan_request *req)
9657{
Avraham Stern3b06d272015-10-12 09:51:34 +03009658 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009659 int i;
9660
9661 if (!req)
9662 return 0;
9663
9664 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9665 if (!nd)
9666 return -ENOBUFS;
9667
Avraham Stern3b06d272015-10-12 09:51:34 +03009668 if (req->n_scan_plans == 1 &&
9669 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9670 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009671 return -ENOBUFS;
9672
Luciano Coelho21fea562015-03-17 16:36:01 +02009673 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9674 return -ENOBUFS;
9675
Luciano Coelho75453cc2015-01-09 14:06:37 +02009676 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9677 if (!freqs)
9678 return -ENOBUFS;
9679
Johannes Berg53b18982016-09-14 09:59:21 +02009680 for (i = 0; i < req->n_channels; i++) {
9681 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9682 return -ENOBUFS;
9683 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009684
9685 nla_nest_end(msg, freqs);
9686
9687 if (req->n_match_sets) {
9688 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009689 if (!matches)
9690 return -ENOBUFS;
9691
Luciano Coelho75453cc2015-01-09 14:06:37 +02009692 for (i = 0; i < req->n_match_sets; i++) {
9693 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009694 if (!match)
9695 return -ENOBUFS;
9696
Johannes Berg53b18982016-09-14 09:59:21 +02009697 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9698 req->match_sets[i].ssid.ssid_len,
9699 req->match_sets[i].ssid.ssid))
9700 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009701 nla_nest_end(msg, match);
9702 }
9703 nla_nest_end(msg, matches);
9704 }
9705
Avraham Stern3b06d272015-10-12 09:51:34 +03009706 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9707 if (!scan_plans)
9708 return -ENOBUFS;
9709
9710 for (i = 0; i < req->n_scan_plans; i++) {
9711 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009712 if (!scan_plan)
9713 return -ENOBUFS;
9714
Avraham Stern3b06d272015-10-12 09:51:34 +03009715 if (!scan_plan ||
9716 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9717 req->scan_plans[i].interval) ||
9718 (req->scan_plans[i].iterations &&
9719 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9720 req->scan_plans[i].iterations)))
9721 return -ENOBUFS;
9722 nla_nest_end(msg, scan_plan);
9723 }
9724 nla_nest_end(msg, scan_plans);
9725
Luciano Coelho75453cc2015-01-09 14:06:37 +02009726 nla_nest_end(msg, nd);
9727
9728 return 0;
9729}
9730
Johannes Bergff1b6e62011-05-04 15:37:28 +02009731static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9732{
9733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9734 struct sk_buff *msg;
9735 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009736 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009737
Johannes Berg964dc9e2013-06-03 17:25:34 +02009738 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009739 return -EOPNOTSUPP;
9740
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009741 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009742 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009743 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9744 rdev->wiphy.wowlan_config->tcp->payload_len +
9745 rdev->wiphy.wowlan_config->tcp->wake_len +
9746 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009747 }
9748
9749 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009750 if (!msg)
9751 return -ENOMEM;
9752
Eric W. Biederman15e47302012-09-07 20:12:54 +00009753 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009754 NL80211_CMD_GET_WOWLAN);
9755 if (!hdr)
9756 goto nla_put_failure;
9757
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009758 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009759 struct nlattr *nl_wowlan;
9760
9761 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9762 if (!nl_wowlan)
9763 goto nla_put_failure;
9764
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009765 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009766 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009767 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009768 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009769 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009770 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009771 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009772 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009773 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009774 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009775 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009776 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009777 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009778 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9779 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009780
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009781 if (nl80211_send_wowlan_patterns(msg, rdev))
9782 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009783
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009784 if (nl80211_send_wowlan_tcp(msg,
9785 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009786 goto nla_put_failure;
9787
Luciano Coelho75453cc2015-01-09 14:06:37 +02009788 if (nl80211_send_wowlan_nd(
9789 msg,
9790 rdev->wiphy.wowlan_config->nd_config))
9791 goto nla_put_failure;
9792
Johannes Bergff1b6e62011-05-04 15:37:28 +02009793 nla_nest_end(msg, nl_wowlan);
9794 }
9795
9796 genlmsg_end(msg, hdr);
9797 return genlmsg_reply(msg, info);
9798
9799nla_put_failure:
9800 nlmsg_free(msg);
9801 return -ENOBUFS;
9802}
9803
Johannes Berg2a0e0472013-01-23 22:57:40 +01009804static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9805 struct nlattr *attr,
9806 struct cfg80211_wowlan *trig)
9807{
9808 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9809 struct cfg80211_wowlan_tcp *cfg;
9810 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9811 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9812 u32 size;
9813 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9814 int err, port;
9815
Johannes Berg964dc9e2013-06-03 17:25:34 +02009816 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009817 return -EINVAL;
9818
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009819 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
9820 nl80211_wowlan_tcp_policy);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009821 if (err)
9822 return err;
9823
9824 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9825 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9826 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9827 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9828 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9829 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9830 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9831 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9832 return -EINVAL;
9833
9834 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009835 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009836 return -EINVAL;
9837
9838 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009839 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009840 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009841 return -EINVAL;
9842
9843 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009844 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009845 return -EINVAL;
9846
9847 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9848 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9849 return -EINVAL;
9850
9851 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9852 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9853
9854 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9855 tokens_size = tokln - sizeof(*tok);
9856
9857 if (!tok->len || tokens_size % tok->len)
9858 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009859 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009860 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009861 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009862 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009863 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009864 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009865 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009866 return -EINVAL;
9867 if (tok->offset + tok->len > data_size)
9868 return -EINVAL;
9869 }
9870
9871 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9872 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009873 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009874 return -EINVAL;
9875 if (seq->len == 0 || seq->len > 4)
9876 return -EINVAL;
9877 if (seq->len + seq->offset > data_size)
9878 return -EINVAL;
9879 }
9880
9881 size = sizeof(*cfg);
9882 size += data_size;
9883 size += wake_size + wake_mask_size;
9884 size += tokens_size;
9885
9886 cfg = kzalloc(size, GFP_KERNEL);
9887 if (!cfg)
9888 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009889 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9890 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009891 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9892 ETH_ALEN);
9893 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9894 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9895 else
9896 port = 0;
9897#ifdef CONFIG_INET
9898 /* allocate a socket and port for it and use it */
9899 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9900 IPPROTO_TCP, &cfg->sock, 1);
9901 if (err) {
9902 kfree(cfg);
9903 return err;
9904 }
9905 if (inet_csk_get_port(cfg->sock->sk, port)) {
9906 sock_release(cfg->sock);
9907 kfree(cfg);
9908 return -EADDRINUSE;
9909 }
9910 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9911#else
9912 if (!port) {
9913 kfree(cfg);
9914 return -EINVAL;
9915 }
9916 cfg->src_port = port;
9917#endif
9918
9919 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9920 cfg->payload_len = data_size;
9921 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9922 memcpy((void *)cfg->payload,
9923 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9924 data_size);
9925 if (seq)
9926 cfg->payload_seq = *seq;
9927 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9928 cfg->wake_len = wake_size;
9929 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9930 memcpy((void *)cfg->wake_data,
9931 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9932 wake_size);
9933 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9934 data_size + wake_size;
9935 memcpy((void *)cfg->wake_mask,
9936 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9937 wake_mask_size);
9938 if (tok) {
9939 cfg->tokens_size = tokens_size;
9940 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9941 }
9942
9943 trig->tcp = cfg;
9944
9945 return 0;
9946}
9947
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009948static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9949 const struct wiphy_wowlan_support *wowlan,
9950 struct nlattr *attr,
9951 struct cfg80211_wowlan *trig)
9952{
9953 struct nlattr **tb;
9954 int err;
9955
9956 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9957 if (!tb)
9958 return -ENOMEM;
9959
9960 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9961 err = -EOPNOTSUPP;
9962 goto out;
9963 }
9964
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009965 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009966 if (err)
9967 goto out;
9968
Johannes Bergad2b26a2014-06-12 21:39:05 +02009969 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009970 err = PTR_ERR_OR_ZERO(trig->nd_config);
9971 if (err)
9972 trig->nd_config = NULL;
9973
9974out:
9975 kfree(tb);
9976 return err;
9977}
9978
Johannes Bergff1b6e62011-05-04 15:37:28 +02009979static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9980{
9981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9982 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009983 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009984 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009985 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009986 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009987 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009988 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009989
Johannes Berg964dc9e2013-06-03 17:25:34 +02009990 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009991 return -EOPNOTSUPP;
9992
Johannes Bergae33bd82012-07-12 16:25:02 +02009993 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9994 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009995 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009996 goto set_wakeup;
9997 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009998
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009999 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
10000 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
10001 nl80211_wowlan_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010002 if (err)
10003 return err;
10004
10005 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
10006 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
10007 return -EINVAL;
10008 new_triggers.any = true;
10009 }
10010
10011 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
10012 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
10013 return -EINVAL;
10014 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010015 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010016 }
10017
10018 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
10019 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
10020 return -EINVAL;
10021 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010022 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010023 }
10024
Johannes Berg77dbbb12011-07-13 10:48:55 +020010025 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
10026 return -EINVAL;
10027
10028 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
10029 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
10030 return -EINVAL;
10031 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010032 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010033 }
10034
10035 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
10036 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
10037 return -EINVAL;
10038 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010039 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010040 }
10041
10042 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
10043 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
10044 return -EINVAL;
10045 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010046 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010047 }
10048
10049 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10050 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10051 return -EINVAL;
10052 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010053 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010054 }
10055
Johannes Bergff1b6e62011-05-04 15:37:28 +020010056 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10057 struct nlattr *pat;
10058 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010059 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010060 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010061
Johannes Berg98fc4382015-03-01 09:10:13 +020010062 regular = true;
10063
Johannes Bergff1b6e62011-05-04 15:37:28 +020010064 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10065 rem)
10066 n_patterns++;
10067 if (n_patterns > wowlan->n_patterns)
10068 return -EINVAL;
10069
10070 new_triggers.patterns = kcalloc(n_patterns,
10071 sizeof(new_triggers.patterns[0]),
10072 GFP_KERNEL);
10073 if (!new_triggers.patterns)
10074 return -ENOMEM;
10075
10076 new_triggers.n_patterns = n_patterns;
10077 i = 0;
10078
10079 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10080 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010081 u8 *mask_pat;
10082
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010083 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10084 NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010085 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010086 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10087 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010088 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010089 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010090 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010091 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010092 goto error;
10093 if (pat_len > wowlan->pattern_max_len ||
10094 pat_len < wowlan->pattern_min_len)
10095 goto error;
10096
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010097 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010098 pkt_offset = 0;
10099 else
10100 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010101 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010102 if (pkt_offset > wowlan->max_pkt_offset)
10103 goto error;
10104 new_triggers.patterns[i].pkt_offset = pkt_offset;
10105
Johannes Berg922bd802014-05-19 17:59:50 +020010106 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10107 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010108 err = -ENOMEM;
10109 goto error;
10110 }
Johannes Berg922bd802014-05-19 17:59:50 +020010111 new_triggers.patterns[i].mask = mask_pat;
10112 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010113 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010114 mask_pat += mask_len;
10115 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010116 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010117 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010118 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010119 pat_len);
10120 i++;
10121 }
10122 }
10123
Johannes Berg2a0e0472013-01-23 22:57:40 +010010124 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010125 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010126 err = nl80211_parse_wowlan_tcp(
10127 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10128 &new_triggers);
10129 if (err)
10130 goto error;
10131 }
10132
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010133 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010134 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010135 err = nl80211_parse_wowlan_nd(
10136 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10137 &new_triggers);
10138 if (err)
10139 goto error;
10140 }
10141
Johannes Berg98fc4382015-03-01 09:10:13 +020010142 /* The 'any' trigger means the device continues operating more or less
10143 * as in its normal operation mode and wakes up the host on most of the
10144 * normal interrupts (like packet RX, ...)
10145 * It therefore makes little sense to combine with the more constrained
10146 * wakeup trigger modes.
10147 */
10148 if (new_triggers.any && regular) {
10149 err = -EINVAL;
10150 goto error;
10151 }
10152
Johannes Bergae33bd82012-07-12 16:25:02 +020010153 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10154 if (!ntrig) {
10155 err = -ENOMEM;
10156 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010157 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010158 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010159 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010160
Johannes Bergae33bd82012-07-12 16:25:02 +020010161 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010162 if (rdev->ops->set_wakeup &&
10163 prev_enabled != !!rdev->wiphy.wowlan_config)
10164 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010165
Johannes Bergff1b6e62011-05-04 15:37:28 +020010166 return 0;
10167 error:
10168 for (i = 0; i < new_triggers.n_patterns; i++)
10169 kfree(new_triggers.patterns[i].mask);
10170 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010171 if (new_triggers.tcp && new_triggers.tcp->sock)
10172 sock_release(new_triggers.tcp->sock);
10173 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010174 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010175 return err;
10176}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010177#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010178
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010179static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10180 struct cfg80211_registered_device *rdev)
10181{
10182 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10183 int i, j, pat_len;
10184 struct cfg80211_coalesce_rules *rule;
10185
10186 if (!rdev->coalesce->n_rules)
10187 return 0;
10188
10189 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10190 if (!nl_rules)
10191 return -ENOBUFS;
10192
10193 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10194 nl_rule = nla_nest_start(msg, i + 1);
10195 if (!nl_rule)
10196 return -ENOBUFS;
10197
10198 rule = &rdev->coalesce->rules[i];
10199 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10200 rule->delay))
10201 return -ENOBUFS;
10202
10203 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10204 rule->condition))
10205 return -ENOBUFS;
10206
10207 nl_pats = nla_nest_start(msg,
10208 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10209 if (!nl_pats)
10210 return -ENOBUFS;
10211
10212 for (j = 0; j < rule->n_patterns; j++) {
10213 nl_pat = nla_nest_start(msg, j + 1);
10214 if (!nl_pat)
10215 return -ENOBUFS;
10216 pat_len = rule->patterns[j].pattern_len;
10217 if (nla_put(msg, NL80211_PKTPAT_MASK,
10218 DIV_ROUND_UP(pat_len, 8),
10219 rule->patterns[j].mask) ||
10220 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10221 rule->patterns[j].pattern) ||
10222 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10223 rule->patterns[j].pkt_offset))
10224 return -ENOBUFS;
10225 nla_nest_end(msg, nl_pat);
10226 }
10227 nla_nest_end(msg, nl_pats);
10228 nla_nest_end(msg, nl_rule);
10229 }
10230 nla_nest_end(msg, nl_rules);
10231
10232 return 0;
10233}
10234
10235static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10236{
10237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10238 struct sk_buff *msg;
10239 void *hdr;
10240
10241 if (!rdev->wiphy.coalesce)
10242 return -EOPNOTSUPP;
10243
10244 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10245 if (!msg)
10246 return -ENOMEM;
10247
10248 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10249 NL80211_CMD_GET_COALESCE);
10250 if (!hdr)
10251 goto nla_put_failure;
10252
10253 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10254 goto nla_put_failure;
10255
10256 genlmsg_end(msg, hdr);
10257 return genlmsg_reply(msg, info);
10258
10259nla_put_failure:
10260 nlmsg_free(msg);
10261 return -ENOBUFS;
10262}
10263
10264void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10265{
10266 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10267 int i, j;
10268 struct cfg80211_coalesce_rules *rule;
10269
10270 if (!coalesce)
10271 return;
10272
10273 for (i = 0; i < coalesce->n_rules; i++) {
10274 rule = &coalesce->rules[i];
10275 for (j = 0; j < rule->n_patterns; j++)
10276 kfree(rule->patterns[j].mask);
10277 kfree(rule->patterns);
10278 }
10279 kfree(coalesce->rules);
10280 kfree(coalesce);
10281 rdev->coalesce = NULL;
10282}
10283
10284static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10285 struct nlattr *rule,
10286 struct cfg80211_coalesce_rules *new_rule)
10287{
10288 int err, i;
10289 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10290 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10291 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10292 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10293
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010294 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
10295 nl80211_coalesce_policy);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010296 if (err)
10297 return err;
10298
10299 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10300 new_rule->delay =
10301 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10302 if (new_rule->delay > coalesce->max_delay)
10303 return -EINVAL;
10304
10305 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10306 new_rule->condition =
10307 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10308 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10309 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10310 return -EINVAL;
10311
10312 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10313 return -EINVAL;
10314
10315 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10316 rem)
10317 n_patterns++;
10318 if (n_patterns > coalesce->n_patterns)
10319 return -EINVAL;
10320
10321 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10322 GFP_KERNEL);
10323 if (!new_rule->patterns)
10324 return -ENOMEM;
10325
10326 new_rule->n_patterns = n_patterns;
10327 i = 0;
10328
10329 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10330 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010331 u8 *mask_pat;
10332
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010333 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010334 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10335 !pat_tb[NL80211_PKTPAT_PATTERN])
10336 return -EINVAL;
10337 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10338 mask_len = DIV_ROUND_UP(pat_len, 8);
10339 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10340 return -EINVAL;
10341 if (pat_len > coalesce->pattern_max_len ||
10342 pat_len < coalesce->pattern_min_len)
10343 return -EINVAL;
10344
10345 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10346 pkt_offset = 0;
10347 else
10348 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10349 if (pkt_offset > coalesce->max_pkt_offset)
10350 return -EINVAL;
10351 new_rule->patterns[i].pkt_offset = pkt_offset;
10352
Johannes Berg922bd802014-05-19 17:59:50 +020010353 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10354 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010355 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010356
10357 new_rule->patterns[i].mask = mask_pat;
10358 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10359 mask_len);
10360
10361 mask_pat += mask_len;
10362 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010363 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010364 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10365 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010366 i++;
10367 }
10368
10369 return 0;
10370}
10371
10372static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10373{
10374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10375 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10376 struct cfg80211_coalesce new_coalesce = {};
10377 struct cfg80211_coalesce *n_coalesce;
10378 int err, rem_rule, n_rules = 0, i, j;
10379 struct nlattr *rule;
10380 struct cfg80211_coalesce_rules *tmp_rule;
10381
10382 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10383 return -EOPNOTSUPP;
10384
10385 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10386 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010387 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010388 return 0;
10389 }
10390
10391 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10392 rem_rule)
10393 n_rules++;
10394 if (n_rules > coalesce->n_rules)
10395 return -EINVAL;
10396
10397 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10398 GFP_KERNEL);
10399 if (!new_coalesce.rules)
10400 return -ENOMEM;
10401
10402 new_coalesce.n_rules = n_rules;
10403 i = 0;
10404
10405 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10406 rem_rule) {
10407 err = nl80211_parse_coalesce_rule(rdev, rule,
10408 &new_coalesce.rules[i]);
10409 if (err)
10410 goto error;
10411
10412 i++;
10413 }
10414
Ilan Peera1056b1b2015-10-22 22:27:46 +030010415 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010416 if (err)
10417 goto error;
10418
10419 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10420 if (!n_coalesce) {
10421 err = -ENOMEM;
10422 goto error;
10423 }
10424 cfg80211_rdev_free_coalesce(rdev);
10425 rdev->coalesce = n_coalesce;
10426
10427 return 0;
10428error:
10429 for (i = 0; i < new_coalesce.n_rules; i++) {
10430 tmp_rule = &new_coalesce.rules[i];
10431 for (j = 0; j < tmp_rule->n_patterns; j++)
10432 kfree(tmp_rule->patterns[j].mask);
10433 kfree(tmp_rule->patterns);
10434 }
10435 kfree(new_coalesce.rules);
10436
10437 return err;
10438}
10439
Johannes Berge5497d72011-07-05 16:35:40 +020010440static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10441{
10442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10443 struct net_device *dev = info->user_ptr[1];
10444 struct wireless_dev *wdev = dev->ieee80211_ptr;
10445 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10446 struct cfg80211_gtk_rekey_data rekey_data;
10447 int err;
10448
10449 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10450 return -EINVAL;
10451
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010452 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10453 info->attrs[NL80211_ATTR_REKEY_DATA],
10454 nl80211_rekey_policy);
Johannes Berge5497d72011-07-05 16:35:40 +020010455 if (err)
10456 return err;
10457
10458 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10459 return -ERANGE;
10460 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10461 return -ERANGE;
10462 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10463 return -ERANGE;
10464
Johannes Berg78f686c2014-09-10 22:28:06 +030010465 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10466 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10467 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010468
10469 wdev_lock(wdev);
10470 if (!wdev->current_bss) {
10471 err = -ENOTCONN;
10472 goto out;
10473 }
10474
10475 if (!rdev->ops->set_rekey_data) {
10476 err = -EOPNOTSUPP;
10477 goto out;
10478 }
10479
Hila Gonene35e4d22012-06-27 17:19:42 +030010480 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010481 out:
10482 wdev_unlock(wdev);
10483 return err;
10484}
10485
Johannes Berg28946da2011-11-04 11:18:12 +010010486static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10487 struct genl_info *info)
10488{
10489 struct net_device *dev = info->user_ptr[1];
10490 struct wireless_dev *wdev = dev->ieee80211_ptr;
10491
10492 if (wdev->iftype != NL80211_IFTYPE_AP &&
10493 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10494 return -EINVAL;
10495
Eric W. Biederman15e47302012-09-07 20:12:54 +000010496 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010497 return -EBUSY;
10498
Eric W. Biederman15e47302012-09-07 20:12:54 +000010499 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010500 return 0;
10501}
10502
Johannes Berg7f6cf312011-11-04 11:18:15 +010010503static int nl80211_probe_client(struct sk_buff *skb,
10504 struct genl_info *info)
10505{
10506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10507 struct net_device *dev = info->user_ptr[1];
10508 struct wireless_dev *wdev = dev->ieee80211_ptr;
10509 struct sk_buff *msg;
10510 void *hdr;
10511 const u8 *addr;
10512 u64 cookie;
10513 int err;
10514
10515 if (wdev->iftype != NL80211_IFTYPE_AP &&
10516 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10517 return -EOPNOTSUPP;
10518
10519 if (!info->attrs[NL80211_ATTR_MAC])
10520 return -EINVAL;
10521
10522 if (!rdev->ops->probe_client)
10523 return -EOPNOTSUPP;
10524
10525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10526 if (!msg)
10527 return -ENOMEM;
10528
Eric W. Biederman15e47302012-09-07 20:12:54 +000010529 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010530 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010531 if (!hdr) {
10532 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010533 goto free_msg;
10534 }
10535
10536 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10537
Hila Gonene35e4d22012-06-27 17:19:42 +030010538 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010539 if (err)
10540 goto free_msg;
10541
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010542 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10543 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010544 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010545
10546 genlmsg_end(msg, hdr);
10547
10548 return genlmsg_reply(msg, info);
10549
10550 nla_put_failure:
10551 err = -ENOBUFS;
10552 free_msg:
10553 nlmsg_free(msg);
10554 return err;
10555}
10556
Johannes Berg5e760232011-11-04 11:18:17 +010010557static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10558{
10559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010560 struct cfg80211_beacon_registration *reg, *nreg;
10561 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010562
10563 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10564 return -EOPNOTSUPP;
10565
Ben Greear37c73b52012-10-26 14:49:25 -070010566 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10567 if (!nreg)
10568 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010569
Ben Greear37c73b52012-10-26 14:49:25 -070010570 /* First, check if already registered. */
10571 spin_lock_bh(&rdev->beacon_registrations_lock);
10572 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10573 if (reg->nlportid == info->snd_portid) {
10574 rv = -EALREADY;
10575 goto out_err;
10576 }
10577 }
10578 /* Add it to the list */
10579 nreg->nlportid = info->snd_portid;
10580 list_add(&nreg->list, &rdev->beacon_registrations);
10581
10582 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010583
10584 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010585out_err:
10586 spin_unlock_bh(&rdev->beacon_registrations_lock);
10587 kfree(nreg);
10588 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010589}
10590
Johannes Berg98104fde2012-06-16 00:19:54 +020010591static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10592{
10593 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10594 struct wireless_dev *wdev = info->user_ptr[1];
10595 int err;
10596
10597 if (!rdev->ops->start_p2p_device)
10598 return -EOPNOTSUPP;
10599
10600 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10601 return -EOPNOTSUPP;
10602
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010603 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020010604 return 0;
10605
Luciano Coelhob6a55012014-02-27 11:07:21 +020010606 if (rfkill_blocked(rdev->rfkill))
10607 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010608
Johannes Bergeeb126e2012-10-23 15:16:50 +020010609 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010610 if (err)
10611 return err;
10612
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010613 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010614 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010615
10616 return 0;
10617}
10618
10619static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10620{
10621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10622 struct wireless_dev *wdev = info->user_ptr[1];
10623
10624 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10625 return -EOPNOTSUPP;
10626
10627 if (!rdev->ops->stop_p2p_device)
10628 return -EOPNOTSUPP;
10629
Johannes Bergf9f47522013-03-19 15:04:07 +010010630 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010631
10632 return 0;
10633}
10634
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010635static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10636{
10637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10638 struct wireless_dev *wdev = info->user_ptr[1];
10639 struct cfg80211_nan_conf conf = {};
10640 int err;
10641
10642 if (wdev->iftype != NL80211_IFTYPE_NAN)
10643 return -EOPNOTSUPP;
10644
Johannes Bergeeb04a92016-11-21 13:55:48 +010010645 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010646 return -EEXIST;
10647
10648 if (rfkill_blocked(rdev->rfkill))
10649 return -ERFKILL;
10650
10651 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10652 return -EINVAL;
10653
10654 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10655 return -EINVAL;
10656
10657 conf.master_pref =
10658 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10659 if (!conf.master_pref)
10660 return -EINVAL;
10661
10662 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10663
10664 err = rdev_start_nan(rdev, wdev, &conf);
10665 if (err)
10666 return err;
10667
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010668 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010669 rdev->opencount++;
10670
10671 return 0;
10672}
10673
10674static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10675{
10676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10677 struct wireless_dev *wdev = info->user_ptr[1];
10678
10679 if (wdev->iftype != NL80211_IFTYPE_NAN)
10680 return -EOPNOTSUPP;
10681
10682 cfg80211_stop_nan(rdev, wdev);
10683
10684 return 0;
10685}
10686
Ayala Bekera442b762016-09-20 17:31:15 +030010687static int validate_nan_filter(struct nlattr *filter_attr)
10688{
10689 struct nlattr *attr;
10690 int len = 0, n_entries = 0, rem;
10691
10692 nla_for_each_nested(attr, filter_attr, rem) {
10693 len += nla_len(attr);
10694 n_entries++;
10695 }
10696
10697 if (len >= U8_MAX)
10698 return -EINVAL;
10699
10700 return n_entries;
10701}
10702
10703static int handle_nan_filter(struct nlattr *attr_filter,
10704 struct cfg80211_nan_func *func,
10705 bool tx)
10706{
10707 struct nlattr *attr;
10708 int n_entries, rem, i;
10709 struct cfg80211_nan_func_filter *filter;
10710
10711 n_entries = validate_nan_filter(attr_filter);
10712 if (n_entries < 0)
10713 return n_entries;
10714
10715 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10716
10717 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10718 if (!filter)
10719 return -ENOMEM;
10720
10721 i = 0;
10722 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020010723 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030010724 filter[i].len = nla_len(attr);
10725 i++;
10726 }
10727 if (tx) {
10728 func->num_tx_filters = n_entries;
10729 func->tx_filters = filter;
10730 } else {
10731 func->num_rx_filters = n_entries;
10732 func->rx_filters = filter;
10733 }
10734
10735 return 0;
10736}
10737
10738static int nl80211_nan_add_func(struct sk_buff *skb,
10739 struct genl_info *info)
10740{
10741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10742 struct wireless_dev *wdev = info->user_ptr[1];
10743 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10744 struct cfg80211_nan_func *func;
10745 struct sk_buff *msg = NULL;
10746 void *hdr = NULL;
10747 int err = 0;
10748
10749 if (wdev->iftype != NL80211_IFTYPE_NAN)
10750 return -EOPNOTSUPP;
10751
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010752 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030010753 return -ENOTCONN;
10754
10755 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10756 return -EINVAL;
10757
10758 if (wdev->owner_nlportid &&
10759 wdev->owner_nlportid != info->snd_portid)
10760 return -ENOTCONN;
10761
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010762 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
10763 info->attrs[NL80211_ATTR_NAN_FUNC],
10764 nl80211_nan_func_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010765 if (err)
10766 return err;
10767
10768 func = kzalloc(sizeof(*func), GFP_KERNEL);
10769 if (!func)
10770 return -ENOMEM;
10771
10772 func->cookie = wdev->wiphy->cookie_counter++;
10773
10774 if (!tb[NL80211_NAN_FUNC_TYPE] ||
10775 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
10776 err = -EINVAL;
10777 goto out;
10778 }
10779
10780
10781 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
10782
10783 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
10784 err = -EINVAL;
10785 goto out;
10786 }
10787
10788 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
10789 sizeof(func->service_id));
10790
10791 func->close_range =
10792 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
10793
10794 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
10795 func->serv_spec_info_len =
10796 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
10797 func->serv_spec_info =
10798 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
10799 func->serv_spec_info_len,
10800 GFP_KERNEL);
10801 if (!func->serv_spec_info) {
10802 err = -ENOMEM;
10803 goto out;
10804 }
10805 }
10806
10807 if (tb[NL80211_NAN_FUNC_TTL])
10808 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
10809
10810 switch (func->type) {
10811 case NL80211_NAN_FUNC_PUBLISH:
10812 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
10813 err = -EINVAL;
10814 goto out;
10815 }
10816
10817 func->publish_type =
10818 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
10819 func->publish_bcast =
10820 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
10821
10822 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
10823 func->publish_bcast) {
10824 err = -EINVAL;
10825 goto out;
10826 }
10827 break;
10828 case NL80211_NAN_FUNC_SUBSCRIBE:
10829 func->subscribe_active =
10830 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
10831 break;
10832 case NL80211_NAN_FUNC_FOLLOW_UP:
10833 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
10834 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
10835 err = -EINVAL;
10836 goto out;
10837 }
10838
10839 func->followup_id =
10840 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
10841 func->followup_reqid =
10842 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
10843 memcpy(func->followup_dest.addr,
10844 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
10845 sizeof(func->followup_dest.addr));
10846 if (func->ttl) {
10847 err = -EINVAL;
10848 goto out;
10849 }
10850 break;
10851 default:
10852 err = -EINVAL;
10853 goto out;
10854 }
10855
10856 if (tb[NL80211_NAN_FUNC_SRF]) {
10857 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
10858
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010859 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
10860 tb[NL80211_NAN_FUNC_SRF],
10861 nl80211_nan_srf_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010862 if (err)
10863 goto out;
10864
10865 func->srf_include =
10866 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
10867
10868 if (srf_tb[NL80211_NAN_SRF_BF]) {
10869 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
10870 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
10871 err = -EINVAL;
10872 goto out;
10873 }
10874
10875 func->srf_bf_len =
10876 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
10877 func->srf_bf =
10878 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
10879 func->srf_bf_len, GFP_KERNEL);
10880 if (!func->srf_bf) {
10881 err = -ENOMEM;
10882 goto out;
10883 }
10884
10885 func->srf_bf_idx =
10886 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
10887 } else {
10888 struct nlattr *attr, *mac_attr =
10889 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
10890 int n_entries, rem, i = 0;
10891
10892 if (!mac_attr) {
10893 err = -EINVAL;
10894 goto out;
10895 }
10896
10897 n_entries = validate_acl_mac_addrs(mac_attr);
10898 if (n_entries <= 0) {
10899 err = -EINVAL;
10900 goto out;
10901 }
10902
10903 func->srf_num_macs = n_entries;
10904 func->srf_macs =
10905 kzalloc(sizeof(*func->srf_macs) * n_entries,
10906 GFP_KERNEL);
10907 if (!func->srf_macs) {
10908 err = -ENOMEM;
10909 goto out;
10910 }
10911
10912 nla_for_each_nested(attr, mac_attr, rem)
10913 memcpy(func->srf_macs[i++].addr, nla_data(attr),
10914 sizeof(*func->srf_macs));
10915 }
10916 }
10917
10918 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
10919 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
10920 func, true);
10921 if (err)
10922 goto out;
10923 }
10924
10925 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
10926 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
10927 func, false);
10928 if (err)
10929 goto out;
10930 }
10931
10932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10933 if (!msg) {
10934 err = -ENOMEM;
10935 goto out;
10936 }
10937
10938 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10939 NL80211_CMD_ADD_NAN_FUNCTION);
10940 /* This can't really happen - we just allocated 4KB */
10941 if (WARN_ON(!hdr)) {
10942 err = -ENOMEM;
10943 goto out;
10944 }
10945
10946 err = rdev_add_nan_func(rdev, wdev, func);
10947out:
10948 if (err < 0) {
10949 cfg80211_free_nan_func(func);
10950 nlmsg_free(msg);
10951 return err;
10952 }
10953
10954 /* propagate the instance id and cookie to userspace */
10955 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
10956 NL80211_ATTR_PAD))
10957 goto nla_put_failure;
10958
10959 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
10960 if (!func_attr)
10961 goto nla_put_failure;
10962
10963 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
10964 func->instance_id))
10965 goto nla_put_failure;
10966
10967 nla_nest_end(msg, func_attr);
10968
10969 genlmsg_end(msg, hdr);
10970 return genlmsg_reply(msg, info);
10971
10972nla_put_failure:
10973 nlmsg_free(msg);
10974 return -ENOBUFS;
10975}
10976
10977static int nl80211_nan_del_func(struct sk_buff *skb,
10978 struct genl_info *info)
10979{
10980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10981 struct wireless_dev *wdev = info->user_ptr[1];
10982 u64 cookie;
10983
10984 if (wdev->iftype != NL80211_IFTYPE_NAN)
10985 return -EOPNOTSUPP;
10986
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010987 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030010988 return -ENOTCONN;
10989
10990 if (!info->attrs[NL80211_ATTR_COOKIE])
10991 return -EINVAL;
10992
10993 if (wdev->owner_nlportid &&
10994 wdev->owner_nlportid != info->snd_portid)
10995 return -ENOTCONN;
10996
10997 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10998
10999 rdev_del_nan_func(rdev, wdev, cookie);
11000
11001 return 0;
11002}
11003
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011004static int nl80211_nan_change_config(struct sk_buff *skb,
11005 struct genl_info *info)
11006{
11007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11008 struct wireless_dev *wdev = info->user_ptr[1];
11009 struct cfg80211_nan_conf conf = {};
11010 u32 changed = 0;
11011
11012 if (wdev->iftype != NL80211_IFTYPE_NAN)
11013 return -EOPNOTSUPP;
11014
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011015 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030011016 return -ENOTCONN;
11017
11018 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
11019 conf.master_pref =
11020 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
11021 if (conf.master_pref <= 1 || conf.master_pref == 255)
11022 return -EINVAL;
11023
11024 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
11025 }
11026
11027 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
11028 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
11029 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
11030 }
11031
11032 if (!changed)
11033 return -EINVAL;
11034
11035 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
11036}
11037
Ayala Beker50bcd312016-09-20 17:31:17 +030011038void cfg80211_nan_match(struct wireless_dev *wdev,
11039 struct cfg80211_nan_match_params *match, gfp_t gfp)
11040{
11041 struct wiphy *wiphy = wdev->wiphy;
11042 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11043 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
11044 struct sk_buff *msg;
11045 void *hdr;
11046
11047 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11048 return;
11049
11050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11051 if (!msg)
11052 return;
11053
11054 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11055 if (!hdr) {
11056 nlmsg_free(msg);
11057 return;
11058 }
11059
11060 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11061 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11062 wdev->netdev->ifindex)) ||
11063 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11064 NL80211_ATTR_PAD))
11065 goto nla_put_failure;
11066
11067 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11068 NL80211_ATTR_PAD) ||
11069 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11070 goto nla_put_failure;
11071
11072 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11073 if (!match_attr)
11074 goto nla_put_failure;
11075
11076 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11077 if (!local_func_attr)
11078 goto nla_put_failure;
11079
11080 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11081 goto nla_put_failure;
11082
11083 nla_nest_end(msg, local_func_attr);
11084
11085 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11086 if (!peer_func_attr)
11087 goto nla_put_failure;
11088
11089 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11090 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11091 goto nla_put_failure;
11092
11093 if (match->info && match->info_len &&
11094 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11095 match->info))
11096 goto nla_put_failure;
11097
11098 nla_nest_end(msg, peer_func_attr);
11099 nla_nest_end(msg, match_attr);
11100 genlmsg_end(msg, hdr);
11101
11102 if (!wdev->owner_nlportid)
11103 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11104 msg, 0, NL80211_MCGRP_NAN, gfp);
11105 else
11106 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11107 wdev->owner_nlportid);
11108
11109 return;
11110
11111nla_put_failure:
11112 nlmsg_free(msg);
11113}
11114EXPORT_SYMBOL(cfg80211_nan_match);
11115
Ayala Beker368e5a72016-09-20 17:31:18 +030011116void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11117 u8 inst_id,
11118 enum nl80211_nan_func_term_reason reason,
11119 u64 cookie, gfp_t gfp)
11120{
11121 struct wiphy *wiphy = wdev->wiphy;
11122 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11123 struct sk_buff *msg;
11124 struct nlattr *func_attr;
11125 void *hdr;
11126
11127 if (WARN_ON(!inst_id))
11128 return;
11129
11130 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11131 if (!msg)
11132 return;
11133
11134 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11135 if (!hdr) {
11136 nlmsg_free(msg);
11137 return;
11138 }
11139
11140 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11141 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11142 wdev->netdev->ifindex)) ||
11143 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11144 NL80211_ATTR_PAD))
11145 goto nla_put_failure;
11146
11147 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11148 NL80211_ATTR_PAD))
11149 goto nla_put_failure;
11150
11151 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11152 if (!func_attr)
11153 goto nla_put_failure;
11154
11155 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11156 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11157 goto nla_put_failure;
11158
11159 nla_nest_end(msg, func_attr);
11160 genlmsg_end(msg, hdr);
11161
11162 if (!wdev->owner_nlportid)
11163 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11164 msg, 0, NL80211_MCGRP_NAN, gfp);
11165 else
11166 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11167 wdev->owner_nlportid);
11168
11169 return;
11170
11171nla_put_failure:
11172 nlmsg_free(msg);
11173}
11174EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11175
Johannes Berg3713b4e2013-02-14 16:19:38 +010011176static int nl80211_get_protocol_features(struct sk_buff *skb,
11177 struct genl_info *info)
11178{
11179 void *hdr;
11180 struct sk_buff *msg;
11181
11182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11183 if (!msg)
11184 return -ENOMEM;
11185
11186 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11187 NL80211_CMD_GET_PROTOCOL_FEATURES);
11188 if (!hdr)
11189 goto nla_put_failure;
11190
11191 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11192 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11193 goto nla_put_failure;
11194
11195 genlmsg_end(msg, hdr);
11196 return genlmsg_reply(msg, info);
11197
11198 nla_put_failure:
11199 kfree_skb(msg);
11200 return -ENOBUFS;
11201}
11202
Jouni Malinen355199e2013-02-27 17:14:27 +020011203static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11204{
11205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11206 struct cfg80211_update_ft_ies_params ft_params;
11207 struct net_device *dev = info->user_ptr[1];
11208
11209 if (!rdev->ops->update_ft_ies)
11210 return -EOPNOTSUPP;
11211
11212 if (!info->attrs[NL80211_ATTR_MDID] ||
11213 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11214 return -EINVAL;
11215
11216 memset(&ft_params, 0, sizeof(ft_params));
11217 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11218 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11219 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11220
11221 return rdev_update_ft_ies(rdev, dev, &ft_params);
11222}
11223
Arend van Spriel5de17982013-04-18 15:49:00 +020011224static int nl80211_crit_protocol_start(struct sk_buff *skb,
11225 struct genl_info *info)
11226{
11227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11228 struct wireless_dev *wdev = info->user_ptr[1];
11229 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11230 u16 duration;
11231 int ret;
11232
11233 if (!rdev->ops->crit_proto_start)
11234 return -EOPNOTSUPP;
11235
11236 if (WARN_ON(!rdev->ops->crit_proto_stop))
11237 return -EINVAL;
11238
11239 if (rdev->crit_proto_nlportid)
11240 return -EBUSY;
11241
11242 /* determine protocol if provided */
11243 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11244 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11245
11246 if (proto >= NUM_NL80211_CRIT_PROTO)
11247 return -EINVAL;
11248
11249 /* timeout must be provided */
11250 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11251 return -EINVAL;
11252
11253 duration =
11254 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11255
11256 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11257 return -ERANGE;
11258
11259 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11260 if (!ret)
11261 rdev->crit_proto_nlportid = info->snd_portid;
11262
11263 return ret;
11264}
11265
11266static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11267 struct genl_info *info)
11268{
11269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11270 struct wireless_dev *wdev = info->user_ptr[1];
11271
11272 if (!rdev->ops->crit_proto_stop)
11273 return -EOPNOTSUPP;
11274
11275 if (rdev->crit_proto_nlportid) {
11276 rdev->crit_proto_nlportid = 0;
11277 rdev_crit_proto_stop(rdev, wdev);
11278 }
11279 return 0;
11280}
11281
Johannes Bergad7e7182013-11-13 13:37:47 +010011282static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11283{
11284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11285 struct wireless_dev *wdev =
11286 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11287 int i, err;
11288 u32 vid, subcmd;
11289
11290 if (!rdev->wiphy.vendor_commands)
11291 return -EOPNOTSUPP;
11292
11293 if (IS_ERR(wdev)) {
11294 err = PTR_ERR(wdev);
11295 if (err != -EINVAL)
11296 return err;
11297 wdev = NULL;
11298 } else if (wdev->wiphy != &rdev->wiphy) {
11299 return -EINVAL;
11300 }
11301
11302 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11303 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11304 return -EINVAL;
11305
11306 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11307 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11308 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11309 const struct wiphy_vendor_command *vcmd;
11310 void *data = NULL;
11311 int len = 0;
11312
11313 vcmd = &rdev->wiphy.vendor_commands[i];
11314
11315 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11316 continue;
11317
11318 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11319 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11320 if (!wdev)
11321 return -EINVAL;
11322 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11323 !wdev->netdev)
11324 return -EINVAL;
11325
11326 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011327 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011328 return -ENETDOWN;
11329 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011330
11331 if (!vcmd->doit)
11332 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011333 } else {
11334 wdev = NULL;
11335 }
11336
11337 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11338 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11339 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11340 }
11341
11342 rdev->cur_cmd_info = info;
11343 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11344 data, len);
11345 rdev->cur_cmd_info = NULL;
11346 return err;
11347 }
11348
11349 return -EOPNOTSUPP;
11350}
11351
Johannes Berg7bdbe402015-08-15 22:39:49 +030011352static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11353 struct netlink_callback *cb,
11354 struct cfg80211_registered_device **rdev,
11355 struct wireless_dev **wdev)
11356{
Johannes Bergc90c39d2016-10-24 14:40:01 +020011357 struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011358 u32 vid, subcmd;
11359 unsigned int i;
11360 int vcmd_idx = -1;
11361 int err;
11362 void *data = NULL;
11363 unsigned int data_len = 0;
11364
11365 rtnl_lock();
11366
11367 if (cb->args[0]) {
11368 /* subtract the 1 again here */
11369 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11370 struct wireless_dev *tmp;
11371
11372 if (!wiphy) {
11373 err = -ENODEV;
11374 goto out_unlock;
11375 }
11376 *rdev = wiphy_to_rdev(wiphy);
11377 *wdev = NULL;
11378
11379 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011380 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011381 if (tmp->identifier == cb->args[1] - 1) {
11382 *wdev = tmp;
11383 break;
11384 }
11385 }
11386 }
11387
11388 /* keep rtnl locked in successful case */
11389 return 0;
11390 }
11391
11392 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Bergc90c39d2016-10-24 14:40:01 +020011393 attrbuf, nl80211_fam.maxattr, nl80211_policy);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011394 if (err)
11395 goto out_unlock;
11396
Johannes Bergc90c39d2016-10-24 14:40:01 +020011397 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
11398 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011399 err = -EINVAL;
11400 goto out_unlock;
11401 }
11402
Johannes Bergc90c39d2016-10-24 14:40:01 +020011403 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011404 if (IS_ERR(*wdev))
11405 *wdev = NULL;
11406
Johannes Bergc90c39d2016-10-24 14:40:01 +020011407 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011408 if (IS_ERR(*rdev)) {
11409 err = PTR_ERR(*rdev);
11410 goto out_unlock;
11411 }
11412
Johannes Bergc90c39d2016-10-24 14:40:01 +020011413 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
11414 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011415
11416 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11417 const struct wiphy_vendor_command *vcmd;
11418
11419 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11420
11421 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11422 continue;
11423
11424 if (!vcmd->dumpit) {
11425 err = -EOPNOTSUPP;
11426 goto out_unlock;
11427 }
11428
11429 vcmd_idx = i;
11430 break;
11431 }
11432
11433 if (vcmd_idx < 0) {
11434 err = -EOPNOTSUPP;
11435 goto out_unlock;
11436 }
11437
Johannes Bergc90c39d2016-10-24 14:40:01 +020011438 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11439 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
11440 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011441 }
11442
11443 /* 0 is the first index - add 1 to parse only once */
11444 cb->args[0] = (*rdev)->wiphy_idx + 1;
11445 /* add 1 to know if it was NULL */
11446 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11447 cb->args[2] = vcmd_idx;
11448 cb->args[3] = (unsigned long)data;
11449 cb->args[4] = data_len;
11450
11451 /* keep rtnl locked in successful case */
11452 return 0;
11453 out_unlock:
11454 rtnl_unlock();
11455 return err;
11456}
11457
11458static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11459 struct netlink_callback *cb)
11460{
11461 struct cfg80211_registered_device *rdev;
11462 struct wireless_dev *wdev;
11463 unsigned int vcmd_idx;
11464 const struct wiphy_vendor_command *vcmd;
11465 void *data;
11466 int data_len;
11467 int err;
11468 struct nlattr *vendor_data;
11469
11470 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11471 if (err)
11472 return err;
11473
11474 vcmd_idx = cb->args[2];
11475 data = (void *)cb->args[3];
11476 data_len = cb->args[4];
11477 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11478
11479 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11480 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11481 if (!wdev)
11482 return -EINVAL;
11483 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11484 !wdev->netdev)
11485 return -EINVAL;
11486
11487 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011488 if (!wdev_running(wdev))
Johannes Berg7bdbe402015-08-15 22:39:49 +030011489 return -ENETDOWN;
11490 }
11491 }
11492
11493 while (1) {
11494 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11495 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11496 NL80211_CMD_VENDOR);
11497 if (!hdr)
11498 break;
11499
11500 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011501 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11502 wdev_id(wdev),
11503 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011504 genlmsg_cancel(skb, hdr);
11505 break;
11506 }
11507
11508 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11509 if (!vendor_data) {
11510 genlmsg_cancel(skb, hdr);
11511 break;
11512 }
11513
11514 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11515 (unsigned long *)&cb->args[5]);
11516 nla_nest_end(skb, vendor_data);
11517
11518 if (err == -ENOBUFS || err == -ENOENT) {
11519 genlmsg_cancel(skb, hdr);
11520 break;
11521 } else if (err) {
11522 genlmsg_cancel(skb, hdr);
11523 goto out;
11524 }
11525
11526 genlmsg_end(skb, hdr);
11527 }
11528
11529 err = skb->len;
11530 out:
11531 rtnl_unlock();
11532 return err;
11533}
11534
Johannes Bergad7e7182013-11-13 13:37:47 +010011535struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11536 enum nl80211_commands cmd,
11537 enum nl80211_attrs attr,
11538 int approxlen)
11539{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011540 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011541
11542 if (WARN_ON(!rdev->cur_cmd_info))
11543 return NULL;
11544
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011545 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011546 rdev->cur_cmd_info->snd_portid,
11547 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011548 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011549}
11550EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11551
11552int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11553{
11554 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11555 void *hdr = ((void **)skb->cb)[1];
11556 struct nlattr *data = ((void **)skb->cb)[2];
11557
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011558 /* clear CB data for netlink core to own from now on */
11559 memset(skb->cb, 0, sizeof(skb->cb));
11560
Johannes Bergad7e7182013-11-13 13:37:47 +010011561 if (WARN_ON(!rdev->cur_cmd_info)) {
11562 kfree_skb(skb);
11563 return -EINVAL;
11564 }
11565
11566 nla_nest_end(skb, data);
11567 genlmsg_end(skb, hdr);
11568 return genlmsg_reply(skb, rdev->cur_cmd_info);
11569}
11570EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11571
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011572static int nl80211_set_qos_map(struct sk_buff *skb,
11573 struct genl_info *info)
11574{
11575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11576 struct cfg80211_qos_map *qos_map = NULL;
11577 struct net_device *dev = info->user_ptr[1];
11578 u8 *pos, len, num_des, des_len, des;
11579 int ret;
11580
11581 if (!rdev->ops->set_qos_map)
11582 return -EOPNOTSUPP;
11583
11584 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11585 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11586 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11587
11588 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11589 len > IEEE80211_QOS_MAP_LEN_MAX)
11590 return -EINVAL;
11591
11592 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11593 if (!qos_map)
11594 return -ENOMEM;
11595
11596 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11597 if (num_des) {
11598 des_len = num_des *
11599 sizeof(struct cfg80211_dscp_exception);
11600 memcpy(qos_map->dscp_exception, pos, des_len);
11601 qos_map->num_des = num_des;
11602 for (des = 0; des < num_des; des++) {
11603 if (qos_map->dscp_exception[des].up > 7) {
11604 kfree(qos_map);
11605 return -EINVAL;
11606 }
11607 }
11608 pos += des_len;
11609 }
11610 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11611 }
11612
11613 wdev_lock(dev->ieee80211_ptr);
11614 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11615 if (!ret)
11616 ret = rdev_set_qos_map(rdev, dev, qos_map);
11617 wdev_unlock(dev->ieee80211_ptr);
11618
11619 kfree(qos_map);
11620 return ret;
11621}
11622
Johannes Berg960d01a2014-09-09 22:55:35 +030011623static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11624{
11625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11626 struct net_device *dev = info->user_ptr[1];
11627 struct wireless_dev *wdev = dev->ieee80211_ptr;
11628 const u8 *peer;
11629 u8 tsid, up;
11630 u16 admitted_time = 0;
11631 int err;
11632
Johannes Berg723e73a2014-10-22 09:25:06 +020011633 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011634 return -EOPNOTSUPP;
11635
11636 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11637 !info->attrs[NL80211_ATTR_USER_PRIO])
11638 return -EINVAL;
11639
11640 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11641 if (tsid >= IEEE80211_NUM_TIDS)
11642 return -EINVAL;
11643
11644 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11645 if (up >= IEEE80211_NUM_UPS)
11646 return -EINVAL;
11647
11648 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011649 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011650 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011651 * need more attributes for that (e.g. BA session requirement);
11652 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011653 */
11654 return -EINVAL;
11655 }
11656
11657 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11658
11659 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11660 admitted_time =
11661 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11662 if (!admitted_time)
11663 return -EINVAL;
11664 }
11665
11666 wdev_lock(wdev);
11667 switch (wdev->iftype) {
11668 case NL80211_IFTYPE_STATION:
11669 case NL80211_IFTYPE_P2P_CLIENT:
11670 if (wdev->current_bss)
11671 break;
11672 err = -ENOTCONN;
11673 goto out;
11674 default:
11675 err = -EOPNOTSUPP;
11676 goto out;
11677 }
11678
11679 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11680
11681 out:
11682 wdev_unlock(wdev);
11683 return err;
11684}
11685
11686static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11687{
11688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11689 struct net_device *dev = info->user_ptr[1];
11690 struct wireless_dev *wdev = dev->ieee80211_ptr;
11691 const u8 *peer;
11692 u8 tsid;
11693 int err;
11694
11695 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11696 return -EINVAL;
11697
11698 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11699 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11700
11701 wdev_lock(wdev);
11702 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11703 wdev_unlock(wdev);
11704
11705 return err;
11706}
11707
Arik Nemtsov1057d352014-11-19 12:54:26 +020011708static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11709 struct genl_info *info)
11710{
11711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11712 struct net_device *dev = info->user_ptr[1];
11713 struct wireless_dev *wdev = dev->ieee80211_ptr;
11714 struct cfg80211_chan_def chandef = {};
11715 const u8 *addr;
11716 u8 oper_class;
11717 int err;
11718
11719 if (!rdev->ops->tdls_channel_switch ||
11720 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11721 return -EOPNOTSUPP;
11722
11723 switch (dev->ieee80211_ptr->iftype) {
11724 case NL80211_IFTYPE_STATION:
11725 case NL80211_IFTYPE_P2P_CLIENT:
11726 break;
11727 default:
11728 return -EOPNOTSUPP;
11729 }
11730
11731 if (!info->attrs[NL80211_ATTR_MAC] ||
11732 !info->attrs[NL80211_ATTR_OPER_CLASS])
11733 return -EINVAL;
11734
11735 err = nl80211_parse_chandef(rdev, info, &chandef);
11736 if (err)
11737 return err;
11738
11739 /*
11740 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11741 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11742 * specification is not defined for them.
11743 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011744 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011745 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11746 chandef.width != NL80211_CHAN_WIDTH_20)
11747 return -EINVAL;
11748
11749 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011750 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11751 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011752 return -EINVAL;
11753
11754 /* don't allow switching to DFS channels */
11755 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11756 return -EINVAL;
11757
11758 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11759 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11760
11761 wdev_lock(wdev);
11762 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11763 wdev_unlock(wdev);
11764
11765 return err;
11766}
11767
11768static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11769 struct genl_info *info)
11770{
11771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11772 struct net_device *dev = info->user_ptr[1];
11773 struct wireless_dev *wdev = dev->ieee80211_ptr;
11774 const u8 *addr;
11775
11776 if (!rdev->ops->tdls_channel_switch ||
11777 !rdev->ops->tdls_cancel_channel_switch ||
11778 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11779 return -EOPNOTSUPP;
11780
11781 switch (dev->ieee80211_ptr->iftype) {
11782 case NL80211_IFTYPE_STATION:
11783 case NL80211_IFTYPE_P2P_CLIENT:
11784 break;
11785 default:
11786 return -EOPNOTSUPP;
11787 }
11788
11789 if (!info->attrs[NL80211_ATTR_MAC])
11790 return -EINVAL;
11791
11792 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11793
11794 wdev_lock(wdev);
11795 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11796 wdev_unlock(wdev);
11797
11798 return 0;
11799}
11800
Michael Braunce0ce132016-10-10 19:12:22 +020011801static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
11802 struct genl_info *info)
11803{
11804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11805 struct net_device *dev = info->user_ptr[1];
11806 struct wireless_dev *wdev = dev->ieee80211_ptr;
11807 const struct nlattr *nla;
11808 bool enabled;
11809
11810 if (netif_running(dev))
11811 return -EBUSY;
11812
11813 if (!rdev->ops->set_multicast_to_unicast)
11814 return -EOPNOTSUPP;
11815
11816 if (wdev->iftype != NL80211_IFTYPE_AP &&
11817 wdev->iftype != NL80211_IFTYPE_P2P_GO)
11818 return -EOPNOTSUPP;
11819
11820 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
11821 enabled = nla_get_flag(nla);
11822
11823 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
11824}
11825
Johannes Berg4c476992010-10-04 21:36:35 +020011826#define NL80211_FLAG_NEED_WIPHY 0x01
11827#define NL80211_FLAG_NEED_NETDEV 0x02
11828#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011829#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11830#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11831 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011832#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011833/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011834#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11835 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011836#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011837
Johannes Bergf84f7712013-11-14 17:14:45 +010011838static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011839 struct genl_info *info)
11840{
11841 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011842 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011843 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011844 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11845
11846 if (rtnl)
11847 rtnl_lock();
11848
11849 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011850 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011851 if (IS_ERR(rdev)) {
11852 if (rtnl)
11853 rtnl_unlock();
11854 return PTR_ERR(rdev);
11855 }
11856 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011857 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11858 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011859 ASSERT_RTNL();
11860
Johannes Berg89a54e42012-06-15 14:33:17 +020011861 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11862 info->attrs);
11863 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011864 if (rtnl)
11865 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011866 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011867 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011868
Johannes Berg89a54e42012-06-15 14:33:17 +020011869 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011870 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011871
Johannes Berg1bf614e2012-06-15 15:23:36 +020011872 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11873 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011874 if (rtnl)
11875 rtnl_unlock();
11876 return -EINVAL;
11877 }
11878
11879 info->user_ptr[1] = dev;
11880 } else {
11881 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011882 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011883
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011884 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11885 !wdev_running(wdev)) {
11886 if (rtnl)
11887 rtnl_unlock();
11888 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011889 }
11890
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011891 if (dev)
11892 dev_hold(dev);
11893
Johannes Berg4c476992010-10-04 21:36:35 +020011894 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011895 }
11896
11897 return 0;
11898}
11899
Johannes Bergf84f7712013-11-14 17:14:45 +010011900static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011901 struct genl_info *info)
11902{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011903 if (info->user_ptr[1]) {
11904 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11905 struct wireless_dev *wdev = info->user_ptr[1];
11906
11907 if (wdev->netdev)
11908 dev_put(wdev->netdev);
11909 } else {
11910 dev_put(info->user_ptr[1]);
11911 }
11912 }
Johannes Berg5393b912014-09-10 15:00:16 +030011913
Johannes Berg4c476992010-10-04 21:36:35 +020011914 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11915 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011916
11917 /* If needed, clear the netlink message payload from the SKB
11918 * as it might contain key data that shouldn't stick around on
11919 * the heap after the SKB is freed. The netlink message header
11920 * is still needed for further processing, so leave it intact.
11921 */
11922 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11923 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11924
11925 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11926 }
Johannes Berg4c476992010-10-04 21:36:35 +020011927}
11928
Johannes Berg4534de82013-11-14 17:14:46 +010011929static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011930 {
11931 .cmd = NL80211_CMD_GET_WIPHY,
11932 .doit = nl80211_get_wiphy,
11933 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011934 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011935 .policy = nl80211_policy,
11936 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011937 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11938 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011939 },
11940 {
11941 .cmd = NL80211_CMD_SET_WIPHY,
11942 .doit = nl80211_set_wiphy,
11943 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011944 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011945 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011946 },
11947 {
11948 .cmd = NL80211_CMD_GET_INTERFACE,
11949 .doit = nl80211_get_interface,
11950 .dumpit = nl80211_dump_interface,
11951 .policy = nl80211_policy,
11952 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011953 .internal_flags = NL80211_FLAG_NEED_WDEV |
11954 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011955 },
11956 {
11957 .cmd = NL80211_CMD_SET_INTERFACE,
11958 .doit = nl80211_set_interface,
11959 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011960 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011961 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11962 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011963 },
11964 {
11965 .cmd = NL80211_CMD_NEW_INTERFACE,
11966 .doit = nl80211_new_interface,
11967 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011968 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011969 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11970 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011971 },
11972 {
11973 .cmd = NL80211_CMD_DEL_INTERFACE,
11974 .doit = nl80211_del_interface,
11975 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011976 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011977 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011978 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011979 },
Johannes Berg41ade002007-12-19 02:03:29 +010011980 {
11981 .cmd = NL80211_CMD_GET_KEY,
11982 .doit = nl80211_get_key,
11983 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011984 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011985 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011986 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011987 },
11988 {
11989 .cmd = NL80211_CMD_SET_KEY,
11990 .doit = nl80211_set_key,
11991 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011992 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011994 NL80211_FLAG_NEED_RTNL |
11995 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011996 },
11997 {
11998 .cmd = NL80211_CMD_NEW_KEY,
11999 .doit = nl80211_new_key,
12000 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012001 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012003 NL80211_FLAG_NEED_RTNL |
12004 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010012005 },
12006 {
12007 .cmd = NL80211_CMD_DEL_KEY,
12008 .doit = nl80211_del_key,
12009 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012010 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012012 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010012013 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010012014 {
12015 .cmd = NL80211_CMD_SET_BEACON,
12016 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012017 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012018 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012020 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012021 },
12022 {
Johannes Berg88600202012-02-13 15:17:18 +010012023 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012024 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012025 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012026 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012028 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012029 },
12030 {
Johannes Berg88600202012-02-13 15:17:18 +010012031 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012032 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012033 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010012034 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012036 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010012037 },
Johannes Berg5727ef12007-12-19 02:03:34 +010012038 {
12039 .cmd = NL80211_CMD_GET_STATION,
12040 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012041 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010012042 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020012043 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12044 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012045 },
12046 {
12047 .cmd = NL80211_CMD_SET_STATION,
12048 .doit = nl80211_set_station,
12049 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012050 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012051 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012052 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012053 },
12054 {
12055 .cmd = NL80211_CMD_NEW_STATION,
12056 .doit = nl80211_new_station,
12057 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012058 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012060 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012061 },
12062 {
12063 .cmd = NL80211_CMD_DEL_STATION,
12064 .doit = nl80211_del_station,
12065 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012066 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012067 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012068 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012069 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012070 {
12071 .cmd = NL80211_CMD_GET_MPATH,
12072 .doit = nl80211_get_mpath,
12073 .dumpit = nl80211_dump_mpath,
12074 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012075 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012076 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012077 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012078 },
12079 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012080 .cmd = NL80211_CMD_GET_MPP,
12081 .doit = nl80211_get_mpp,
12082 .dumpit = nl80211_dump_mpp,
12083 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012084 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012085 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12086 NL80211_FLAG_NEED_RTNL,
12087 },
12088 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012089 .cmd = NL80211_CMD_SET_MPATH,
12090 .doit = nl80211_set_mpath,
12091 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012092 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012093 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012094 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012095 },
12096 {
12097 .cmd = NL80211_CMD_NEW_MPATH,
12098 .doit = nl80211_new_mpath,
12099 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012100 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012101 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012102 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012103 },
12104 {
12105 .cmd = NL80211_CMD_DEL_MPATH,
12106 .doit = nl80211_del_mpath,
12107 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012108 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012109 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012110 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012111 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012112 {
12113 .cmd = NL80211_CMD_SET_BSS,
12114 .doit = nl80211_set_bss,
12115 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012116 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012117 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012118 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012119 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012120 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012121 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012122 .doit = nl80211_get_reg_do,
12123 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012124 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012125 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012126 /* can be retrieved by unprivileged users */
12127 },
Johannes Bergb6863032015-10-15 09:25:18 +020012128#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012129 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012130 .cmd = NL80211_CMD_SET_REG,
12131 .doit = nl80211_set_reg,
12132 .policy = nl80211_policy,
12133 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012134 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012135 },
Johannes Bergb6863032015-10-15 09:25:18 +020012136#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012137 {
12138 .cmd = NL80211_CMD_REQ_SET_REG,
12139 .doit = nl80211_req_set_reg,
12140 .policy = nl80211_policy,
12141 .flags = GENL_ADMIN_PERM,
12142 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012143 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012144 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12145 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012146 .policy = nl80211_policy,
12147 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012149 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012150 },
12151 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012152 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12153 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012157 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012158 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012159 {
Johannes Berg2a519312009-02-10 21:25:55 +010012160 .cmd = NL80211_CMD_TRIGGER_SCAN,
12161 .doit = nl80211_trigger_scan,
12162 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012163 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012164 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012165 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012166 },
12167 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012168 .cmd = NL80211_CMD_ABORT_SCAN,
12169 .doit = nl80211_abort_scan,
12170 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012171 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012172 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12173 NL80211_FLAG_NEED_RTNL,
12174 },
12175 {
Johannes Berg2a519312009-02-10 21:25:55 +010012176 .cmd = NL80211_CMD_GET_SCAN,
12177 .policy = nl80211_policy,
12178 .dumpit = nl80211_dump_scan,
12179 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012180 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012181 .cmd = NL80211_CMD_START_SCHED_SCAN,
12182 .doit = nl80211_start_sched_scan,
12183 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012184 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012185 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12186 NL80211_FLAG_NEED_RTNL,
12187 },
12188 {
12189 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12190 .doit = nl80211_stop_sched_scan,
12191 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012192 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012193 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12194 NL80211_FLAG_NEED_RTNL,
12195 },
12196 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012197 .cmd = NL80211_CMD_AUTHENTICATE,
12198 .doit = nl80211_authenticate,
12199 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012200 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012201 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012202 NL80211_FLAG_NEED_RTNL |
12203 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012204 },
12205 {
12206 .cmd = NL80211_CMD_ASSOCIATE,
12207 .doit = nl80211_associate,
12208 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012209 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012210 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012211 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012212 },
12213 {
12214 .cmd = NL80211_CMD_DEAUTHENTICATE,
12215 .doit = nl80211_deauthenticate,
12216 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012217 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012218 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012219 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012220 },
12221 {
12222 .cmd = NL80211_CMD_DISASSOCIATE,
12223 .doit = nl80211_disassociate,
12224 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012225 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012226 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012227 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012228 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012229 {
12230 .cmd = NL80211_CMD_JOIN_IBSS,
12231 .doit = nl80211_join_ibss,
12232 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012233 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012234 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012235 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012236 },
12237 {
12238 .cmd = NL80211_CMD_LEAVE_IBSS,
12239 .doit = nl80211_leave_ibss,
12240 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012241 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012242 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012243 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012244 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012245#ifdef CONFIG_NL80211_TESTMODE
12246 {
12247 .cmd = NL80211_CMD_TESTMODE,
12248 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012249 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012250 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012251 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012252 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12253 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012254 },
12255#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012256 {
12257 .cmd = NL80211_CMD_CONNECT,
12258 .doit = nl80211_connect,
12259 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012260 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012261 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012262 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012263 },
12264 {
vamsi krishna088e8df2016-10-27 16:51:11 +030012265 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
12266 .doit = nl80211_update_connect_params,
12267 .policy = nl80211_policy,
12268 .flags = GENL_ADMIN_PERM,
12269 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12270 NL80211_FLAG_NEED_RTNL,
12271 },
12272 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020012273 .cmd = NL80211_CMD_DISCONNECT,
12274 .doit = nl80211_disconnect,
12275 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012276 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012277 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012278 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012279 },
Johannes Berg463d0182009-07-14 00:33:35 +020012280 {
12281 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12282 .doit = nl80211_wiphy_netns,
12283 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012284 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012285 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12286 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012287 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012288 {
12289 .cmd = NL80211_CMD_GET_SURVEY,
12290 .policy = nl80211_policy,
12291 .dumpit = nl80211_dump_survey,
12292 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012293 {
12294 .cmd = NL80211_CMD_SET_PMKSA,
12295 .doit = nl80211_setdel_pmksa,
12296 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012297 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012299 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012300 },
12301 {
12302 .cmd = NL80211_CMD_DEL_PMKSA,
12303 .doit = nl80211_setdel_pmksa,
12304 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012305 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012307 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012308 },
12309 {
12310 .cmd = NL80211_CMD_FLUSH_PMKSA,
12311 .doit = nl80211_flush_pmksa,
12312 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012313 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012315 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012316 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012317 {
12318 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12319 .doit = nl80211_remain_on_channel,
12320 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012321 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012322 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012323 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012324 },
12325 {
12326 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12327 .doit = nl80211_cancel_remain_on_channel,
12328 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012329 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012330 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012331 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012332 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012333 {
12334 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12335 .doit = nl80211_set_tx_bitrate_mask,
12336 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012337 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012338 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12339 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012340 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012341 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012342 .cmd = NL80211_CMD_REGISTER_FRAME,
12343 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012344 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012345 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012346 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012347 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012348 },
12349 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012350 .cmd = NL80211_CMD_FRAME,
12351 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012352 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012353 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012354 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012355 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012356 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012357 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012358 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12359 .doit = nl80211_tx_mgmt_cancel_wait,
12360 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012361 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012362 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012363 NL80211_FLAG_NEED_RTNL,
12364 },
12365 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012366 .cmd = NL80211_CMD_SET_POWER_SAVE,
12367 .doit = nl80211_set_power_save,
12368 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012369 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012370 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12371 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012372 },
12373 {
12374 .cmd = NL80211_CMD_GET_POWER_SAVE,
12375 .doit = nl80211_get_power_save,
12376 .policy = nl80211_policy,
12377 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012378 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12379 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012380 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012381 {
12382 .cmd = NL80211_CMD_SET_CQM,
12383 .doit = nl80211_set_cqm,
12384 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012385 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012386 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12387 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012388 },
Johannes Bergf444de02010-05-05 15:25:02 +020012389 {
12390 .cmd = NL80211_CMD_SET_CHANNEL,
12391 .doit = nl80211_set_channel,
12392 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012393 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012394 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12395 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012396 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012397 {
12398 .cmd = NL80211_CMD_SET_WDS_PEER,
12399 .doit = nl80211_set_wds_peer,
12400 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012401 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012402 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12403 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012404 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012405 {
12406 .cmd = NL80211_CMD_JOIN_MESH,
12407 .doit = nl80211_join_mesh,
12408 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012409 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12411 NL80211_FLAG_NEED_RTNL,
12412 },
12413 {
12414 .cmd = NL80211_CMD_LEAVE_MESH,
12415 .doit = nl80211_leave_mesh,
12416 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012417 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12419 NL80211_FLAG_NEED_RTNL,
12420 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012421 {
12422 .cmd = NL80211_CMD_JOIN_OCB,
12423 .doit = nl80211_join_ocb,
12424 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012425 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12427 NL80211_FLAG_NEED_RTNL,
12428 },
12429 {
12430 .cmd = NL80211_CMD_LEAVE_OCB,
12431 .doit = nl80211_leave_ocb,
12432 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012433 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012434 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12435 NL80211_FLAG_NEED_RTNL,
12436 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012437#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012438 {
12439 .cmd = NL80211_CMD_GET_WOWLAN,
12440 .doit = nl80211_get_wowlan,
12441 .policy = nl80211_policy,
12442 /* can be retrieved by unprivileged users */
12443 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12444 NL80211_FLAG_NEED_RTNL,
12445 },
12446 {
12447 .cmd = NL80211_CMD_SET_WOWLAN,
12448 .doit = nl80211_set_wowlan,
12449 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012450 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012451 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12452 NL80211_FLAG_NEED_RTNL,
12453 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012454#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012455 {
12456 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12457 .doit = nl80211_set_rekey_data,
12458 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012459 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012460 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012461 NL80211_FLAG_NEED_RTNL |
12462 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012463 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012464 {
12465 .cmd = NL80211_CMD_TDLS_MGMT,
12466 .doit = nl80211_tdls_mgmt,
12467 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012468 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12470 NL80211_FLAG_NEED_RTNL,
12471 },
12472 {
12473 .cmd = NL80211_CMD_TDLS_OPER,
12474 .doit = nl80211_tdls_oper,
12475 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012476 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12478 NL80211_FLAG_NEED_RTNL,
12479 },
Johannes Berg28946da2011-11-04 11:18:12 +010012480 {
12481 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12482 .doit = nl80211_register_unexpected_frame,
12483 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012484 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012485 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12486 NL80211_FLAG_NEED_RTNL,
12487 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012488 {
12489 .cmd = NL80211_CMD_PROBE_CLIENT,
12490 .doit = nl80211_probe_client,
12491 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012492 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012494 NL80211_FLAG_NEED_RTNL,
12495 },
Johannes Berg5e760232011-11-04 11:18:17 +010012496 {
12497 .cmd = NL80211_CMD_REGISTER_BEACONS,
12498 .doit = nl80211_register_beacons,
12499 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012500 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010012501 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12502 NL80211_FLAG_NEED_RTNL,
12503 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012504 {
12505 .cmd = NL80211_CMD_SET_NOACK_MAP,
12506 .doit = nl80211_set_noack_map,
12507 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012508 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012509 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12510 NL80211_FLAG_NEED_RTNL,
12511 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012512 {
12513 .cmd = NL80211_CMD_START_P2P_DEVICE,
12514 .doit = nl80211_start_p2p_device,
12515 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012516 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012517 .internal_flags = NL80211_FLAG_NEED_WDEV |
12518 NL80211_FLAG_NEED_RTNL,
12519 },
12520 {
12521 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12522 .doit = nl80211_stop_p2p_device,
12523 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012524 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012525 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12526 NL80211_FLAG_NEED_RTNL,
12527 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012528 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012529 .cmd = NL80211_CMD_START_NAN,
12530 .doit = nl80211_start_nan,
12531 .policy = nl80211_policy,
12532 .flags = GENL_ADMIN_PERM,
12533 .internal_flags = NL80211_FLAG_NEED_WDEV |
12534 NL80211_FLAG_NEED_RTNL,
12535 },
12536 {
12537 .cmd = NL80211_CMD_STOP_NAN,
12538 .doit = nl80211_stop_nan,
12539 .policy = nl80211_policy,
12540 .flags = GENL_ADMIN_PERM,
12541 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12542 NL80211_FLAG_NEED_RTNL,
12543 },
12544 {
Ayala Bekera442b762016-09-20 17:31:15 +030012545 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12546 .doit = nl80211_nan_add_func,
12547 .policy = nl80211_policy,
12548 .flags = GENL_ADMIN_PERM,
12549 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12550 NL80211_FLAG_NEED_RTNL,
12551 },
12552 {
12553 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12554 .doit = nl80211_nan_del_func,
12555 .policy = nl80211_policy,
12556 .flags = GENL_ADMIN_PERM,
12557 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12558 NL80211_FLAG_NEED_RTNL,
12559 },
12560 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012561 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12562 .doit = nl80211_nan_change_config,
12563 .policy = nl80211_policy,
12564 .flags = GENL_ADMIN_PERM,
12565 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12566 NL80211_FLAG_NEED_RTNL,
12567 },
12568 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012569 .cmd = NL80211_CMD_SET_MCAST_RATE,
12570 .doit = nl80211_set_mcast_rate,
12571 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012572 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012573 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12574 NL80211_FLAG_NEED_RTNL,
12575 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012576 {
12577 .cmd = NL80211_CMD_SET_MAC_ACL,
12578 .doit = nl80211_set_mac_acl,
12579 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012580 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012581 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12582 NL80211_FLAG_NEED_RTNL,
12583 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012584 {
12585 .cmd = NL80211_CMD_RADAR_DETECT,
12586 .doit = nl80211_start_radar_detection,
12587 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012588 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12590 NL80211_FLAG_NEED_RTNL,
12591 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012592 {
12593 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12594 .doit = nl80211_get_protocol_features,
12595 .policy = nl80211_policy,
12596 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012597 {
12598 .cmd = NL80211_CMD_UPDATE_FT_IES,
12599 .doit = nl80211_update_ft_ies,
12600 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012601 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12603 NL80211_FLAG_NEED_RTNL,
12604 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012605 {
12606 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12607 .doit = nl80211_crit_protocol_start,
12608 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012609 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012610 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12611 NL80211_FLAG_NEED_RTNL,
12612 },
12613 {
12614 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12615 .doit = nl80211_crit_protocol_stop,
12616 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012617 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012618 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12619 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012620 },
12621 {
12622 .cmd = NL80211_CMD_GET_COALESCE,
12623 .doit = nl80211_get_coalesce,
12624 .policy = nl80211_policy,
12625 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12626 NL80211_FLAG_NEED_RTNL,
12627 },
12628 {
12629 .cmd = NL80211_CMD_SET_COALESCE,
12630 .doit = nl80211_set_coalesce,
12631 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012632 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012633 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12634 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012635 },
12636 {
12637 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12638 .doit = nl80211_channel_switch,
12639 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012640 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12642 NL80211_FLAG_NEED_RTNL,
12643 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012644 {
12645 .cmd = NL80211_CMD_VENDOR,
12646 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012647 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012648 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012649 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012650 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12651 NL80211_FLAG_NEED_RTNL,
12652 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012653 {
12654 .cmd = NL80211_CMD_SET_QOS_MAP,
12655 .doit = nl80211_set_qos_map,
12656 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012657 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012658 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12659 NL80211_FLAG_NEED_RTNL,
12660 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012661 {
12662 .cmd = NL80211_CMD_ADD_TX_TS,
12663 .doit = nl80211_add_tx_ts,
12664 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012665 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012666 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12667 NL80211_FLAG_NEED_RTNL,
12668 },
12669 {
12670 .cmd = NL80211_CMD_DEL_TX_TS,
12671 .doit = nl80211_del_tx_ts,
12672 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012673 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012674 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12675 NL80211_FLAG_NEED_RTNL,
12676 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012677 {
12678 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12679 .doit = nl80211_tdls_channel_switch,
12680 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012681 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12683 NL80211_FLAG_NEED_RTNL,
12684 },
12685 {
12686 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12687 .doit = nl80211_tdls_cancel_channel_switch,
12688 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012689 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12691 NL80211_FLAG_NEED_RTNL,
12692 },
Michael Braunce0ce132016-10-10 19:12:22 +020012693 {
12694 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
12695 .doit = nl80211_set_multicast_to_unicast,
12696 .policy = nl80211_policy,
12697 .flags = GENL_UNS_ADMIN_PERM,
12698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12699 NL80211_FLAG_NEED_RTNL,
12700 },
Johannes Berg55682962007-09-20 13:09:35 -040012701};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012702
Johannes Berg56989f62016-10-24 14:40:05 +020012703static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020012704 .name = NL80211_GENL_NAME, /* have users key off the name instead */
12705 .hdrsize = 0, /* no private header */
12706 .version = 1, /* no particular meaning now */
12707 .maxattr = NL80211_ATTR_MAX,
12708 .netnsok = true,
12709 .pre_doit = nl80211_pre_doit,
12710 .post_doit = nl80211_post_doit,
12711 .module = THIS_MODULE,
12712 .ops = nl80211_ops,
12713 .n_ops = ARRAY_SIZE(nl80211_ops),
12714 .mcgrps = nl80211_mcgrps,
12715 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
12716};
12717
Johannes Berg55682962007-09-20 13:09:35 -040012718/* notification functions */
12719
Johannes Berg3bb20552014-05-26 13:52:25 +020012720void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12721 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012722{
12723 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012724 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012725
Johannes Berg3bb20552014-05-26 13:52:25 +020012726 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12727 cmd != NL80211_CMD_DEL_WIPHY);
12728
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012730 if (!msg)
12731 return;
12732
Johannes Berg3bb20552014-05-26 13:52:25 +020012733 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040012734 nlmsg_free(msg);
12735 return;
12736 }
12737
Johannes Berg68eb5502013-11-19 15:19:38 +010012738 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012739 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012740}
12741
Denis Kenzior896ff062016-08-03 16:58:33 -050012742void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
12743 struct wireless_dev *wdev,
12744 enum nl80211_commands cmd)
12745{
12746 struct sk_buff *msg;
12747
12748 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
12749 cmd != NL80211_CMD_DEL_INTERFACE);
12750
12751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12752 if (!msg)
12753 return;
12754
12755 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
12756 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
12757 nlmsg_free(msg);
12758 return;
12759 }
12760
12761 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12762 NL80211_MCGRP_CONFIG, GFP_KERNEL);
12763}
12764
Johannes Berg362a4152009-05-24 16:43:15 +020012765static int nl80211_add_scan_req(struct sk_buff *msg,
12766 struct cfg80211_registered_device *rdev)
12767{
12768 struct cfg80211_scan_request *req = rdev->scan_req;
12769 struct nlattr *nest;
12770 int i;
12771
12772 if (WARN_ON(!req))
12773 return 0;
12774
12775 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
12776 if (!nest)
12777 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012778 for (i = 0; i < req->n_ssids; i++) {
12779 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
12780 goto nla_put_failure;
12781 }
Johannes Berg362a4152009-05-24 16:43:15 +020012782 nla_nest_end(msg, nest);
12783
12784 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
12785 if (!nest)
12786 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012787 for (i = 0; i < req->n_channels; i++) {
12788 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
12789 goto nla_put_failure;
12790 }
Johannes Berg362a4152009-05-24 16:43:15 +020012791 nla_nest_end(msg, nest);
12792
David S. Miller9360ffd2012-03-29 04:41:26 -040012793 if (req->ie &&
12794 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
12795 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020012796
Johannes Bergae917c92013-10-25 11:05:22 +020012797 if (req->flags &&
12798 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
12799 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070012800
Avraham Stern1d762502016-07-05 17:10:13 +030012801 if (req->info.scan_start_tsf &&
12802 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
12803 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
12804 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
12805 req->info.tsf_bssid)))
12806 goto nla_put_failure;
12807
Johannes Berg362a4152009-05-24 16:43:15 +020012808 return 0;
12809 nla_put_failure:
12810 return -ENOBUFS;
12811}
12812
Johannes Berga538e2d2009-06-16 19:56:42 +020012813static int nl80211_send_scan_msg(struct sk_buff *msg,
12814 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012815 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012816 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020012817 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010012818{
12819 void *hdr;
12820
Eric W. Biederman15e47302012-09-07 20:12:54 +000012821 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010012822 if (!hdr)
12823 return -1;
12824
David S. Miller9360ffd2012-03-29 04:41:26 -040012825 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020012826 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12827 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012828 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12829 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012830 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010012831
Johannes Berg362a4152009-05-24 16:43:15 +020012832 /* ignore errors and send incomplete event anyway */
12833 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010012834
Johannes Berg053c0952015-01-16 22:09:00 +010012835 genlmsg_end(msg, hdr);
12836 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010012837
12838 nla_put_failure:
12839 genlmsg_cancel(msg, hdr);
12840 return -EMSGSIZE;
12841}
12842
Luciano Coelho807f8a82011-05-11 17:09:35 +030012843static int
12844nl80211_send_sched_scan_msg(struct sk_buff *msg,
12845 struct cfg80211_registered_device *rdev,
12846 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012847 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030012848{
12849 void *hdr;
12850
Eric W. Biederman15e47302012-09-07 20:12:54 +000012851 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012852 if (!hdr)
12853 return -1;
12854
David S. Miller9360ffd2012-03-29 04:41:26 -040012855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12857 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012858
Johannes Berg053c0952015-01-16 22:09:00 +010012859 genlmsg_end(msg, hdr);
12860 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012861
12862 nla_put_failure:
12863 genlmsg_cancel(msg, hdr);
12864 return -EMSGSIZE;
12865}
12866
Johannes Berga538e2d2009-06-16 19:56:42 +020012867void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012868 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012869{
12870 struct sk_buff *msg;
12871
Thomas Graf58050fc2012-06-28 03:57:45 +000012872 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012873 if (!msg)
12874 return;
12875
Johannes Bergfd014282012-06-18 19:17:03 +020012876 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012877 NL80211_CMD_TRIGGER_SCAN) < 0) {
12878 nlmsg_free(msg);
12879 return;
12880 }
12881
Johannes Berg68eb5502013-11-19 15:19:38 +010012882 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012883 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012884}
12885
Johannes Bergf9d15d12014-01-22 11:14:19 +020012886struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12887 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012888{
12889 struct sk_buff *msg;
12890
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012891 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012892 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012893 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012894
Johannes Bergfd014282012-06-18 19:17:03 +020012895 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012896 aborted ? NL80211_CMD_SCAN_ABORTED :
12897 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012898 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012899 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012900 }
12901
Johannes Bergf9d15d12014-01-22 11:14:19 +020012902 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012903}
12904
Johannes Bergf9d15d12014-01-22 11:14:19 +020012905void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12906 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012907{
Johannes Berg2a519312009-02-10 21:25:55 +010012908 if (!msg)
12909 return;
12910
Johannes Berg68eb5502013-11-19 15:19:38 +010012911 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012912 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012913}
12914
Luciano Coelho807f8a82011-05-11 17:09:35 +030012915void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12916 struct net_device *netdev)
12917{
12918 struct sk_buff *msg;
12919
12920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12921 if (!msg)
12922 return;
12923
12924 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12925 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12926 nlmsg_free(msg);
12927 return;
12928 }
12929
Johannes Berg68eb5502013-11-19 15:19:38 +010012930 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012931 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012932}
12933
12934void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12935 struct net_device *netdev, u32 cmd)
12936{
12937 struct sk_buff *msg;
12938
Thomas Graf58050fc2012-06-28 03:57:45 +000012939 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012940 if (!msg)
12941 return;
12942
12943 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12944 nlmsg_free(msg);
12945 return;
12946 }
12947
Johannes Berg68eb5502013-11-19 15:19:38 +010012948 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012949 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012950}
12951
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012952static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12953 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012954{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012955 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012956 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12957 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012958
David S. Miller9360ffd2012-03-29 04:41:26 -040012959 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12960 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12961 NL80211_REGDOM_TYPE_WORLD))
12962 goto nla_put_failure;
12963 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12964 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12965 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12966 goto nla_put_failure;
12967 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12968 request->intersect) {
12969 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12970 NL80211_REGDOM_TYPE_INTERSECTION))
12971 goto nla_put_failure;
12972 } else {
12973 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12974 NL80211_REGDOM_TYPE_COUNTRY) ||
12975 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12976 request->alpha2))
12977 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012978 }
12979
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012980 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12981 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12982
12983 if (wiphy &&
12984 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12985 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012986
12987 if (wiphy &&
12988 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12989 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12990 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012991 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012992
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012993 return true;
12994
12995nla_put_failure:
12996 return false;
12997}
12998
12999/*
13000 * This can happen on global regulatory changes or device specific settings
13001 * based on custom regulatory domains.
13002 */
13003void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
13004 struct regulatory_request *request)
13005{
13006 struct sk_buff *msg;
13007 void *hdr;
13008
13009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13010 if (!msg)
13011 return;
13012
13013 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
13014 if (!hdr) {
13015 nlmsg_free(msg);
13016 return;
13017 }
13018
13019 if (nl80211_reg_change_event_fill(msg, request) == false)
13020 goto nla_put_failure;
13021
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013022 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013023
Johannes Bergbc43b282009-07-25 10:54:13 +020013024 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013025 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013026 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020013027 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040013028
13029 return;
13030
13031nla_put_failure:
13032 genlmsg_cancel(msg, hdr);
13033 nlmsg_free(msg);
13034}
13035
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013036static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
13037 struct net_device *netdev,
13038 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013039 enum nl80211_commands cmd, gfp_t gfp,
13040 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013041{
13042 struct sk_buff *msg;
13043 void *hdr;
13044
Johannes Berge6d6e342009-07-01 21:26:47 +020013045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013046 if (!msg)
13047 return;
13048
13049 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13050 if (!hdr) {
13051 nlmsg_free(msg);
13052 return;
13053 }
13054
David S. Miller9360ffd2012-03-29 04:41:26 -040013055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13057 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
13058 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013059
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013060 if (uapsd_queues >= 0) {
13061 struct nlattr *nla_wmm =
13062 nla_nest_start(msg, NL80211_ATTR_STA_WME);
13063 if (!nla_wmm)
13064 goto nla_put_failure;
13065
13066 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
13067 uapsd_queues))
13068 goto nla_put_failure;
13069
13070 nla_nest_end(msg, nla_wmm);
13071 }
13072
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013073 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013074
Johannes Berg68eb5502013-11-19 15:19:38 +010013075 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013076 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013077 return;
13078
13079 nla_put_failure:
13080 genlmsg_cancel(msg, hdr);
13081 nlmsg_free(msg);
13082}
13083
13084void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013085 struct net_device *netdev, const u8 *buf,
13086 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013087{
13088 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013089 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013090}
13091
13092void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
13093 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013094 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013095{
Johannes Berge6d6e342009-07-01 21:26:47 +020013096 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013097 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013098}
13099
Jouni Malinen53b46b82009-03-27 20:53:56 +020013100void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013101 struct net_device *netdev, const u8 *buf,
13102 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013103{
13104 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013105 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013106}
13107
Jouni Malinen53b46b82009-03-27 20:53:56 +020013108void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13109 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013110 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013111{
13112 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013113 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013114}
13115
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013116void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13117 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013118{
Johannes Berg947add32013-02-22 22:05:20 +010013119 struct wireless_dev *wdev = dev->ieee80211_ptr;
13120 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013121 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013122 const struct ieee80211_mgmt *mgmt = (void *)buf;
13123 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013124
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013125 if (WARN_ON(len < 2))
13126 return;
13127
13128 if (ieee80211_is_deauth(mgmt->frame_control))
13129 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13130 else
13131 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13132
13133 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013134 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013135}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013136EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013137
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013138static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13139 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013140 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013141{
13142 struct sk_buff *msg;
13143 void *hdr;
13144
Johannes Berge6d6e342009-07-01 21:26:47 +020013145 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013146 if (!msg)
13147 return;
13148
13149 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13150 if (!hdr) {
13151 nlmsg_free(msg);
13152 return;
13153 }
13154
David S. Miller9360ffd2012-03-29 04:41:26 -040013155 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13156 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13157 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13158 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13159 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013160
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013161 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013162
Johannes Berg68eb5502013-11-19 15:19:38 +010013163 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013164 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013165 return;
13166
13167 nla_put_failure:
13168 genlmsg_cancel(msg, hdr);
13169 nlmsg_free(msg);
13170}
13171
13172void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013173 struct net_device *netdev, const u8 *addr,
13174 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013175{
13176 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013177 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013178}
13179
13180void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013181 struct net_device *netdev, const u8 *addr,
13182 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013183{
Johannes Berge6d6e342009-07-01 21:26:47 +020013184 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13185 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013186}
13187
Samuel Ortizb23aa672009-07-01 21:26:54 +020013188void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13189 struct net_device *netdev, const u8 *bssid,
13190 const u8 *req_ie, size_t req_ie_len,
13191 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013192 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013193{
13194 struct sk_buff *msg;
13195 void *hdr;
13196
Thomas Graf58050fc2012-06-28 03:57:45 +000013197 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013198 if (!msg)
13199 return;
13200
13201 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13202 if (!hdr) {
13203 nlmsg_free(msg);
13204 return;
13205 }
13206
David S. Miller9360ffd2012-03-29 04:41:26 -040013207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13209 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013210 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13211 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13212 status) ||
13213 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013214 (req_ie &&
13215 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13216 (resp_ie &&
13217 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13218 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013219
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013220 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013221
Johannes Berg68eb5502013-11-19 15:19:38 +010013222 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013223 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013224 return;
13225
13226 nla_put_failure:
13227 genlmsg_cancel(msg, hdr);
13228 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013229}
13230
13231void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13232 struct net_device *netdev, const u8 *bssid,
13233 const u8 *req_ie, size_t req_ie_len,
13234 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
13235{
13236 struct sk_buff *msg;
13237 void *hdr;
13238
Thomas Graf58050fc2012-06-28 03:57:45 +000013239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013240 if (!msg)
13241 return;
13242
13243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13244 if (!hdr) {
13245 nlmsg_free(msg);
13246 return;
13247 }
13248
David S. Miller9360ffd2012-03-29 04:41:26 -040013249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13251 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13252 (req_ie &&
13253 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13254 (resp_ie &&
13255 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13256 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013257
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013258 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013259
Johannes Berg68eb5502013-11-19 15:19:38 +010013260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013261 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013262 return;
13263
13264 nla_put_failure:
13265 genlmsg_cancel(msg, hdr);
13266 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013267}
13268
13269void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13270 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013271 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013272{
13273 struct sk_buff *msg;
13274 void *hdr;
13275
Thomas Graf58050fc2012-06-28 03:57:45 +000013276 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013277 if (!msg)
13278 return;
13279
13280 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13281 if (!hdr) {
13282 nlmsg_free(msg);
13283 return;
13284 }
13285
David S. Miller9360ffd2012-03-29 04:41:26 -040013286 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13287 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13288 (from_ap && reason &&
13289 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13290 (from_ap &&
13291 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13292 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13293 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013294
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013295 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013296
Johannes Berg68eb5502013-11-19 15:19:38 +010013297 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013298 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013299 return;
13300
13301 nla_put_failure:
13302 genlmsg_cancel(msg, hdr);
13303 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013304}
13305
Johannes Berg04a773a2009-04-19 21:24:32 +020013306void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13307 struct net_device *netdev, const u8 *bssid,
13308 gfp_t gfp)
13309{
13310 struct sk_buff *msg;
13311 void *hdr;
13312
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013313 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013314 if (!msg)
13315 return;
13316
13317 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13318 if (!hdr) {
13319 nlmsg_free(msg);
13320 return;
13321 }
13322
David S. Miller9360ffd2012-03-29 04:41:26 -040013323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13325 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13326 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013327
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013328 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013329
Johannes Berg68eb5502013-11-19 15:19:38 +010013330 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013331 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013332 return;
13333
13334 nla_put_failure:
13335 genlmsg_cancel(msg, hdr);
13336 nlmsg_free(msg);
13337}
13338
Johannes Berg947add32013-02-22 22:05:20 +010013339void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13340 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013341{
Johannes Berg947add32013-02-22 22:05:20 +010013342 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013343 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013344 struct sk_buff *msg;
13345 void *hdr;
13346
Johannes Berg947add32013-02-22 22:05:20 +010013347 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13348 return;
13349
13350 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13351
Javier Cardonac93b5e72011-04-07 15:08:34 -070013352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13353 if (!msg)
13354 return;
13355
13356 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13357 if (!hdr) {
13358 nlmsg_free(msg);
13359 return;
13360 }
13361
David S. Miller9360ffd2012-03-29 04:41:26 -040013362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013363 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13364 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013365 (ie_len && ie &&
13366 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13367 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013368
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013369 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013370
Johannes Berg68eb5502013-11-19 15:19:38 +010013371 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013372 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013373 return;
13374
13375 nla_put_failure:
13376 genlmsg_cancel(msg, hdr);
13377 nlmsg_free(msg);
13378}
Johannes Berg947add32013-02-22 22:05:20 +010013379EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013380
Jouni Malinena3b8b052009-03-27 21:59:49 +020013381void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13382 struct net_device *netdev, const u8 *addr,
13383 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013384 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013385{
13386 struct sk_buff *msg;
13387 void *hdr;
13388
Johannes Berge6d6e342009-07-01 21:26:47 +020013389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013390 if (!msg)
13391 return;
13392
13393 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13394 if (!hdr) {
13395 nlmsg_free(msg);
13396 return;
13397 }
13398
David S. Miller9360ffd2012-03-29 04:41:26 -040013399 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13400 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13401 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13402 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13403 (key_id != -1 &&
13404 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13405 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13406 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013407
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013408 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013409
Johannes Berg68eb5502013-11-19 15:19:38 +010013410 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013411 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013412 return;
13413
13414 nla_put_failure:
13415 genlmsg_cancel(msg, hdr);
13416 nlmsg_free(msg);
13417}
13418
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013419void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13420 struct ieee80211_channel *channel_before,
13421 struct ieee80211_channel *channel_after)
13422{
13423 struct sk_buff *msg;
13424 void *hdr;
13425 struct nlattr *nl_freq;
13426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013428 if (!msg)
13429 return;
13430
13431 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13432 if (!hdr) {
13433 nlmsg_free(msg);
13434 return;
13435 }
13436
13437 /*
13438 * Since we are applying the beacon hint to a wiphy we know its
13439 * wiphy_idx is valid
13440 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013441 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13442 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013443
13444 /* Before */
13445 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13446 if (!nl_freq)
13447 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013448 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013449 goto nla_put_failure;
13450 nla_nest_end(msg, nl_freq);
13451
13452 /* After */
13453 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13454 if (!nl_freq)
13455 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013456 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013457 goto nla_put_failure;
13458 nla_nest_end(msg, nl_freq);
13459
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013460 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013461
Johannes Berg463d0182009-07-14 00:33:35 +020013462 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013463 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013464 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013465 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013466
13467 return;
13468
13469nla_put_failure:
13470 genlmsg_cancel(msg, hdr);
13471 nlmsg_free(msg);
13472}
13473
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013474static void nl80211_send_remain_on_chan_event(
13475 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013476 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013477 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013478 unsigned int duration, gfp_t gfp)
13479{
13480 struct sk_buff *msg;
13481 void *hdr;
13482
13483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13484 if (!msg)
13485 return;
13486
13487 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13488 if (!hdr) {
13489 nlmsg_free(msg);
13490 return;
13491 }
13492
David S. Miller9360ffd2012-03-29 04:41:26 -040013493 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013494 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13495 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013496 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13497 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013498 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013499 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13500 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013501 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13502 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013503 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013504
David S. Miller9360ffd2012-03-29 04:41:26 -040013505 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13506 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13507 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013508
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013509 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013510
Johannes Berg68eb5502013-11-19 15:19:38 +010013511 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013512 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013513 return;
13514
13515 nla_put_failure:
13516 genlmsg_cancel(msg, hdr);
13517 nlmsg_free(msg);
13518}
13519
Johannes Berg947add32013-02-22 22:05:20 +010013520void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13521 struct ieee80211_channel *chan,
13522 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013523{
Johannes Berg947add32013-02-22 22:05:20 +010013524 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013525 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013526
13527 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013528 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013529 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013530 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013531}
Johannes Berg947add32013-02-22 22:05:20 +010013532EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013533
Johannes Berg947add32013-02-22 22:05:20 +010013534void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13535 struct ieee80211_channel *chan,
13536 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013537{
Johannes Berg947add32013-02-22 22:05:20 +010013538 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013540
13541 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013542 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013543 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013544}
Johannes Berg947add32013-02-22 22:05:20 +010013545EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013546
Johannes Berg947add32013-02-22 22:05:20 +010013547void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13548 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013549{
Johannes Berg947add32013-02-22 22:05:20 +010013550 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013551 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013552 struct sk_buff *msg;
13553
Johannes Berg947add32013-02-22 22:05:20 +010013554 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13555
Thomas Graf58050fc2012-06-28 03:57:45 +000013556 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013557 if (!msg)
13558 return;
13559
Johannes Bergcf5ead82014-11-14 17:14:00 +010013560 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013561 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013562 nlmsg_free(msg);
13563 return;
13564 }
13565
Johannes Berg68eb5502013-11-19 15:19:38 +010013566 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013567 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013568}
Johannes Berg947add32013-02-22 22:05:20 +010013569EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013570
Johannes Bergcf5ead82014-11-14 17:14:00 +010013571void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13572 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013573{
Johannes Berg947add32013-02-22 22:05:20 +010013574 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013575 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013576 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013577 struct station_info empty_sinfo = {};
13578
13579 if (!sinfo)
13580 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013581
Johannes Berg947add32013-02-22 22:05:20 +010013582 trace_cfg80211_del_sta(dev, mac_addr);
13583
Thomas Graf58050fc2012-06-28 03:57:45 +000013584 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013585 if (!msg)
13586 return;
13587
Johannes Bergcf5ead82014-11-14 17:14:00 +010013588 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013589 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013590 nlmsg_free(msg);
13591 return;
13592 }
13593
Johannes Berg68eb5502013-11-19 15:19:38 +010013594 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013595 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013596}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013597EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013598
Johannes Berg947add32013-02-22 22:05:20 +010013599void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13600 enum nl80211_connect_failed_reason reason,
13601 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013602{
Johannes Berg947add32013-02-22 22:05:20 +010013603 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013604 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013605 struct sk_buff *msg;
13606 void *hdr;
13607
13608 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13609 if (!msg)
13610 return;
13611
13612 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13613 if (!hdr) {
13614 nlmsg_free(msg);
13615 return;
13616 }
13617
13618 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13619 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13620 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13621 goto nla_put_failure;
13622
13623 genlmsg_end(msg, hdr);
13624
Johannes Berg68eb5502013-11-19 15:19:38 +010013625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013626 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013627 return;
13628
13629 nla_put_failure:
13630 genlmsg_cancel(msg, hdr);
13631 nlmsg_free(msg);
13632}
Johannes Berg947add32013-02-22 22:05:20 +010013633EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013634
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013635static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13636 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013637{
13638 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013639 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013640 struct sk_buff *msg;
13641 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013642 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013643
Eric W. Biederman15e47302012-09-07 20:12:54 +000013644 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013645 return false;
13646
13647 msg = nlmsg_new(100, gfp);
13648 if (!msg)
13649 return true;
13650
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013651 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013652 if (!hdr) {
13653 nlmsg_free(msg);
13654 return true;
13655 }
13656
David S. Miller9360ffd2012-03-29 04:41:26 -040013657 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13658 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13659 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13660 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013661
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013662 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013663 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013664 return true;
13665
13666 nla_put_failure:
13667 genlmsg_cancel(msg, hdr);
13668 nlmsg_free(msg);
13669 return true;
13670}
13671
Johannes Berg947add32013-02-22 22:05:20 +010013672bool cfg80211_rx_spurious_frame(struct net_device *dev,
13673 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013674{
Johannes Berg947add32013-02-22 22:05:20 +010013675 struct wireless_dev *wdev = dev->ieee80211_ptr;
13676 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013677
Johannes Berg947add32013-02-22 22:05:20 +010013678 trace_cfg80211_rx_spurious_frame(dev, addr);
13679
13680 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13681 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13682 trace_cfg80211_return_bool(false);
13683 return false;
13684 }
13685 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13686 addr, gfp);
13687 trace_cfg80211_return_bool(ret);
13688 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013689}
Johannes Berg947add32013-02-22 22:05:20 +010013690EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13691
13692bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13693 const u8 *addr, gfp_t gfp)
13694{
13695 struct wireless_dev *wdev = dev->ieee80211_ptr;
13696 bool ret;
13697
13698 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13699
13700 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13701 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13702 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13703 trace_cfg80211_return_bool(false);
13704 return false;
13705 }
13706 ret = __nl80211_unexpected_frame(dev,
13707 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13708 addr, gfp);
13709 trace_cfg80211_return_bool(ret);
13710 return ret;
13711}
13712EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013713
Johannes Berg2e161f72010-08-12 15:38:38 +020013714int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013715 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013716 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013717 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013718{
Johannes Berg71bbc992012-06-15 15:30:18 +020013719 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013720 struct sk_buff *msg;
13721 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020013722
13723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13724 if (!msg)
13725 return -ENOMEM;
13726
Johannes Berg2e161f72010-08-12 15:38:38 +020013727 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020013728 if (!hdr) {
13729 nlmsg_free(msg);
13730 return -ENOMEM;
13731 }
13732
David S. Miller9360ffd2012-03-29 04:41:26 -040013733 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013734 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13735 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013736 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13737 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013738 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
13739 (sig_dbm &&
13740 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013741 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
13742 (flags &&
13743 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013744 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013745
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013746 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013747
Eric W. Biederman15e47302012-09-07 20:12:54 +000013748 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020013749
13750 nla_put_failure:
13751 genlmsg_cancel(msg, hdr);
13752 nlmsg_free(msg);
13753 return -ENOBUFS;
13754}
13755
Johannes Berg947add32013-02-22 22:05:20 +010013756void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
13757 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013758{
Johannes Berg947add32013-02-22 22:05:20 +010013759 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013760 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020013761 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013762 struct sk_buff *msg;
13763 void *hdr;
13764
Johannes Berg947add32013-02-22 22:05:20 +010013765 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
13766
Jouni Malinen026331c2010-02-15 12:53:10 +020013767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13768 if (!msg)
13769 return;
13770
Johannes Berg2e161f72010-08-12 15:38:38 +020013771 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020013772 if (!hdr) {
13773 nlmsg_free(msg);
13774 return;
13775 }
13776
David S. Miller9360ffd2012-03-29 04:41:26 -040013777 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013778 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13779 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013780 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13781 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013782 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013783 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13784 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013785 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
13786 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013787
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013788 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013789
Johannes Berg68eb5502013-11-19 15:19:38 +010013790 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013791 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013792 return;
13793
13794 nla_put_failure:
13795 genlmsg_cancel(msg, hdr);
13796 nlmsg_free(msg);
13797}
Johannes Berg947add32013-02-22 22:05:20 +010013798EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020013799
Johannes Berg5b97f492014-11-26 12:37:43 +010013800static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
13801 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013802{
Johannes Berg947add32013-02-22 22:05:20 +010013803 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010013804 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13805 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13806 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013807
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013808 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010013809 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013810
Johannes Berg5b97f492014-11-26 12:37:43 +010013811 cb = (void **)msg->cb;
13812
13813 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
13814 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013815 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010013816 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013817 }
13818
David S. Miller9360ffd2012-03-29 04:41:26 -040013819 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013820 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040013821 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013822
Johannes Berg5b97f492014-11-26 12:37:43 +010013823 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013824 goto nla_put_failure;
13825
Johannes Berg5b97f492014-11-26 12:37:43 +010013826 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
13827 if (!cb[1])
13828 goto nla_put_failure;
13829
13830 cb[2] = rdev;
13831
13832 return msg;
13833 nla_put_failure:
13834 nlmsg_free(msg);
13835 return NULL;
13836}
13837
13838static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
13839{
13840 void **cb = (void **)msg->cb;
13841 struct cfg80211_registered_device *rdev = cb[2];
13842
13843 nla_nest_end(msg, cb[1]);
13844 genlmsg_end(msg, cb[0]);
13845
13846 memset(msg->cb, 0, sizeof(msg->cb));
13847
13848 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13849 NL80211_MCGRP_MLME, gfp);
13850}
13851
13852void cfg80211_cqm_rssi_notify(struct net_device *dev,
13853 enum nl80211_cqm_rssi_threshold_event rssi_event,
13854 gfp_t gfp)
13855{
13856 struct sk_buff *msg;
13857
13858 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
13859
Johannes Berg98f03342014-11-26 12:42:02 +010013860 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13861 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13862 return;
13863
Johannes Berg5b97f492014-11-26 12:37:43 +010013864 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13865 if (!msg)
13866 return;
13867
David S. Miller9360ffd2012-03-29 04:41:26 -040013868 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13869 rssi_event))
13870 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013871
Johannes Berg5b97f492014-11-26 12:37:43 +010013872 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013873
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013874 return;
13875
13876 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013877 nlmsg_free(msg);
13878}
Johannes Berg947add32013-02-22 22:05:20 +010013879EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013880
Johannes Berg5b97f492014-11-26 12:37:43 +010013881void cfg80211_cqm_txe_notify(struct net_device *dev,
13882 const u8 *peer, u32 num_packets,
13883 u32 rate, u32 intvl, gfp_t gfp)
13884{
13885 struct sk_buff *msg;
13886
13887 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13888 if (!msg)
13889 return;
13890
13891 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13892 goto nla_put_failure;
13893
13894 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13895 goto nla_put_failure;
13896
13897 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13898 goto nla_put_failure;
13899
13900 cfg80211_send_cqm(msg, gfp);
13901 return;
13902
13903 nla_put_failure:
13904 nlmsg_free(msg);
13905}
13906EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13907
13908void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13909 const u8 *peer, u32 num_packets, gfp_t gfp)
13910{
13911 struct sk_buff *msg;
13912
13913 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13914
13915 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13916 if (!msg)
13917 return;
13918
13919 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13920 goto nla_put_failure;
13921
13922 cfg80211_send_cqm(msg, gfp);
13923 return;
13924
13925 nla_put_failure:
13926 nlmsg_free(msg);
13927}
13928EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13929
Johannes Berg98f03342014-11-26 12:42:02 +010013930void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13931{
13932 struct sk_buff *msg;
13933
13934 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13935 if (!msg)
13936 return;
13937
13938 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13939 goto nla_put_failure;
13940
13941 cfg80211_send_cqm(msg, gfp);
13942 return;
13943
13944 nla_put_failure:
13945 nlmsg_free(msg);
13946}
13947EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13948
Johannes Berg947add32013-02-22 22:05:20 +010013949static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13950 struct net_device *netdev, const u8 *bssid,
13951 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013952{
13953 struct sk_buff *msg;
13954 struct nlattr *rekey_attr;
13955 void *hdr;
13956
Thomas Graf58050fc2012-06-28 03:57:45 +000013957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013958 if (!msg)
13959 return;
13960
13961 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13962 if (!hdr) {
13963 nlmsg_free(msg);
13964 return;
13965 }
13966
David S. Miller9360ffd2012-03-29 04:41:26 -040013967 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13968 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13969 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13970 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013971
13972 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13973 if (!rekey_attr)
13974 goto nla_put_failure;
13975
David S. Miller9360ffd2012-03-29 04:41:26 -040013976 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13977 NL80211_REPLAY_CTR_LEN, replay_ctr))
13978 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013979
13980 nla_nest_end(msg, rekey_attr);
13981
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013982 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013983
Johannes Berg68eb5502013-11-19 15:19:38 +010013984 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013985 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013986 return;
13987
13988 nla_put_failure:
13989 genlmsg_cancel(msg, hdr);
13990 nlmsg_free(msg);
13991}
13992
Johannes Berg947add32013-02-22 22:05:20 +010013993void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13994 const u8 *replay_ctr, gfp_t gfp)
13995{
13996 struct wireless_dev *wdev = dev->ieee80211_ptr;
13997 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013998 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013999
14000 trace_cfg80211_gtk_rekey_notify(dev, bssid);
14001 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
14002}
14003EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
14004
14005static void
14006nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
14007 struct net_device *netdev, int index,
14008 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014009{
14010 struct sk_buff *msg;
14011 struct nlattr *attr;
14012 void *hdr;
14013
Thomas Graf58050fc2012-06-28 03:57:45 +000014014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014015 if (!msg)
14016 return;
14017
14018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
14019 if (!hdr) {
14020 nlmsg_free(msg);
14021 return;
14022 }
14023
David S. Miller9360ffd2012-03-29 04:41:26 -040014024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14025 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14026 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014027
14028 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
14029 if (!attr)
14030 goto nla_put_failure;
14031
David S. Miller9360ffd2012-03-29 04:41:26 -040014032 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
14033 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
14034 (preauth &&
14035 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
14036 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014037
14038 nla_nest_end(msg, attr);
14039
Johannes Berg3b7b72e2011-10-22 19:05:51 +020014040 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014041
Johannes Berg68eb5502013-11-19 15:19:38 +010014042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014043 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030014044 return;
14045
14046 nla_put_failure:
14047 genlmsg_cancel(msg, hdr);
14048 nlmsg_free(msg);
14049}
14050
Johannes Berg947add32013-02-22 22:05:20 +010014051void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
14052 const u8 *bssid, bool preauth, gfp_t gfp)
14053{
14054 struct wireless_dev *wdev = dev->ieee80211_ptr;
14055 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014056 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014057
14058 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
14059 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
14060}
14061EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
14062
14063static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
14064 struct net_device *netdev,
14065 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020014066 gfp_t gfp,
14067 enum nl80211_commands notif,
14068 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070014069{
14070 struct sk_buff *msg;
14071 void *hdr;
14072
Thomas Graf58050fc2012-06-28 03:57:45 +000014073 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014074 if (!msg)
14075 return;
14076
Luciano Coelhof8d75522014-11-07 14:31:35 +020014077 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070014078 if (!hdr) {
14079 nlmsg_free(msg);
14080 return;
14081 }
14082
Johannes Berg683b6d32012-11-08 21:25:48 +010014083 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
14084 goto nla_put_failure;
14085
14086 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040014087 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070014088
Luciano Coelhof8d75522014-11-07 14:31:35 +020014089 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
14090 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
14091 goto nla_put_failure;
14092
Thomas Pedersen53145262012-04-06 13:35:47 -070014093 genlmsg_end(msg, hdr);
14094
Johannes Berg68eb5502013-11-19 15:19:38 +010014095 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014096 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070014097 return;
14098
14099 nla_put_failure:
14100 genlmsg_cancel(msg, hdr);
14101 nlmsg_free(msg);
14102}
14103
Johannes Berg947add32013-02-22 22:05:20 +010014104void cfg80211_ch_switch_notify(struct net_device *dev,
14105 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014106{
Johannes Berg947add32013-02-22 22:05:20 +010014107 struct wireless_dev *wdev = dev->ieee80211_ptr;
14108 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014109 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014110
Simon Wunderliche487eae2013-11-21 18:19:51 +010014111 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014112
Simon Wunderliche487eae2013-11-21 18:19:51 +010014113 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014114
Michal Kazior9e0e2962014-01-29 14:22:27 +010014115 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014116 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014117 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14118 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014119}
14120EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14121
Luciano Coelhof8d75522014-11-07 14:31:35 +020014122void cfg80211_ch_switch_started_notify(struct net_device *dev,
14123 struct cfg80211_chan_def *chandef,
14124 u8 count)
14125{
14126 struct wireless_dev *wdev = dev->ieee80211_ptr;
14127 struct wiphy *wiphy = wdev->wiphy;
14128 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14129
14130 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14131
14132 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14133 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14134}
14135EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14136
Thomas Pedersen84f10702012-07-12 16:17:33 -070014137void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014138nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014139 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014140 enum nl80211_radar_event event,
14141 struct net_device *netdev, gfp_t gfp)
14142{
14143 struct sk_buff *msg;
14144 void *hdr;
14145
14146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14147 if (!msg)
14148 return;
14149
14150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14151 if (!hdr) {
14152 nlmsg_free(msg);
14153 return;
14154 }
14155
14156 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14157 goto nla_put_failure;
14158
14159 /* NOP and radar events don't need a netdev parameter */
14160 if (netdev) {
14161 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14162
14163 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014164 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14165 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014166 goto nla_put_failure;
14167 }
14168
14169 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14170 goto nla_put_failure;
14171
14172 if (nl80211_send_chandef(msg, chandef))
14173 goto nla_put_failure;
14174
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014175 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014176
Johannes Berg68eb5502013-11-19 15:19:38 +010014177 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014178 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014179 return;
14180
14181 nla_put_failure:
14182 genlmsg_cancel(msg, hdr);
14183 nlmsg_free(msg);
14184}
14185
Johannes Berg7f6cf312011-11-04 11:18:15 +010014186void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14187 u64 cookie, bool acked, gfp_t gfp)
14188{
14189 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014190 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014191 struct sk_buff *msg;
14192 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014193
Beni Lev4ee3e062012-08-27 12:49:39 +030014194 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14195
Thomas Graf58050fc2012-06-28 03:57:45 +000014196 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014197
Johannes Berg7f6cf312011-11-04 11:18:15 +010014198 if (!msg)
14199 return;
14200
14201 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14202 if (!hdr) {
14203 nlmsg_free(msg);
14204 return;
14205 }
14206
David S. Miller9360ffd2012-03-29 04:41:26 -040014207 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14209 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014210 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14211 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014212 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14213 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014214
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014215 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014216
Johannes Berg68eb5502013-11-19 15:19:38 +010014217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014218 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014219 return;
14220
14221 nla_put_failure:
14222 genlmsg_cancel(msg, hdr);
14223 nlmsg_free(msg);
14224}
14225EXPORT_SYMBOL(cfg80211_probe_status);
14226
Johannes Berg5e760232011-11-04 11:18:17 +010014227void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14228 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014229 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014230{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014232 struct sk_buff *msg;
14233 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014234 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014235
Beni Lev4ee3e062012-08-27 12:49:39 +030014236 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14237
Ben Greear37c73b52012-10-26 14:49:25 -070014238 spin_lock_bh(&rdev->beacon_registrations_lock);
14239 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14240 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14241 if (!msg) {
14242 spin_unlock_bh(&rdev->beacon_registrations_lock);
14243 return;
14244 }
Johannes Berg5e760232011-11-04 11:18:17 +010014245
Ben Greear37c73b52012-10-26 14:49:25 -070014246 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14247 if (!hdr)
14248 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014249
Ben Greear37c73b52012-10-26 14:49:25 -070014250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14251 (freq &&
14252 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14253 (sig_dbm &&
14254 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14255 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14256 goto nla_put_failure;
14257
14258 genlmsg_end(msg, hdr);
14259
14260 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014261 }
Ben Greear37c73b52012-10-26 14:49:25 -070014262 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014263 return;
14264
14265 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014266 spin_unlock_bh(&rdev->beacon_registrations_lock);
14267 if (hdr)
14268 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014269 nlmsg_free(msg);
14270}
14271EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14272
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014273#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014274static int cfg80211_net_detect_results(struct sk_buff *msg,
14275 struct cfg80211_wowlan_wakeup *wakeup)
14276{
14277 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14278 struct nlattr *nl_results, *nl_match, *nl_freqs;
14279 int i, j;
14280
14281 nl_results = nla_nest_start(
14282 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14283 if (!nl_results)
14284 return -EMSGSIZE;
14285
14286 for (i = 0; i < nd->n_matches; i++) {
14287 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14288
14289 nl_match = nla_nest_start(msg, i);
14290 if (!nl_match)
14291 break;
14292
14293 /* The SSID attribute is optional in nl80211, but for
14294 * simplicity reasons it's always present in the
14295 * cfg80211 structure. If a driver can't pass the
14296 * SSID, that needs to be changed. A zero length SSID
14297 * is still a valid SSID (wildcard), so it cannot be
14298 * used for this purpose.
14299 */
14300 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14301 match->ssid.ssid)) {
14302 nla_nest_cancel(msg, nl_match);
14303 goto out;
14304 }
14305
14306 if (match->n_channels) {
14307 nl_freqs = nla_nest_start(
14308 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14309 if (!nl_freqs) {
14310 nla_nest_cancel(msg, nl_match);
14311 goto out;
14312 }
14313
14314 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014315 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014316 nla_nest_cancel(msg, nl_freqs);
14317 nla_nest_cancel(msg, nl_match);
14318 goto out;
14319 }
14320 }
14321
14322 nla_nest_end(msg, nl_freqs);
14323 }
14324
14325 nla_nest_end(msg, nl_match);
14326 }
14327
14328out:
14329 nla_nest_end(msg, nl_results);
14330 return 0;
14331}
14332
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014333void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14334 struct cfg80211_wowlan_wakeup *wakeup,
14335 gfp_t gfp)
14336{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014337 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014338 struct sk_buff *msg;
14339 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014340 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014341
14342 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14343
14344 if (wakeup)
14345 size += wakeup->packet_present_len;
14346
14347 msg = nlmsg_new(size, gfp);
14348 if (!msg)
14349 return;
14350
14351 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14352 if (!hdr)
14353 goto free_msg;
14354
14355 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014356 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14357 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014358 goto free_msg;
14359
14360 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14361 wdev->netdev->ifindex))
14362 goto free_msg;
14363
14364 if (wakeup) {
14365 struct nlattr *reasons;
14366
14367 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014368 if (!reasons)
14369 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014370
14371 if (wakeup->disconnect &&
14372 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14373 goto free_msg;
14374 if (wakeup->magic_pkt &&
14375 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14376 goto free_msg;
14377 if (wakeup->gtk_rekey_failure &&
14378 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14379 goto free_msg;
14380 if (wakeup->eap_identity_req &&
14381 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14382 goto free_msg;
14383 if (wakeup->four_way_handshake &&
14384 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14385 goto free_msg;
14386 if (wakeup->rfkill_release &&
14387 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14388 goto free_msg;
14389
14390 if (wakeup->pattern_idx >= 0 &&
14391 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14392 wakeup->pattern_idx))
14393 goto free_msg;
14394
Johannes Bergae917c92013-10-25 11:05:22 +020014395 if (wakeup->tcp_match &&
14396 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14397 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014398
Johannes Bergae917c92013-10-25 11:05:22 +020014399 if (wakeup->tcp_connlost &&
14400 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14401 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014402
Johannes Bergae917c92013-10-25 11:05:22 +020014403 if (wakeup->tcp_nomoretokens &&
14404 nla_put_flag(msg,
14405 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14406 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014407
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014408 if (wakeup->packet) {
14409 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14410 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14411
14412 if (!wakeup->packet_80211) {
14413 pkt_attr =
14414 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14415 len_attr =
14416 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14417 }
14418
14419 if (wakeup->packet_len &&
14420 nla_put_u32(msg, len_attr, wakeup->packet_len))
14421 goto free_msg;
14422
14423 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14424 wakeup->packet))
14425 goto free_msg;
14426 }
14427
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014428 if (wakeup->net_detect &&
14429 cfg80211_net_detect_results(msg, wakeup))
14430 goto free_msg;
14431
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014432 nla_nest_end(msg, reasons);
14433 }
14434
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014435 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014436
Johannes Berg68eb5502013-11-19 15:19:38 +010014437 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014438 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014439 return;
14440
14441 free_msg:
14442 nlmsg_free(msg);
14443}
14444EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14445#endif
14446
Jouni Malinen3475b092012-11-16 22:49:57 +020014447void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14448 enum nl80211_tdls_operation oper,
14449 u16 reason_code, gfp_t gfp)
14450{
14451 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014452 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014453 struct sk_buff *msg;
14454 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014455
14456 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14457 reason_code);
14458
14459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14460 if (!msg)
14461 return;
14462
14463 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14464 if (!hdr) {
14465 nlmsg_free(msg);
14466 return;
14467 }
14468
14469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14470 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14471 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14472 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14473 (reason_code > 0 &&
14474 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14475 goto nla_put_failure;
14476
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014477 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014478
Johannes Berg68eb5502013-11-19 15:19:38 +010014479 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014480 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014481 return;
14482
14483 nla_put_failure:
14484 genlmsg_cancel(msg, hdr);
14485 nlmsg_free(msg);
14486}
14487EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14488
Jouni Malinen026331c2010-02-15 12:53:10 +020014489static int nl80211_netlink_notify(struct notifier_block * nb,
14490 unsigned long state,
14491 void *_notify)
14492{
14493 struct netlink_notify *notify = _notify;
14494 struct cfg80211_registered_device *rdev;
14495 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014496 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014497
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014498 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014499 return NOTIFY_DONE;
14500
14501 rcu_read_lock();
14502
Johannes Berg5e760232011-11-04 11:18:17 +010014503 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014504 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014505 bool schedule_scan_stop = false;
14506 struct cfg80211_sched_scan_request *sched_scan_req =
14507 rcu_dereference(rdev->sched_scan_req);
14508
14509 if (sched_scan_req && notify->portid &&
14510 sched_scan_req->owner_nlportid == notify->portid)
14511 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010014512
Johannes Berg53873f12016-05-03 16:52:04 +030014513 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014514 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014515
Johannes Berg78f22b62014-03-24 17:57:27 +010014516 if (wdev->owner_nlportid == notify->portid)
14517 schedule_destroy_work = true;
14518 }
14519
Ben Greear37c73b52012-10-26 14:49:25 -070014520 spin_lock_bh(&rdev->beacon_registrations_lock);
14521 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14522 list) {
14523 if (reg->nlportid == notify->portid) {
14524 list_del(&reg->list);
14525 kfree(reg);
14526 break;
14527 }
14528 }
14529 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014530
14531 if (schedule_destroy_work) {
14532 struct cfg80211_iface_destroy *destroy;
14533
14534 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14535 if (destroy) {
14536 destroy->nlportid = notify->portid;
14537 spin_lock(&rdev->destroy_list_lock);
14538 list_add(&destroy->list, &rdev->destroy_list);
14539 spin_unlock(&rdev->destroy_list_lock);
14540 schedule_work(&rdev->destroy_work);
14541 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014542 } else if (schedule_scan_stop) {
14543 sched_scan_req->owner_nlportid = 0;
14544
14545 if (rdev->ops->sched_scan_stop &&
14546 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14547 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014548 }
Johannes Berg5e760232011-11-04 11:18:17 +010014549 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014550
14551 rcu_read_unlock();
14552
Ilan peer05050752015-03-04 00:32:06 -050014553 /*
14554 * It is possible that the user space process that is controlling the
14555 * indoor setting disappeared, so notify the regulatory core.
14556 */
14557 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014558 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014559}
14560
14561static struct notifier_block nl80211_netlink_notifier = {
14562 .notifier_call = nl80211_netlink_notify,
14563};
14564
Jouni Malinen355199e2013-02-27 17:14:27 +020014565void cfg80211_ft_event(struct net_device *netdev,
14566 struct cfg80211_ft_event_params *ft_event)
14567{
14568 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014569 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014570 struct sk_buff *msg;
14571 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014572
14573 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14574
14575 if (!ft_event->target_ap)
14576 return;
14577
14578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14579 if (!msg)
14580 return;
14581
14582 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014583 if (!hdr)
14584 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014585
Johannes Bergae917c92013-10-25 11:05:22 +020014586 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14587 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14588 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14589 goto out;
14590
14591 if (ft_event->ies &&
14592 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14593 goto out;
14594 if (ft_event->ric_ies &&
14595 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14596 ft_event->ric_ies))
14597 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014598
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014599 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014600
Johannes Berg68eb5502013-11-19 15:19:38 +010014601 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014602 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014603 return;
14604 out:
14605 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014606}
14607EXPORT_SYMBOL(cfg80211_ft_event);
14608
Arend van Spriel5de17982013-04-18 15:49:00 +020014609void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14610{
14611 struct cfg80211_registered_device *rdev;
14612 struct sk_buff *msg;
14613 void *hdr;
14614 u32 nlportid;
14615
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014616 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014617 if (!rdev->crit_proto_nlportid)
14618 return;
14619
14620 nlportid = rdev->crit_proto_nlportid;
14621 rdev->crit_proto_nlportid = 0;
14622
14623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14624 if (!msg)
14625 return;
14626
14627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14628 if (!hdr)
14629 goto nla_put_failure;
14630
14631 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014632 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14633 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014634 goto nla_put_failure;
14635
14636 genlmsg_end(msg, hdr);
14637
14638 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14639 return;
14640
14641 nla_put_failure:
14642 if (hdr)
14643 genlmsg_cancel(msg, hdr);
14644 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014645}
14646EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14647
Johannes Berg348baf02014-01-24 14:06:29 +010014648void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14649{
14650 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014651 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014652 struct sk_buff *msg;
14653 void *hdr;
14654
14655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14656 if (!msg)
14657 return;
14658
14659 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14660 if (!hdr)
14661 goto out;
14662
14663 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14664 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014665 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14666 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014667 goto out;
14668
14669 genlmsg_end(msg, hdr);
14670
14671 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14672 NL80211_MCGRP_MLME, GFP_KERNEL);
14673 return;
14674 out:
14675 nlmsg_free(msg);
14676}
14677
Johannes Berg55682962007-09-20 13:09:35 -040014678/* initialisation/exit functions */
14679
Johannes Berg56989f62016-10-24 14:40:05 +020014680int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040014681{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014682 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014683
Johannes Berg489111e2016-10-24 14:40:03 +020014684 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040014685 if (err)
14686 return err;
14687
Jouni Malinen026331c2010-02-15 12:53:10 +020014688 err = netlink_register_notifier(&nl80211_netlink_notifier);
14689 if (err)
14690 goto err_out;
14691
Johannes Berg55682962007-09-20 13:09:35 -040014692 return 0;
14693 err_out:
14694 genl_unregister_family(&nl80211_fam);
14695 return err;
14696}
14697
14698void nl80211_exit(void)
14699{
Jouni Malinen026331c2010-02-15 12:53:10 +020014700 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014701 genl_unregister_family(&nl80211_fam);
14702}