blob: 4ba0d5902082babde9f4bdfc1932dba1057c72cf [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030059 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010060 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
61};
62
63static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010064 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
65 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
66 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
67 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
68 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030069 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010071 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010072#endif
73};
74
Johannes Berg89a54e42012-06-15 14:33:17 +020075/* returns ERR_PTR values */
76static struct wireless_dev *
77__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040078{
Johannes Berg89a54e42012-06-15 14:33:17 +020079 struct cfg80211_registered_device *rdev;
80 struct wireless_dev *result = NULL;
81 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
82 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
83 u64 wdev_id;
84 int wiphy_idx = -1;
85 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg5fe231e2013-05-08 21:45:15 +020087 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (!have_ifidx && !have_wdev_id)
90 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040091
Johannes Berg89a54e42012-06-15 14:33:17 +020092 if (have_ifidx)
93 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
94 if (have_wdev_id) {
95 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
96 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040097 }
98
Johannes Berg89a54e42012-06-15 14:33:17 +020099 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
100 struct wireless_dev *wdev;
101
102 if (wiphy_net(&rdev->wiphy) != netns)
103 continue;
104
105 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
106 continue;
107
Johannes Berg53873f12016-05-03 16:52:04 +0300108 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200109 if (have_ifidx && wdev->netdev &&
110 wdev->netdev->ifindex == ifidx) {
111 result = wdev;
112 break;
113 }
114 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
115 result = wdev;
116 break;
117 }
118 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200119
120 if (result)
121 break;
122 }
123
124 if (result)
125 return result;
126 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400127}
128
Johannes Berga9455402012-06-15 13:32:49 +0200129static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200130__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200131{
Johannes Berg7fee4772012-06-15 14:09:58 +0200132 struct cfg80211_registered_device *rdev = NULL, *tmp;
133 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg5fe231e2013-05-08 21:45:15 +0200135 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200136
Johannes Berg878d9ec2012-06-15 14:18:32 +0200137 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200138 !attrs[NL80211_ATTR_IFINDEX] &&
139 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 return ERR_PTR(-EINVAL);
141
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200143 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200144 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200145
Johannes Berg89a54e42012-06-15 14:33:17 +0200146 if (attrs[NL80211_ATTR_WDEV]) {
147 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
148 struct wireless_dev *wdev;
149 bool found = false;
150
151 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
152 if (tmp) {
153 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300154 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200155 if (wdev->identifier != (u32)wdev_id)
156 continue;
157 found = true;
158 break;
159 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200160
161 if (!found)
162 tmp = NULL;
163
164 if (rdev && tmp != rdev)
165 return ERR_PTR(-EINVAL);
166 rdev = tmp;
167 }
168 }
169
Johannes Berg878d9ec2012-06-15 14:18:32 +0200170 if (attrs[NL80211_ATTR_IFINDEX]) {
171 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700172
Ying Xue7f2b8562014-01-15 10:23:45 +0800173 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 if (netdev) {
175 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800176 tmp = wiphy_to_rdev(
177 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 else
179 tmp = NULL;
180
Johannes Berg7fee4772012-06-15 14:09:58 +0200181 /* not wireless device -- return error */
182 if (!tmp)
183 return ERR_PTR(-EINVAL);
184
185 /* mismatch -- return error */
186 if (rdev && tmp != rdev)
187 return ERR_PTR(-EINVAL);
188
189 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200190 }
Johannes Berga9455402012-06-15 13:32:49 +0200191 }
192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (!rdev)
194 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200195
Johannes Berg4f7eff12012-06-15 14:14:22 +0200196 if (netns != wiphy_net(&rdev->wiphy))
197 return ERR_PTR(-ENODEV);
198
199 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200200}
201
202/*
203 * This function returns a pointer to the driver
204 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200205 *
206 * The result of this can be a PTR_ERR and hence must
207 * be checked with IS_ERR() for errors.
208 */
209static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200210cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200211{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200212 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200213}
214
Johannes Berg55682962007-09-20 13:09:35 -0400215/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300216static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400217 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
218 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700219 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200220 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200222 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530223 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100224 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
225 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
226 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
227
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200228 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
229 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200233 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400234
235 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
236 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
237 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Eliad Pellere007b852011-11-24 18:13:56 +0200239 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
240 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100241
Johannes Bergb9454e82009-07-08 13:29:08 +0200242 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100243 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
244 .len = WLAN_MAX_KEY_LEN },
245 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
246 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
247 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200248 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200249 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100250
251 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
252 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
253 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
254 .len = IEEE80211_MAX_DATA_LEN },
255 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
256 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
258 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
259 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
260 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
261 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100263 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200264 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100265 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800266 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100267 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700269 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
270 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
271
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300272 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
273 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
274 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200275 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
276 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100277 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300278
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800279 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700280 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700281
Johannes Berg6c739412011-11-03 09:27:01 +0100282 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200283
284 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
285 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
286 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100287 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
288 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200289
290 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
291 .len = IEEE80211_MAX_SSID_LEN },
292 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
293 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200294 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300295 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300296 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300297 [NL80211_ATTR_STA_FLAGS2] = {
298 .len = sizeof(struct nl80211_sta_flag_update),
299 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300300 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300301 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
302 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200303 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
304 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
305 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200306 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100307 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100308 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
309 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100310 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
311 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200312 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200313 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
314 .len = IEEE80211_MAX_DATA_LEN },
315 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200316 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200317 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300318 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200319 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300320 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200322 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900323 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
324 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100325 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100326 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100327 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200328 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700329 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300330 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200331 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200332 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300333 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300334 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
335 .len = IEEE80211_MAX_DATA_LEN },
336 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
337 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530338 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300339 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530340 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300341 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
342 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
343 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
344 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300346 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100347 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200348 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
349 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700350 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800351 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
352 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
353 .len = NL80211_HT_CAPABILITY_LEN
354 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100355 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530356 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530357 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200358 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700359 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300360 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000361 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700362 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100363 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
364 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530365 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
366 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200367 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
368 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100369 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100370 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
371 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
372 .len = NL80211_VHT_CAPABILITY_LEN,
373 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200374 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
375 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
376 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300377 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200378 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
379 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
380 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300381 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
382 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530383 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
384 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200385 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100386 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100387 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
388 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
389 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800390 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
391 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200392 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
393 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530394 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200395 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300396 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300397 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300398 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
399 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
400 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300401 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200402 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200403 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200404 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200405 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500406 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200407 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100408 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Ayala Beker17b94242016-03-17 15:41:38 +0200409 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300410 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
411 .len = VHT_MUMIMO_GROUPS_DATA_LEN
412 },
413 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300414 [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
415 [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
Ayala Bekera442b762016-09-20 17:31:15 +0300416 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Vamsi Krishna45816392016-12-02 23:59:08 +0200417 [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
Johannes Berg55682962007-09-20 13:09:35 -0400418};
419
Johannes Berge31b8212010-10-05 19:39:30 +0200420/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000421static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200422 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200423 [NL80211_KEY_IDX] = { .type = NLA_U8 },
424 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200425 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200426 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
427 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200428 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100429 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
430};
431
432/* policy for the key default flags */
433static const struct nla_policy
434nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
435 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
436 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200437};
438
Johannes Bergff1b6e62011-05-04 15:37:28 +0200439/* policy for WoWLAN attributes */
440static const struct nla_policy
441nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
442 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
443 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
444 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
445 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200446 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
447 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
448 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
449 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100450 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300451 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100452};
453
454static const struct nla_policy
455nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
456 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
457 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
458 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
459 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
460 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
461 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
462 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
463 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
464 },
465 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
466 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
467 },
468 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
469 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
470 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200471};
472
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700473/* policy for coalesce rule attributes */
474static const struct nla_policy
475nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
476 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
477 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
478 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
479};
480
Johannes Berge5497d72011-07-05 16:35:40 +0200481/* policy for GTK rekey offload attributes */
482static const struct nla_policy
483nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
484 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
485 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
486 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
487};
488
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300489static const struct nla_policy
490nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200491 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300492 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700493 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300494};
495
Avraham Stern3b06d272015-10-12 09:51:34 +0300496static const struct nla_policy
497nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
498 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
499 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
500};
501
Arend van Spriel38de03d2016-03-02 20:37:18 +0100502static const struct nla_policy
503nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
504 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
505 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
506 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
507 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
508 },
509};
510
Ayala Bekera442b762016-09-20 17:31:15 +0300511/* policy for NAN function attributes */
512static const struct nla_policy
513nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
514 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
515 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
516 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
517 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
518 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
519 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
520 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
521 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
522 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
523 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
524 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
525 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
526 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
527 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
528 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
529 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
530 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
531 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
532};
533
534/* policy for Service Response Filter attributes */
535static const struct nla_policy
536nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
537 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
538 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
539 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
540 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
541 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
542};
543
Johannes Berg97990a02013-04-19 01:02:55 +0200544static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
545 struct netlink_callback *cb,
546 struct cfg80211_registered_device **rdev,
547 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100548{
Johannes Berg67748892010-10-04 21:14:06 +0200549 int err;
550
Johannes Berg97990a02013-04-19 01:02:55 +0200551 if (!cb->args[0]) {
552 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
553 nl80211_fam.attrbuf, nl80211_fam.maxattr,
554 nl80211_policy);
555 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +0100556 return err;
Johannes Berg97990a02013-04-19 01:02:55 +0200557
558 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
559 nl80211_fam.attrbuf);
Johannes Berg56769e72017-03-15 14:26:04 +0100560 if (IS_ERR(*wdev))
561 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800562 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200563 /* 0 is the first index - add 1 to parse only once */
564 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200565 cb->args[1] = (*wdev)->identifier;
566 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200567 /* subtract the 1 again here */
568 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200569 struct wireless_dev *tmp;
570
Johannes Berg56769e72017-03-15 14:26:04 +0100571 if (!wiphy)
572 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800573 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200574 *wdev = NULL;
575
Johannes Berg53873f12016-05-03 16:52:04 +0300576 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200577 if (tmp->identifier == cb->args[1]) {
578 *wdev = tmp;
579 break;
580 }
581 }
Johannes Berg97990a02013-04-19 01:02:55 +0200582
Johannes Berg56769e72017-03-15 14:26:04 +0100583 if (!*wdev)
584 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200585 }
586
Johannes Berg67748892010-10-04 21:14:06 +0200587 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200588}
589
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100590/* IE validation */
591static bool is_valid_ie_attr(const struct nlattr *attr)
592{
593 const u8 *pos;
594 int len;
595
596 if (!attr)
597 return true;
598
599 pos = nla_data(attr);
600 len = nla_len(attr);
601
602 while (len) {
603 u8 elemlen;
604
605 if (len < 2)
606 return false;
607 len -= 2;
608
609 elemlen = pos[1];
610 if (elemlen > len)
611 return false;
612
613 len -= elemlen;
614 pos += 2 + elemlen;
615 }
616
617 return true;
618}
619
Johannes Berg55682962007-09-20 13:09:35 -0400620/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000621static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400622 int flags, u8 cmd)
623{
624 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000625 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400626}
627
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400628static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100629 struct ieee80211_channel *chan,
630 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400631{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200632 /* Some channels must be completely excluded from the
633 * list to protect old user-space tools from breaking
634 */
635 if (!large && chan->flags &
636 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
637 return 0;
638
David S. Miller9360ffd2012-03-29 04:41:26 -0400639 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
640 chan->center_freq))
641 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400642
David S. Miller9360ffd2012-03-29 04:41:26 -0400643 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
644 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
645 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200646 if (chan->flags & IEEE80211_CHAN_NO_IR) {
647 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
648 goto nla_put_failure;
649 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
650 goto nla_put_failure;
651 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100652 if (chan->flags & IEEE80211_CHAN_RADAR) {
653 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
654 goto nla_put_failure;
655 if (large) {
656 u32 time;
657
658 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
659
660 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
661 chan->dfs_state))
662 goto nla_put_failure;
663 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
664 time))
665 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100666 if (nla_put_u32(msg,
667 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
668 chan->dfs_cac_ms))
669 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100670 }
671 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400672
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100673 if (large) {
674 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
675 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
676 goto nla_put_failure;
677 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
678 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
679 goto nla_put_failure;
680 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
681 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
682 goto nla_put_failure;
683 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
684 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
685 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200686 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
687 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
688 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300689 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
690 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200691 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200692 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
693 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
694 goto nla_put_failure;
695 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
696 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
697 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100698 }
699
David S. Miller9360ffd2012-03-29 04:41:26 -0400700 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
701 DBM_TO_MBM(chan->max_power)))
702 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400703
704 return 0;
705
706 nla_put_failure:
707 return -ENOBUFS;
708}
709
Johannes Berg55682962007-09-20 13:09:35 -0400710/* netlink command implementations */
711
Johannes Bergb9454e82009-07-08 13:29:08 +0200712struct key_parse {
713 struct key_params p;
714 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200715 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200716 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100717 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200718};
719
720static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
721{
722 struct nlattr *tb[NL80211_KEY_MAX + 1];
723 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
724 nl80211_key_policy);
725 if (err)
726 return err;
727
728 k->def = !!tb[NL80211_KEY_DEFAULT];
729 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
730
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100731 if (k->def) {
732 k->def_uni = true;
733 k->def_multi = true;
734 }
735 if (k->defmgmt)
736 k->def_multi = true;
737
Johannes Bergb9454e82009-07-08 13:29:08 +0200738 if (tb[NL80211_KEY_IDX])
739 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
740
741 if (tb[NL80211_KEY_DATA]) {
742 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
743 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
744 }
745
746 if (tb[NL80211_KEY_SEQ]) {
747 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
748 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
749 }
750
751 if (tb[NL80211_KEY_CIPHER])
752 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
753
Johannes Berge31b8212010-10-05 19:39:30 +0200754 if (tb[NL80211_KEY_TYPE]) {
755 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
756 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
757 return -EINVAL;
758 }
759
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100760 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
761 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700762
Johannes Berg2da8f412012-01-20 13:52:37 +0100763 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
764 tb[NL80211_KEY_DEFAULT_TYPES],
765 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (err)
767 return err;
768
769 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
770 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
771 }
772
Johannes Bergb9454e82009-07-08 13:29:08 +0200773 return 0;
774}
775
776static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
777{
778 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
779 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
780 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
781 }
782
783 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
784 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
785 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
786 }
787
788 if (info->attrs[NL80211_ATTR_KEY_IDX])
789 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
790
791 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
792 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
793
794 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
795 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
796
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100797 if (k->def) {
798 k->def_uni = true;
799 k->def_multi = true;
800 }
801 if (k->defmgmt)
802 k->def_multi = true;
803
Johannes Berge31b8212010-10-05 19:39:30 +0200804 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
805 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
806 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
807 return -EINVAL;
808 }
809
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100810 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
811 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
812 int err = nla_parse_nested(
813 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
814 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
815 nl80211_key_default_policy);
816 if (err)
817 return err;
818
819 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
820 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
821 }
822
Johannes Bergb9454e82009-07-08 13:29:08 +0200823 return 0;
824}
825
826static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
827{
828 int err;
829
830 memset(k, 0, sizeof(*k));
831 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200832 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200833
834 if (info->attrs[NL80211_ATTR_KEY])
835 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
836 else
837 err = nl80211_parse_key_old(info, k);
838
839 if (err)
840 return err;
841
842 if (k->def && k->defmgmt)
843 return -EINVAL;
844
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100845 if (k->defmgmt) {
846 if (k->def_uni || !k->def_multi)
847 return -EINVAL;
848 }
849
Johannes Bergb9454e82009-07-08 13:29:08 +0200850 if (k->idx != -1) {
851 if (k->defmgmt) {
852 if (k->idx < 4 || k->idx > 5)
853 return -EINVAL;
854 } else if (k->def) {
855 if (k->idx < 0 || k->idx > 3)
856 return -EINVAL;
857 } else {
858 if (k->idx < 0 || k->idx > 5)
859 return -EINVAL;
860 }
861 }
862
863 return 0;
864}
865
Johannes Bergfffd0932009-07-08 14:22:54 +0200866static struct cfg80211_cached_keys *
867nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530868 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200869{
870 struct key_parse parse;
871 struct nlattr *key;
872 struct cfg80211_cached_keys *result;
873 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200874 bool have_key = false;
875
876 nla_for_each_nested(key, keys, rem) {
877 have_key = true;
878 break;
879 }
880
881 if (!have_key)
882 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200883
884 result = kzalloc(sizeof(*result), GFP_KERNEL);
885 if (!result)
886 return ERR_PTR(-ENOMEM);
887
888 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200889
890 nla_for_each_nested(key, keys, rem) {
891 memset(&parse, 0, sizeof(parse));
892 parse.idx = -1;
893
894 err = nl80211_parse_key_new(key, &parse);
895 if (err)
896 goto error;
897 err = -EINVAL;
898 if (!parse.p.key)
899 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200900 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200901 goto error;
902 if (parse.def) {
903 if (def)
904 goto error;
905 def = 1;
906 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100907 if (!parse.def_uni || !parse.def_multi)
908 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200909 } else if (parse.defmgmt)
910 goto error;
911 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200912 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200913 if (err)
914 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200915 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
916 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
917 err = -EINVAL;
918 goto error;
919 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200920 result->params[parse.idx].cipher = parse.p.cipher;
921 result->params[parse.idx].key_len = parse.p.key_len;
922 result->params[parse.idx].key = result->data[parse.idx];
923 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530924
Johannes Berg386b1f22016-09-13 16:10:02 +0200925 /* must be WEP key if we got here */
926 if (no_ht)
927 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200928 }
929
Johannes Bergf1c1f172016-09-13 17:08:23 +0200930 if (result->def < 0) {
931 err = -EINVAL;
932 goto error;
933 }
934
Johannes Bergfffd0932009-07-08 14:22:54 +0200935 return result;
936 error:
937 kfree(result);
938 return ERR_PTR(err);
939}
940
941static int nl80211_key_allowed(struct wireless_dev *wdev)
942{
943 ASSERT_WDEV_LOCK(wdev);
944
Johannes Bergfffd0932009-07-08 14:22:54 +0200945 switch (wdev->iftype) {
946 case NL80211_IFTYPE_AP:
947 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200948 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700949 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200950 break;
951 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200952 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200953 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200954 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200955 return -ENOLINK;
956 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100957 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100958 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100959 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300960 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100961 case NL80211_IFTYPE_P2P_DEVICE:
962 case NL80211_IFTYPE_WDS:
963 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200964 return -EINVAL;
965 }
966
967 return 0;
968}
969
Jouni Malinen664834d2014-01-15 00:01:44 +0200970static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
971 struct nlattr *tb)
972{
973 struct ieee80211_channel *chan;
974
975 if (tb == NULL)
976 return NULL;
977 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
978 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
979 return NULL;
980 return chan;
981}
982
Johannes Berg7527a782011-05-13 10:58:57 +0200983static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
984{
985 struct nlattr *nl_modes = nla_nest_start(msg, attr);
986 int i;
987
988 if (!nl_modes)
989 goto nla_put_failure;
990
991 i = 0;
992 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400993 if ((ifmodes & 1) && nla_put_flag(msg, i))
994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995 ifmodes >>= 1;
996 i++;
997 }
998
999 nla_nest_end(msg, nl_modes);
1000 return 0;
1001
1002nla_put_failure:
1003 return -ENOBUFS;
1004}
1005
1006static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001007 struct sk_buff *msg,
1008 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001009{
1010 struct nlattr *nl_combis;
1011 int i, j;
1012
1013 nl_combis = nla_nest_start(msg,
1014 NL80211_ATTR_INTERFACE_COMBINATIONS);
1015 if (!nl_combis)
1016 goto nla_put_failure;
1017
1018 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1019 const struct ieee80211_iface_combination *c;
1020 struct nlattr *nl_combi, *nl_limits;
1021
1022 c = &wiphy->iface_combinations[i];
1023
1024 nl_combi = nla_nest_start(msg, i + 1);
1025 if (!nl_combi)
1026 goto nla_put_failure;
1027
1028 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1029 if (!nl_limits)
1030 goto nla_put_failure;
1031
1032 for (j = 0; j < c->n_limits; j++) {
1033 struct nlattr *nl_limit;
1034
1035 nl_limit = nla_nest_start(msg, j + 1);
1036 if (!nl_limit)
1037 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001038 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1039 c->limits[j].max))
1040 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001041 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1042 c->limits[j].types))
1043 goto nla_put_failure;
1044 nla_nest_end(msg, nl_limit);
1045 }
1046
1047 nla_nest_end(msg, nl_limits);
1048
David S. Miller9360ffd2012-03-29 04:41:26 -04001049 if (c->beacon_int_infra_match &&
1050 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1051 goto nla_put_failure;
1052 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1053 c->num_different_channels) ||
1054 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1055 c->max_interfaces))
1056 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001057 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001058 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1059 c->radar_detect_widths) ||
1060 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1061 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001062 goto nla_put_failure;
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05301063 if (c->beacon_int_min_gcd &&
1064 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1065 c->beacon_int_min_gcd))
1066 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001067
1068 nla_nest_end(msg, nl_combi);
1069 }
1070
1071 nla_nest_end(msg, nl_combis);
1072
1073 return 0;
1074nla_put_failure:
1075 return -ENOBUFS;
1076}
1077
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001079static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1080 struct sk_buff *msg)
1081{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001082 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001083 struct nlattr *nl_tcp;
1084
1085 if (!tcp)
1086 return 0;
1087
1088 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1089 if (!nl_tcp)
1090 return -ENOBUFS;
1091
1092 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1093 tcp->data_payload_max))
1094 return -ENOBUFS;
1095
1096 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1097 tcp->data_payload_max))
1098 return -ENOBUFS;
1099
1100 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1101 return -ENOBUFS;
1102
1103 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1104 sizeof(*tcp->tok), tcp->tok))
1105 return -ENOBUFS;
1106
1107 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1108 tcp->data_interval_max))
1109 return -ENOBUFS;
1110
1111 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1112 tcp->wake_payload_max))
1113 return -ENOBUFS;
1114
1115 nla_nest_end(msg, nl_tcp);
1116 return 0;
1117}
1118
Johannes Berg3713b4e2013-02-14 16:19:38 +01001119static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001120 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001121 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001122{
1123 struct nlattr *nl_wowlan;
1124
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001125 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001126 return 0;
1127
1128 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1129 if (!nl_wowlan)
1130 return -ENOBUFS;
1131
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001132 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001134 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001135 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001136 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001137 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001138 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001139 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001140 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001141 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001142 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001144 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001146 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1148 return -ENOBUFS;
1149
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001150 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001151 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001152 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1153 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1154 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1155 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001156 };
1157
1158 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1159 sizeof(pat), &pat))
1160 return -ENOBUFS;
1161 }
1162
Luciano Coelho75453cc2015-01-09 14:06:37 +02001163 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1164 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1165 rdev->wiphy.wowlan->max_nd_match_sets))
1166 return -ENOBUFS;
1167
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001168 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001169 return -ENOBUFS;
1170
Johannes Berg3713b4e2013-02-14 16:19:38 +01001171 nla_nest_end(msg, nl_wowlan);
1172
1173 return 0;
1174}
1175#endif
1176
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001177static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001178 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001179{
1180 struct nl80211_coalesce_rule_support rule;
1181
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001182 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001183 return 0;
1184
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001185 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1186 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1187 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1188 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1189 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1190 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001191
1192 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1193 return -ENOBUFS;
1194
1195 return 0;
1196}
1197
Johannes Berg3713b4e2013-02-14 16:19:38 +01001198static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1199 struct ieee80211_supported_band *sband)
1200{
1201 struct nlattr *nl_rates, *nl_rate;
1202 struct ieee80211_rate *rate;
1203 int i;
1204
1205 /* add HT info */
1206 if (sband->ht_cap.ht_supported &&
1207 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1208 sizeof(sband->ht_cap.mcs),
1209 &sband->ht_cap.mcs) ||
1210 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1211 sband->ht_cap.cap) ||
1212 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1213 sband->ht_cap.ampdu_factor) ||
1214 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1215 sband->ht_cap.ampdu_density)))
1216 return -ENOBUFS;
1217
1218 /* add VHT info */
1219 if (sband->vht_cap.vht_supported &&
1220 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1221 sizeof(sband->vht_cap.vht_mcs),
1222 &sband->vht_cap.vht_mcs) ||
1223 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1224 sband->vht_cap.cap)))
1225 return -ENOBUFS;
1226
1227 /* add bitrates */
1228 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1229 if (!nl_rates)
1230 return -ENOBUFS;
1231
1232 for (i = 0; i < sband->n_bitrates; i++) {
1233 nl_rate = nla_nest_start(msg, i);
1234 if (!nl_rate)
1235 return -ENOBUFS;
1236
1237 rate = &sband->bitrates[i];
1238 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1239 rate->bitrate))
1240 return -ENOBUFS;
1241 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1242 nla_put_flag(msg,
1243 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1244 return -ENOBUFS;
1245
1246 nla_nest_end(msg, nl_rate);
1247 }
1248
1249 nla_nest_end(msg, nl_rates);
1250
1251 return 0;
1252}
1253
1254static int
1255nl80211_send_mgmt_stypes(struct sk_buff *msg,
1256 const struct ieee80211_txrx_stypes *mgmt_stypes)
1257{
1258 u16 stypes;
1259 struct nlattr *nl_ftypes, *nl_ifs;
1260 enum nl80211_iftype ift;
1261 int i;
1262
1263 if (!mgmt_stypes)
1264 return 0;
1265
1266 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1267 if (!nl_ifs)
1268 return -ENOBUFS;
1269
1270 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1271 nl_ftypes = nla_nest_start(msg, ift);
1272 if (!nl_ftypes)
1273 return -ENOBUFS;
1274 i = 0;
1275 stypes = mgmt_stypes[ift].tx;
1276 while (stypes) {
1277 if ((stypes & 1) &&
1278 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1279 (i << 4) | IEEE80211_FTYPE_MGMT))
1280 return -ENOBUFS;
1281 stypes >>= 1;
1282 i++;
1283 }
1284 nla_nest_end(msg, nl_ftypes);
1285 }
1286
1287 nla_nest_end(msg, nl_ifs);
1288
1289 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1290 if (!nl_ifs)
1291 return -ENOBUFS;
1292
1293 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1294 nl_ftypes = nla_nest_start(msg, ift);
1295 if (!nl_ftypes)
1296 return -ENOBUFS;
1297 i = 0;
1298 stypes = mgmt_stypes[ift].rx;
1299 while (stypes) {
1300 if ((stypes & 1) &&
1301 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1302 (i << 4) | IEEE80211_FTYPE_MGMT))
1303 return -ENOBUFS;
1304 stypes >>= 1;
1305 i++;
1306 }
1307 nla_nest_end(msg, nl_ftypes);
1308 }
1309 nla_nest_end(msg, nl_ifs);
1310
1311 return 0;
1312}
1313
Johannes Berg86e8cf92013-06-19 10:57:22 +02001314struct nl80211_dump_wiphy_state {
1315 s64 filter_wiphy;
1316 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301317 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001318 bool split;
1319};
1320
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001322 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001324 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001325{
1326 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001327 struct nlattr *nl_bands, *nl_band;
1328 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001329 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001330 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001331 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001332 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001333 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001335 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001336
Johannes Berg3bb20552014-05-26 13:52:25 +02001337 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001338 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 return -ENOBUFS;
1340
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 if (WARN_ON(!state))
1342 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001343
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001347 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001349 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001350
Johannes Berg3bb20552014-05-26 13:52:25 +02001351 if (cmd != NL80211_CMD_NEW_WIPHY)
1352 goto finish;
1353
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 case 0:
1356 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001359 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001367 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001369 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001373 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001375 rdev->wiphy.max_match_sets) ||
1376 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1377 rdev->wiphy.max_sched_scan_plans) ||
1378 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1379 rdev->wiphy.max_sched_scan_plan_interval) ||
1380 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1381 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001382 goto nla_put_failure;
1383
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001384 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1386 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001387 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1389 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001390 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1392 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001393 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1395 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001396 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001397 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1398 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001399 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001401 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001402 state->split_start++;
1403 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 break;
1405 case 1:
1406 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001407 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1408 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001409 goto nla_put_failure;
1410
Johannes Berg3713b4e2013-02-14 16:19:38 +01001411 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001412 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001413 goto nla_put_failure;
1414
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001415 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001416 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1417 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001418
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001420 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001422 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001424
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001425 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001427 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001429
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001430 if ((rdev->wiphy.available_antennas_tx ||
1431 rdev->wiphy.available_antennas_rx) &&
1432 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 u32 tx_ant = 0, rx_ant = 0;
1434 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001435
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001436 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 if (!res) {
1438 if (nla_put_u32(msg,
1439 NL80211_ATTR_WIPHY_ANTENNA_TX,
1440 tx_ant) ||
1441 nla_put_u32(msg,
1442 NL80211_ATTR_WIPHY_ANTENNA_RX,
1443 rx_ant))
1444 goto nla_put_failure;
1445 }
Johannes Bergee688b002008-01-24 19:38:39 +01001446 }
1447
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 state->split_start++;
1449 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 break;
1451 case 2:
1452 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001453 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 state->split_start++;
1456 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 break;
1458 case 3:
1459 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1460 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001461 goto nla_put_failure;
1462
Johannes Berg86e8cf92013-06-19 10:57:22 +02001463 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001464 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 struct ieee80211_supported_band *sband;
1466
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001467 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468
1469 if (!sband)
1470 continue;
1471
1472 nl_band = nla_nest_start(msg, band);
1473 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001474 goto nla_put_failure;
1475
Johannes Berg86e8cf92013-06-19 10:57:22 +02001476 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 case 0:
1478 if (nl80211_send_band_rateinfo(msg, sband))
1479 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001480 state->chan_start++;
1481 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 break;
1483 default:
1484 /* add frequencies */
1485 nl_freqs = nla_nest_start(
1486 msg, NL80211_BAND_ATTR_FREQS);
1487 if (!nl_freqs)
1488 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001489
Johannes Berg86e8cf92013-06-19 10:57:22 +02001490 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 i < sband->n_channels;
1492 i++) {
1493 nl_freq = nla_nest_start(msg, i);
1494 if (!nl_freq)
1495 goto nla_put_failure;
1496
1497 chan = &sband->channels[i];
1498
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 if (nl80211_msg_put_channel(
1500 msg, chan,
1501 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 goto nla_put_failure;
1503
1504 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001505 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 break;
1507 }
1508 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001511 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 nla_nest_end(msg, nl_freqs);
1513 }
1514
1515 nla_nest_end(msg, nl_band);
1516
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001519 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 band--;
1521 break;
1522 }
Johannes Bergee688b002008-01-24 19:38:39 +01001523 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001525
Johannes Berg57fbcce2016-04-12 15:56:15 +02001526 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001529 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001530
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001532 if (state->band_start == 0 && state->chan_start == 0)
1533 state->split_start++;
1534 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 break;
1536 case 4:
1537 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1538 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001539 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540
1541 i = 0;
1542#define CMD(op, n) \
1543 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001544 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 i++; \
1546 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1547 goto nla_put_failure; \
1548 } \
1549 } while (0)
1550
1551 CMD(add_virtual_intf, NEW_INTERFACE);
1552 CMD(change_virtual_intf, SET_INTERFACE);
1553 CMD(add_key, NEW_KEY);
1554 CMD(start_ap, START_AP);
1555 CMD(add_station, NEW_STATION);
1556 CMD(add_mpath, NEW_MPATH);
1557 CMD(update_mesh_config, SET_MESH_CONFIG);
1558 CMD(change_bss, SET_BSS);
1559 CMD(auth, AUTHENTICATE);
1560 CMD(assoc, ASSOCIATE);
1561 CMD(deauth, DEAUTHENTICATE);
1562 CMD(disassoc, DISASSOCIATE);
1563 CMD(join_ibss, JOIN_IBSS);
1564 CMD(join_mesh, JOIN_MESH);
1565 CMD(set_pmksa, SET_PMKSA);
1566 CMD(del_pmksa, DEL_PMKSA);
1567 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1570 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1571 CMD(mgmt_tx, FRAME);
1572 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001573 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 i++;
1575 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1576 goto nla_put_failure;
1577 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1579 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 i++;
1581 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1582 goto nla_put_failure;
1583 }
1584 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 CMD(tdls_mgmt, TDLS_MGMT);
1587 CMD(tdls_oper, TDLS_OPER);
1588 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 CMD(sched_scan_start, START_SCHED_SCAN);
1591 CMD(probe_client, PROBE_CLIENT);
1592 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 i++;
1595 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1596 goto nla_put_failure;
1597 }
1598 CMD(start_p2p_device, START_P2P_DEVICE);
1599 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001600#ifdef CONFIG_NL80211_TESTMODE
1601 CMD(testmode_cmd, TESTMODE);
1602#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001603 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001604 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1605 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001607 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001608 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001609 if (rdev->wiphy.features &
1610 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001611 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001612 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001613 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001614#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001615
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 i++;
1618 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001619 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001620 }
1621
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 i++;
1624 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1625 goto nla_put_failure;
1626 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001627
Johannes Berg3713b4e2013-02-14 16:19:38 +01001628 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001629 state->split_start++;
1630 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001631 break;
1632 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 if (rdev->ops->remain_on_channel &&
1634 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 nla_put_u32(msg,
1636 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001638 goto nla_put_failure;
1639
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1642 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001643
Johannes Berg3713b4e2013-02-14 16:19:38 +01001644 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1645 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001646 state->split_start++;
1647 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 break;
1649 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001650#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001651 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001652 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001653 state->split_start++;
1654 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001655 break;
1656#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001657 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658#endif
1659 case 7:
1660 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001662 goto nla_put_failure;
1663
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001665 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001666 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001667
Johannes Berg86e8cf92013-06-19 10:57:22 +02001668 state->split_start++;
1669 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670 break;
1671 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001673 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675 goto nla_put_failure;
1676
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001677 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001678 /*
1679 * We can only add the per-channel limit information if the
1680 * dump is split, otherwise it makes it too big. Therefore
1681 * only advertise it in that case.
1682 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001683 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001684 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1685 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686 goto nla_put_failure;
1687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1691 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692 goto nla_put_failure;
1693
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001694 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1695 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001696 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001698 goto nla_put_failure;
1699
1700 /*
1701 * Any information below this point is only available to
1702 * applications that can deal with it being split. This
1703 * helps ensure that newly added capabilities don't break
1704 * older tools by overrunning their buffers.
1705 *
1706 * We still increment split_start so that in the split
1707 * case we'll continue with more data in the next round,
1708 * but break unconditionally so unsplit data stops here.
1709 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001710 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001711 break;
1712 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001713 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001714 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001715 rdev->wiphy.extended_capabilities_len,
1716 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001717 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001718 rdev->wiphy.extended_capabilities_len,
1719 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001720 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001722 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001723 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001724 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1725 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001726 goto nla_put_failure;
1727
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001728 state->split_start++;
1729 break;
1730 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001731 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001732 goto nla_put_failure;
1733
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001734 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001735 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1736 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1737 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001738
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001739 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001740 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001741 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001742 goto nla_put_failure;
1743
Johannes Bergad7e7182013-11-13 13:37:47 +01001744 state->split_start++;
1745 break;
1746 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001747 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001748 const struct nl80211_vendor_cmd_info *info;
1749 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001750
Johannes Berg567ffc32013-12-18 14:43:31 +01001751 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1752 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001753 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001754
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1756 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001757 if (nla_put(msg, i + 1, sizeof(*info), info))
1758 goto nla_put_failure;
1759 }
1760 nla_nest_end(msg, nested);
1761 }
1762
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001763 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001764 const struct nl80211_vendor_cmd_info *info;
1765 struct nlattr *nested;
1766
1767 nested = nla_nest_start(msg,
1768 NL80211_ATTR_VENDOR_EVENTS);
1769 if (!nested)
1770 goto nla_put_failure;
1771
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1773 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001774 if (nla_put(msg, i + 1, sizeof(*info), info))
1775 goto nla_put_failure;
1776 }
1777 nla_nest_end(msg, nested);
1778 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001779 state->split_start++;
1780 break;
1781 case 12:
1782 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1783 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1784 rdev->wiphy.max_num_csa_counters))
1785 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001786
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001787 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1788 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1789 goto nla_put_failure;
1790
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001791 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1792 sizeof(rdev->wiphy.ext_features),
1793 rdev->wiphy.ext_features))
1794 goto nla_put_failure;
1795
Arend van Spriel38de03d2016-03-02 20:37:18 +01001796 if (rdev->wiphy.bss_select_support) {
1797 struct nlattr *nested;
1798 u32 bss_select_support = rdev->wiphy.bss_select_support;
1799
1800 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1801 if (!nested)
1802 goto nla_put_failure;
1803
1804 i = 0;
1805 while (bss_select_support) {
1806 if ((bss_select_support & 1) &&
1807 nla_put_flag(msg, i))
1808 goto nla_put_failure;
1809 i++;
1810 bss_select_support >>= 1;
1811 }
1812 nla_nest_end(msg, nested);
1813 }
1814
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301815 state->split_start++;
1816 break;
1817 case 13:
1818 if (rdev->wiphy.num_iftype_ext_capab &&
1819 rdev->wiphy.iftype_ext_capab) {
1820 struct nlattr *nested_ext_capab, *nested;
1821
1822 nested = nla_nest_start(msg,
1823 NL80211_ATTR_IFTYPE_EXT_CAPA);
1824 if (!nested)
1825 goto nla_put_failure;
1826
1827 for (i = state->capa_start;
1828 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1829 const struct wiphy_iftype_ext_capab *capab;
1830
1831 capab = &rdev->wiphy.iftype_ext_capab[i];
1832
1833 nested_ext_capab = nla_nest_start(msg, i);
1834 if (!nested_ext_capab ||
1835 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1836 capab->iftype) ||
1837 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1838 capab->extended_capabilities_len,
1839 capab->extended_capabilities) ||
1840 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1841 capab->extended_capabilities_len,
1842 capab->extended_capabilities_mask))
1843 goto nla_put_failure;
1844
1845 nla_nest_end(msg, nested_ext_capab);
1846 if (state->split)
1847 break;
1848 }
1849 nla_nest_end(msg, nested);
1850 if (i < rdev->wiphy.num_iftype_ext_capab) {
1851 state->capa_start = i + 1;
1852 break;
1853 }
1854 }
1855
Johannes Berg3713b4e2013-02-14 16:19:38 +01001856 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001857 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001858 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001859 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001860 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001861 genlmsg_end(msg, hdr);
1862 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001863
1864 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001865 genlmsg_cancel(msg, hdr);
1866 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001867}
1868
Johannes Berg86e8cf92013-06-19 10:57:22 +02001869static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1870 struct netlink_callback *cb,
1871 struct nl80211_dump_wiphy_state *state)
1872{
1873 struct nlattr **tb = nl80211_fam.attrbuf;
1874 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1875 tb, nl80211_fam.maxattr, nl80211_policy);
1876 /* ignore parse errors for backward compatibility */
1877 if (ret)
1878 return 0;
1879
1880 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1881 if (tb[NL80211_ATTR_WIPHY])
1882 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1883 if (tb[NL80211_ATTR_WDEV])
1884 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1885 if (tb[NL80211_ATTR_IFINDEX]) {
1886 struct net_device *netdev;
1887 struct cfg80211_registered_device *rdev;
1888 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1889
Ying Xue7f2b8562014-01-15 10:23:45 +08001890 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001891 if (!netdev)
1892 return -ENODEV;
1893 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001894 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001895 netdev->ieee80211_ptr->wiphy);
1896 state->filter_wiphy = rdev->wiphy_idx;
1897 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001898 }
1899
1900 return 0;
1901}
1902
Johannes Berg55682962007-09-20 13:09:35 -04001903static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1904{
Johannes Berg645e77d2013-03-01 14:03:49 +01001905 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001906 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001907 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001908
Johannes Berg5fe231e2013-05-08 21:45:15 +02001909 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001910 if (!state) {
1911 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001912 if (!state) {
1913 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001914 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001915 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001916 state->filter_wiphy = -1;
1917 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1918 if (ret) {
1919 kfree(state);
1920 rtnl_unlock();
1921 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001922 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001923 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001924 }
1925
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001926 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1927 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001928 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001930 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001931 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001932 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001933 continue;
1934 /* attempt to fit multiple wiphy data chunks into the skb */
1935 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001936 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1937 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001938 NETLINK_CB(cb->skb).portid,
1939 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001940 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001941 if (ret < 0) {
1942 /*
1943 * If sending the wiphy data didn't fit (ENOBUFS
1944 * or EMSGSIZE returned), this SKB is still
1945 * empty (so it's not too big because another
1946 * wiphy dataset is already in the skb) and
1947 * we've not tried to adjust the dump allocation
1948 * yet ... then adjust the alloc size to be
1949 * bigger, and return 1 but with the empty skb.
1950 * This results in an empty message being RX'ed
1951 * in userspace, but that is ignored.
1952 *
1953 * We can then retry with the larger buffer.
1954 */
1955 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001956 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001957 cb->min_dump_alloc < 4096) {
1958 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001959 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001960 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001961 return 1;
1962 }
1963 idx--;
1964 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001965 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001966 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001967 break;
Johannes Berg55682962007-09-20 13:09:35 -04001968 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001969 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001970
Johannes Berg86e8cf92013-06-19 10:57:22 +02001971 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001972
1973 return skb->len;
1974}
1975
Johannes Berg86e8cf92013-06-19 10:57:22 +02001976static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1977{
1978 kfree((void *)cb->args[0]);
1979 return 0;
1980}
1981
Johannes Berg55682962007-09-20 13:09:35 -04001982static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1983{
1984 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001986 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001987
Johannes Berg645e77d2013-03-01 14:03:49 +01001988 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001989 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001990 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001991
Johannes Berg3bb20552014-05-26 13:52:25 +02001992 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1993 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001994 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001995 nlmsg_free(msg);
1996 return -ENOBUFS;
1997 }
Johannes Berg55682962007-09-20 13:09:35 -04001998
Johannes Berg134e6372009-07-10 09:51:34 +00001999 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002000}
2001
Jouni Malinen31888482008-10-30 16:59:24 +02002002static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2003 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2004 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2005 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2006 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2007 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2008};
2009
2010static int parse_txq_params(struct nlattr *tb[],
2011 struct ieee80211_txq_params *txq_params)
2012{
Johannes Berga3304b02012-03-28 11:04:24 +02002013 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002014 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2015 !tb[NL80211_TXQ_ATTR_AIFS])
2016 return -EINVAL;
2017
Johannes Berga3304b02012-03-28 11:04:24 +02002018 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002019 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2020 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2021 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2022 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2023
Johannes Berga3304b02012-03-28 11:04:24 +02002024 if (txq_params->ac >= NL80211_NUM_ACS)
2025 return -EINVAL;
2026
Jouni Malinen31888482008-10-30 16:59:24 +02002027 return 0;
2028}
2029
Johannes Bergf444de02010-05-05 15:25:02 +02002030static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2031{
2032 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002033 * You can only set the channel explicitly for WDS interfaces,
2034 * all others have their channel managed via their respective
2035 * "establish a connection" command (connect, join, ...)
2036 *
2037 * For AP/GO and mesh mode, the channel can be set with the
2038 * channel userspace API, but is only stored and passed to the
2039 * low-level driver when the AP starts or the mesh is joined.
2040 * This is for backward compatibility, userspace can also give
2041 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002042 *
2043 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002044 * whatever else is going on, so they have their own special
2045 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002046 */
2047 return !wdev ||
2048 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002049 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002050 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2051 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002052}
2053
Johannes Berg683b6d32012-11-08 21:25:48 +01002054static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2055 struct genl_info *info,
2056 struct cfg80211_chan_def *chandef)
2057{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302058 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002059
2060 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2061 return -EINVAL;
2062
2063 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2064
2065 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002066 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2067 chandef->center_freq1 = control_freq;
2068 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002069
2070 /* Primary channel not allowed */
2071 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2072 return -EINVAL;
2073
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002074 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2075 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002076
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002077 chantype = nla_get_u32(
2078 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2079
2080 switch (chantype) {
2081 case NL80211_CHAN_NO_HT:
2082 case NL80211_CHAN_HT20:
2083 case NL80211_CHAN_HT40PLUS:
2084 case NL80211_CHAN_HT40MINUS:
2085 cfg80211_chandef_create(chandef, chandef->chan,
2086 chantype);
2087 break;
2088 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002089 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002090 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002091 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2092 chandef->width =
2093 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2094 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2095 chandef->center_freq1 =
2096 nla_get_u32(
2097 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2098 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2099 chandef->center_freq2 =
2100 nla_get_u32(
2101 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2102 }
2103
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002104 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002105 return -EINVAL;
2106
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002107 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2108 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002109 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002110
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002111 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2112 chandef->width == NL80211_CHAN_WIDTH_10) &&
2113 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2114 return -EINVAL;
2115
Johannes Berg683b6d32012-11-08 21:25:48 +01002116 return 0;
2117}
2118
Johannes Bergf444de02010-05-05 15:25:02 +02002119static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002120 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002121 struct genl_info *info)
2122{
Johannes Berg683b6d32012-11-08 21:25:48 +01002123 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002124 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002125 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002126 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002127
Jouni Malinene16821b2014-04-28 11:22:08 +03002128 if (dev)
2129 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002130 if (!nl80211_can_set_dev_channel(wdev))
2131 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002132 if (wdev)
2133 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002134
Johannes Berg683b6d32012-11-08 21:25:48 +01002135 result = nl80211_parse_chandef(rdev, info, &chandef);
2136 if (result)
2137 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002138
Johannes Berge8c9bd52012-06-06 08:18:22 +02002139 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002140 case NL80211_IFTYPE_AP:
2141 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002142 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2143 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002144 result = -EINVAL;
2145 break;
2146 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002147 if (wdev->beacon_interval) {
2148 if (!dev || !rdev->ops->set_ap_chanwidth ||
2149 !(rdev->wiphy.features &
2150 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2151 result = -EBUSY;
2152 break;
2153 }
2154
2155 /* Only allow dynamic channel width changes */
2156 if (chandef.chan != wdev->preset_chandef.chan) {
2157 result = -EBUSY;
2158 break;
2159 }
2160 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2161 if (result)
2162 break;
2163 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002164 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002165 result = 0;
2166 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002167 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002168 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002169 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002170 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002171 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002172 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002173 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002174 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002175 }
Johannes Bergf444de02010-05-05 15:25:02 +02002176
2177 return result;
2178}
2179
2180static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2181{
Johannes Berg4c476992010-10-04 21:36:35 +02002182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2183 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002184
Jouni Malinene16821b2014-04-28 11:22:08 +03002185 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002186}
2187
Bill Jordane8347eb2010-10-01 13:54:28 -04002188static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2189{
Johannes Berg43b19952010-10-07 13:10:30 +02002190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2191 struct net_device *dev = info->user_ptr[1];
2192 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002193 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002194
2195 if (!info->attrs[NL80211_ATTR_MAC])
2196 return -EINVAL;
2197
Johannes Berg43b19952010-10-07 13:10:30 +02002198 if (netif_running(dev))
2199 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002200
Johannes Berg43b19952010-10-07 13:10:30 +02002201 if (!rdev->ops->set_wds_peer)
2202 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002203
Johannes Berg43b19952010-10-07 13:10:30 +02002204 if (wdev->iftype != NL80211_IFTYPE_WDS)
2205 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002206
2207 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002208 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002209}
2210
Johannes Berg55682962007-09-20 13:09:35 -04002211static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2212{
2213 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002214 struct net_device *netdev = NULL;
2215 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002216 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002217 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002218 u32 changed;
2219 u8 retry_short = 0, retry_long = 0;
2220 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002221 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002222
Johannes Berg5fe231e2013-05-08 21:45:15 +02002223 ASSERT_RTNL();
2224
Johannes Bergf444de02010-05-05 15:25:02 +02002225 /*
2226 * Try to find the wiphy and netdev. Normally this
2227 * function shouldn't need the netdev, but this is
2228 * done for backward compatibility -- previously
2229 * setting the channel was done per wiphy, but now
2230 * it is per netdev. Previous userland like hostapd
2231 * also passed a netdev to set_wiphy, so that it is
2232 * possible to let that go to the right netdev!
2233 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002234
Johannes Bergf444de02010-05-05 15:25:02 +02002235 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2236 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2237
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002239 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002240 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002241 else
Johannes Bergf444de02010-05-05 15:25:02 +02002242 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002243 }
2244
Johannes Bergf444de02010-05-05 15:25:02 +02002245 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002246 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2247 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002248 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002249 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002250 wdev = NULL;
2251 netdev = NULL;
2252 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002253 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002254 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002255
2256 /*
2257 * end workaround code, by now the rdev is available
2258 * and locked, and wdev may or may not be NULL.
2259 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002260
2261 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002262 result = cfg80211_dev_rename(
2263 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002264
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002265 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002266 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002267
Jouni Malinen31888482008-10-30 16:59:24 +02002268 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2269 struct ieee80211_txq_params txq_params;
2270 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2271
Ying Xue7f2b8562014-01-15 10:23:45 +08002272 if (!rdev->ops->set_txq_params)
2273 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002274
Ying Xue7f2b8562014-01-15 10:23:45 +08002275 if (!netdev)
2276 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002277
Johannes Berg133a3ff2011-11-03 14:50:13 +01002278 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2280 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002281
Ying Xue7f2b8562014-01-15 10:23:45 +08002282 if (!netif_running(netdev))
2283 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002284
Jouni Malinen31888482008-10-30 16:59:24 +02002285 nla_for_each_nested(nl_txq_params,
2286 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2287 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002288 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2289 nla_data(nl_txq_params),
2290 nla_len(nl_txq_params),
2291 txq_params_policy);
2292 if (result)
2293 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002294 result = parse_txq_params(tb, &txq_params);
2295 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002296 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002297
Hila Gonene35e4d22012-06-27 17:19:42 +03002298 result = rdev_set_txq_params(rdev, netdev,
2299 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002300 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002301 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002302 }
2303 }
2304
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002305 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002306 result = __nl80211_set_channel(
2307 rdev,
2308 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2309 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002310 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002311 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002312 }
2313
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002314 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002315 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002316 enum nl80211_tx_power_setting type;
2317 int idx, mbm = 0;
2318
Johannes Bergc8442112012-10-24 10:17:18 +02002319 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2320 txp_wdev = NULL;
2321
Ying Xue7f2b8562014-01-15 10:23:45 +08002322 if (!rdev->ops->set_tx_power)
2323 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002324
2325 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2326 type = nla_get_u32(info->attrs[idx]);
2327
2328 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 (type != NL80211_TX_POWER_AUTOMATIC))
2330 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002331
2332 if (type != NL80211_TX_POWER_AUTOMATIC) {
2333 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2334 mbm = nla_get_u32(info->attrs[idx]);
2335 }
2336
Johannes Bergc8442112012-10-24 10:17:18 +02002337 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002338 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002339 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002340 }
2341
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002342 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2343 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2344 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002345
Bruno Randolf7f531e02010-12-16 11:30:22 +09002346 if ((!rdev->wiphy.available_antennas_tx &&
2347 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002348 !rdev->ops->set_antenna)
2349 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002350
2351 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2352 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2353
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002354 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002355 * available antenna masks, except for the "all" mask */
2356 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002357 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2358 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002359
Bruno Randolf7f531e02010-12-16 11:30:22 +09002360 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2361 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002362
Hila Gonene35e4d22012-06-27 17:19:42 +03002363 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002364 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002365 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002366 }
2367
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002368 changed = 0;
2369
2370 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2371 retry_short = nla_get_u8(
2372 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002373 if (retry_short == 0)
2374 return -EINVAL;
2375
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002376 changed |= WIPHY_PARAM_RETRY_SHORT;
2377 }
2378
2379 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2380 retry_long = nla_get_u8(
2381 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002382 if (retry_long == 0)
2383 return -EINVAL;
2384
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002385 changed |= WIPHY_PARAM_RETRY_LONG;
2386 }
2387
2388 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2389 frag_threshold = nla_get_u32(
2390 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002391 if (frag_threshold < 256)
2392 return -EINVAL;
2393
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002394 if (frag_threshold != (u32) -1) {
2395 /*
2396 * Fragments (apart from the last one) are required to
2397 * have even length. Make the fragmentation code
2398 * simpler by stripping LSB should someone try to use
2399 * odd threshold value.
2400 */
2401 frag_threshold &= ~0x1;
2402 }
2403 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2404 }
2405
2406 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2407 rts_threshold = nla_get_u32(
2408 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2409 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2410 }
2411
Lukáš Turek81077e82009-12-21 22:50:47 +01002412 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002413 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2414 return -EINVAL;
2415
Lukáš Turek81077e82009-12-21 22:50:47 +01002416 coverage_class = nla_get_u8(
2417 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2418 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2419 }
2420
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002421 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2422 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2423 return -EOPNOTSUPP;
2424
2425 changed |= WIPHY_PARAM_DYN_ACK;
2426 }
2427
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002428 if (changed) {
2429 u8 old_retry_short, old_retry_long;
2430 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002431 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002432
Ying Xue7f2b8562014-01-15 10:23:45 +08002433 if (!rdev->ops->set_wiphy_params)
2434 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002435
2436 old_retry_short = rdev->wiphy.retry_short;
2437 old_retry_long = rdev->wiphy.retry_long;
2438 old_frag_threshold = rdev->wiphy.frag_threshold;
2439 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002440 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002441
2442 if (changed & WIPHY_PARAM_RETRY_SHORT)
2443 rdev->wiphy.retry_short = retry_short;
2444 if (changed & WIPHY_PARAM_RETRY_LONG)
2445 rdev->wiphy.retry_long = retry_long;
2446 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2447 rdev->wiphy.frag_threshold = frag_threshold;
2448 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2449 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002450 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2451 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002452
Hila Gonene35e4d22012-06-27 17:19:42 +03002453 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002454 if (result) {
2455 rdev->wiphy.retry_short = old_retry_short;
2456 rdev->wiphy.retry_long = old_retry_long;
2457 rdev->wiphy.frag_threshold = old_frag_threshold;
2458 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002459 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002460 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002461 }
2462 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002463 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002464}
2465
Johannes Berg71bbc992012-06-15 15:30:18 +02002466static inline u64 wdev_id(struct wireless_dev *wdev)
2467{
2468 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002469 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002470}
Johannes Berg55682962007-09-20 13:09:35 -04002471
Johannes Berg683b6d32012-11-08 21:25:48 +01002472static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002473 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002474{
Johannes Berg601555c2014-11-27 17:26:56 +01002475 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2476 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002477
Johannes Berg683b6d32012-11-08 21:25:48 +01002478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2479 chandef->chan->center_freq))
2480 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002481 switch (chandef->width) {
2482 case NL80211_CHAN_WIDTH_20_NOHT:
2483 case NL80211_CHAN_WIDTH_20:
2484 case NL80211_CHAN_WIDTH_40:
2485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2486 cfg80211_get_chandef_type(chandef)))
2487 return -ENOBUFS;
2488 break;
2489 default:
2490 break;
2491 }
2492 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2493 return -ENOBUFS;
2494 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2495 return -ENOBUFS;
2496 if (chandef->center_freq2 &&
2497 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002498 return -ENOBUFS;
2499 return 0;
2500}
2501
Eric W. Biederman15e47302012-09-07 20:12:54 +00002502static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002503 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002504 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002505{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002506 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002507 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002508 void *hdr;
2509
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002510 if (removal)
2511 cmd = NL80211_CMD_DEL_INTERFACE;
2512
2513 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002514 if (!hdr)
2515 return -1;
2516
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002517 if (dev &&
2518 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002519 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002520 goto nla_put_failure;
2521
2522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2523 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002524 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2525 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002526 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002527 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2528 rdev->devlist_generation ^
2529 (cfg80211_rdev_list_generation << 2)))
2530 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002531
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002532 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002533 int ret;
2534 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002535
Johannes Berg683b6d32012-11-08 21:25:48 +01002536 ret = rdev_get_channel(rdev, wdev, &chandef);
2537 if (ret == 0) {
2538 if (nl80211_send_chandef(msg, &chandef))
2539 goto nla_put_failure;
2540 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002541 }
2542
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002543 if (rdev->ops->get_tx_power) {
2544 int dbm, ret;
2545
2546 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2547 if (ret == 0 &&
2548 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2549 DBM_TO_MBM(dbm)))
2550 goto nla_put_failure;
2551 }
2552
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002553 if (wdev->ssid_len) {
2554 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2555 goto nla_put_failure;
2556 }
2557
Johannes Berg053c0952015-01-16 22:09:00 +01002558 genlmsg_end(msg, hdr);
2559 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002560
2561 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002562 genlmsg_cancel(msg, hdr);
2563 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002564}
2565
2566static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2567{
2568 int wp_idx = 0;
2569 int if_idx = 0;
2570 int wp_start = cb->args[0];
2571 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002572 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002573 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002574 struct wireless_dev *wdev;
Johannes Berg56769e72017-03-15 14:26:04 +01002575 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04002576
Johannes Berg5fe231e2013-05-08 21:45:15 +02002577 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002578 if (!cb->args[2]) {
2579 struct nl80211_dump_wiphy_state state = {
2580 .filter_wiphy = -1,
2581 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002582
2583 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2584 if (ret)
Johannes Berg56769e72017-03-15 14:26:04 +01002585 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002586
2587 filter_wiphy = state.filter_wiphy;
2588
2589 /*
2590 * if filtering, set cb->args[2] to +1 since 0 is the default
2591 * value needed to determine that parsing is necessary.
2592 */
2593 if (filter_wiphy >= 0)
2594 cb->args[2] = filter_wiphy + 1;
2595 else
2596 cb->args[2] = -1;
2597 } else if (cb->args[2] > 0) {
2598 filter_wiphy = cb->args[2] - 1;
2599 }
2600
Johannes Bergf5ea9122009-08-07 16:17:38 +02002601 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2602 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002603 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002604 if (wp_idx < wp_start) {
2605 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002606 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002607 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002608
2609 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2610 continue;
2611
Johannes Berg55682962007-09-20 13:09:35 -04002612 if_idx = 0;
2613
Johannes Berg53873f12016-05-03 16:52:04 +03002614 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002615 if (if_idx < if_start) {
2616 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002617 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002618 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002619 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002620 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002621 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002622 goto out;
2623 }
2624 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002625 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002626
2627 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002628 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002629 out:
Johannes Berg55682962007-09-20 13:09:35 -04002630 cb->args[0] = wp_idx;
2631 cb->args[1] = if_idx;
2632
Johannes Berg56769e72017-03-15 14:26:04 +01002633 ret = skb->len;
2634 out_unlock:
2635 rtnl_unlock();
2636
2637 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04002638}
2639
2640static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2641{
2642 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002643 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002644 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002645
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002646 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002647 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002648 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002649
Eric W. Biederman15e47302012-09-07 20:12:54 +00002650 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002651 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002652 nlmsg_free(msg);
2653 return -ENOBUFS;
2654 }
Johannes Berg55682962007-09-20 13:09:35 -04002655
Johannes Berg134e6372009-07-10 09:51:34 +00002656 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002657}
2658
Michael Wu66f7ac52008-01-31 19:48:22 +01002659static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2660 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2661 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2662 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2663 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2664 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002665 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002666};
2667
2668static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2669{
2670 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2671 int flag;
2672
2673 *mntrflags = 0;
2674
2675 if (!nla)
2676 return -EINVAL;
2677
2678 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2679 nla, mntr_flags_policy))
2680 return -EINVAL;
2681
2682 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2683 if (flags[flag])
2684 *mntrflags |= (1<<flag);
2685
2686 return 0;
2687}
2688
Johannes Berg9bc383d2009-11-19 11:55:19 +01002689static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002690 struct net_device *netdev, u8 use_4addr,
2691 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002692{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002693 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002694 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002695 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002696 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002697 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002698
2699 switch (iftype) {
2700 case NL80211_IFTYPE_AP_VLAN:
2701 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2702 return 0;
2703 break;
2704 case NL80211_IFTYPE_STATION:
2705 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2706 return 0;
2707 break;
2708 default:
2709 break;
2710 }
2711
2712 return -EOPNOTSUPP;
2713}
2714
Johannes Berg55682962007-09-20 13:09:35 -04002715static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2716{
Johannes Berg4c476992010-10-04 21:36:35 +02002717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002718 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002719 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002720 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002721 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002722 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002723 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002724
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002725 memset(&params, 0, sizeof(params));
2726
Johannes Berg04a773a2009-04-19 21:24:32 +02002727 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002728
Johannes Berg723b0382008-09-16 20:22:09 +02002729 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002730 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002731 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002732 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002733 if (ntype > NL80211_IFTYPE_MAX)
2734 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002735 }
2736
Johannes Berg92ffe052008-09-16 20:39:36 +02002737 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002738 struct wireless_dev *wdev = dev->ieee80211_ptr;
2739
Johannes Berg4c476992010-10-04 21:36:35 +02002740 if (ntype != NL80211_IFTYPE_MESH_POINT)
2741 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002742 if (netif_running(dev))
2743 return -EBUSY;
2744
2745 wdev_lock(wdev);
2746 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2747 IEEE80211_MAX_MESH_ID_LEN);
2748 wdev->mesh_id_up_len =
2749 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2750 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2751 wdev->mesh_id_up_len);
2752 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002753 }
2754
Felix Fietkau8b787642009-11-10 18:53:10 +01002755 if (info->attrs[NL80211_ATTR_4ADDR]) {
2756 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2757 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002758 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002759 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002760 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002761 } else {
2762 params.use_4addr = -1;
2763 }
2764
Johannes Berg92ffe052008-09-16 20:39:36 +02002765 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002766 if (ntype != NL80211_IFTYPE_MONITOR)
2767 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002768 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2769 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002770 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002771 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002772
2773 flags = &_flags;
2774 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002775 }
Johannes Berg3b858752009-03-12 09:55:09 +01002776
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002777 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2778 const u8 *mumimo_groups;
2779 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2780
2781 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2782 return -EOPNOTSUPP;
2783
2784 mumimo_groups =
2785 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2786
2787 /* bits 0 and 63 are reserved and must be zero */
2788 if ((mumimo_groups[0] & BIT(7)) ||
2789 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2790 return -EINVAL;
2791
2792 memcpy(params.vht_mumimo_groups, mumimo_groups,
2793 VHT_MUMIMO_GROUPS_DATA_LEN);
2794 change = true;
2795 }
2796
2797 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2798 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2799
2800 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2801 return -EOPNOTSUPP;
2802
2803 nla_memcpy(params.macaddr,
2804 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2805 ETH_ALEN);
2806 change = true;
2807 }
2808
Luciano Coelho18003292013-08-29 13:26:57 +03002809 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002810 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2811 return -EOPNOTSUPP;
2812
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002813 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002814 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002815 else
2816 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002817
Johannes Berg9bc383d2009-11-19 11:55:19 +01002818 if (!err && params.use_4addr != -1)
2819 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2820
Johannes Berg55682962007-09-20 13:09:35 -04002821 return err;
2822}
2823
2824static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2825{
Johannes Berg4c476992010-10-04 21:36:35 +02002826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002827 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002828 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002829 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002830 int err;
2831 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002832 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002833
Johannes Berg78f22b62014-03-24 17:57:27 +01002834 /* to avoid failing a new interface creation due to pending removal */
2835 cfg80211_destroy_ifaces(rdev);
2836
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002837 memset(&params, 0, sizeof(params));
2838
Johannes Berg55682962007-09-20 13:09:35 -04002839 if (!info->attrs[NL80211_ATTR_IFNAME])
2840 return -EINVAL;
2841
2842 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2843 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2844 if (type > NL80211_IFTYPE_MAX)
2845 return -EINVAL;
2846 }
2847
Johannes Berg79c97e92009-07-07 03:56:12 +02002848 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002849 !(rdev->wiphy.interface_modes & (1 << type)))
2850 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002851
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002852 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002853 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2854 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002855 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2856 ETH_ALEN);
2857 if (!is_valid_ether_addr(params.macaddr))
2858 return -EADDRNOTAVAIL;
2859 }
2860
Johannes Berg9bc383d2009-11-19 11:55:19 +01002861 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002862 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002863 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002864 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002865 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002866 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002867
Michael Wu66f7ac52008-01-31 19:48:22 +01002868 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2869 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2870 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002871
Luciano Coelho18003292013-08-29 13:26:57 +03002872 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002873 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2874 return -EOPNOTSUPP;
2875
Johannes Berga18c7192015-02-24 10:56:42 +01002876 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2877 if (!msg)
2878 return -ENOMEM;
2879
Hila Gonene35e4d22012-06-27 17:19:42 +03002880 wdev = rdev_add_virtual_intf(rdev,
2881 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002882 NET_NAME_USER, type, err ? NULL : &flags,
2883 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002884 if (WARN_ON(!wdev)) {
2885 nlmsg_free(msg);
2886 return -EPROTO;
2887 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002888 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002889 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002890 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002891
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002892 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002893 wdev->owner_nlportid = info->snd_portid;
2894
Johannes Berg98104fde2012-06-16 00:19:54 +02002895 switch (type) {
2896 case NL80211_IFTYPE_MESH_POINT:
2897 if (!info->attrs[NL80211_ATTR_MESH_ID])
2898 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002899 wdev_lock(wdev);
2900 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2901 IEEE80211_MAX_MESH_ID_LEN);
2902 wdev->mesh_id_up_len =
2903 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2904 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2905 wdev->mesh_id_up_len);
2906 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002907 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002908 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002909 case NL80211_IFTYPE_P2P_DEVICE:
2910 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002911 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002912 * through the netdev notifier and must be added here
2913 */
2914 mutex_init(&wdev->mtx);
2915 INIT_LIST_HEAD(&wdev->event_list);
2916 spin_lock_init(&wdev->event_lock);
2917 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2918 spin_lock_init(&wdev->mgmt_registrations_lock);
2919
Johannes Berg98104fde2012-06-16 00:19:54 +02002920 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002921 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002922 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002923 break;
2924 default:
2925 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002926 }
2927
Eric W. Biederman15e47302012-09-07 20:12:54 +00002928 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002929 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002930 nlmsg_free(msg);
2931 return -ENOBUFS;
2932 }
2933
Denis Kenzior896ff062016-08-03 16:58:33 -05002934 /*
2935 * For wdevs which have no associated netdev object (e.g. of type
2936 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2937 * For all other types, the event will be generated from the
2938 * netdev notifier
2939 */
2940 if (!wdev->netdev)
2941 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002942
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002943 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002944}
2945
2946static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2947{
Johannes Berg4c476992010-10-04 21:36:35 +02002948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002949 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002950
Johannes Berg4c476992010-10-04 21:36:35 +02002951 if (!rdev->ops->del_virtual_intf)
2952 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002953
Johannes Berg84efbb82012-06-16 00:00:26 +02002954 /*
2955 * If we remove a wireless device without a netdev then clear
2956 * user_ptr[1] so that nl80211_post_doit won't dereference it
2957 * to check if it needs to do dev_put(). Otherwise it crashes
2958 * since the wdev has been freed, unlike with a netdev where
2959 * we need the dev_put() for the netdev to really be freed.
2960 */
2961 if (!wdev->netdev)
2962 info->user_ptr[1] = NULL;
2963
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002964 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002965}
2966
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002967static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2968{
2969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2970 struct net_device *dev = info->user_ptr[1];
2971 u16 noack_map;
2972
2973 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2974 return -EINVAL;
2975
2976 if (!rdev->ops->set_noack_map)
2977 return -EOPNOTSUPP;
2978
2979 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2980
Hila Gonene35e4d22012-06-27 17:19:42 +03002981 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002982}
2983
Johannes Berg41ade002007-12-19 02:03:29 +01002984struct get_key_cookie {
2985 struct sk_buff *msg;
2986 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002987 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002988};
2989
2990static void get_key_callback(void *c, struct key_params *params)
2991{
Johannes Bergb9454e82009-07-08 13:29:08 +02002992 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002993 struct get_key_cookie *cookie = c;
2994
David S. Miller9360ffd2012-03-29 04:41:26 -04002995 if ((params->key &&
2996 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2997 params->key_len, params->key)) ||
2998 (params->seq &&
2999 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3000 params->seq_len, params->seq)) ||
3001 (params->cipher &&
3002 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3003 params->cipher)))
3004 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003005
Johannes Bergb9454e82009-07-08 13:29:08 +02003006 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3007 if (!key)
3008 goto nla_put_failure;
3009
David S. Miller9360ffd2012-03-29 04:41:26 -04003010 if ((params->key &&
3011 nla_put(cookie->msg, NL80211_KEY_DATA,
3012 params->key_len, params->key)) ||
3013 (params->seq &&
3014 nla_put(cookie->msg, NL80211_KEY_SEQ,
3015 params->seq_len, params->seq)) ||
3016 (params->cipher &&
3017 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3018 params->cipher)))
3019 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003020
David S. Miller9360ffd2012-03-29 04:41:26 -04003021 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3022 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003023
3024 nla_nest_end(cookie->msg, key);
3025
Johannes Berg41ade002007-12-19 02:03:29 +01003026 return;
3027 nla_put_failure:
3028 cookie->error = 1;
3029}
3030
3031static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3032{
Johannes Berg4c476992010-10-04 21:36:35 +02003033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003034 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003035 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003036 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003037 const u8 *mac_addr = NULL;
3038 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003039 struct get_key_cookie cookie = {
3040 .error = 0,
3041 };
3042 void *hdr;
3043 struct sk_buff *msg;
3044
3045 if (info->attrs[NL80211_ATTR_KEY_IDX])
3046 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3047
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003048 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003049 return -EINVAL;
3050
3051 if (info->attrs[NL80211_ATTR_MAC])
3052 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3053
Johannes Berge31b8212010-10-05 19:39:30 +02003054 pairwise = !!mac_addr;
3055 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3056 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003057
Johannes Berge31b8212010-10-05 19:39:30 +02003058 if (kt >= NUM_NL80211_KEYTYPES)
3059 return -EINVAL;
3060 if (kt != NL80211_KEYTYPE_GROUP &&
3061 kt != NL80211_KEYTYPE_PAIRWISE)
3062 return -EINVAL;
3063 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3064 }
3065
Johannes Berg4c476992010-10-04 21:36:35 +02003066 if (!rdev->ops->get_key)
3067 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003068
Johannes Berg0fa7b392015-01-23 11:10:12 +01003069 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3070 return -ENOENT;
3071
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003072 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003073 if (!msg)
3074 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003075
Eric W. Biederman15e47302012-09-07 20:12:54 +00003076 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003077 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003078 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003079 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003080
3081 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003082 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003083
David S. Miller9360ffd2012-03-29 04:41:26 -04003084 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3085 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3086 goto nla_put_failure;
3087 if (mac_addr &&
3088 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3089 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003090
Hila Gonene35e4d22012-06-27 17:19:42 +03003091 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3092 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003093
3094 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003095 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003096
3097 if (cookie.error)
3098 goto nla_put_failure;
3099
3100 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003101 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003102
3103 nla_put_failure:
3104 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003105 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003106 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003107 return err;
3108}
3109
3110static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3111{
Johannes Berg4c476992010-10-04 21:36:35 +02003112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003113 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003114 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003115 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003116
Johannes Bergb9454e82009-07-08 13:29:08 +02003117 err = nl80211_parse_key(info, &key);
3118 if (err)
3119 return err;
3120
3121 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003122 return -EINVAL;
3123
Johannes Bergb9454e82009-07-08 13:29:08 +02003124 /* only support setting default key */
3125 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003126 return -EINVAL;
3127
Johannes Bergfffd0932009-07-08 14:22:54 +02003128 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003129
3130 if (key.def) {
3131 if (!rdev->ops->set_default_key) {
3132 err = -EOPNOTSUPP;
3133 goto out;
3134 }
3135
3136 err = nl80211_key_allowed(dev->ieee80211_ptr);
3137 if (err)
3138 goto out;
3139
Hila Gonene35e4d22012-06-27 17:19:42 +03003140 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003141 key.def_uni, key.def_multi);
3142
3143 if (err)
3144 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003145
Johannes Berg3d23e342009-09-29 23:27:28 +02003146#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003147 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003148#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003149 } else {
3150 if (key.def_uni || !key.def_multi) {
3151 err = -EINVAL;
3152 goto out;
3153 }
3154
3155 if (!rdev->ops->set_default_mgmt_key) {
3156 err = -EOPNOTSUPP;
3157 goto out;
3158 }
3159
3160 err = nl80211_key_allowed(dev->ieee80211_ptr);
3161 if (err)
3162 goto out;
3163
Hila Gonene35e4d22012-06-27 17:19:42 +03003164 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003165 if (err)
3166 goto out;
3167
3168#ifdef CONFIG_CFG80211_WEXT
3169 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3170#endif
3171 }
3172
3173 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003174 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003175
Johannes Berg41ade002007-12-19 02:03:29 +01003176 return err;
3177}
3178
3179static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3180{
Johannes Berg4c476992010-10-04 21:36:35 +02003181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003182 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003183 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003184 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003185 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003186
Johannes Bergb9454e82009-07-08 13:29:08 +02003187 err = nl80211_parse_key(info, &key);
3188 if (err)
3189 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003190
Johannes Bergb9454e82009-07-08 13:29:08 +02003191 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003192 return -EINVAL;
3193
Johannes Berg41ade002007-12-19 02:03:29 +01003194 if (info->attrs[NL80211_ATTR_MAC])
3195 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3196
Johannes Berge31b8212010-10-05 19:39:30 +02003197 if (key.type == -1) {
3198 if (mac_addr)
3199 key.type = NL80211_KEYTYPE_PAIRWISE;
3200 else
3201 key.type = NL80211_KEYTYPE_GROUP;
3202 }
3203
3204 /* for now */
3205 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3206 key.type != NL80211_KEYTYPE_GROUP)
3207 return -EINVAL;
3208
Johannes Berg4c476992010-10-04 21:36:35 +02003209 if (!rdev->ops->add_key)
3210 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003211
Johannes Berge31b8212010-10-05 19:39:30 +02003212 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3213 key.type == NL80211_KEYTYPE_PAIRWISE,
3214 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003215 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003216
3217 wdev_lock(dev->ieee80211_ptr);
3218 err = nl80211_key_allowed(dev->ieee80211_ptr);
3219 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003220 err = rdev_add_key(rdev, dev, key.idx,
3221 key.type == NL80211_KEYTYPE_PAIRWISE,
3222 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003223 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003224
Johannes Berg41ade002007-12-19 02:03:29 +01003225 return err;
3226}
3227
3228static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3229{
Johannes Berg4c476992010-10-04 21:36:35 +02003230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003231 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003232 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003233 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003234 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003235
Johannes Bergb9454e82009-07-08 13:29:08 +02003236 err = nl80211_parse_key(info, &key);
3237 if (err)
3238 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003239
3240 if (info->attrs[NL80211_ATTR_MAC])
3241 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3242
Johannes Berge31b8212010-10-05 19:39:30 +02003243 if (key.type == -1) {
3244 if (mac_addr)
3245 key.type = NL80211_KEYTYPE_PAIRWISE;
3246 else
3247 key.type = NL80211_KEYTYPE_GROUP;
3248 }
3249
3250 /* for now */
3251 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3252 key.type != NL80211_KEYTYPE_GROUP)
3253 return -EINVAL;
3254
Johannes Berg4c476992010-10-04 21:36:35 +02003255 if (!rdev->ops->del_key)
3256 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003257
Johannes Bergfffd0932009-07-08 14:22:54 +02003258 wdev_lock(dev->ieee80211_ptr);
3259 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003260
Johannes Berg0fa7b392015-01-23 11:10:12 +01003261 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003262 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3263 err = -ENOENT;
3264
Johannes Bergfffd0932009-07-08 14:22:54 +02003265 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003266 err = rdev_del_key(rdev, dev, key.idx,
3267 key.type == NL80211_KEYTYPE_PAIRWISE,
3268 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003269
Johannes Berg3d23e342009-09-29 23:27:28 +02003270#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003271 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003272 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003273 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003274 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003275 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3276 }
3277#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003278 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003279
Johannes Berg41ade002007-12-19 02:03:29 +01003280 return err;
3281}
3282
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303283/* This function returns an error or the number of nested attributes */
3284static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3285{
3286 struct nlattr *attr;
3287 int n_entries = 0, tmp;
3288
3289 nla_for_each_nested(attr, nl_attr, tmp) {
3290 if (nla_len(attr) != ETH_ALEN)
3291 return -EINVAL;
3292
3293 n_entries++;
3294 }
3295
3296 return n_entries;
3297}
3298
3299/*
3300 * This function parses ACL information and allocates memory for ACL data.
3301 * On successful return, the calling function is responsible to free the
3302 * ACL buffer returned by this function.
3303 */
3304static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3305 struct genl_info *info)
3306{
3307 enum nl80211_acl_policy acl_policy;
3308 struct nlattr *attr;
3309 struct cfg80211_acl_data *acl;
3310 int i = 0, n_entries, tmp;
3311
3312 if (!wiphy->max_acl_mac_addrs)
3313 return ERR_PTR(-EOPNOTSUPP);
3314
3315 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3316 return ERR_PTR(-EINVAL);
3317
3318 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3319 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3320 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3321 return ERR_PTR(-EINVAL);
3322
3323 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3324 return ERR_PTR(-EINVAL);
3325
3326 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3327 if (n_entries < 0)
3328 return ERR_PTR(n_entries);
3329
3330 if (n_entries > wiphy->max_acl_mac_addrs)
3331 return ERR_PTR(-ENOTSUPP);
3332
3333 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3334 GFP_KERNEL);
3335 if (!acl)
3336 return ERR_PTR(-ENOMEM);
3337
3338 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3339 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3340 i++;
3341 }
3342
3343 acl->n_acl_entries = n_entries;
3344 acl->acl_policy = acl_policy;
3345
3346 return acl;
3347}
3348
3349static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3350{
3351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3352 struct net_device *dev = info->user_ptr[1];
3353 struct cfg80211_acl_data *acl;
3354 int err;
3355
3356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3357 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3358 return -EOPNOTSUPP;
3359
3360 if (!dev->ieee80211_ptr->beacon_interval)
3361 return -EINVAL;
3362
3363 acl = parse_acl_data(&rdev->wiphy, info);
3364 if (IS_ERR(acl))
3365 return PTR_ERR(acl);
3366
3367 err = rdev_set_mac_acl(rdev, dev, acl);
3368
3369 kfree(acl);
3370
3371 return err;
3372}
3373
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303374static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3375 u8 *rates, u8 rates_len)
3376{
3377 u8 i;
3378 u32 mask = 0;
3379
3380 for (i = 0; i < rates_len; i++) {
3381 int rate = (rates[i] & 0x7f) * 5;
3382 int ridx;
3383
3384 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3385 struct ieee80211_rate *srate =
3386 &sband->bitrates[ridx];
3387 if (rate == srate->bitrate) {
3388 mask |= 1 << ridx;
3389 break;
3390 }
3391 }
3392 if (ridx == sband->n_bitrates)
3393 return 0; /* rate not found */
3394 }
3395
3396 return mask;
3397}
3398
3399static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3400 u8 *rates, u8 rates_len,
3401 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3402{
3403 u8 i;
3404
3405 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3406
3407 for (i = 0; i < rates_len; i++) {
3408 int ridx, rbit;
3409
3410 ridx = rates[i] / 8;
3411 rbit = BIT(rates[i] % 8);
3412
3413 /* check validity */
3414 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3415 return false;
3416
3417 /* check availability */
3418 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3419 mcs[ridx] |= rbit;
3420 else
3421 return false;
3422 }
3423
3424 return true;
3425}
3426
3427static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3428{
3429 u16 mcs_mask = 0;
3430
3431 switch (vht_mcs_map) {
3432 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3433 break;
3434 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3435 mcs_mask = 0x00FF;
3436 break;
3437 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3438 mcs_mask = 0x01FF;
3439 break;
3440 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3441 mcs_mask = 0x03FF;
3442 break;
3443 default:
3444 break;
3445 }
3446
3447 return mcs_mask;
3448}
3449
3450static void vht_build_mcs_mask(u16 vht_mcs_map,
3451 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3452{
3453 u8 nss;
3454
3455 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3456 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3457 vht_mcs_map >>= 2;
3458 }
3459}
3460
3461static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3462 struct nl80211_txrate_vht *txrate,
3463 u16 mcs[NL80211_VHT_NSS_MAX])
3464{
3465 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3466 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3467 u8 i;
3468
3469 if (!sband->vht_cap.vht_supported)
3470 return false;
3471
3472 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3473
3474 /* Build vht_mcs_mask from VHT capabilities */
3475 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3476
3477 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3478 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3479 mcs[i] = txrate->mcs[i];
3480 else
3481 return false;
3482 }
3483
3484 return true;
3485}
3486
3487static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3488 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3489 .len = NL80211_MAX_SUPP_RATES },
3490 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3491 .len = NL80211_MAX_SUPP_HT_RATES },
3492 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3493 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3494};
3495
3496static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3497 struct cfg80211_bitrate_mask *mask)
3498{
3499 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3501 int rem, i;
3502 struct nlattr *tx_rates;
3503 struct ieee80211_supported_band *sband;
3504 u16 vht_tx_mcs_map;
3505
3506 memset(mask, 0, sizeof(*mask));
3507 /* Default to all rates enabled */
3508 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3509 sband = rdev->wiphy.bands[i];
3510
3511 if (!sband)
3512 continue;
3513
3514 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3515 memcpy(mask->control[i].ht_mcs,
3516 sband->ht_cap.mcs.rx_mask,
3517 sizeof(mask->control[i].ht_mcs));
3518
3519 if (!sband->vht_cap.vht_supported)
3520 continue;
3521
3522 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3523 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3524 }
3525
3526 /* if no rates are given set it back to the defaults */
3527 if (!info->attrs[NL80211_ATTR_TX_RATES])
3528 goto out;
3529
3530 /* The nested attribute uses enum nl80211_band as the index. This maps
3531 * directly to the enum nl80211_band values used in cfg80211.
3532 */
3533 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3534 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3535 enum nl80211_band band = nla_type(tx_rates);
3536 int err;
3537
3538 if (band < 0 || band >= NUM_NL80211_BANDS)
3539 return -EINVAL;
3540 sband = rdev->wiphy.bands[band];
3541 if (sband == NULL)
3542 return -EINVAL;
3543 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
3544 nla_len(tx_rates), nl80211_txattr_policy);
3545 if (err)
3546 return err;
3547 if (tb[NL80211_TXRATE_LEGACY]) {
3548 mask->control[band].legacy = rateset_to_mask(
3549 sband,
3550 nla_data(tb[NL80211_TXRATE_LEGACY]),
3551 nla_len(tb[NL80211_TXRATE_LEGACY]));
3552 if ((mask->control[band].legacy == 0) &&
3553 nla_len(tb[NL80211_TXRATE_LEGACY]))
3554 return -EINVAL;
3555 }
3556 if (tb[NL80211_TXRATE_HT]) {
3557 if (!ht_rateset_to_mask(
3558 sband,
3559 nla_data(tb[NL80211_TXRATE_HT]),
3560 nla_len(tb[NL80211_TXRATE_HT]),
3561 mask->control[band].ht_mcs))
3562 return -EINVAL;
3563 }
3564 if (tb[NL80211_TXRATE_VHT]) {
3565 if (!vht_set_mcs_mask(
3566 sband,
3567 nla_data(tb[NL80211_TXRATE_VHT]),
3568 mask->control[band].vht_mcs))
3569 return -EINVAL;
3570 }
3571 if (tb[NL80211_TXRATE_GI]) {
3572 mask->control[band].gi =
3573 nla_get_u8(tb[NL80211_TXRATE_GI]);
3574 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3575 return -EINVAL;
3576 }
3577
3578 if (mask->control[band].legacy == 0) {
3579 /* don't allow empty legacy rates if HT or VHT
3580 * are not even supported.
3581 */
3582 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3583 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3584 return -EINVAL;
3585
3586 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3587 if (mask->control[band].ht_mcs[i])
3588 goto out;
3589
3590 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3591 if (mask->control[band].vht_mcs[i])
3592 goto out;
3593
3594 /* legacy and mcs rates may not be both empty */
3595 return -EINVAL;
3596 }
3597 }
3598
3599out:
3600 return 0;
3601}
3602
Johannes Berg8564e382016-09-19 09:44:44 +02003603static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3604 enum nl80211_band band,
3605 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303606{
Johannes Berg8564e382016-09-19 09:44:44 +02003607 u32 count_ht, count_vht, i;
3608 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303609
3610 /* Allow only one rate */
3611 if (hweight32(rate) > 1)
3612 return -EINVAL;
3613
3614 count_ht = 0;
3615 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003616 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303617 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003618 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303619 count_ht++;
3620 if (count_ht > 1)
3621 return -EINVAL;
3622 }
3623 if (count_ht && rate)
3624 return -EINVAL;
3625 }
3626
3627 count_vht = 0;
3628 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003629 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303630 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003631 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303632 count_vht++;
3633 if (count_vht > 1)
3634 return -EINVAL;
3635 }
3636 if (count_vht && rate)
3637 return -EINVAL;
3638 }
3639
3640 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3641 return -EINVAL;
3642
Johannes Berg8564e382016-09-19 09:44:44 +02003643 if (rate &&
3644 !wiphy_ext_feature_isset(&rdev->wiphy,
3645 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3646 return -EINVAL;
3647 if (count_ht &&
3648 !wiphy_ext_feature_isset(&rdev->wiphy,
3649 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3650 return -EINVAL;
3651 if (count_vht &&
3652 !wiphy_ext_feature_isset(&rdev->wiphy,
3653 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3654 return -EINVAL;
3655
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303656 return 0;
3657}
3658
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003659static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003660 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003661{
Johannes Berg88600202012-02-13 15:17:18 +01003662 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003663
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003664 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3665 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3666 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3667 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003668 return -EINVAL;
3669
Johannes Berg88600202012-02-13 15:17:18 +01003670 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003671
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003672 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3673 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3674 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003675 if (!bcn->head_len)
3676 return -EINVAL;
3677 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003678 }
3679
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003680 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3681 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3682 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003683 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003684 }
3685
Johannes Berg4c476992010-10-04 21:36:35 +02003686 if (!haveinfo)
3687 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003688
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003689 if (attrs[NL80211_ATTR_IE]) {
3690 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3691 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003692 }
3693
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003694 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003695 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003696 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003697 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003698 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003699 }
3700
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003701 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003702 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003703 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003704 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003705 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003706 }
3707
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003708 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3709 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3710 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003711 }
3712
Johannes Berg88600202012-02-13 15:17:18 +01003713 return 0;
3714}
3715
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003716static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3717 struct cfg80211_ap_settings *params)
3718{
3719 struct wireless_dev *wdev;
3720 bool ret = false;
3721
Johannes Berg53873f12016-05-03 16:52:04 +03003722 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003723 if (wdev->iftype != NL80211_IFTYPE_AP &&
3724 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3725 continue;
3726
Johannes Berg683b6d32012-11-08 21:25:48 +01003727 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003728 continue;
3729
Johannes Berg683b6d32012-11-08 21:25:48 +01003730 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003731 ret = true;
3732 break;
3733 }
3734
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003735 return ret;
3736}
3737
Jouni Malinene39e5b52012-09-30 19:29:39 +03003738static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3739 enum nl80211_auth_type auth_type,
3740 enum nl80211_commands cmd)
3741{
3742 if (auth_type > NL80211_AUTHTYPE_MAX)
3743 return false;
3744
3745 switch (cmd) {
3746 case NL80211_CMD_AUTHENTICATE:
3747 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3748 auth_type == NL80211_AUTHTYPE_SAE)
3749 return false;
3750 return true;
3751 case NL80211_CMD_CONNECT:
3752 case NL80211_CMD_START_AP:
3753 /* SAE not supported yet */
3754 if (auth_type == NL80211_AUTHTYPE_SAE)
3755 return false;
3756 return true;
3757 default:
3758 return false;
3759 }
3760}
3761
Johannes Berg88600202012-02-13 15:17:18 +01003762static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3763{
3764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3765 struct net_device *dev = info->user_ptr[1];
3766 struct wireless_dev *wdev = dev->ieee80211_ptr;
3767 struct cfg80211_ap_settings params;
3768 int err;
3769
3770 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3771 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3772 return -EOPNOTSUPP;
3773
3774 if (!rdev->ops->start_ap)
3775 return -EOPNOTSUPP;
3776
3777 if (wdev->beacon_interval)
3778 return -EALREADY;
3779
3780 memset(&params, 0, sizeof(params));
3781
3782 /* these are required for START_AP */
3783 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3784 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3785 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3786 return -EINVAL;
3787
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003788 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003789 if (err)
3790 return err;
3791
3792 params.beacon_interval =
3793 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3794 params.dtim_period =
3795 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3796
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05303797 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3798 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003799 if (err)
3800 return err;
3801
3802 /*
3803 * In theory, some of these attributes should be required here
3804 * but since they were not used when the command was originally
3805 * added, keep them optional for old user space programs to let
3806 * them continue to work with drivers that do not need the
3807 * additional information -- drivers must check!
3808 */
3809 if (info->attrs[NL80211_ATTR_SSID]) {
3810 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3811 params.ssid_len =
3812 nla_len(info->attrs[NL80211_ATTR_SSID]);
3813 if (params.ssid_len == 0 ||
3814 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3815 return -EINVAL;
3816 }
3817
3818 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3819 params.hidden_ssid = nla_get_u32(
3820 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3821 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3822 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3823 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3824 return -EINVAL;
3825 }
3826
3827 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3828
3829 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3830 params.auth_type = nla_get_u32(
3831 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003832 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3833 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003834 return -EINVAL;
3835 } else
3836 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3837
3838 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3839 NL80211_MAX_NR_CIPHER_SUITES);
3840 if (err)
3841 return err;
3842
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303843 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3844 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3845 return -EOPNOTSUPP;
3846 params.inactivity_timeout = nla_get_u16(
3847 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3848 }
3849
Johannes Berg53cabad2012-11-14 15:17:28 +01003850 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3851 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3852 return -EINVAL;
3853 params.p2p_ctwindow =
3854 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3855 if (params.p2p_ctwindow > 127)
3856 return -EINVAL;
3857 if (params.p2p_ctwindow != 0 &&
3858 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3859 return -EINVAL;
3860 }
3861
3862 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3863 u8 tmp;
3864
3865 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3866 return -EINVAL;
3867 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3868 if (tmp > 1)
3869 return -EINVAL;
3870 params.p2p_opp_ps = tmp;
3871 if (params.p2p_opp_ps != 0 &&
3872 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3873 return -EINVAL;
3874 }
3875
Johannes Bergaa430da2012-05-16 23:50:18 +02003876 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003877 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3878 if (err)
3879 return err;
3880 } else if (wdev->preset_chandef.chan) {
3881 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003882 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003883 return -EINVAL;
3884
Arik Nemtsov923b3522015-07-08 15:41:44 +03003885 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3886 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003887 return -EINVAL;
3888
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303889 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3890 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3891 if (err)
3892 return err;
3893
Johannes Berg8564e382016-09-19 09:44:44 +02003894 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3895 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303896 if (err)
3897 return err;
3898 }
3899
Eliad Peller18998c32014-09-10 14:07:34 +03003900 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3901 params.smps_mode =
3902 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3903 switch (params.smps_mode) {
3904 case NL80211_SMPS_OFF:
3905 break;
3906 case NL80211_SMPS_STATIC:
3907 if (!(rdev->wiphy.features &
3908 NL80211_FEATURE_STATIC_SMPS))
3909 return -EINVAL;
3910 break;
3911 case NL80211_SMPS_DYNAMIC:
3912 if (!(rdev->wiphy.features &
3913 NL80211_FEATURE_DYNAMIC_SMPS))
3914 return -EINVAL;
3915 break;
3916 default:
3917 return -EINVAL;
3918 }
3919 } else {
3920 params.smps_mode = NL80211_SMPS_OFF;
3921 }
3922
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303923 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3924 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3925 return -EOPNOTSUPP;
3926
Ola Olsson4baf6be2015-10-29 07:04:58 +01003927 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3928 params.acl = parse_acl_data(&rdev->wiphy, info);
3929 if (IS_ERR(params.acl))
3930 return PTR_ERR(params.acl);
3931 }
3932
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003933 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003934 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003935 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003936 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003937 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003938 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003939 wdev->ssid_len = params.ssid_len;
3940 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003941 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003942 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303943
3944 kfree(params.acl);
3945
Johannes Berg56d18932011-05-09 18:41:15 +02003946 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003947}
3948
Johannes Berg88600202012-02-13 15:17:18 +01003949static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3950{
3951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3952 struct net_device *dev = info->user_ptr[1];
3953 struct wireless_dev *wdev = dev->ieee80211_ptr;
3954 struct cfg80211_beacon_data params;
3955 int err;
3956
3957 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3958 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3959 return -EOPNOTSUPP;
3960
3961 if (!rdev->ops->change_beacon)
3962 return -EOPNOTSUPP;
3963
3964 if (!wdev->beacon_interval)
3965 return -EINVAL;
3966
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003967 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003968 if (err)
3969 return err;
3970
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003971 wdev_lock(wdev);
3972 err = rdev_change_beacon(rdev, dev, &params);
3973 wdev_unlock(wdev);
3974
3975 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003976}
3977
3978static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003979{
Johannes Berg4c476992010-10-04 21:36:35 +02003980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3981 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003982
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003983 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003984}
3985
Johannes Berg5727ef12007-12-19 02:03:34 +01003986static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3987 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3988 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3989 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003990 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003991 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003992 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003993};
3994
Johannes Bergeccb8e82009-05-11 21:57:56 +03003995static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003996 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003997 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003998{
3999 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004000 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004001 int flag;
4002
Johannes Bergeccb8e82009-05-11 21:57:56 +03004003 /*
4004 * Try parsing the new attribute first so userspace
4005 * can specify both for older kernels.
4006 */
4007 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4008 if (nla) {
4009 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004010
Johannes Bergeccb8e82009-05-11 21:57:56 +03004011 sta_flags = nla_data(nla);
4012 params->sta_flags_mask = sta_flags->mask;
4013 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004015 if ((params->sta_flags_mask |
4016 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4017 return -EINVAL;
4018 return 0;
4019 }
4020
4021 /* if present, parse the old attribute */
4022
4023 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004024 if (!nla)
4025 return 0;
4026
4027 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4028 nla, sta_flags_policy))
4029 return -EINVAL;
4030
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004031 /*
4032 * Only allow certain flags for interface types so that
4033 * other attributes are silently ignored. Remember that
4034 * this is backward compatibility code with old userspace
4035 * and shouldn't be hit in other cases anyway.
4036 */
4037 switch (iftype) {
4038 case NL80211_IFTYPE_AP:
4039 case NL80211_IFTYPE_AP_VLAN:
4040 case NL80211_IFTYPE_P2P_GO:
4041 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4042 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4043 BIT(NL80211_STA_FLAG_WME) |
4044 BIT(NL80211_STA_FLAG_MFP);
4045 break;
4046 case NL80211_IFTYPE_P2P_CLIENT:
4047 case NL80211_IFTYPE_STATION:
4048 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4049 BIT(NL80211_STA_FLAG_TDLS_PEER);
4050 break;
4051 case NL80211_IFTYPE_MESH_POINT:
4052 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4053 BIT(NL80211_STA_FLAG_MFP) |
4054 BIT(NL80211_STA_FLAG_AUTHORIZED);
4055 default:
4056 return -EINVAL;
4057 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004058
Johannes Berg3383b5a2012-05-10 20:14:43 +02004059 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4060 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004061 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004062
Johannes Berg3383b5a2012-05-10 20:14:43 +02004063 /* no longer support new API additions in old API */
4064 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4065 return -EINVAL;
4066 }
4067 }
4068
Johannes Berg5727ef12007-12-19 02:03:34 +01004069 return 0;
4070}
4071
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004072static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4073 int attr)
4074{
4075 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004076 u32 bitrate;
4077 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004078 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004079
4080 rate = nla_nest_start(msg, attr);
4081 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004082 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004083
4084 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4085 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004086 /* report 16-bit bitrate only if we can */
4087 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004088 if (bitrate > 0 &&
4089 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4090 return false;
4091 if (bitrate_compat > 0 &&
4092 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4093 return false;
4094
Johannes Bergb51f3be2015-01-15 16:14:02 +01004095 switch (info->bw) {
4096 case RATE_INFO_BW_5:
4097 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4098 break;
4099 case RATE_INFO_BW_10:
4100 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4101 break;
4102 default:
4103 WARN_ON(1);
4104 /* fall through */
4105 case RATE_INFO_BW_20:
4106 rate_flg = 0;
4107 break;
4108 case RATE_INFO_BW_40:
4109 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4110 break;
4111 case RATE_INFO_BW_80:
4112 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4113 break;
4114 case RATE_INFO_BW_160:
4115 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4116 break;
4117 }
4118
4119 if (rate_flg && nla_put_flag(msg, rate_flg))
4120 return false;
4121
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004122 if (info->flags & RATE_INFO_FLAGS_MCS) {
4123 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4124 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004125 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4126 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4127 return false;
4128 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4129 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4130 return false;
4131 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4132 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004133 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4134 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4135 return false;
4136 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004137
4138 nla_nest_end(msg, rate);
4139 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004140}
4141
Felix Fietkau119363c2013-04-22 16:29:30 +02004142static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4143 int id)
4144{
4145 void *attr;
4146 int i = 0;
4147
4148 if (!mask)
4149 return true;
4150
4151 attr = nla_nest_start(msg, id);
4152 if (!attr)
4153 return false;
4154
4155 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4156 if (!(mask & BIT(i)))
4157 continue;
4158
4159 if (nla_put_u8(msg, i, signal[i]))
4160 return false;
4161 }
4162
4163 nla_nest_end(msg, attr);
4164
4165 return true;
4166}
4167
Johannes Bergcf5ead82014-11-14 17:14:00 +01004168static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4169 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004170 struct cfg80211_registered_device *rdev,
4171 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004172 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004173{
4174 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004175 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004176
Johannes Bergcf5ead82014-11-14 17:14:00 +01004177 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004178 if (!hdr)
4179 return -1;
4180
David S. Miller9360ffd2012-03-29 04:41:26 -04004181 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4182 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4183 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4184 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004185
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004186 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4187 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004188 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004189
4190#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004191 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304192 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004193 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4194 sinfo->memb)) \
4195 goto nla_put_failure; \
4196 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004197#define PUT_SINFO_U64(attr, memb) do { \
4198 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4199 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4200 sinfo->memb, NL80211_STA_INFO_PAD)) \
4201 goto nla_put_failure; \
4202 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004203
4204 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4205 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4206
4207 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4208 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004209 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004210 (u32)sinfo->rx_bytes))
4211 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004212
4213 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4214 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004215 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4216 (u32)sinfo->tx_bytes))
4217 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004218
Johannes Bergd686b922016-04-26 09:54:11 +02004219 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4220 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004221 PUT_SINFO(LLID, llid, u16);
4222 PUT_SINFO(PLID, plid, u16);
4223 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004224 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004225
John W. Linville66266b32012-03-15 13:25:41 -04004226 switch (rdev->wiphy.signal_type) {
4227 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004228 PUT_SINFO(SIGNAL, signal, u8);
4229 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004230 break;
4231 default:
4232 break;
4233 }
Johannes Berg319090b2014-11-17 14:08:11 +01004234 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004235 if (!nl80211_put_signal(msg, sinfo->chains,
4236 sinfo->chain_signal,
4237 NL80211_STA_INFO_CHAIN_SIGNAL))
4238 goto nla_put_failure;
4239 }
Johannes Berg319090b2014-11-17 14:08:11 +01004240 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004241 if (!nl80211_put_signal(msg, sinfo->chains,
4242 sinfo->chain_signal_avg,
4243 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4244 goto nla_put_failure;
4245 }
Johannes Berg319090b2014-11-17 14:08:11 +01004246 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004247 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4248 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004249 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004250 }
Johannes Berg319090b2014-11-17 14:08:11 +01004251 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004252 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4253 NL80211_STA_INFO_RX_BITRATE))
4254 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004255 }
Johannes Berg319090b2014-11-17 14:08:11 +01004256
4257 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4258 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4259 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4260 PUT_SINFO(TX_FAILED, tx_failed, u32);
4261 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4262 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4263 PUT_SINFO(LOCAL_PM, local_pm, u32);
4264 PUT_SINFO(PEER_PM, peer_pm, u32);
4265 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4266
4267 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004268 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4269 if (!bss_param)
4270 goto nla_put_failure;
4271
David S. Miller9360ffd2012-03-29 04:41:26 -04004272 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4273 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4274 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4275 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4276 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4277 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4278 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4279 sinfo->bss_param.dtim_period) ||
4280 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4281 sinfo->bss_param.beacon_interval))
4282 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004283
4284 nla_nest_end(msg, bss_param);
4285 }
Johannes Berg319090b2014-11-17 14:08:11 +01004286 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004287 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4288 sizeof(struct nl80211_sta_flag_update),
4289 &sinfo->sta_flags))
4290 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004291
Johannes Bergd686b922016-04-26 09:54:11 +02004292 PUT_SINFO_U64(T_OFFSET, t_offset);
4293 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4294 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004295 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004296
4297#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004298#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004299
4300 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4301 struct nlattr *tidsattr;
4302 int tid;
4303
4304 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4305 if (!tidsattr)
4306 goto nla_put_failure;
4307
4308 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4309 struct cfg80211_tid_stats *tidstats;
4310 struct nlattr *tidattr;
4311
4312 tidstats = &sinfo->pertid[tid];
4313
4314 if (!tidstats->filled)
4315 continue;
4316
4317 tidattr = nla_nest_start(msg, tid + 1);
4318 if (!tidattr)
4319 goto nla_put_failure;
4320
Johannes Bergd686b922016-04-26 09:54:11 +02004321#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004322 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004323 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4324 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004325 goto nla_put_failure; \
4326 } while (0)
4327
Johannes Bergd686b922016-04-26 09:54:11 +02004328 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4329 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4330 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4331 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004332
Johannes Bergd686b922016-04-26 09:54:11 +02004333#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004334 nla_nest_end(msg, tidattr);
4335 }
4336
4337 nla_nest_end(msg, tidsattr);
4338 }
4339
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004340 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004341
Johannes Berg319090b2014-11-17 14:08:11 +01004342 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004343 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4344 sinfo->assoc_req_ies))
4345 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004346
Johannes Berg053c0952015-01-16 22:09:00 +01004347 genlmsg_end(msg, hdr);
4348 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004349
4350 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004351 genlmsg_cancel(msg, hdr);
4352 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004353}
4354
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004356 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004357{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004359 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004360 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004361 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004362 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004363 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004364
Johannes Berg56769e72017-03-15 14:26:04 +01004365 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004366 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004367 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01004368 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004369
Johannes Berg97990a02013-04-19 01:02:55 +02004370 if (!wdev->netdev) {
4371 err = -EINVAL;
4372 goto out_err;
4373 }
4374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004375 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004376 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004377 goto out_err;
4378 }
4379
Johannes Bergbba95fe2008-07-29 13:22:51 +02004380 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004381 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004382 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004383 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004384 if (err == -ENOENT)
4385 break;
4386 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004387 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004388
Johannes Bergcf5ead82014-11-14 17:14:00 +01004389 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004390 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004391 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004392 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004393 &sinfo) < 0)
4394 goto out;
4395
4396 sta_idx++;
4397 }
4398
Johannes Bergbba95fe2008-07-29 13:22:51 +02004399 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004400 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004401 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004402 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01004403 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02004404
4405 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004406}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004407
Johannes Berg5727ef12007-12-19 02:03:34 +01004408static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4409{
Johannes Berg4c476992010-10-04 21:36:35 +02004410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4411 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004412 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004413 struct sk_buff *msg;
4414 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004415 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004416
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004417 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004418
4419 if (!info->attrs[NL80211_ATTR_MAC])
4420 return -EINVAL;
4421
4422 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4423
Johannes Berg4c476992010-10-04 21:36:35 +02004424 if (!rdev->ops->get_station)
4425 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004426
Hila Gonene35e4d22012-06-27 17:19:42 +03004427 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004428 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004429 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004431 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004432 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004433 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004434
Johannes Bergcf5ead82014-11-14 17:14:00 +01004435 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4436 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004437 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004438 nlmsg_free(msg);
4439 return -ENOBUFS;
4440 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004441
Johannes Berg4c476992010-10-04 21:36:35 +02004442 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004443}
4444
Johannes Berg77ee7c82013-02-15 00:48:33 +01004445int cfg80211_check_station_change(struct wiphy *wiphy,
4446 struct station_parameters *params,
4447 enum cfg80211_station_type statype)
4448{
Ayala Bekere4208422015-10-23 11:20:06 +03004449 if (params->listen_interval != -1 &&
4450 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004451 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004452
Ayala Beker17b94242016-03-17 15:41:38 +02004453 if (params->support_p2p_ps != -1 &&
4454 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4455 return -EINVAL;
4456
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004457 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004458 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4459 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004460 return -EINVAL;
4461
4462 /* When you run into this, adjust the code below for the new flag */
4463 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4464
4465 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004466 case CFG80211_STA_MESH_PEER_KERNEL:
4467 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004468 /*
4469 * No ignoring the TDLS flag here -- the userspace mesh
4470 * code doesn't have the bug of including TDLS in the
4471 * mask everywhere.
4472 */
4473 if (params->sta_flags_mask &
4474 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4475 BIT(NL80211_STA_FLAG_MFP) |
4476 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4477 return -EINVAL;
4478 break;
4479 case CFG80211_STA_TDLS_PEER_SETUP:
4480 case CFG80211_STA_TDLS_PEER_ACTIVE:
4481 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4482 return -EINVAL;
4483 /* ignore since it can't change */
4484 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4485 break;
4486 default:
4487 /* disallow mesh-specific things */
4488 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4489 return -EINVAL;
4490 if (params->local_pm)
4491 return -EINVAL;
4492 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4493 return -EINVAL;
4494 }
4495
4496 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4497 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4498 /* TDLS can't be set, ... */
4499 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4500 return -EINVAL;
4501 /*
4502 * ... but don't bother the driver with it. This works around
4503 * a hostapd/wpa_supplicant issue -- it always includes the
4504 * TLDS_PEER flag in the mask even for AP mode.
4505 */
4506 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4507 }
4508
Ayala Beker47edb112015-09-21 15:49:53 +03004509 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4510 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004511 /* reject other things that can't change */
4512 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4513 return -EINVAL;
4514 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4515 return -EINVAL;
4516 if (params->supported_rates)
4517 return -EINVAL;
4518 if (params->ext_capab || params->ht_capa || params->vht_capa)
4519 return -EINVAL;
4520 }
4521
Ayala Beker47edb112015-09-21 15:49:53 +03004522 if (statype != CFG80211_STA_AP_CLIENT &&
4523 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004524 if (params->vlan)
4525 return -EINVAL;
4526 }
4527
4528 switch (statype) {
4529 case CFG80211_STA_AP_MLME_CLIENT:
4530 /* Use this only for authorizing/unauthorizing a station */
4531 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4532 return -EOPNOTSUPP;
4533 break;
4534 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004535 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004536 /* accept only the listed bits */
4537 if (params->sta_flags_mask &
4538 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4539 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4540 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4541 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4542 BIT(NL80211_STA_FLAG_WME) |
4543 BIT(NL80211_STA_FLAG_MFP)))
4544 return -EINVAL;
4545
4546 /* but authenticated/associated only if driver handles it */
4547 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4548 params->sta_flags_mask &
4549 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4550 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4551 return -EINVAL;
4552 break;
4553 case CFG80211_STA_IBSS:
4554 case CFG80211_STA_AP_STA:
4555 /* reject any changes other than AUTHORIZED */
4556 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4557 return -EINVAL;
4558 break;
4559 case CFG80211_STA_TDLS_PEER_SETUP:
4560 /* reject any changes other than AUTHORIZED or WME */
4561 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4562 BIT(NL80211_STA_FLAG_WME)))
4563 return -EINVAL;
4564 /* force (at least) rates when authorizing */
4565 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4566 !params->supported_rates)
4567 return -EINVAL;
4568 break;
4569 case CFG80211_STA_TDLS_PEER_ACTIVE:
4570 /* reject any changes */
4571 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004572 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004573 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4574 return -EINVAL;
4575 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004576 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004577 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4578 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004579 return -EINVAL;
4580 break;
4581 }
4582
4583 return 0;
4584}
4585EXPORT_SYMBOL(cfg80211_check_station_change);
4586
Johannes Berg5727ef12007-12-19 02:03:34 +01004587/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004588 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004589 */
Johannes Berg80b99892011-11-18 16:23:01 +01004590static struct net_device *get_vlan(struct genl_info *info,
4591 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004592{
Johannes Berg463d0182009-07-14 00:33:35 +02004593 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004594 struct net_device *v;
4595 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004596
Johannes Berg80b99892011-11-18 16:23:01 +01004597 if (!vlanattr)
4598 return NULL;
4599
4600 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4601 if (!v)
4602 return ERR_PTR(-ENODEV);
4603
4604 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4605 ret = -EINVAL;
4606 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004607 }
Johannes Berg80b99892011-11-18 16:23:01 +01004608
Johannes Berg77ee7c82013-02-15 00:48:33 +01004609 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4610 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4611 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4612 ret = -EINVAL;
4613 goto error;
4614 }
4615
Johannes Berg80b99892011-11-18 16:23:01 +01004616 if (!netif_running(v)) {
4617 ret = -ENETDOWN;
4618 goto error;
4619 }
4620
4621 return v;
4622 error:
4623 dev_put(v);
4624 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004625}
4626
Johannes Berg94e860f2014-01-20 23:58:15 +01004627static const struct nla_policy
4628nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004629 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4630 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4631};
4632
Johannes Bergff276692013-02-15 00:09:01 +01004633static int nl80211_parse_sta_wme(struct genl_info *info,
4634 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004635{
Jouni Malinendf881292013-02-14 21:10:54 +02004636 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4637 struct nlattr *nla;
4638 int err;
4639
Jouni Malinendf881292013-02-14 21:10:54 +02004640 /* parse WME attributes if present */
4641 if (!info->attrs[NL80211_ATTR_STA_WME])
4642 return 0;
4643
4644 nla = info->attrs[NL80211_ATTR_STA_WME];
4645 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4646 nl80211_sta_wme_policy);
4647 if (err)
4648 return err;
4649
4650 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4651 params->uapsd_queues = nla_get_u8(
4652 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4653 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4654 return -EINVAL;
4655
4656 if (tb[NL80211_STA_WME_MAX_SP])
4657 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4658
4659 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4660 return -EINVAL;
4661
4662 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4663
4664 return 0;
4665}
4666
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304667static int nl80211_parse_sta_channel_info(struct genl_info *info,
4668 struct station_parameters *params)
4669{
4670 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4671 params->supported_channels =
4672 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4673 params->supported_channels_len =
4674 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4675 /*
4676 * Need to include at least one (first channel, number of
4677 * channels) tuple for each subband, and must have proper
4678 * tuples for the rest of the data as well.
4679 */
4680 if (params->supported_channels_len < 2)
4681 return -EINVAL;
4682 if (params->supported_channels_len % 2)
4683 return -EINVAL;
4684 }
4685
4686 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4687 params->supported_oper_classes =
4688 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4689 params->supported_oper_classes_len =
4690 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4691 /*
4692 * The value of the Length field of the Supported Operating
4693 * Classes element is between 2 and 253.
4694 */
4695 if (params->supported_oper_classes_len < 2 ||
4696 params->supported_oper_classes_len > 253)
4697 return -EINVAL;
4698 }
4699 return 0;
4700}
4701
Johannes Bergff276692013-02-15 00:09:01 +01004702static int nl80211_set_station_tdls(struct genl_info *info,
4703 struct station_parameters *params)
4704{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304705 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004706 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004707 if (info->attrs[NL80211_ATTR_PEER_AID])
4708 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004709 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4710 params->ht_capa =
4711 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4712 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4713 params->vht_capa =
4714 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4715
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304716 err = nl80211_parse_sta_channel_info(info, params);
4717 if (err)
4718 return err;
4719
Johannes Bergff276692013-02-15 00:09:01 +01004720 return nl80211_parse_sta_wme(info, params);
4721}
4722
Johannes Berg5727ef12007-12-19 02:03:34 +01004723static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4724{
Johannes Berg4c476992010-10-04 21:36:35 +02004725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004726 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004727 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004728 u8 *mac_addr;
4729 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004730
4731 memset(&params, 0, sizeof(params));
4732
Johannes Berg77ee7c82013-02-15 00:48:33 +01004733 if (!rdev->ops->change_station)
4734 return -EOPNOTSUPP;
4735
Ayala Bekere4208422015-10-23 11:20:06 +03004736 /*
4737 * AID and listen_interval properties can be set only for unassociated
4738 * station. Include these parameters here and will check them in
4739 * cfg80211_check_station_change().
4740 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004741 if (info->attrs[NL80211_ATTR_STA_AID])
4742 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004743
4744 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4745 params.listen_interval =
4746 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4747 else
4748 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004749
Ayala Beker17b94242016-03-17 15:41:38 +02004750 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4751 u8 tmp;
4752
4753 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4754 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4755 return -EINVAL;
4756
4757 params.support_p2p_ps = tmp;
4758 } else {
4759 params.support_p2p_ps = -1;
4760 }
4761
Johannes Berg5727ef12007-12-19 02:03:34 +01004762 if (!info->attrs[NL80211_ATTR_MAC])
4763 return -EINVAL;
4764
4765 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4766
4767 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4768 params.supported_rates =
4769 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4770 params.supported_rates_len =
4771 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4772 }
4773
Jouni Malinen9d62a982013-02-14 21:10:13 +02004774 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4775 params.capability =
4776 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4777 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4778 }
4779
4780 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4781 params.ext_capab =
4782 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4783 params.ext_capab_len =
4784 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4785 }
4786
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004787 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004788 return -EINVAL;
4789
Johannes Bergf8bacc22013-02-14 23:27:01 +01004790 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004791 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004792 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4793 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4794 return -EINVAL;
4795 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004796
Johannes Bergf8bacc22013-02-14 23:27:01 +01004797 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004798 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004799 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4800 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4801 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004802 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4803 params.peer_aid = nla_get_u16(
4804 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4805 if (params.peer_aid > IEEE80211_MAX_AID)
4806 return -EINVAL;
4807 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004808 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4809 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004810
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004811 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4812 enum nl80211_mesh_power_mode pm = nla_get_u32(
4813 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4814
4815 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4816 pm > NL80211_MESH_POWER_MAX)
4817 return -EINVAL;
4818
4819 params.local_pm = pm;
4820 }
4821
Johannes Berg77ee7c82013-02-15 00:48:33 +01004822 /* Include parameters for TDLS peer (will check later) */
4823 err = nl80211_set_station_tdls(info, &params);
4824 if (err)
4825 return err;
4826
4827 params.vlan = get_vlan(info, rdev);
4828 if (IS_ERR(params.vlan))
4829 return PTR_ERR(params.vlan);
4830
Johannes Berga97f4422009-06-18 17:23:43 +02004831 switch (dev->ieee80211_ptr->iftype) {
4832 case NL80211_IFTYPE_AP:
4833 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004834 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004835 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004836 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004837 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004838 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004839 break;
4840 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004841 err = -EOPNOTSUPP;
4842 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004843 }
4844
Johannes Berg77ee7c82013-02-15 00:48:33 +01004845 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004846 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004847
Johannes Berg77ee7c82013-02-15 00:48:33 +01004848 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004849 if (params.vlan)
4850 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004851
Johannes Berg5727ef12007-12-19 02:03:34 +01004852 return err;
4853}
4854
4855static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4856{
Johannes Berg4c476992010-10-04 21:36:35 +02004857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004858 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004859 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004860 struct station_parameters params;
4861 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004862 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4863 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004864
4865 memset(&params, 0, sizeof(params));
4866
Johannes Berg984c3112013-02-14 23:43:25 +01004867 if (!rdev->ops->add_station)
4868 return -EOPNOTSUPP;
4869
Johannes Berg5727ef12007-12-19 02:03:34 +01004870 if (!info->attrs[NL80211_ATTR_MAC])
4871 return -EINVAL;
4872
Johannes Berg5727ef12007-12-19 02:03:34 +01004873 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4874 return -EINVAL;
4875
4876 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4877 return -EINVAL;
4878
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004879 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4880 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004881 return -EINVAL;
4882
Johannes Berg5727ef12007-12-19 02:03:34 +01004883 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4884 params.supported_rates =
4885 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4886 params.supported_rates_len =
4887 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4888 params.listen_interval =
4889 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004890
Ayala Beker17b94242016-03-17 15:41:38 +02004891 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4892 u8 tmp;
4893
4894 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4895 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4896 return -EINVAL;
4897
4898 params.support_p2p_ps = tmp;
4899 } else {
4900 /*
4901 * if not specified, assume it's supported for P2P GO interface,
4902 * and is NOT supported for AP interface
4903 */
4904 params.support_p2p_ps =
4905 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4906 }
4907
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004908 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004909 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004910 else
4911 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004912 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4913 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004914
Jouni Malinen9d62a982013-02-14 21:10:13 +02004915 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4916 params.capability =
4917 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4918 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4919 }
4920
4921 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4922 params.ext_capab =
4923 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4924 params.ext_capab_len =
4925 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4926 }
4927
Jouni Malinen36aedc902008-08-25 11:58:58 +03004928 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4929 params.ht_capa =
4930 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004931
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004932 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4933 params.vht_capa =
4934 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4935
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004936 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4937 params.opmode_notif_used = true;
4938 params.opmode_notif =
4939 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4940 }
4941
Johannes Bergf8bacc22013-02-14 23:27:01 +01004942 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004943 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004944 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4945 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4946 return -EINVAL;
4947 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004948
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304949 err = nl80211_parse_sta_channel_info(info, &params);
4950 if (err)
4951 return err;
4952
Johannes Bergff276692013-02-15 00:09:01 +01004953 err = nl80211_parse_sta_wme(info, &params);
4954 if (err)
4955 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004956
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004957 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004958 return -EINVAL;
4959
Johannes Berg496fcc22015-03-12 08:53:27 +02004960 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4961 * as userspace might just pass through the capabilities from the IEs
4962 * directly, rather than enforcing this restriction and returning an
4963 * error in this case.
4964 */
4965 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4966 params.ht_capa = NULL;
4967 params.vht_capa = NULL;
4968 }
4969
Johannes Berg77ee7c82013-02-15 00:48:33 +01004970 /* When you run into this, adjust the code below for the new flag */
4971 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4972
Johannes Bergbdd90d52011-12-14 12:20:27 +01004973 switch (dev->ieee80211_ptr->iftype) {
4974 case NL80211_IFTYPE_AP:
4975 case NL80211_IFTYPE_AP_VLAN:
4976 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004977 /* ignore WME attributes if iface/sta is not capable */
4978 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4979 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4980 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004981
Johannes Bergbdd90d52011-12-14 12:20:27 +01004982 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004983 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4984 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004985 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004986 /* but don't bother the driver with it */
4987 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004988
Johannes Bergd582cff2012-10-26 17:53:44 +02004989 /* allow authenticated/associated only if driver handles it */
4990 if (!(rdev->wiphy.features &
4991 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004992 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004993 return -EINVAL;
4994
Johannes Bergbda95eb2015-11-26 16:26:13 +01004995 /* Older userspace, or userspace wanting to be compatible with
4996 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4997 * and assoc flags in the mask, but assumes the station will be
4998 * added as associated anyway since this was the required driver
4999 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5000 * introduced.
5001 * In order to not bother drivers with this quirk in the API
5002 * set the flags in both the mask and set for new stations in
5003 * this case.
5004 */
5005 if (!(params.sta_flags_mask & auth_assoc)) {
5006 params.sta_flags_mask |= auth_assoc;
5007 params.sta_flags_set |= auth_assoc;
5008 }
5009
Johannes Bergbdd90d52011-12-14 12:20:27 +01005010 /* must be last in here for error handling */
5011 params.vlan = get_vlan(info, rdev);
5012 if (IS_ERR(params.vlan))
5013 return PTR_ERR(params.vlan);
5014 break;
5015 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005016 /* ignore uAPSD data */
5017 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5018
Johannes Bergd582cff2012-10-26 17:53:44 +02005019 /* associated is disallowed */
5020 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5021 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005022 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005023 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5024 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005025 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005026 break;
5027 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005028 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005029 /* ignore uAPSD data */
5030 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5031
Johannes Berg77ee7c82013-02-15 00:48:33 +01005032 /* these are disallowed */
5033 if (params.sta_flags_mask &
5034 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5035 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005036 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005037 /* Only TDLS peers can be added */
5038 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5039 return -EINVAL;
5040 /* Can only add if TDLS ... */
5041 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5042 return -EOPNOTSUPP;
5043 /* ... with external setup is supported */
5044 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5045 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005046 /*
5047 * Older wpa_supplicant versions always mark the TDLS peer
5048 * as authorized, but it shouldn't yet be.
5049 */
5050 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005051 break;
5052 default:
5053 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005054 }
5055
Johannes Bergbdd90d52011-12-14 12:20:27 +01005056 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005057
Hila Gonene35e4d22012-06-27 17:19:42 +03005058 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005059
Johannes Berg5727ef12007-12-19 02:03:34 +01005060 if (params.vlan)
5061 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005062 return err;
5063}
5064
5065static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5066{
Johannes Berg4c476992010-10-04 21:36:35 +02005067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5068 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005069 struct station_del_parameters params;
5070
5071 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005072
5073 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005074 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005075
Johannes Berge80cf852009-05-11 14:43:13 +02005076 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005077 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005079 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5080 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005081
Johannes Berg4c476992010-10-04 21:36:35 +02005082 if (!rdev->ops->del_station)
5083 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005084
Jouni Malinen98856862014-10-20 13:20:45 +03005085 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5086 params.subtype =
5087 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5088 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5089 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5090 return -EINVAL;
5091 } else {
5092 /* Default to Deauthentication frame */
5093 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5094 }
5095
5096 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5097 params.reason_code =
5098 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5099 if (params.reason_code == 0)
5100 return -EINVAL; /* 0 is reserved */
5101 } else {
5102 /* Default to reason code 2 */
5103 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5104 }
5105
Jouni Malinen89c771e2014-10-10 20:52:40 +03005106 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005107}
5108
Eric W. Biederman15e47302012-09-07 20:12:54 +00005109static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005110 int flags, struct net_device *dev,
5111 u8 *dst, u8 *next_hop,
5112 struct mpath_info *pinfo)
5113{
5114 void *hdr;
5115 struct nlattr *pinfoattr;
5116
Henning Rogge1ef4c852014-11-04 16:14:58 +01005117 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005118 if (!hdr)
5119 return -1;
5120
David S. Miller9360ffd2012-03-29 04:41:26 -04005121 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5123 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5124 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5125 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005126
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005127 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5128 if (!pinfoattr)
5129 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005130 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5131 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5132 pinfo->frame_qlen))
5133 goto nla_put_failure;
5134 if (((pinfo->filled & MPATH_INFO_SN) &&
5135 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5136 ((pinfo->filled & MPATH_INFO_METRIC) &&
5137 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5138 pinfo->metric)) ||
5139 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5140 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5141 pinfo->exptime)) ||
5142 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5143 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5144 pinfo->flags)) ||
5145 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5146 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5147 pinfo->discovery_timeout)) ||
5148 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5149 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5150 pinfo->discovery_retries)))
5151 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005152
5153 nla_nest_end(msg, pinfoattr);
5154
Johannes Berg053c0952015-01-16 22:09:00 +01005155 genlmsg_end(msg, hdr);
5156 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005157
5158 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005159 genlmsg_cancel(msg, hdr);
5160 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005161}
5162
5163static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005164 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005165{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005166 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005167 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005168 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005169 u8 dst[ETH_ALEN];
5170 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005171 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005172 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005173
Johannes Berg56769e72017-03-15 14:26:04 +01005174 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005175 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005176 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005177 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005178
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005179 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005180 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005181 goto out_err;
5182 }
5183
Johannes Berg97990a02013-04-19 01:02:55 +02005184 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005185 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005186 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005187 }
5188
Johannes Bergbba95fe2008-07-29 13:22:51 +02005189 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005190 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005191 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005192 if (err == -ENOENT)
5193 break;
5194 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005195 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005196
Eric W. Biederman15e47302012-09-07 20:12:54 +00005197 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005198 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005199 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005200 &pinfo) < 0)
5201 goto out;
5202
5203 path_idx++;
5204 }
5205
Johannes Bergbba95fe2008-07-29 13:22:51 +02005206 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005207 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005208 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005209 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005210 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005211 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005212}
5213
5214static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
5215{
Johannes Berg4c476992010-10-04 21:36:35 +02005216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005217 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005218 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005219 struct mpath_info pinfo;
5220 struct sk_buff *msg;
5221 u8 *dst = NULL;
5222 u8 next_hop[ETH_ALEN];
5223
5224 memset(&pinfo, 0, sizeof(pinfo));
5225
5226 if (!info->attrs[NL80211_ATTR_MAC])
5227 return -EINVAL;
5228
5229 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5230
Johannes Berg4c476992010-10-04 21:36:35 +02005231 if (!rdev->ops->get_mpath)
5232 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005233
Johannes Berg4c476992010-10-04 21:36:35 +02005234 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5235 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005236
Hila Gonene35e4d22012-06-27 17:19:42 +03005237 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005238 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005239 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005240
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005241 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005242 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005243 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005244
Eric W. Biederman15e47302012-09-07 20:12:54 +00005245 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005246 dev, dst, next_hop, &pinfo) < 0) {
5247 nlmsg_free(msg);
5248 return -ENOBUFS;
5249 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005250
Johannes Berg4c476992010-10-04 21:36:35 +02005251 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005252}
5253
5254static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5255{
Johannes Berg4c476992010-10-04 21:36:35 +02005256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5257 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005258 u8 *dst = NULL;
5259 u8 *next_hop = NULL;
5260
5261 if (!info->attrs[NL80211_ATTR_MAC])
5262 return -EINVAL;
5263
5264 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5265 return -EINVAL;
5266
5267 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5268 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5269
Johannes Berg4c476992010-10-04 21:36:35 +02005270 if (!rdev->ops->change_mpath)
5271 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005272
Johannes Berg4c476992010-10-04 21:36:35 +02005273 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5274 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005275
Hila Gonene35e4d22012-06-27 17:19:42 +03005276 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005277}
Johannes Berg4c476992010-10-04 21:36:35 +02005278
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005279static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5280{
Johannes Berg4c476992010-10-04 21:36:35 +02005281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5282 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005283 u8 *dst = NULL;
5284 u8 *next_hop = NULL;
5285
5286 if (!info->attrs[NL80211_ATTR_MAC])
5287 return -EINVAL;
5288
5289 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5290 return -EINVAL;
5291
5292 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5293 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5294
Johannes Berg4c476992010-10-04 21:36:35 +02005295 if (!rdev->ops->add_mpath)
5296 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005297
Johannes Berg4c476992010-10-04 21:36:35 +02005298 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5299 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005300
Hila Gonene35e4d22012-06-27 17:19:42 +03005301 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005302}
5303
5304static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5305{
Johannes Berg4c476992010-10-04 21:36:35 +02005306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5307 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005308 u8 *dst = NULL;
5309
5310 if (info->attrs[NL80211_ATTR_MAC])
5311 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5312
Johannes Berg4c476992010-10-04 21:36:35 +02005313 if (!rdev->ops->del_mpath)
5314 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005315
Hila Gonene35e4d22012-06-27 17:19:42 +03005316 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005317}
5318
Henning Rogge66be7d22014-09-12 08:58:49 +02005319static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5320{
5321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5322 int err;
5323 struct net_device *dev = info->user_ptr[1];
5324 struct mpath_info pinfo;
5325 struct sk_buff *msg;
5326 u8 *dst = NULL;
5327 u8 mpp[ETH_ALEN];
5328
5329 memset(&pinfo, 0, sizeof(pinfo));
5330
5331 if (!info->attrs[NL80211_ATTR_MAC])
5332 return -EINVAL;
5333
5334 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5335
5336 if (!rdev->ops->get_mpp)
5337 return -EOPNOTSUPP;
5338
5339 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5340 return -EOPNOTSUPP;
5341
5342 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5343 if (err)
5344 return err;
5345
5346 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5347 if (!msg)
5348 return -ENOMEM;
5349
5350 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5351 dev, dst, mpp, &pinfo) < 0) {
5352 nlmsg_free(msg);
5353 return -ENOBUFS;
5354 }
5355
5356 return genlmsg_reply(msg, info);
5357}
5358
5359static int nl80211_dump_mpp(struct sk_buff *skb,
5360 struct netlink_callback *cb)
5361{
5362 struct mpath_info pinfo;
5363 struct cfg80211_registered_device *rdev;
5364 struct wireless_dev *wdev;
5365 u8 dst[ETH_ALEN];
5366 u8 mpp[ETH_ALEN];
5367 int path_idx = cb->args[2];
5368 int err;
5369
Johannes Berg56769e72017-03-15 14:26:04 +01005370 rtnl_lock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005371 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5372 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +01005373 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02005374
5375 if (!rdev->ops->dump_mpp) {
5376 err = -EOPNOTSUPP;
5377 goto out_err;
5378 }
5379
5380 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5381 err = -EOPNOTSUPP;
5382 goto out_err;
5383 }
5384
5385 while (1) {
5386 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5387 mpp, &pinfo);
5388 if (err == -ENOENT)
5389 break;
5390 if (err)
5391 goto out_err;
5392
5393 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5394 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5395 wdev->netdev, dst, mpp,
5396 &pinfo) < 0)
5397 goto out;
5398
5399 path_idx++;
5400 }
5401
5402 out:
5403 cb->args[2] = path_idx;
5404 err = skb->len;
5405 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01005406 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02005407 return err;
5408}
5409
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005410static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5411{
Johannes Berg4c476992010-10-04 21:36:35 +02005412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5413 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005414 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005415 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005416 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005417
5418 memset(&params, 0, sizeof(params));
5419 /* default to not changing parameters */
5420 params.use_cts_prot = -1;
5421 params.use_short_preamble = -1;
5422 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005423 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005424 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005425 params.p2p_ctwindow = -1;
5426 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005427
5428 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5429 params.use_cts_prot =
5430 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5431 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5432 params.use_short_preamble =
5433 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5434 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5435 params.use_short_slot_time =
5436 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005437 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5438 params.basic_rates =
5439 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5440 params.basic_rates_len =
5441 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5442 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005443 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5444 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005445 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5446 params.ht_opmode =
5447 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005448
Johannes Berg53cabad2012-11-14 15:17:28 +01005449 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5450 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5451 return -EINVAL;
5452 params.p2p_ctwindow =
5453 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5454 if (params.p2p_ctwindow < 0)
5455 return -EINVAL;
5456 if (params.p2p_ctwindow != 0 &&
5457 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5458 return -EINVAL;
5459 }
5460
5461 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5462 u8 tmp;
5463
5464 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5465 return -EINVAL;
5466 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5467 if (tmp > 1)
5468 return -EINVAL;
5469 params.p2p_opp_ps = tmp;
5470 if (params.p2p_opp_ps &&
5471 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5472 return -EINVAL;
5473 }
5474
Johannes Berg4c476992010-10-04 21:36:35 +02005475 if (!rdev->ops->change_bss)
5476 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005477
Johannes Berg074ac8d2010-09-16 14:58:22 +02005478 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005479 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5480 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005481
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005482 wdev_lock(wdev);
5483 err = rdev_change_bss(rdev, dev, &params);
5484 wdev_unlock(wdev);
5485
5486 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005487}
5488
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005489static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5490{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005491 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005492 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005493 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005494 u32 owner_nlportid;
5495
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005496 /*
5497 * You should only get this when cfg80211 hasn't yet initialized
5498 * completely when built-in to the kernel right between the time
5499 * window between nl80211_init() and regulatory_init(), if that is
5500 * even possible.
5501 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005502 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005503 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005504
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005505 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5506 user_reg_hint_type =
5507 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5508 else
5509 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5510
5511 switch (user_reg_hint_type) {
5512 case NL80211_USER_REG_HINT_USER:
5513 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005514 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5515 return -EINVAL;
5516
5517 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5518 return regulatory_hint_user(data, user_reg_hint_type);
5519 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005520 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5521 owner_nlportid = info->snd_portid;
5522 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5523 } else {
5524 owner_nlportid = 0;
5525 is_indoor = true;
5526 }
5527
5528 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005529 default:
5530 return -EINVAL;
5531 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005532}
5533
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005534static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005535 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005536{
Johannes Berg4c476992010-10-04 21:36:35 +02005537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005538 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005539 struct wireless_dev *wdev = dev->ieee80211_ptr;
5540 struct mesh_config cur_params;
5541 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005542 void *hdr;
5543 struct nlattr *pinfoattr;
5544 struct sk_buff *msg;
5545
Johannes Berg29cbe682010-12-03 09:20:44 +01005546 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5547 return -EOPNOTSUPP;
5548
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005549 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005550 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005551
Johannes Berg29cbe682010-12-03 09:20:44 +01005552 wdev_lock(wdev);
5553 /* If not connected, get default parameters */
5554 if (!wdev->mesh_id_len)
5555 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5556 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005557 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005558 wdev_unlock(wdev);
5559
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005560 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005561 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005562
5563 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005564 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005565 if (!msg)
5566 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005567 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005568 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005569 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005570 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005571 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005572 if (!pinfoattr)
5573 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005574 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5575 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5576 cur_params.dot11MeshRetryTimeout) ||
5577 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5578 cur_params.dot11MeshConfirmTimeout) ||
5579 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5580 cur_params.dot11MeshHoldingTimeout) ||
5581 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5582 cur_params.dot11MeshMaxPeerLinks) ||
5583 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5584 cur_params.dot11MeshMaxRetries) ||
5585 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5586 cur_params.dot11MeshTTL) ||
5587 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5588 cur_params.element_ttl) ||
5589 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5590 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005591 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5592 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005593 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5594 cur_params.dot11MeshHWMPmaxPREQretries) ||
5595 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5596 cur_params.path_refresh_time) ||
5597 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5598 cur_params.min_discovery_timeout) ||
5599 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5600 cur_params.dot11MeshHWMPactivePathTimeout) ||
5601 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5602 cur_params.dot11MeshHWMPpreqMinInterval) ||
5603 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5604 cur_params.dot11MeshHWMPperrMinInterval) ||
5605 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5606 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5607 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5608 cur_params.dot11MeshHWMPRootMode) ||
5609 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5610 cur_params.dot11MeshHWMPRannInterval) ||
5611 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5612 cur_params.dot11MeshGateAnnouncementProtocol) ||
5613 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5614 cur_params.dot11MeshForwarding) ||
5615 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005616 cur_params.rssi_threshold) ||
5617 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005618 cur_params.ht_opmode) ||
5619 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5620 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5621 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005622 cur_params.dot11MeshHWMProotInterval) ||
5623 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005624 cur_params.dot11MeshHWMPconfirmationInterval) ||
5625 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5626 cur_params.power_mode) ||
5627 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005628 cur_params.dot11MeshAwakeWindowDuration) ||
5629 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5630 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005631 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005632 nla_nest_end(msg, pinfoattr);
5633 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005634 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005635
Johannes Berg3b858752009-03-12 09:55:09 +01005636 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005637 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005638 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005639 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005640 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005641}
5642
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005643static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005644 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5645 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5646 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5647 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5648 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5649 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005650 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005651 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005652 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005653 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5654 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5655 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5656 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5657 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005658 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005659 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005660 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005661 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005662 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005663 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005664 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5665 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005666 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5667 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005668 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005669 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5670 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005671 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005672};
5673
Javier Cardonac80d5452010-12-16 17:37:49 -08005674static const struct nla_policy
5675 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005676 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005677 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5678 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005679 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005680 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005681 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005682 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005683 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005684 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005685};
5686
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005687static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5688{
5689 u8 val = nla_get_u8(nla);
5690 if (val < min || val > max)
5691 return -EINVAL;
5692 *out = val;
5693 return 0;
5694}
5695
5696static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5697{
5698 u8 val = nla_get_u8(nla);
5699 if (val < min || val > max)
5700 return -EINVAL;
5701 *out = val;
5702 return 0;
5703}
5704
5705static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5706{
5707 u16 val = nla_get_u16(nla);
5708 if (val < min || val > max)
5709 return -EINVAL;
5710 *out = val;
5711 return 0;
5712}
5713
5714static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5715{
5716 u32 val = nla_get_u32(nla);
5717 if (val < min || val > max)
5718 return -EINVAL;
5719 *out = val;
5720 return 0;
5721}
5722
5723static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5724{
5725 s32 val = nla_get_s32(nla);
5726 if (val < min || val > max)
5727 return -EINVAL;
5728 *out = val;
5729 return 0;
5730}
5731
Johannes Bergff9a71a2016-08-11 14:59:53 +02005732static int nl80211_check_power_mode(const struct nlattr *nla,
5733 enum nl80211_mesh_power_mode min,
5734 enum nl80211_mesh_power_mode max,
5735 enum nl80211_mesh_power_mode *out)
5736{
5737 u32 val = nla_get_u32(nla);
5738 if (val < min || val > max)
5739 return -EINVAL;
5740 *out = val;
5741 return 0;
5742}
5743
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005744static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005745 struct mesh_config *cfg,
5746 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005747{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005748 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005749 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005750 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005751
Marco Porschea54fba2013-01-07 16:04:48 +01005752#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5753do { \
5754 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005755 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005756 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005757 mask |= (1 << (attr - 1)); \
5758 } \
5759} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005760
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005761 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005762 return -EINVAL;
5763 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005764 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005765 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005766 return -EINVAL;
5767
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005768 /* This makes sure that there aren't more than 32 mesh config
5769 * parameters (otherwise our bitfield scheme would not work.) */
5770 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5771
5772 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005773 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005774 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005775 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005776 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005777 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005778 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005779 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005780 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005781 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005783 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005784 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005785 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005786 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005787 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005788 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005789 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005790 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005791 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005792 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005793 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005794 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005795 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005796 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5797 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005798 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005799 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005800 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005801 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005802 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005803 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005804 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005805 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005807 mask, NL80211_MESHCONF_MIN_DISCOVERY_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, dot11MeshHWMPactivePathTimeout,
5810 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005811 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005812 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005813 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005814 1, 65535, mask,
5815 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005816 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005817 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005818 1, 65535, mask,
5819 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005820 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005822 dot11MeshHWMPnetDiameterTraversalTime,
5823 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005824 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005825 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5827 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005828 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5830 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005831 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005832 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005833 dot11MeshGateAnnouncementProtocol, 0, 1,
5834 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005835 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005836 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005837 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005838 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005840 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005841 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005842 /*
5843 * Check HT operation mode based on
5844 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5845 */
5846 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5847 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5848
5849 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5850 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5851 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5852 return -EINVAL;
5853
5854 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5855 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5856 return -EINVAL;
5857
5858 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5859 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5860 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5861 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5862 return -EINVAL;
5863 break;
5864 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5865 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5866 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5867 return -EINVAL;
5868 break;
5869 }
5870 cfg->ht_opmode = ht_opmode;
Masashi Honmaf9bd7912017-01-26 08:56:13 +09005871 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09005872 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005874 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005875 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005876 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005877 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005878 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005879 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005880 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005881 dot11MeshHWMPconfirmationInterval,
5882 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005883 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005884 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005885 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5886 NL80211_MESH_POWER_ACTIVE,
5887 NL80211_MESH_POWER_MAX,
5888 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005889 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5891 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005892 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005894 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005895 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005896 if (mask_out)
5897 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005898
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005899 return 0;
5900
5901#undef FILL_IN_MESH_PARAM_IF_SET
5902}
5903
Javier Cardonac80d5452010-12-16 17:37:49 -08005904static int nl80211_parse_mesh_setup(struct genl_info *info,
5905 struct mesh_setup *setup)
5906{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005908 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5909
5910 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5911 return -EINVAL;
5912 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5913 info->attrs[NL80211_ATTR_MESH_SETUP],
5914 nl80211_mesh_setup_params_policy))
5915 return -EINVAL;
5916
Javier Cardonad299a1f2012-03-31 11:31:33 -07005917 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5918 setup->sync_method =
5919 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5920 IEEE80211_SYNC_METHOD_VENDOR :
5921 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5922
Javier Cardonac80d5452010-12-16 17:37:49 -08005923 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5924 setup->path_sel_proto =
5925 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5926 IEEE80211_PATH_PROTOCOL_VENDOR :
5927 IEEE80211_PATH_PROTOCOL_HWMP;
5928
5929 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5930 setup->path_metric =
5931 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5932 IEEE80211_PATH_METRIC_VENDOR :
5933 IEEE80211_PATH_METRIC_AIRTIME;
5934
Javier Cardona581a8b02011-04-07 15:08:27 -07005935 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005936 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005937 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005938 if (!is_valid_ie_attr(ieattr))
5939 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005940 setup->ie = nla_data(ieattr);
5941 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005942 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005943 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5944 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5945 return -EINVAL;
5946 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005947 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5948 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005949 if (setup->is_secure)
5950 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005951
Colleen Twitty6e16d902013-05-08 11:45:59 -07005952 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5953 if (!setup->user_mpm)
5954 return -EINVAL;
5955 setup->auth_id =
5956 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5957 }
5958
Javier Cardonac80d5452010-12-16 17:37:49 -08005959 return 0;
5960}
5961
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005962static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005963 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005964{
5965 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5966 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005967 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005968 struct mesh_config cfg;
5969 u32 mask;
5970 int err;
5971
Johannes Berg29cbe682010-12-03 09:20:44 +01005972 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5973 return -EOPNOTSUPP;
5974
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005975 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005976 return -EOPNOTSUPP;
5977
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005978 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005979 if (err)
5980 return err;
5981
Johannes Berg29cbe682010-12-03 09:20:44 +01005982 wdev_lock(wdev);
5983 if (!wdev->mesh_id_len)
5984 err = -ENOLINK;
5985
5986 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005987 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005988
5989 wdev_unlock(wdev);
5990
5991 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005992}
5993
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005994static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5995 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005996{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005997 struct nlattr *nl_reg_rules;
5998 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005999
Johannes Berg458f4f92012-12-06 15:47:38 +01006000 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6001 (regdom->dfs_region &&
6002 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006003 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006004
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006005 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6006 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006007 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006008
Johannes Berg458f4f92012-12-06 15:47:38 +01006009 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006010 struct nlattr *nl_reg_rule;
6011 const struct ieee80211_reg_rule *reg_rule;
6012 const struct ieee80211_freq_range *freq_range;
6013 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006014 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006015
Johannes Berg458f4f92012-12-06 15:47:38 +01006016 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006017 freq_range = &reg_rule->freq_range;
6018 power_rule = &reg_rule->power_rule;
6019
6020 nl_reg_rule = nla_nest_start(msg, i);
6021 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006022 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006023
Janusz Dziedzic97524822014-01-30 09:52:20 +01006024 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6025 if (!max_bandwidth_khz)
6026 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6027 reg_rule);
6028
David S. Miller9360ffd2012-03-29 04:41:26 -04006029 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6030 reg_rule->flags) ||
6031 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6032 freq_range->start_freq_khz) ||
6033 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6034 freq_range->end_freq_khz) ||
6035 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006036 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006037 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6038 power_rule->max_antenna_gain) ||
6039 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006040 power_rule->max_eirp) ||
6041 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6042 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006043 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006044
6045 nla_nest_end(msg, nl_reg_rule);
6046 }
6047
6048 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006049 return 0;
6050
6051nla_put_failure:
6052 return -EMSGSIZE;
6053}
6054
6055static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6056{
6057 const struct ieee80211_regdomain *regdom = NULL;
6058 struct cfg80211_registered_device *rdev;
6059 struct wiphy *wiphy = NULL;
6060 struct sk_buff *msg;
6061 void *hdr;
6062
6063 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6064 if (!msg)
6065 return -ENOBUFS;
6066
6067 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6068 NL80211_CMD_GET_REG);
6069 if (!hdr)
6070 goto put_failure;
6071
6072 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006073 bool self_managed;
6074
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006075 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6076 if (IS_ERR(rdev)) {
6077 nlmsg_free(msg);
6078 return PTR_ERR(rdev);
6079 }
6080
6081 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006082 self_managed = wiphy->regulatory_flags &
6083 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006084 regdom = get_wiphy_regdom(wiphy);
6085
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006086 /* a self-managed-reg device must have a private regdom */
6087 if (WARN_ON(!regdom && self_managed)) {
6088 nlmsg_free(msg);
6089 return -EINVAL;
6090 }
6091
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006092 if (regdom &&
6093 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6094 goto nla_put_failure;
6095 }
6096
6097 if (!wiphy && reg_last_request_cell_base() &&
6098 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6099 NL80211_USER_REG_HINT_CELL_BASE))
6100 goto nla_put_failure;
6101
6102 rcu_read_lock();
6103
6104 if (!regdom)
6105 regdom = rcu_dereference(cfg80211_regdomain);
6106
6107 if (nl80211_put_regdom(regdom, msg))
6108 goto nla_put_failure_rcu;
6109
6110 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006111
6112 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006113 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006114
Johannes Berg458f4f92012-12-06 15:47:38 +01006115nla_put_failure_rcu:
6116 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006117nla_put_failure:
6118 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006119put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006120 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006121 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006122}
6123
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006124static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6125 u32 seq, int flags, struct wiphy *wiphy,
6126 const struct ieee80211_regdomain *regdom)
6127{
6128 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6129 NL80211_CMD_GET_REG);
6130
6131 if (!hdr)
6132 return -1;
6133
6134 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6135
6136 if (nl80211_put_regdom(regdom, msg))
6137 goto nla_put_failure;
6138
6139 if (!wiphy && reg_last_request_cell_base() &&
6140 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6141 NL80211_USER_REG_HINT_CELL_BASE))
6142 goto nla_put_failure;
6143
6144 if (wiphy &&
6145 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6146 goto nla_put_failure;
6147
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006148 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6149 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6150 goto nla_put_failure;
6151
Johannes Berg053c0952015-01-16 22:09:00 +01006152 genlmsg_end(msg, hdr);
6153 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006154
6155nla_put_failure:
6156 genlmsg_cancel(msg, hdr);
6157 return -EMSGSIZE;
6158}
6159
6160static int nl80211_get_reg_dump(struct sk_buff *skb,
6161 struct netlink_callback *cb)
6162{
6163 const struct ieee80211_regdomain *regdom = NULL;
6164 struct cfg80211_registered_device *rdev;
6165 int err, reg_idx, start = cb->args[2];
6166
6167 rtnl_lock();
6168
6169 if (cfg80211_regdomain && start == 0) {
6170 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6171 NLM_F_MULTI, NULL,
6172 rtnl_dereference(cfg80211_regdomain));
6173 if (err < 0)
6174 goto out_err;
6175 }
6176
6177 /* the global regdom is idx 0 */
6178 reg_idx = 1;
6179 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6180 regdom = get_wiphy_regdom(&rdev->wiphy);
6181 if (!regdom)
6182 continue;
6183
6184 if (++reg_idx <= start)
6185 continue;
6186
6187 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6188 NLM_F_MULTI, &rdev->wiphy, regdom);
6189 if (err < 0) {
6190 reg_idx--;
6191 break;
6192 }
6193 }
6194
6195 cb->args[2] = reg_idx;
6196 err = skb->len;
6197out_err:
6198 rtnl_unlock();
6199 return err;
6200}
6201
Johannes Bergb6863032015-10-15 09:25:18 +02006202#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6203static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6204 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6205 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6206 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6207 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6208 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6209 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6210 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6211};
6212
6213static int parse_reg_rule(struct nlattr *tb[],
6214 struct ieee80211_reg_rule *reg_rule)
6215{
6216 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6217 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6218
6219 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6220 return -EINVAL;
6221 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6222 return -EINVAL;
6223 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6224 return -EINVAL;
6225 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6226 return -EINVAL;
6227 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6228 return -EINVAL;
6229
6230 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6231
6232 freq_range->start_freq_khz =
6233 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6234 freq_range->end_freq_khz =
6235 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6236 freq_range->max_bandwidth_khz =
6237 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6238
6239 power_rule->max_eirp =
6240 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6241
6242 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6243 power_rule->max_antenna_gain =
6244 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6245
6246 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6247 reg_rule->dfs_cac_ms =
6248 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6249
6250 return 0;
6251}
6252
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006253static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6254{
6255 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6256 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006257 char *alpha2;
6258 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006259 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006260 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006261 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006262
6263 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6264 return -EINVAL;
6265
6266 if (!info->attrs[NL80211_ATTR_REG_RULES])
6267 return -EINVAL;
6268
6269 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6270
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006271 if (info->attrs[NL80211_ATTR_DFS_REGION])
6272 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6273
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006274 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006275 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006276 num_rules++;
6277 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006278 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006279 }
6280
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006281 if (!reg_is_valid_request(alpha2))
6282 return -EINVAL;
6283
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006284 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006285 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006286
6287 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006288 if (!rd)
6289 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006290
6291 rd->n_reg_rules = num_rules;
6292 rd->alpha2[0] = alpha2[0];
6293 rd->alpha2[1] = alpha2[1];
6294
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006295 /*
6296 * Disable DFS master mode if the DFS region was
6297 * not supported or known on this kernel.
6298 */
6299 if (reg_supported_dfs_region(dfs_region))
6300 rd->dfs_region = dfs_region;
6301
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006302 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006303 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01006304 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
6305 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
6306 reg_rule_policy);
6307 if (r)
6308 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006309 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6310 if (r)
6311 goto bad_reg;
6312
6313 rule_idx++;
6314
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006315 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6316 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006317 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006318 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006319 }
6320
Johannes Berg06627992016-06-09 10:40:09 +02006321 /* set_regdom takes ownership of rd */
6322 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006323 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006324 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006325 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006326}
Johannes Bergb6863032015-10-15 09:25:18 +02006327#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006328
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006329static int validate_scan_freqs(struct nlattr *freqs)
6330{
6331 struct nlattr *attr1, *attr2;
6332 int n_channels = 0, tmp1, tmp2;
6333
6334 nla_for_each_nested(attr1, freqs, tmp1) {
6335 n_channels++;
6336 /*
6337 * Some hardware has a limited channel list for
6338 * scanning, and it is pretty much nonsensical
6339 * to scan for a channel twice, so disallow that
6340 * and don't require drivers to check that the
6341 * channel list they get isn't longer than what
6342 * they can scan, as long as they can scan all
6343 * the channels they registered at once.
6344 */
6345 nla_for_each_nested(attr2, freqs, tmp2)
6346 if (attr1 != attr2 &&
6347 nla_get_u32(attr1) == nla_get_u32(attr2))
6348 return 0;
6349 }
6350
6351 return n_channels;
6352}
6353
Johannes Berg57fbcce2016-04-12 15:56:15 +02006354static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006355{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006356 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006357}
6358
6359static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6360 struct cfg80211_bss_selection *bss_select)
6361{
6362 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6363 struct nlattr *nest;
6364 int err;
6365 bool found = false;
6366 int i;
6367
6368 /* only process one nested attribute */
6369 nest = nla_data(nla);
6370 if (!nla_ok(nest, nla_len(nest)))
6371 return -EINVAL;
6372
6373 err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
6374 nla_len(nest), nl80211_bss_select_policy);
6375 if (err)
6376 return err;
6377
6378 /* only one attribute may be given */
6379 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6380 if (attr[i]) {
6381 if (found)
6382 return -EINVAL;
6383 found = true;
6384 }
6385 }
6386
6387 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6388
6389 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6390 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6391
6392 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6393 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6394 bss_select->param.band_pref =
6395 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6396 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6397 return -EINVAL;
6398 }
6399
6400 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6401 struct nl80211_bss_select_rssi_adjust *adj_param;
6402
6403 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6404 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6405 bss_select->param.adjust.band = adj_param->band;
6406 bss_select->param.adjust.delta = adj_param->delta;
6407 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6408 return -EINVAL;
6409 }
6410
6411 /* user-space did not provide behaviour attribute */
6412 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6413 return -EINVAL;
6414
6415 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6416 return -EINVAL;
6417
6418 return 0;
6419}
6420
Johannes Bergad2b26a2014-06-12 21:39:05 +02006421static int nl80211_parse_random_mac(struct nlattr **attrs,
6422 u8 *mac_addr, u8 *mac_addr_mask)
6423{
6424 int i;
6425
6426 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006427 eth_zero_addr(mac_addr);
6428 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006429 mac_addr[0] = 0x2;
6430 mac_addr_mask[0] = 0x3;
6431
6432 return 0;
6433 }
6434
6435 /* need both or none */
6436 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6437 return -EINVAL;
6438
6439 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6440 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6441
6442 /* don't allow or configure an mcast address */
6443 if (!is_multicast_ether_addr(mac_addr_mask) ||
6444 is_multicast_ether_addr(mac_addr))
6445 return -EINVAL;
6446
6447 /*
6448 * allow users to pass a MAC address that has bits set outside
6449 * of the mask, but don't bother drivers with having to deal
6450 * with such bits
6451 */
6452 for (i = 0; i < ETH_ALEN; i++)
6453 mac_addr[i] &= mac_addr_mask[i];
6454
6455 return 0;
6456}
6457
Johannes Berg2a519312009-02-10 21:25:55 +01006458static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6459{
Johannes Berg4c476992010-10-04 21:36:35 +02006460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006461 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006462 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006463 struct nlattr *attr;
6464 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006465 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006466 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006467
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006468 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6469 return -EINVAL;
6470
Johannes Berg79c97e92009-07-07 03:56:12 +02006471 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006472
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006473 if (wdev->iftype == NL80211_IFTYPE_NAN)
6474 return -EOPNOTSUPP;
6475
Johannes Berg4c476992010-10-04 21:36:35 +02006476 if (!rdev->ops->scan)
6477 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006478
Johannes Bergf9d15d12014-01-22 11:14:19 +02006479 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006480 err = -EBUSY;
6481 goto unlock;
6482 }
Johannes Berg2a519312009-02-10 21:25:55 +01006483
6484 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006485 n_channels = validate_scan_freqs(
6486 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006487 if (!n_channels) {
6488 err = -EINVAL;
6489 goto unlock;
6490 }
Johannes Berg2a519312009-02-10 21:25:55 +01006491 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006492 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006493 }
6494
6495 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6496 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6497 n_ssids++;
6498
Johannes Bergf9f47522013-03-19 15:04:07 +01006499 if (n_ssids > wiphy->max_scan_ssids) {
6500 err = -EINVAL;
6501 goto unlock;
6502 }
Johannes Berg2a519312009-02-10 21:25:55 +01006503
Jouni Malinen70692ad2009-02-16 19:39:13 +02006504 if (info->attrs[NL80211_ATTR_IE])
6505 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6506 else
6507 ie_len = 0;
6508
Johannes Bergf9f47522013-03-19 15:04:07 +01006509 if (ie_len > wiphy->max_scan_ie_len) {
6510 err = -EINVAL;
6511 goto unlock;
6512 }
Johannes Berg18a83652009-03-31 12:12:05 +02006513
Johannes Berg2a519312009-02-10 21:25:55 +01006514 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006515 + sizeof(*request->ssids) * n_ssids
6516 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006517 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006518 if (!request) {
6519 err = -ENOMEM;
6520 goto unlock;
6521 }
Johannes Berg2a519312009-02-10 21:25:55 +01006522
Johannes Berg2a519312009-02-10 21:25:55 +01006523 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006524 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006525 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006526 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006527 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006528 request->ie = (void *)(request->ssids + n_ssids);
6529 else
6530 request->ie = (void *)(request->channels + n_channels);
6531 }
Johannes Berg2a519312009-02-10 21:25:55 +01006532
Johannes Berg584991d2009-11-02 13:32:03 +01006533 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006534 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6535 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006536 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006537 struct ieee80211_channel *chan;
6538
6539 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6540
6541 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006542 err = -EINVAL;
6543 goto out_free;
6544 }
Johannes Berg584991d2009-11-02 13:32:03 +01006545
6546 /* ignore disabled channels */
6547 if (chan->flags & IEEE80211_CHAN_DISABLED)
6548 continue;
6549
6550 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006551 i++;
6552 }
6553 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006554 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006555
Johannes Berg2a519312009-02-10 21:25:55 +01006556 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006557 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006558 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006559
Johannes Berg2a519312009-02-10 21:25:55 +01006560 if (!wiphy->bands[band])
6561 continue;
6562 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006563 struct ieee80211_channel *chan;
6564
6565 chan = &wiphy->bands[band]->channels[j];
6566
6567 if (chan->flags & IEEE80211_CHAN_DISABLED)
6568 continue;
6569
6570 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006571 i++;
6572 }
6573 }
6574 }
6575
Johannes Berg584991d2009-11-02 13:32:03 +01006576 if (!i) {
6577 err = -EINVAL;
6578 goto out_free;
6579 }
6580
6581 request->n_channels = i;
6582
Johannes Berg2a519312009-02-10 21:25:55 +01006583 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006584 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006585 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006586 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006587 err = -EINVAL;
6588 goto out_free;
6589 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006590 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006591 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006592 i++;
6593 }
6594 }
6595
Jouni Malinen70692ad2009-02-16 19:39:13 +02006596 if (info->attrs[NL80211_ATTR_IE]) {
6597 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006598 memcpy((void *)request->ie,
6599 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006600 request->ie_len);
6601 }
6602
Johannes Berg57fbcce2016-04-12 15:56:15 +02006603 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006604 if (wiphy->bands[i])
6605 request->rates[i] =
6606 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006607
6608 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6609 nla_for_each_nested(attr,
6610 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6611 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006612 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006613
Johannes Berg57fbcce2016-04-12 15:56:15 +02006614 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006615 err = -EINVAL;
6616 goto out_free;
6617 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006618
6619 if (!wiphy->bands[band])
6620 continue;
6621
Johannes Berg34850ab2011-07-18 18:08:35 +02006622 err = ieee80211_get_ratemask(wiphy->bands[band],
6623 nla_data(attr),
6624 nla_len(attr),
6625 &request->rates[band]);
6626 if (err)
6627 goto out_free;
6628 }
6629 }
6630
Avraham Stern1d762502016-07-05 17:10:13 +03006631 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6632 if (!wiphy_ext_feature_isset(wiphy,
6633 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6634 err = -EOPNOTSUPP;
6635 goto out_free;
6636 }
6637
6638 request->duration =
6639 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6640 request->duration_mandatory =
6641 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6642 }
6643
Sam Leffler46856bb2012-10-11 21:03:32 -07006644 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006645 request->flags = nla_get_u32(
6646 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006647 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6648 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006649 err = -EOPNOTSUPP;
6650 goto out_free;
6651 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006652
6653 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6654 if (!(wiphy->features &
6655 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6656 err = -EOPNOTSUPP;
6657 goto out_free;
6658 }
6659
6660 if (wdev->current_bss) {
6661 err = -EOPNOTSUPP;
6662 goto out_free;
6663 }
6664
6665 err = nl80211_parse_random_mac(info->attrs,
6666 request->mac_addr,
6667 request->mac_addr_mask);
6668 if (err)
6669 goto out_free;
6670 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006671 }
Sam Lefflered4737712012-10-11 21:03:31 -07006672
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306673 request->no_cck =
6674 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6675
Vamsi Krishna45816392016-12-02 23:59:08 +02006676 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6677 * BSSID to scan for. This was problematic because that same attribute
6678 * was already used for another purpose (local random MAC address). The
6679 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6680 * compatibility with older userspace components, also use the
6681 * NL80211_ATTR_MAC value here if it can be determined to be used for
6682 * the specific BSSID use case instead of the random MAC address
6683 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6684 */
6685 if (info->attrs[NL80211_ATTR_BSSID])
6686 memcpy(request->bssid,
6687 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
6688 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
6689 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02006690 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6691 ETH_ALEN);
6692 else
6693 eth_broadcast_addr(request->bssid);
6694
Johannes Bergfd014282012-06-18 19:17:03 +02006695 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006696 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006697 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006698
Johannes Berg79c97e92009-07-07 03:56:12 +02006699 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006700 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006701
Johannes Berg463d0182009-07-14 00:33:35 +02006702 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006703 nl80211_send_scan_start(rdev, wdev);
6704 if (wdev->netdev)
6705 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006706 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006707 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006708 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006709 kfree(request);
6710 }
Johannes Berg3b858752009-03-12 09:55:09 +01006711
Johannes Bergf9f47522013-03-19 15:04:07 +01006712 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006713 return err;
6714}
6715
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306716static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6717{
6718 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6719 struct wireless_dev *wdev = info->user_ptr[1];
6720
6721 if (!rdev->ops->abort_scan)
6722 return -EOPNOTSUPP;
6723
6724 if (rdev->scan_msg)
6725 return 0;
6726
6727 if (!rdev->scan_req)
6728 return -ENOENT;
6729
6730 rdev_abort_scan(rdev, wdev);
6731 return 0;
6732}
6733
Avraham Stern3b06d272015-10-12 09:51:34 +03006734static int
6735nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6736 struct cfg80211_sched_scan_request *request,
6737 struct nlattr **attrs)
6738{
6739 int tmp, err, i = 0;
6740 struct nlattr *attr;
6741
6742 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6743 u32 interval;
6744
6745 /*
6746 * If scan plans are not specified,
6747 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6748 * case one scan plan will be set with the specified scan
6749 * interval and infinite number of iterations.
6750 */
6751 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6752 return -EINVAL;
6753
6754 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6755 if (!interval)
6756 return -EINVAL;
6757
6758 request->scan_plans[0].interval =
6759 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6760 if (!request->scan_plans[0].interval)
6761 return -EINVAL;
6762
6763 if (request->scan_plans[0].interval >
6764 wiphy->max_sched_scan_plan_interval)
6765 request->scan_plans[0].interval =
6766 wiphy->max_sched_scan_plan_interval;
6767
6768 return 0;
6769 }
6770
6771 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6772 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6773
6774 if (WARN_ON(i >= n_plans))
6775 return -EINVAL;
6776
6777 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6778 nla_data(attr), nla_len(attr),
6779 nl80211_plan_policy);
6780 if (err)
6781 return err;
6782
6783 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6784 return -EINVAL;
6785
6786 request->scan_plans[i].interval =
6787 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6788 if (!request->scan_plans[i].interval ||
6789 request->scan_plans[i].interval >
6790 wiphy->max_sched_scan_plan_interval)
6791 return -EINVAL;
6792
6793 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6794 request->scan_plans[i].iterations =
6795 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6796 if (!request->scan_plans[i].iterations ||
6797 (request->scan_plans[i].iterations >
6798 wiphy->max_sched_scan_plan_iterations))
6799 return -EINVAL;
6800 } else if (i < n_plans - 1) {
6801 /*
6802 * All scan plans but the last one must specify
6803 * a finite number of iterations
6804 */
6805 return -EINVAL;
6806 }
6807
6808 i++;
6809 }
6810
6811 /*
6812 * The last scan plan must not specify the number of
6813 * iterations, it is supposed to run infinitely
6814 */
6815 if (request->scan_plans[n_plans - 1].iterations)
6816 return -EINVAL;
6817
6818 return 0;
6819}
6820
Luciano Coelho256da022014-11-10 16:13:46 +02006821static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006822nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006823 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006824{
6825 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006826 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006827 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006828 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006829 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006830 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006831 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006832
Luciano Coelho256da022014-11-10 16:13:46 +02006833 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6834 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006835
Luciano Coelho256da022014-11-10 16:13:46 +02006836 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006837 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006838 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006839 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006840 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006841 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006842 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006843 }
6844
Luciano Coelho256da022014-11-10 16:13:46 +02006845 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6846 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006847 tmp)
6848 n_ssids++;
6849
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006850 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006851 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006852
Johannes Bergea73cbc2014-01-24 10:53:53 +01006853 /*
6854 * First, count the number of 'real' matchsets. Due to an issue with
6855 * the old implementation, matchsets containing only the RSSI attribute
6856 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6857 * RSSI for all matchsets, rather than their own matchset for reporting
6858 * all APs with a strong RSSI. This is needed to be compatible with
6859 * older userspace that treated a matchset with only the RSSI as the
6860 * global RSSI for all other matchsets - if there are other matchsets.
6861 */
Luciano Coelho256da022014-11-10 16:13:46 +02006862 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006863 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006864 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006865 tmp) {
6866 struct nlattr *rssi;
6867
6868 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6869 nla_data(attr), nla_len(attr),
6870 nl80211_match_policy);
6871 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006872 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006873 /* add other standalone attributes here */
6874 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6875 n_match_sets++;
6876 continue;
6877 }
6878 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6879 if (rssi)
6880 default_match_rssi = nla_get_s32(rssi);
6881 }
6882 }
6883
6884 /* However, if there's no other matchset, add the RSSI one */
6885 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6886 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006887
6888 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006889 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006890
Luciano Coelho256da022014-11-10 16:13:46 +02006891 if (attrs[NL80211_ATTR_IE])
6892 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006893 else
6894 ie_len = 0;
6895
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006896 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006897 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006898
Avraham Stern3b06d272015-10-12 09:51:34 +03006899 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6900 /*
6901 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6902 * each scan plan already specifies its own interval
6903 */
6904 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6905 return ERR_PTR(-EINVAL);
6906
6907 nla_for_each_nested(attr,
6908 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6909 n_plans++;
6910 } else {
6911 /*
6912 * The scan interval attribute is kept for backward
6913 * compatibility. If no scan plans are specified and sched scan
6914 * interval is specified, one scan plan will be set with this
6915 * scan interval and infinite number of iterations.
6916 */
6917 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6918 return ERR_PTR(-EINVAL);
6919
6920 n_plans = 1;
6921 }
6922
6923 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6924 return ERR_PTR(-EINVAL);
6925
Luciano Coelho807f8a82011-05-11 17:09:35 +03006926 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006927 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006928 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006929 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006930 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006931 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006932 if (!request)
6933 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006934
6935 if (n_ssids)
6936 request->ssids = (void *)&request->channels[n_channels];
6937 request->n_ssids = n_ssids;
6938 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006939 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006940 request->ie = (void *)(request->ssids + n_ssids);
6941 else
6942 request->ie = (void *)(request->channels + n_channels);
6943 }
6944
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006945 if (n_match_sets) {
6946 if (request->ie)
6947 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006948 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006949 request->match_sets =
6950 (void *)(request->ssids + n_ssids);
6951 else
6952 request->match_sets =
6953 (void *)(request->channels + n_channels);
6954 }
6955 request->n_match_sets = n_match_sets;
6956
Avraham Stern3b06d272015-10-12 09:51:34 +03006957 if (n_match_sets)
6958 request->scan_plans = (void *)(request->match_sets +
6959 n_match_sets);
6960 else if (request->ie)
6961 request->scan_plans = (void *)(request->ie + ie_len);
6962 else if (n_ssids)
6963 request->scan_plans = (void *)(request->ssids + n_ssids);
6964 else
6965 request->scan_plans = (void *)(request->channels + n_channels);
6966
6967 request->n_scan_plans = n_plans;
6968
Luciano Coelho807f8a82011-05-11 17:09:35 +03006969 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006970 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006971 /* user specified, bail out if channel not found */
6972 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006973 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006974 tmp) {
6975 struct ieee80211_channel *chan;
6976
6977 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6978
6979 if (!chan) {
6980 err = -EINVAL;
6981 goto out_free;
6982 }
6983
6984 /* ignore disabled channels */
6985 if (chan->flags & IEEE80211_CHAN_DISABLED)
6986 continue;
6987
6988 request->channels[i] = chan;
6989 i++;
6990 }
6991 } else {
6992 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006993 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006994 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006995
Luciano Coelho807f8a82011-05-11 17:09:35 +03006996 if (!wiphy->bands[band])
6997 continue;
6998 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6999 struct ieee80211_channel *chan;
7000
7001 chan = &wiphy->bands[band]->channels[j];
7002
7003 if (chan->flags & IEEE80211_CHAN_DISABLED)
7004 continue;
7005
7006 request->channels[i] = chan;
7007 i++;
7008 }
7009 }
7010 }
7011
7012 if (!i) {
7013 err = -EINVAL;
7014 goto out_free;
7015 }
7016
7017 request->n_channels = i;
7018
7019 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007020 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007021 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007022 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007023 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007024 err = -EINVAL;
7025 goto out_free;
7026 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007027 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007028 memcpy(request->ssids[i].ssid, nla_data(attr),
7029 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007030 i++;
7031 }
7032 }
7033
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007034 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007035 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007036 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007037 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007038 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007039 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007040
Johannes Bergae811e22014-01-24 10:17:47 +01007041 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7042 nla_data(attr), nla_len(attr),
7043 nl80211_match_policy);
7044 if (err)
7045 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007046 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007047 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007048 if (WARN_ON(i >= n_match_sets)) {
7049 /* this indicates a programming error,
7050 * the loop above should have verified
7051 * things properly
7052 */
7053 err = -EINVAL;
7054 goto out_free;
7055 }
7056
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007057 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7058 err = -EINVAL;
7059 goto out_free;
7060 }
7061 memcpy(request->match_sets[i].ssid.ssid,
7062 nla_data(ssid), nla_len(ssid));
7063 request->match_sets[i].ssid.ssid_len =
7064 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007065 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007066 request->match_sets[i].rssi_thold =
7067 default_match_rssi;
7068 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7069 if (rssi)
7070 request->match_sets[i].rssi_thold =
7071 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007072 }
7073 i++;
7074 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007075
7076 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007077 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007078 request->match_sets[0].rssi_thold = default_match_rssi;
7079
7080 request->min_rssi_thold = INT_MAX;
7081 for (i = 0; i < n_match_sets; i++)
7082 request->min_rssi_thold =
7083 min(request->match_sets[i].rssi_thold,
7084 request->min_rssi_thold);
7085 } else {
7086 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007087 }
7088
Johannes Berg9900e482014-02-04 21:01:25 +01007089 if (ie_len) {
7090 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007091 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007092 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007093 request->ie_len);
7094 }
7095
Luciano Coelho256da022014-11-10 16:13:46 +02007096 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007097 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007098 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007099 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7100 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007101 err = -EOPNOTSUPP;
7102 goto out_free;
7103 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007104
7105 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7106 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7107
7108 if (!wdev) /* must be net-detect */
7109 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7110
7111 if (!(wiphy->features & flg)) {
7112 err = -EOPNOTSUPP;
7113 goto out_free;
7114 }
7115
7116 if (wdev && wdev->current_bss) {
7117 err = -EOPNOTSUPP;
7118 goto out_free;
7119 }
7120
7121 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7122 request->mac_addr_mask);
7123 if (err)
7124 goto out_free;
7125 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007126 }
Sam Lefflered4737712012-10-11 21:03:31 -07007127
Luciano Coelho9c748932015-01-16 16:04:09 +02007128 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7129 request->delay =
7130 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7131
Avraham Stern3b06d272015-10-12 09:51:34 +03007132 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7133 if (err)
7134 goto out_free;
7135
Sam Leffler15d60302012-10-11 21:03:34 -07007136 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007137
Luciano Coelho256da022014-11-10 16:13:46 +02007138 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007139
7140out_free:
7141 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007142 return ERR_PTR(err);
7143}
7144
7145static int nl80211_start_sched_scan(struct sk_buff *skb,
7146 struct genl_info *info)
7147{
7148 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7149 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007150 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007151 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007152 int err;
7153
7154 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7155 !rdev->ops->sched_scan_start)
7156 return -EOPNOTSUPP;
7157
7158 if (rdev->sched_scan_req)
7159 return -EINPROGRESS;
7160
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007161 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7162 info->attrs);
7163
7164 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007165 if (err)
7166 goto out_err;
7167
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007168 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007169 if (err)
7170 goto out_free;
7171
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007172 sched_scan_req->dev = dev;
7173 sched_scan_req->wiphy = &rdev->wiphy;
7174
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007175 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7176 sched_scan_req->owner_nlportid = info->snd_portid;
7177
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007178 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007179
7180 nl80211_send_sched_scan(rdev, dev,
7181 NL80211_CMD_START_SCHED_SCAN);
7182 return 0;
7183
7184out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007185 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007186out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007187 return err;
7188}
7189
7190static int nl80211_stop_sched_scan(struct sk_buff *skb,
7191 struct genl_info *info)
7192{
7193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7194
7195 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7196 !rdev->ops->sched_scan_stop)
7197 return -EOPNOTSUPP;
7198
Johannes Berg5fe231e2013-05-08 21:45:15 +02007199 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007200}
7201
Simon Wunderlich04f39042013-02-08 18:16:19 +01007202static int nl80211_start_radar_detection(struct sk_buff *skb,
7203 struct genl_info *info)
7204{
7205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7206 struct net_device *dev = info->user_ptr[1];
7207 struct wireless_dev *wdev = dev->ieee80211_ptr;
7208 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007209 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007210 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007211 int err;
7212
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007213 dfs_region = reg_get_dfs_region(wdev->wiphy);
7214 if (dfs_region == NL80211_DFS_UNSET)
7215 return -EINVAL;
7216
Simon Wunderlich04f39042013-02-08 18:16:19 +01007217 err = nl80211_parse_chandef(rdev, info, &chandef);
7218 if (err)
7219 return err;
7220
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007221 if (netif_carrier_ok(dev))
7222 return -EBUSY;
7223
Amar Singhal42839af2014-03-19 18:36:58 -07007224 if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD)
7225 return -EOPNOTSUPP;
7226
Simon Wunderlich04f39042013-02-08 18:16:19 +01007227 if (wdev->cac_started)
7228 return -EBUSY;
7229
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007230 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007231 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007232 if (err < 0)
7233 return err;
7234
7235 if (err == 0)
7236 return -EINVAL;
7237
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007238 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007239 return -EINVAL;
7240
7241 if (!rdev->ops->start_radar_detection)
7242 return -EOPNOTSUPP;
7243
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007244 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7245 if (WARN_ON(!cac_time_ms))
7246 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7247
Ilan Peera1056b12015-10-22 22:27:46 +03007248 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007249 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007250 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007251 wdev->cac_started = true;
7252 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007253 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007254 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007255 return err;
7256}
7257
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007258static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7259{
7260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7261 struct net_device *dev = info->user_ptr[1];
7262 struct wireless_dev *wdev = dev->ieee80211_ptr;
7263 struct cfg80211_csa_settings params;
7264 /* csa_attrs is defined static to avoid waste of stack size - this
7265 * function is called under RTNL lock, so this should not be a problem.
7266 */
7267 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007268 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007269 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007270 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007271 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007272
7273 if (!rdev->ops->channel_switch ||
7274 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7275 return -EOPNOTSUPP;
7276
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007277 switch (dev->ieee80211_ptr->iftype) {
7278 case NL80211_IFTYPE_AP:
7279 case NL80211_IFTYPE_P2P_GO:
7280 need_new_beacon = true;
7281
7282 /* useless if AP is not running */
7283 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007284 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007285 break;
7286 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007287 if (!wdev->ssid_len)
7288 return -ENOTCONN;
7289 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007290 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007291 if (!wdev->mesh_id_len)
7292 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007293 break;
7294 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007295 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007296 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007297
7298 memset(&params, 0, sizeof(params));
7299
7300 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7301 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7302 return -EINVAL;
7303
7304 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007305 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007306 return -EINVAL;
7307
Luciano Coelho252e07c2014-10-08 09:48:34 +03007308 /* Even though the attribute is u32, the specification says
7309 * u8, so let's make sure we don't overflow.
7310 */
7311 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7312 if (cs_count > 255)
7313 return -EINVAL;
7314
7315 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007316
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007317 if (!need_new_beacon)
7318 goto skip_beacons;
7319
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007320 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7321 if (err)
7322 return err;
7323
7324 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7325 info->attrs[NL80211_ATTR_CSA_IES],
7326 nl80211_policy);
7327 if (err)
7328 return err;
7329
7330 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7331 if (err)
7332 return err;
7333
7334 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7335 return -EINVAL;
7336
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007337 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7338 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007339 return -EINVAL;
7340
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007341 params.n_counter_offsets_beacon = len / sizeof(u16);
7342 if (rdev->wiphy.max_num_csa_counters &&
7343 (params.n_counter_offsets_beacon >
7344 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007345 return -EINVAL;
7346
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007347 params.counter_offsets_beacon =
7348 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7349
7350 /* sanity checks - counters should fit and be the same */
7351 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7352 u16 offset = params.counter_offsets_beacon[i];
7353
7354 if (offset >= params.beacon_csa.tail_len)
7355 return -EINVAL;
7356
7357 if (params.beacon_csa.tail[offset] != params.count)
7358 return -EINVAL;
7359 }
7360
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007361 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007362 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7363 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007364 return -EINVAL;
7365
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007366 params.n_counter_offsets_presp = len / sizeof(u16);
7367 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007368 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007369 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007370 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007371
7372 params.counter_offsets_presp =
7373 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7374
7375 /* sanity checks - counters should fit and be the same */
7376 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7377 u16 offset = params.counter_offsets_presp[i];
7378
7379 if (offset >= params.beacon_csa.probe_resp_len)
7380 return -EINVAL;
7381
7382 if (params.beacon_csa.probe_resp[offset] !=
7383 params.count)
7384 return -EINVAL;
7385 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007386 }
7387
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007388skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007389 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7390 if (err)
7391 return err;
7392
Arik Nemtsov923b3522015-07-08 15:41:44 +03007393 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7394 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007395 return -EINVAL;
7396
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007397 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7398 &params.chandef,
7399 wdev->iftype);
7400 if (err < 0)
7401 return err;
7402
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007403 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007404 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007405
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007406 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7407 params.block_tx = true;
7408
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007409 wdev_lock(wdev);
7410 err = rdev_channel_switch(rdev, dev, &params);
7411 wdev_unlock(wdev);
7412
7413 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007414}
7415
Johannes Berg9720bb32011-06-21 09:45:33 +02007416static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7417 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007418 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007419 struct wireless_dev *wdev,
7420 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007421{
Johannes Berg48ab9052009-07-10 18:42:31 +02007422 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007423 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007424 void *hdr;
7425 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007426
7427 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007428
Eric W. Biederman15e47302012-09-07 20:12:54 +00007429 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007430 NL80211_CMD_NEW_SCAN_RESULTS);
7431 if (!hdr)
7432 return -1;
7433
Johannes Berg9720bb32011-06-21 09:45:33 +02007434 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7435
Johannes Berg97990a02013-04-19 01:02:55 +02007436 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7437 goto nla_put_failure;
7438 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007439 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7440 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007441 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7442 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007443 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007444
7445 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7446 if (!bss)
7447 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007448 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007449 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007450 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007451
7452 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007453 /* indicate whether we have probe response data or not */
7454 if (rcu_access_pointer(res->proberesp_ies) &&
7455 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7456 goto fail_unlock_rcu;
7457
7458 /* this pointer prefers to be pointed to probe response data
7459 * but is always valid
7460 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007461 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007462 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007463 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7464 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007465 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007466 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7467 ies->len, ies->data))
7468 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007469 }
Johannes Berg0e227082014-08-12 20:34:30 +02007470
7471 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007472 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007473 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007474 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7475 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007476 goto fail_unlock_rcu;
7477 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7478 ies->len, ies->data))
7479 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007480 }
7481 rcu_read_unlock();
7482
David S. Miller9360ffd2012-03-29 04:41:26 -04007483 if (res->beacon_interval &&
7484 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7485 goto nla_put_failure;
7486 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7487 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007488 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007489 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7490 jiffies_to_msecs(jiffies - intbss->ts)))
7491 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007492
Avraham Stern1d762502016-07-05 17:10:13 +03007493 if (intbss->parent_tsf &&
7494 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7495 intbss->parent_tsf, NL80211_BSS_PAD) ||
7496 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7497 intbss->parent_bssid)))
7498 goto nla_put_failure;
7499
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007500 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007501 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7502 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007503 goto nla_put_failure;
7504
Johannes Berg77965c92009-02-18 18:45:06 +01007505 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007506 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007507 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7508 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007509 break;
7510 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007511 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7512 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007513 break;
7514 default:
7515 break;
7516 }
7517
Johannes Berg48ab9052009-07-10 18:42:31 +02007518 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007519 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007520 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007521 if (intbss == wdev->current_bss &&
7522 nla_put_u32(msg, NL80211_BSS_STATUS,
7523 NL80211_BSS_STATUS_ASSOCIATED))
7524 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007525 break;
7526 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007527 if (intbss == wdev->current_bss &&
7528 nla_put_u32(msg, NL80211_BSS_STATUS,
7529 NL80211_BSS_STATUS_IBSS_JOINED))
7530 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007531 break;
7532 default:
7533 break;
7534 }
7535
Johannes Berg2a519312009-02-10 21:25:55 +01007536 nla_nest_end(msg, bss);
7537
Johannes Berg053c0952015-01-16 22:09:00 +01007538 genlmsg_end(msg, hdr);
7539 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007540
Johannes Berg8cef2c92013-02-05 16:54:31 +01007541 fail_unlock_rcu:
7542 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007543 nla_put_failure:
7544 genlmsg_cancel(msg, hdr);
7545 return -EMSGSIZE;
7546}
7547
Johannes Berg97990a02013-04-19 01:02:55 +02007548static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007549{
Johannes Berg48ab9052009-07-10 18:42:31 +02007550 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007551 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007552 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007553 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007554 int err;
7555
Johannes Berg56769e72017-03-15 14:26:04 +01007556 rtnl_lock();
Johannes Berg97990a02013-04-19 01:02:55 +02007557 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg56769e72017-03-15 14:26:04 +01007558 if (err) {
7559 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02007560 return err;
Johannes Berg56769e72017-03-15 14:26:04 +01007561 }
Johannes Berg2a519312009-02-10 21:25:55 +01007562
Johannes Berg48ab9052009-07-10 18:42:31 +02007563 wdev_lock(wdev);
7564 spin_lock_bh(&rdev->bss_lock);
7565 cfg80211_bss_expire(rdev);
7566
Johannes Berg9720bb32011-06-21 09:45:33 +02007567 cb->seq = rdev->bss_generation;
7568
Johannes Berg48ab9052009-07-10 18:42:31 +02007569 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007570 if (++idx <= start)
7571 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007572 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007573 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007574 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007575 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007576 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007577 }
7578 }
7579
Johannes Berg48ab9052009-07-10 18:42:31 +02007580 spin_unlock_bh(&rdev->bss_lock);
7581 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007582
Johannes Berg97990a02013-04-19 01:02:55 +02007583 cb->args[2] = idx;
Johannes Berg56769e72017-03-15 14:26:04 +01007584 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007585
Johannes Berg67748892010-10-04 21:14:06 +02007586 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007587}
7588
Eric W. Biederman15e47302012-09-07 20:12:54 +00007589static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007590 int flags, struct net_device *dev,
7591 bool allow_radio_stats,
7592 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007593{
7594 void *hdr;
7595 struct nlattr *infoattr;
7596
Johannes Berg11f78ac2014-11-14 16:43:50 +01007597 /* skip radio stats if userspace didn't request them */
7598 if (!survey->channel && !allow_radio_stats)
7599 return 0;
7600
Eric W. Biederman15e47302012-09-07 20:12:54 +00007601 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007602 NL80211_CMD_NEW_SURVEY_RESULTS);
7603 if (!hdr)
7604 return -ENOMEM;
7605
David S. Miller9360ffd2012-03-29 04:41:26 -04007606 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7607 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007608
7609 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7610 if (!infoattr)
7611 goto nla_put_failure;
7612
Johannes Berg11f78ac2014-11-14 16:43:50 +01007613 if (survey->channel &&
7614 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007615 survey->channel->center_freq))
7616 goto nla_put_failure;
7617
7618 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7619 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7620 goto nla_put_failure;
7621 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7622 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7623 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007624 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007625 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7626 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007627 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007628 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007629 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7630 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007631 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007632 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007633 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7634 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007635 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007636 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007637 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7638 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007639 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007640 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007641 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7642 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007643 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007644 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007645 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7646 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007647 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007648
7649 nla_nest_end(msg, infoattr);
7650
Johannes Berg053c0952015-01-16 22:09:00 +01007651 genlmsg_end(msg, hdr);
7652 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007653
7654 nla_put_failure:
7655 genlmsg_cancel(msg, hdr);
7656 return -EMSGSIZE;
7657}
7658
Johannes Berg11f78ac2014-11-14 16:43:50 +01007659static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007660{
7661 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007662 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007663 struct wireless_dev *wdev;
7664 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007665 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007666 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007667
Johannes Berg56769e72017-03-15 14:26:04 +01007668 rtnl_lock();
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007669 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007670 if (res)
Johannes Berg56769e72017-03-15 14:26:04 +01007671 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01007672
Johannes Berg11f78ac2014-11-14 16:43:50 +01007673 /* prepare_wdev_dump parsed the attributes */
7674 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7675
Johannes Berg97990a02013-04-19 01:02:55 +02007676 if (!wdev->netdev) {
7677 res = -EINVAL;
7678 goto out_err;
7679 }
7680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007681 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007682 res = -EOPNOTSUPP;
7683 goto out_err;
7684 }
7685
7686 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007687 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007688 if (res == -ENOENT)
7689 break;
7690 if (res)
7691 goto out_err;
7692
Johannes Berg11f78ac2014-11-14 16:43:50 +01007693 /* don't send disabled channels, but do send non-channel data */
7694 if (survey.channel &&
7695 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007696 survey_idx++;
7697 continue;
7698 }
7699
Holger Schurig61fa7132009-11-11 12:25:40 +01007700 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007701 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007702 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007703 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007704 goto out;
7705 survey_idx++;
7706 }
7707
7708 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007709 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007710 res = skb->len;
7711 out_err:
Johannes Berg56769e72017-03-15 14:26:04 +01007712 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01007713 return res;
7714}
7715
Samuel Ortizb23aa672009-07-01 21:26:54 +02007716static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7717{
7718 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7719 NL80211_WPA_VERSION_2));
7720}
7721
Jouni Malinen636a5d32009-03-19 13:39:22 +02007722static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7723{
Johannes Berg4c476992010-10-04 21:36:35 +02007724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7725 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007726 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007727 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7728 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007729 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007730 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007731 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007732
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007733 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7734 return -EINVAL;
7735
7736 if (!info->attrs[NL80211_ATTR_MAC])
7737 return -EINVAL;
7738
Jouni Malinen17780922009-03-27 20:52:47 +02007739 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7740 return -EINVAL;
7741
Johannes Berg19957bb2009-07-02 17:20:43 +02007742 if (!info->attrs[NL80211_ATTR_SSID])
7743 return -EINVAL;
7744
7745 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7746 return -EINVAL;
7747
Johannes Bergfffd0932009-07-08 14:22:54 +02007748 err = nl80211_parse_key(info, &key);
7749 if (err)
7750 return err;
7751
7752 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007753 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7754 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007755 if (!key.p.key || !key.p.key_len)
7756 return -EINVAL;
7757 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7758 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7759 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7760 key.p.key_len != WLAN_KEY_LEN_WEP104))
7761 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007762 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007763 return -EINVAL;
7764 } else {
7765 key.p.key_len = 0;
7766 key.p.key = NULL;
7767 }
7768
Johannes Bergafea0b72010-08-10 09:46:42 +02007769 if (key.idx >= 0) {
7770 int i;
7771 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007772
Johannes Bergafea0b72010-08-10 09:46:42 +02007773 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7774 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7775 ok = true;
7776 break;
7777 }
7778 }
Johannes Berg4c476992010-10-04 21:36:35 +02007779 if (!ok)
7780 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007781 }
7782
Johannes Berg4c476992010-10-04 21:36:35 +02007783 if (!rdev->ops->auth)
7784 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007785
Johannes Berg074ac8d2010-09-16 14:58:22 +02007786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007787 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7788 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007789
Johannes Berg19957bb2009-07-02 17:20:43 +02007790 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007791 chan = nl80211_get_valid_chan(&rdev->wiphy,
7792 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7793 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007794 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007795
Johannes Berg19957bb2009-07-02 17:20:43 +02007796 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7797 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7798
7799 if (info->attrs[NL80211_ATTR_IE]) {
7800 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7801 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7802 }
7803
7804 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007805 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007806 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007807
Jouni Malinene39e5b52012-09-30 19:29:39 +03007808 if (auth_type == NL80211_AUTHTYPE_SAE &&
7809 !info->attrs[NL80211_ATTR_SAE_DATA])
7810 return -EINVAL;
7811
7812 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7813 if (auth_type != NL80211_AUTHTYPE_SAE)
7814 return -EINVAL;
7815 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7816 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7817 /* need to include at least Auth Transaction and Status Code */
7818 if (sae_data_len < 4)
7819 return -EINVAL;
7820 }
7821
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007822 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7823
Johannes Berg95de8172012-01-20 13:55:25 +01007824 /*
7825 * Since we no longer track auth state, ignore
7826 * requests to only change local state.
7827 */
7828 if (local_state_change)
7829 return 0;
7830
Johannes Berg91bf9b22013-05-15 17:44:01 +02007831 wdev_lock(dev->ieee80211_ptr);
7832 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7833 ssid, ssid_len, ie, ie_len,
7834 key.p.key, key.p.key_len, key.idx,
7835 sae_data, sae_data_len);
7836 wdev_unlock(dev->ieee80211_ptr);
7837 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007838}
7839
Johannes Bergc0692b82010-08-27 14:26:53 +03007840static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7841 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007842 struct cfg80211_crypto_settings *settings,
7843 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007844{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007845 memset(settings, 0, sizeof(*settings));
7846
Samuel Ortizb23aa672009-07-01 21:26:54 +02007847 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7848
Johannes Bergc0692b82010-08-27 14:26:53 +03007849 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7850 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007851
Johannes Bergc0692b82010-08-27 14:26:53 +03007852 proto = nla_get_u16(
7853 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7854 settings->control_port_ethertype = cpu_to_be16(proto);
7855 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7856 proto != ETH_P_PAE)
7857 return -EINVAL;
7858 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7859 settings->control_port_no_encrypt = true;
7860 } else
7861 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7862
Samuel Ortizb23aa672009-07-01 21:26:54 +02007863 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7864 void *data;
7865 int len, i;
7866
7867 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7868 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7869 settings->n_ciphers_pairwise = len / sizeof(u32);
7870
7871 if (len % sizeof(u32))
7872 return -EINVAL;
7873
Johannes Berg3dc27d22009-07-02 21:36:37 +02007874 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007875 return -EINVAL;
7876
7877 memcpy(settings->ciphers_pairwise, data, len);
7878
7879 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007880 if (!cfg80211_supported_cipher_suite(
7881 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007882 settings->ciphers_pairwise[i]))
7883 return -EINVAL;
7884 }
7885
7886 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7887 settings->cipher_group =
7888 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007889 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7890 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007891 return -EINVAL;
7892 }
7893
7894 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7895 settings->wpa_versions =
7896 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7897 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7898 return -EINVAL;
7899 }
7900
7901 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7902 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007903 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007904
7905 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7906 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7907 settings->n_akm_suites = len / sizeof(u32);
7908
7909 if (len % sizeof(u32))
7910 return -EINVAL;
7911
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007912 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7913 return -EINVAL;
7914
Samuel Ortizb23aa672009-07-01 21:26:54 +02007915 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007916 }
7917
7918 return 0;
7919}
7920
Jouni Malinen636a5d32009-03-19 13:39:22 +02007921static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7922{
Johannes Berg4c476992010-10-04 21:36:35 +02007923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7924 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007925 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007926 struct cfg80211_assoc_request req = {};
7927 const u8 *bssid, *ssid;
7928 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007929
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007930 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7931 return -EINVAL;
7932
7933 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007934 !info->attrs[NL80211_ATTR_SSID] ||
7935 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007936 return -EINVAL;
7937
Johannes Berg4c476992010-10-04 21:36:35 +02007938 if (!rdev->ops->assoc)
7939 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007940
Johannes Berg074ac8d2010-09-16 14:58:22 +02007941 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007942 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7943 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007944
Johannes Berg19957bb2009-07-02 17:20:43 +02007945 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007946
Jouni Malinen664834d2014-01-15 00:01:44 +02007947 chan = nl80211_get_valid_chan(&rdev->wiphy,
7948 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7949 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007950 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007951
Johannes Berg19957bb2009-07-02 17:20:43 +02007952 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7953 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007954
7955 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007956 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7957 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007958 }
7959
Jouni Malinendc6382c2009-05-06 22:09:37 +03007960 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007961 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007962 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007963 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007964 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007965 else if (mfp != NL80211_MFP_NO)
7966 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007967 }
7968
Johannes Berg3e5d7642009-07-07 14:37:26 +02007969 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007970 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007971
Ben Greear7e7c8922011-11-18 11:31:59 -08007972 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007973 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007974
7975 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007976 memcpy(&req.ht_capa_mask,
7977 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7978 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007979
7980 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007981 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007982 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007983 memcpy(&req.ht_capa,
7984 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7985 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007986 }
7987
Johannes Bergee2aca32013-02-21 17:36:01 +01007988 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007989 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007990
7991 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007992 memcpy(&req.vht_capa_mask,
7993 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7994 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007995
7996 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007997 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007998 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007999 memcpy(&req.vht_capa,
8000 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8001 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008002 }
8003
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008004 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008005 if (!((rdev->wiphy.features &
8006 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8007 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8008 !wiphy_ext_feature_isset(&rdev->wiphy,
8009 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008010 return -EINVAL;
8011 req.flags |= ASSOC_REQ_USE_RRM;
8012 }
8013
Johannes Bergf62fab72013-02-21 20:09:09 +01008014 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008015 if (!err) {
8016 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01008017 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8018 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008019 wdev_unlock(dev->ieee80211_ptr);
8020 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008021
Jouni Malinen636a5d32009-03-19 13:39:22 +02008022 return err;
8023}
8024
8025static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8026{
Johannes Berg4c476992010-10-04 21:36:35 +02008027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8028 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008029 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008030 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008031 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008032 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008033
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8035 return -EINVAL;
8036
8037 if (!info->attrs[NL80211_ATTR_MAC])
8038 return -EINVAL;
8039
8040 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8041 return -EINVAL;
8042
Johannes Berg4c476992010-10-04 21:36:35 +02008043 if (!rdev->ops->deauth)
8044 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008045
Johannes Berg074ac8d2010-09-16 14:58:22 +02008046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8048 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008049
Johannes Berg19957bb2009-07-02 17:20:43 +02008050 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008051
Johannes Berg19957bb2009-07-02 17:20:43 +02008052 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8053 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008054 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008055 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008056 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008057
8058 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008059 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8060 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008061 }
8062
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008063 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8064
Johannes Berg91bf9b22013-05-15 17:44:01 +02008065 wdev_lock(dev->ieee80211_ptr);
8066 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8067 local_state_change);
8068 wdev_unlock(dev->ieee80211_ptr);
8069 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008070}
8071
8072static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8073{
Johannes Berg4c476992010-10-04 21:36:35 +02008074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8075 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008076 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008077 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008078 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008079 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008080
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008081 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8082 return -EINVAL;
8083
8084 if (!info->attrs[NL80211_ATTR_MAC])
8085 return -EINVAL;
8086
8087 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8088 return -EINVAL;
8089
Johannes Berg4c476992010-10-04 21:36:35 +02008090 if (!rdev->ops->disassoc)
8091 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008092
Johannes Berg074ac8d2010-09-16 14:58:22 +02008093 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008094 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8095 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008096
Johannes Berg19957bb2009-07-02 17:20:43 +02008097 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008098
Johannes Berg19957bb2009-07-02 17:20:43 +02008099 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8100 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008101 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008102 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008103 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008104
8105 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008106 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8107 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008108 }
8109
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008110 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8111
Johannes Berg91bf9b22013-05-15 17:44:01 +02008112 wdev_lock(dev->ieee80211_ptr);
8113 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8114 local_state_change);
8115 wdev_unlock(dev->ieee80211_ptr);
8116 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008117}
8118
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008119static bool
8120nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008121 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008122 int rateval)
8123{
8124 struct wiphy *wiphy = &rdev->wiphy;
8125 bool found = false;
8126 int band, i;
8127
Johannes Berg57fbcce2016-04-12 15:56:15 +02008128 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008129 struct ieee80211_supported_band *sband;
8130
8131 sband = wiphy->bands[band];
8132 if (!sband)
8133 continue;
8134
8135 for (i = 0; i < sband->n_bitrates; i++) {
8136 if (sband->bitrates[i].bitrate == rateval) {
8137 mcast_rate[band] = i + 1;
8138 found = true;
8139 break;
8140 }
8141 }
8142 }
8143
8144 return found;
8145}
8146
Johannes Berg04a773a2009-04-19 21:24:32 +02008147static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8148{
Johannes Berg4c476992010-10-04 21:36:35 +02008149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8150 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008151 struct cfg80211_ibss_params ibss;
8152 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008153 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008154 int err;
8155
Johannes Berg8e30bc52009-04-22 17:45:38 +02008156 memset(&ibss, 0, sizeof(ibss));
8157
Johannes Berg04a773a2009-04-19 21:24:32 +02008158 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8159 return -EINVAL;
8160
Johannes Berg683b6d32012-11-08 21:25:48 +01008161 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008162 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8163 return -EINVAL;
8164
Johannes Berg8e30bc52009-04-22 17:45:38 +02008165 ibss.beacon_interval = 100;
8166
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308167 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008168 ibss.beacon_interval =
8169 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308170
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05308171 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8172 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308173 if (err)
8174 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008175
Johannes Berg4c476992010-10-04 21:36:35 +02008176 if (!rdev->ops->join_ibss)
8177 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008178
Johannes Berg4c476992010-10-04 21:36:35 +02008179 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8180 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008181
Johannes Berg79c97e92009-07-07 03:56:12 +02008182 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008183
Johannes Berg39193492011-09-16 13:45:25 +02008184 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008185 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008186
8187 if (!is_valid_ether_addr(ibss.bssid))
8188 return -EINVAL;
8189 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008190 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8191 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8192
8193 if (info->attrs[NL80211_ATTR_IE]) {
8194 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8195 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8196 }
8197
Johannes Berg683b6d32012-11-08 21:25:48 +01008198 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8199 if (err)
8200 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008201
Ilan Peer174e0cd2014-02-23 09:13:01 +02008202 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8203 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008204 return -EINVAL;
8205
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008206 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008207 case NL80211_CHAN_WIDTH_5:
8208 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008209 case NL80211_CHAN_WIDTH_20_NOHT:
8210 break;
8211 case NL80211_CHAN_WIDTH_20:
8212 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008213 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8214 return -EINVAL;
8215 break;
8216 case NL80211_CHAN_WIDTH_80:
8217 case NL80211_CHAN_WIDTH_80P80:
8218 case NL80211_CHAN_WIDTH_160:
8219 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8220 return -EINVAL;
8221 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8222 NL80211_EXT_FEATURE_VHT_IBSS))
8223 return -EINVAL;
8224 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008225 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008226 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008227 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008228
Johannes Berg04a773a2009-04-19 21:24:32 +02008229 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008230 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008231
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008232 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8233 u8 *rates =
8234 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8235 int n_rates =
8236 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8237 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008238 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008239
Johannes Berg34850ab2011-07-18 18:08:35 +02008240 err = ieee80211_get_ratemask(sband, rates, n_rates,
8241 &ibss.basic_rates);
8242 if (err)
8243 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008244 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008245
Simon Wunderlich803768f2013-06-28 10:39:58 +02008246 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8247 memcpy(&ibss.ht_capa_mask,
8248 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8249 sizeof(ibss.ht_capa_mask));
8250
8251 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8252 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8253 return -EINVAL;
8254 memcpy(&ibss.ht_capa,
8255 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8256 sizeof(ibss.ht_capa));
8257 }
8258
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008259 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8260 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8261 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8262 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008263
Johannes Berg4c476992010-10-04 21:36:35 +02008264 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308265 bool no_ht = false;
8266
Johannes Berg4c476992010-10-04 21:36:35 +02008267 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308268 info->attrs[NL80211_ATTR_KEYS],
8269 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008270 if (IS_ERR(connkeys))
8271 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308272
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008273 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8274 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008275 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308276 return -EINVAL;
8277 }
Johannes Berg4c476992010-10-04 21:36:35 +02008278 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008279
Antonio Quartulli267335d2012-01-31 20:25:47 +01008280 ibss.control_port =
8281 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8282
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008283 ibss.userspace_handles_dfs =
8284 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8285
Johannes Berg4c476992010-10-04 21:36:35 +02008286 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008287 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008288 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008289 return err;
8290}
8291
8292static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8293{
Johannes Berg4c476992010-10-04 21:36:35 +02008294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8295 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008296
Johannes Berg4c476992010-10-04 21:36:35 +02008297 if (!rdev->ops->leave_ibss)
8298 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008299
Johannes Berg4c476992010-10-04 21:36:35 +02008300 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8301 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008302
Johannes Berg4c476992010-10-04 21:36:35 +02008303 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008304}
8305
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008306static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8307{
8308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8309 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008310 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008311 u32 nla_rate;
8312 int err;
8313
8314 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008315 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8316 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008317 return -EOPNOTSUPP;
8318
8319 if (!rdev->ops->set_mcast_rate)
8320 return -EOPNOTSUPP;
8321
8322 memset(mcast_rate, 0, sizeof(mcast_rate));
8323
8324 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8325 return -EINVAL;
8326
8327 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8328 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8329 return -EINVAL;
8330
Ilan Peera1056b12015-10-22 22:27:46 +03008331 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008332
8333 return err;
8334}
8335
Johannes Bergad7e7182013-11-13 13:37:47 +01008336static struct sk_buff *
8337__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008338 struct wireless_dev *wdev, int approxlen,
8339 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008340 enum nl80211_attrs attr,
8341 const struct nl80211_vendor_cmd_info *info,
8342 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008343{
8344 struct sk_buff *skb;
8345 void *hdr;
8346 struct nlattr *data;
8347
8348 skb = nlmsg_new(approxlen + 100, gfp);
8349 if (!skb)
8350 return NULL;
8351
8352 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8353 if (!hdr) {
8354 kfree_skb(skb);
8355 return NULL;
8356 }
8357
8358 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8359 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008360
8361 if (info) {
8362 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8363 info->vendor_id))
8364 goto nla_put_failure;
8365 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8366 info->subcmd))
8367 goto nla_put_failure;
8368 }
8369
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008370 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008371 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8372 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008373 goto nla_put_failure;
8374 if (wdev->netdev &&
8375 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8376 wdev->netdev->ifindex))
8377 goto nla_put_failure;
8378 }
8379
Johannes Bergad7e7182013-11-13 13:37:47 +01008380 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008381 if (!data)
8382 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008383
8384 ((void **)skb->cb)[0] = rdev;
8385 ((void **)skb->cb)[1] = hdr;
8386 ((void **)skb->cb)[2] = data;
8387
8388 return skb;
8389
8390 nla_put_failure:
8391 kfree_skb(skb);
8392 return NULL;
8393}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008394
Johannes Berge03ad6e2014-01-01 17:22:30 +01008395struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008396 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008397 enum nl80211_commands cmd,
8398 enum nl80211_attrs attr,
8399 int vendor_event_idx,
8400 int approxlen, gfp_t gfp)
8401{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008402 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008403 const struct nl80211_vendor_cmd_info *info;
8404
8405 switch (cmd) {
8406 case NL80211_CMD_TESTMODE:
8407 if (WARN_ON(vendor_event_idx != -1))
8408 return NULL;
8409 info = NULL;
8410 break;
8411 case NL80211_CMD_VENDOR:
8412 if (WARN_ON(vendor_event_idx < 0 ||
8413 vendor_event_idx >= wiphy->n_vendor_events))
8414 return NULL;
8415 info = &wiphy->vendor_events[vendor_event_idx];
8416 break;
8417 default:
8418 WARN_ON(1);
8419 return NULL;
8420 }
8421
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008422 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008423 cmd, attr, info, gfp);
8424}
8425EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8426
8427void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8428{
8429 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8430 void *hdr = ((void **)skb->cb)[1];
8431 struct nlattr *data = ((void **)skb->cb)[2];
8432 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8433
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008434 /* clear CB data for netlink core to own from now on */
8435 memset(skb->cb, 0, sizeof(skb->cb));
8436
Johannes Berge03ad6e2014-01-01 17:22:30 +01008437 nla_nest_end(skb, data);
8438 genlmsg_end(skb, hdr);
8439
8440 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8441 mcgrp = NL80211_MCGRP_VENDOR;
8442
8443 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8444 mcgrp, gfp);
8445}
8446EXPORT_SYMBOL(__cfg80211_send_event_skb);
8447
Johannes Bergaff89a92009-07-01 21:26:51 +02008448#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008449static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8450{
Johannes Berg4c476992010-10-04 21:36:35 +02008451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008452 struct wireless_dev *wdev =
8453 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008454 int err;
8455
David Spinadelfc73f112013-07-31 18:04:15 +03008456 if (!rdev->ops->testmode_cmd)
8457 return -EOPNOTSUPP;
8458
8459 if (IS_ERR(wdev)) {
8460 err = PTR_ERR(wdev);
8461 if (err != -EINVAL)
8462 return err;
8463 wdev = NULL;
8464 } else if (wdev->wiphy != &rdev->wiphy) {
8465 return -EINVAL;
8466 }
8467
Johannes Bergaff89a92009-07-01 21:26:51 +02008468 if (!info->attrs[NL80211_ATTR_TESTDATA])
8469 return -EINVAL;
8470
Johannes Bergad7e7182013-11-13 13:37:47 +01008471 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008472 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008473 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8474 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008475 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008476
Johannes Bergaff89a92009-07-01 21:26:51 +02008477 return err;
8478}
8479
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008480static int nl80211_testmode_dump(struct sk_buff *skb,
8481 struct netlink_callback *cb)
8482{
Johannes Berg00918d32011-12-13 17:22:05 +01008483 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008484 int err;
8485 long phy_idx;
8486 void *data = NULL;
8487 int data_len = 0;
8488
Johannes Berg5fe231e2013-05-08 21:45:15 +02008489 rtnl_lock();
8490
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008491 if (cb->args[0]) {
8492 /*
8493 * 0 is a valid index, but not valid for args[0],
8494 * so we need to offset by 1.
8495 */
8496 phy_idx = cb->args[0] - 1;
8497 } else {
8498 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8499 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8500 nl80211_policy);
8501 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008502 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008503
Johannes Berg2bd7e352012-06-15 14:23:16 +02008504 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8505 nl80211_fam.attrbuf);
8506 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008507 err = PTR_ERR(rdev);
8508 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008509 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008510 phy_idx = rdev->wiphy_idx;
8511 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008512
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008513 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8514 cb->args[1] =
8515 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8516 }
8517
8518 if (cb->args[1]) {
8519 data = nla_data((void *)cb->args[1]);
8520 data_len = nla_len((void *)cb->args[1]);
8521 }
8522
Johannes Berg00918d32011-12-13 17:22:05 +01008523 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8524 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008525 err = -ENOENT;
8526 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008527 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008528
Johannes Berg00918d32011-12-13 17:22:05 +01008529 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008530 err = -EOPNOTSUPP;
8531 goto out_err;
8532 }
8533
8534 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008535 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008536 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8537 NL80211_CMD_TESTMODE);
8538 struct nlattr *tmdata;
8539
Dan Carpentercb35fba2013-08-14 14:50:01 +03008540 if (!hdr)
8541 break;
8542
David S. Miller9360ffd2012-03-29 04:41:26 -04008543 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008544 genlmsg_cancel(skb, hdr);
8545 break;
8546 }
8547
8548 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8549 if (!tmdata) {
8550 genlmsg_cancel(skb, hdr);
8551 break;
8552 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008553 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008554 nla_nest_end(skb, tmdata);
8555
8556 if (err == -ENOBUFS || err == -ENOENT) {
8557 genlmsg_cancel(skb, hdr);
8558 break;
8559 } else if (err) {
8560 genlmsg_cancel(skb, hdr);
8561 goto out_err;
8562 }
8563
8564 genlmsg_end(skb, hdr);
8565 }
8566
8567 err = skb->len;
8568 /* see above */
8569 cb->args[0] = phy_idx + 1;
8570 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008571 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008572 return err;
8573}
Johannes Bergaff89a92009-07-01 21:26:51 +02008574#endif
8575
Samuel Ortizb23aa672009-07-01 21:26:54 +02008576static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8577{
Johannes Berg4c476992010-10-04 21:36:35 +02008578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8579 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008580 struct cfg80211_connect_params connect;
8581 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008582 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008583 int err;
8584
8585 memset(&connect, 0, sizeof(connect));
8586
8587 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8588 return -EINVAL;
8589
8590 if (!info->attrs[NL80211_ATTR_SSID] ||
8591 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8592 return -EINVAL;
8593
8594 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8595 connect.auth_type =
8596 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008597 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8598 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008599 return -EINVAL;
8600 } else
8601 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8602
8603 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8604
Johannes Bergc0692b82010-08-27 14:26:53 +03008605 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008606 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008607 if (err)
8608 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008609
Johannes Berg074ac8d2010-09-16 14:58:22 +02008610 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008611 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8612 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008613
Johannes Berg79c97e92009-07-07 03:56:12 +02008614 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008615
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308616 connect.bg_scan_period = -1;
8617 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8618 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8619 connect.bg_scan_period =
8620 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8621 }
8622
Samuel Ortizb23aa672009-07-01 21:26:54 +02008623 if (info->attrs[NL80211_ATTR_MAC])
8624 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008625 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8626 connect.bssid_hint =
8627 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008628 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8629 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8630
8631 if (info->attrs[NL80211_ATTR_IE]) {
8632 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8633 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8634 }
8635
Jouni Malinencee00a92013-01-15 17:15:57 +02008636 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8637 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8638 if (connect.mfp != NL80211_MFP_REQUIRED &&
8639 connect.mfp != NL80211_MFP_NO)
8640 return -EINVAL;
8641 } else {
8642 connect.mfp = NL80211_MFP_NO;
8643 }
8644
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008645 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8646 connect.prev_bssid =
8647 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8648
Samuel Ortizb23aa672009-07-01 21:26:54 +02008649 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008650 connect.channel = nl80211_get_valid_chan(
8651 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8652 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008653 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008654 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008655 connect.channel_hint = nl80211_get_valid_chan(
8656 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8657 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008658 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008659 }
8660
Johannes Bergfffd0932009-07-08 14:22:54 +02008661 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8662 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308663 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008664 if (IS_ERR(connkeys))
8665 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008666 }
8667
Ben Greear7e7c8922011-11-18 11:31:59 -08008668 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8669 connect.flags |= ASSOC_REQ_DISABLE_HT;
8670
8671 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8672 memcpy(&connect.ht_capa_mask,
8673 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8674 sizeof(connect.ht_capa_mask));
8675
8676 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008677 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008678 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008679 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008680 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008681 memcpy(&connect.ht_capa,
8682 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8683 sizeof(connect.ht_capa));
8684 }
8685
Johannes Bergee2aca32013-02-21 17:36:01 +01008686 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8687 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8688
8689 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8690 memcpy(&connect.vht_capa_mask,
8691 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8692 sizeof(connect.vht_capa_mask));
8693
8694 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8695 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008696 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008697 return -EINVAL;
8698 }
8699 memcpy(&connect.vht_capa,
8700 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8701 sizeof(connect.vht_capa));
8702 }
8703
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008704 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008705 if (!((rdev->wiphy.features &
8706 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8707 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8708 !wiphy_ext_feature_isset(&rdev->wiphy,
8709 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008710 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008711 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008712 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008713 connect.flags |= ASSOC_REQ_USE_RRM;
8714 }
8715
Lior David34d50512016-01-28 10:58:25 +02008716 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008717 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008718 kzfree(connkeys);
8719 return -EOPNOTSUPP;
8720 }
8721
Arend van Spriel38de03d2016-03-02 20:37:18 +01008722 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8723 /* bss selection makes no sense if bssid is set */
8724 if (connect.bssid) {
8725 kzfree(connkeys);
8726 return -EINVAL;
8727 }
8728
8729 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8730 wiphy, &connect.bss_select);
8731 if (err) {
8732 kzfree(connkeys);
8733 return err;
8734 }
8735 }
8736
Johannes Berg83739b02013-05-15 17:44:01 +02008737 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008738 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8739 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008740 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008741 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008742 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008743 return err;
8744}
8745
8746static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8747{
Johannes Berg4c476992010-10-04 21:36:35 +02008748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8749 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008750 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008751 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008752
8753 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8754 reason = WLAN_REASON_DEAUTH_LEAVING;
8755 else
8756 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8757
8758 if (reason == 0)
8759 return -EINVAL;
8760
Johannes Berg074ac8d2010-09-16 14:58:22 +02008761 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008762 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8763 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008764
Johannes Berg83739b02013-05-15 17:44:01 +02008765 wdev_lock(dev->ieee80211_ptr);
8766 ret = cfg80211_disconnect(rdev, dev, reason, true);
8767 wdev_unlock(dev->ieee80211_ptr);
8768 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008769}
8770
Johannes Berg463d0182009-07-14 00:33:35 +02008771static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8772{
Johannes Berg4c476992010-10-04 21:36:35 +02008773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008774 struct net *net;
8775 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008776
Vadim Kochan4b681c82015-01-12 16:34:05 +02008777 if (info->attrs[NL80211_ATTR_PID]) {
8778 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8779
8780 net = get_net_ns_by_pid(pid);
8781 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8782 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8783
8784 net = get_net_ns_by_fd(fd);
8785 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008786 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008787 }
Johannes Berg463d0182009-07-14 00:33:35 +02008788
Johannes Berg4c476992010-10-04 21:36:35 +02008789 if (IS_ERR(net))
8790 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008791
8792 err = 0;
8793
8794 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008795 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8796 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008797
Johannes Berg463d0182009-07-14 00:33:35 +02008798 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008799 return err;
8800}
8801
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008802static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8803{
Johannes Berg4c476992010-10-04 21:36:35 +02008804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008805 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8806 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008807 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008808 struct cfg80211_pmksa pmksa;
8809
8810 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8811
8812 if (!info->attrs[NL80211_ATTR_MAC])
8813 return -EINVAL;
8814
8815 if (!info->attrs[NL80211_ATTR_PMKID])
8816 return -EINVAL;
8817
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008818 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8819 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8820
Johannes Berg074ac8d2010-09-16 14:58:22 +02008821 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008822 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8823 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008824
8825 switch (info->genlhdr->cmd) {
8826 case NL80211_CMD_SET_PMKSA:
8827 rdev_ops = rdev->ops->set_pmksa;
8828 break;
8829 case NL80211_CMD_DEL_PMKSA:
8830 rdev_ops = rdev->ops->del_pmksa;
8831 break;
8832 default:
8833 WARN_ON(1);
8834 break;
8835 }
8836
Johannes Berg4c476992010-10-04 21:36:35 +02008837 if (!rdev_ops)
8838 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008839
Johannes Berg4c476992010-10-04 21:36:35 +02008840 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008841}
8842
8843static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8844{
Johannes Berg4c476992010-10-04 21:36:35 +02008845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8846 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008847
Johannes Berg074ac8d2010-09-16 14:58:22 +02008848 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008849 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8850 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008851
Johannes Berg4c476992010-10-04 21:36:35 +02008852 if (!rdev->ops->flush_pmksa)
8853 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008854
Hila Gonene35e4d22012-06-27 17:19:42 +03008855 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008856}
8857
Arik Nemtsov109086c2011-09-28 14:12:50 +03008858static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8859{
8860 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8861 struct net_device *dev = info->user_ptr[1];
8862 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308863 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008864 u16 status_code;
8865 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008866 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008867
8868 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8869 !rdev->ops->tdls_mgmt)
8870 return -EOPNOTSUPP;
8871
8872 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8873 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8874 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8875 !info->attrs[NL80211_ATTR_IE] ||
8876 !info->attrs[NL80211_ATTR_MAC])
8877 return -EINVAL;
8878
8879 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8880 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8881 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8882 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008883 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308884 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8885 peer_capability =
8886 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008887
Hila Gonene35e4d22012-06-27 17:19:42 +03008888 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308889 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008890 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008891 nla_data(info->attrs[NL80211_ATTR_IE]),
8892 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008893}
8894
8895static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8896{
8897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8898 struct net_device *dev = info->user_ptr[1];
8899 enum nl80211_tdls_operation operation;
8900 u8 *peer;
8901
8902 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8903 !rdev->ops->tdls_oper)
8904 return -EOPNOTSUPP;
8905
8906 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8907 !info->attrs[NL80211_ATTR_MAC])
8908 return -EINVAL;
8909
8910 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8911 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8912
Hila Gonene35e4d22012-06-27 17:19:42 +03008913 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008914}
8915
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008916static int nl80211_remain_on_channel(struct sk_buff *skb,
8917 struct genl_info *info)
8918{
Johannes Berg4c476992010-10-04 21:36:35 +02008919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008920 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008921 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008922 struct sk_buff *msg;
8923 void *hdr;
8924 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008925 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008926 int err;
8927
8928 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8929 !info->attrs[NL80211_ATTR_DURATION])
8930 return -EINVAL;
8931
8932 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8933
Johannes Berg7c4ef712011-11-18 15:33:48 +01008934 if (!rdev->ops->remain_on_channel ||
8935 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008936 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008937
Johannes Bergebf348f2012-06-01 12:50:54 +02008938 /*
8939 * We should be on that channel for at least a minimum amount of
8940 * time (10ms) but no longer than the driver supports.
8941 */
8942 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8943 duration > rdev->wiphy.max_remain_on_channel_duration)
8944 return -EINVAL;
8945
Johannes Berg683b6d32012-11-08 21:25:48 +01008946 err = nl80211_parse_chandef(rdev, info, &chandef);
8947 if (err)
8948 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008949
8950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008951 if (!msg)
8952 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008953
Eric W. Biederman15e47302012-09-07 20:12:54 +00008954 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008955 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008956 if (!hdr) {
8957 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008958 goto free_msg;
8959 }
8960
Johannes Berg683b6d32012-11-08 21:25:48 +01008961 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8962 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008963
8964 if (err)
8965 goto free_msg;
8966
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008967 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8968 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008969 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008970
8971 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008972
8973 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008974
8975 nla_put_failure:
8976 err = -ENOBUFS;
8977 free_msg:
8978 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008979 return err;
8980}
8981
8982static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8983 struct genl_info *info)
8984{
Johannes Berg4c476992010-10-04 21:36:35 +02008985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008986 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008987 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008988
8989 if (!info->attrs[NL80211_ATTR_COOKIE])
8990 return -EINVAL;
8991
Johannes Berg4c476992010-10-04 21:36:35 +02008992 if (!rdev->ops->cancel_remain_on_channel)
8993 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008994
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008995 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8996
Hila Gonene35e4d22012-06-27 17:19:42 +03008997 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008998}
8999
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009000static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9001 struct genl_info *info)
9002{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009003 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009005 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309006 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009007
Johannes Berg4c476992010-10-04 21:36:35 +02009008 if (!rdev->ops->set_bitrate_mask)
9009 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009010
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309011 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9012 if (err)
9013 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009014
Hila Gonene35e4d22012-06-27 17:19:42 +03009015 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009016}
9017
Johannes Berg2e161f72010-08-12 15:38:38 +02009018static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009019{
Johannes Berg4c476992010-10-04 21:36:35 +02009020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009021 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009022 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009023
9024 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9025 return -EINVAL;
9026
Johannes Berg2e161f72010-08-12 15:38:38 +02009027 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9028 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009029
Johannes Berg71bbc992012-06-15 15:30:18 +02009030 switch (wdev->iftype) {
9031 case NL80211_IFTYPE_STATION:
9032 case NL80211_IFTYPE_ADHOC:
9033 case NL80211_IFTYPE_P2P_CLIENT:
9034 case NL80211_IFTYPE_AP:
9035 case NL80211_IFTYPE_AP_VLAN:
9036 case NL80211_IFTYPE_MESH_POINT:
9037 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009038 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009039 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009040 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009041 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009042 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009043 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009044
9045 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009046 if (!rdev->ops->mgmt_tx)
9047 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009048
Eric W. Biederman15e47302012-09-07 20:12:54 +00009049 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009050 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9051 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009052}
9053
Johannes Berg2e161f72010-08-12 15:38:38 +02009054static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009055{
Johannes Berg4c476992010-10-04 21:36:35 +02009056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009057 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009058 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009059 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009060 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009061 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009062 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009063 struct cfg80211_mgmt_tx_params params = {
9064 .dont_wait_for_ack =
9065 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9066 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009067
Johannes Berg683b6d32012-11-08 21:25:48 +01009068 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009069 return -EINVAL;
9070
Johannes Berg4c476992010-10-04 21:36:35 +02009071 if (!rdev->ops->mgmt_tx)
9072 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009073
Johannes Berg71bbc992012-06-15 15:30:18 +02009074 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009075 case NL80211_IFTYPE_P2P_DEVICE:
9076 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9077 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009078 case NL80211_IFTYPE_STATION:
9079 case NL80211_IFTYPE_ADHOC:
9080 case NL80211_IFTYPE_P2P_CLIENT:
9081 case NL80211_IFTYPE_AP:
9082 case NL80211_IFTYPE_AP_VLAN:
9083 case NL80211_IFTYPE_MESH_POINT:
9084 case NL80211_IFTYPE_P2P_GO:
9085 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009086 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009087 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009088 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009089 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009090
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009091 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009092 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009093 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009094 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009095
9096 /*
9097 * We should wait on the channel for at least a minimum amount
9098 * of time (10ms) but no longer than the driver supports.
9099 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009100 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9101 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009102 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009103 }
9104
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009105 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009106
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009107 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009108 return -EINVAL;
9109
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009110 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309111
Antonio Quartulliea141b752013-06-11 14:20:03 +02009112 /* get the channel if any has been specified, otherwise pass NULL to
9113 * the driver. The latter will use the current one
9114 */
9115 chandef.chan = NULL;
9116 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9117 err = nl80211_parse_chandef(rdev, info, &chandef);
9118 if (err)
9119 return err;
9120 }
9121
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009122 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009123 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009124
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009125 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9126 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9127
9128 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9129 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9130 int i;
9131
9132 if (len % sizeof(u16))
9133 return -EINVAL;
9134
9135 params.n_csa_offsets = len / sizeof(u16);
9136 params.csa_offsets =
9137 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9138
9139 /* check that all the offsets fit the frame */
9140 for (i = 0; i < params.n_csa_offsets; i++) {
9141 if (params.csa_offsets[i] >= params.len)
9142 return -EINVAL;
9143 }
9144 }
9145
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009146 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009147 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9148 if (!msg)
9149 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009150
Eric W. Biederman15e47302012-09-07 20:12:54 +00009151 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009152 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009153 if (!hdr) {
9154 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009155 goto free_msg;
9156 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009157 }
Johannes Berge247bd902011-11-04 11:18:21 +01009158
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009159 params.chan = chandef.chan;
9160 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009161 if (err)
9162 goto free_msg;
9163
Johannes Berge247bd902011-11-04 11:18:21 +01009164 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009165 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9166 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009167 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009168
Johannes Berge247bd902011-11-04 11:18:21 +01009169 genlmsg_end(msg, hdr);
9170 return genlmsg_reply(msg, info);
9171 }
9172
9173 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009174
9175 nla_put_failure:
9176 err = -ENOBUFS;
9177 free_msg:
9178 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009179 return err;
9180}
9181
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009182static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9183{
9184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009185 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009186 u64 cookie;
9187
9188 if (!info->attrs[NL80211_ATTR_COOKIE])
9189 return -EINVAL;
9190
9191 if (!rdev->ops->mgmt_tx_cancel_wait)
9192 return -EOPNOTSUPP;
9193
Johannes Berg71bbc992012-06-15 15:30:18 +02009194 switch (wdev->iftype) {
9195 case NL80211_IFTYPE_STATION:
9196 case NL80211_IFTYPE_ADHOC:
9197 case NL80211_IFTYPE_P2P_CLIENT:
9198 case NL80211_IFTYPE_AP:
9199 case NL80211_IFTYPE_AP_VLAN:
9200 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009201 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009202 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009203 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009204 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009205 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009206 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009207
9208 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9209
Hila Gonene35e4d22012-06-27 17:19:42 +03009210 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009211}
9212
Kalle Valoffb9eb32010-02-17 17:58:10 +02009213static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9214{
Johannes Berg4c476992010-10-04 21:36:35 +02009215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009216 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009217 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009218 u8 ps_state;
9219 bool state;
9220 int err;
9221
Johannes Berg4c476992010-10-04 21:36:35 +02009222 if (!info->attrs[NL80211_ATTR_PS_STATE])
9223 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009224
9225 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9226
Johannes Berg4c476992010-10-04 21:36:35 +02009227 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9228 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009229
9230 wdev = dev->ieee80211_ptr;
9231
Johannes Berg4c476992010-10-04 21:36:35 +02009232 if (!rdev->ops->set_power_mgmt)
9233 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009234
9235 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9236
9237 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009238 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009239
Hila Gonene35e4d22012-06-27 17:19:42 +03009240 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009241 if (!err)
9242 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009243 return err;
9244}
9245
9246static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9247{
Johannes Berg4c476992010-10-04 21:36:35 +02009248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009249 enum nl80211_ps_state ps_state;
9250 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009251 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009252 struct sk_buff *msg;
9253 void *hdr;
9254 int err;
9255
Kalle Valoffb9eb32010-02-17 17:58:10 +02009256 wdev = dev->ieee80211_ptr;
9257
Johannes Berg4c476992010-10-04 21:36:35 +02009258 if (!rdev->ops->set_power_mgmt)
9259 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009260
9261 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009262 if (!msg)
9263 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009264
Eric W. Biederman15e47302012-09-07 20:12:54 +00009265 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009266 NL80211_CMD_GET_POWER_SAVE);
9267 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009268 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009269 goto free_msg;
9270 }
9271
9272 if (wdev->ps)
9273 ps_state = NL80211_PS_ENABLED;
9274 else
9275 ps_state = NL80211_PS_DISABLED;
9276
David S. Miller9360ffd2012-03-29 04:41:26 -04009277 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9278 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009279
9280 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009281 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009282
Johannes Berg4c476992010-10-04 21:36:35 +02009283 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009284 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009285 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009286 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009287 return err;
9288}
9289
Johannes Berg94e860f2014-01-20 23:58:15 +01009290static const struct nla_policy
9291nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009292 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9293 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9294 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009295 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9296 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9297 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009298};
9299
Thomas Pedersen84f10702012-07-12 16:17:33 -07009300static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009301 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009302{
9303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009304 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009305 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009306
Johannes Bergd9d8b012012-11-26 12:51:52 +01009307 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009308 return -EINVAL;
9309
Thomas Pedersen84f10702012-07-12 16:17:33 -07009310 if (!rdev->ops->set_cqm_txe_config)
9311 return -EOPNOTSUPP;
9312
9313 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9314 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9315 return -EOPNOTSUPP;
9316
Hila Gonene35e4d22012-06-27 17:19:42 +03009317 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009318}
9319
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009320static int nl80211_set_cqm_rssi(struct genl_info *info,
9321 s32 threshold, u32 hysteresis)
9322{
Johannes Berg4c476992010-10-04 21:36:35 +02009323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009324 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009325 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009326
9327 if (threshold > 0)
9328 return -EINVAL;
9329
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009330 /* disabling - hysteresis should also be zero then */
9331 if (threshold == 0)
9332 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009333
Johannes Berg4c476992010-10-04 21:36:35 +02009334 if (!rdev->ops->set_cqm_rssi_config)
9335 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009336
Johannes Berg074ac8d2010-09-16 14:58:22 +02009337 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009338 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9339 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009340
Hila Gonene35e4d22012-06-27 17:19:42 +03009341 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009342}
9343
9344static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9345{
9346 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9347 struct nlattr *cqm;
9348 int err;
9349
9350 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009351 if (!cqm)
9352 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009353
9354 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9355 nl80211_attr_cqm_policy);
9356 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009357 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009358
9359 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9360 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009361 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9362 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009363
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009364 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9365 }
9366
9367 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9368 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9369 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9370 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9371 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9372 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9373
9374 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9375 }
9376
9377 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009378}
9379
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009380static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
9381{
9382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9383 struct net_device *dev = info->user_ptr[1];
9384 struct ocb_setup setup = {};
9385 int err;
9386
9387 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9388 if (err)
9389 return err;
9390
9391 return cfg80211_join_ocb(rdev, dev, &setup);
9392}
9393
9394static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9395{
9396 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9397 struct net_device *dev = info->user_ptr[1];
9398
9399 return cfg80211_leave_ocb(rdev, dev);
9400}
9401
Johannes Berg29cbe682010-12-03 09:20:44 +01009402static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9403{
9404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9405 struct net_device *dev = info->user_ptr[1];
9406 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009407 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009408 int err;
9409
9410 /* start with default */
9411 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009412 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009413
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009414 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009415 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009416 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009417 if (err)
9418 return err;
9419 }
9420
9421 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9422 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9423 return -EINVAL;
9424
Javier Cardonac80d5452010-12-16 17:37:49 -08009425 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9426 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9427
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009428 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9429 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9430 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9431 return -EINVAL;
9432
Marco Porsch9bdbf042013-01-07 16:04:51 +01009433 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9434 setup.beacon_interval =
9435 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309436
Purushottam Kushwahac6800ff2016-10-12 18:26:51 +05309437 err = cfg80211_validate_beacon_int(rdev,
9438 NL80211_IFTYPE_MESH_POINT,
9439 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309440 if (err)
9441 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009442 }
9443
9444 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9445 setup.dtim_period =
9446 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9447 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9448 return -EINVAL;
9449 }
9450
Javier Cardonac80d5452010-12-16 17:37:49 -08009451 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9452 /* parse additional setup parameters if given */
9453 err = nl80211_parse_mesh_setup(info, &setup);
9454 if (err)
9455 return err;
9456 }
9457
Thomas Pedersend37bb182013-03-04 13:06:13 -08009458 if (setup.user_mpm)
9459 cfg.auto_open_plinks = false;
9460
Johannes Bergcc1d2802012-05-16 23:50:20 +02009461 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009462 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9463 if (err)
9464 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009465 } else {
9466 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009467 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009468 }
9469
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009470 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9471 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9472 int n_rates =
9473 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9474 struct ieee80211_supported_band *sband;
9475
9476 if (!setup.chandef.chan)
9477 return -EINVAL;
9478
9479 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9480
9481 err = ieee80211_get_ratemask(sband, rates, n_rates,
9482 &setup.basic_rates);
9483 if (err)
9484 return err;
9485 }
9486
Johannes Berg8564e382016-09-19 09:44:44 +02009487 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9488 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9489 if (err)
9490 return err;
9491
9492 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9493 &setup.beacon_rate);
9494 if (err)
9495 return err;
9496 }
9497
Javier Cardonac80d5452010-12-16 17:37:49 -08009498 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009499}
9500
9501static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9502{
9503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9504 struct net_device *dev = info->user_ptr[1];
9505
9506 return cfg80211_leave_mesh(rdev, dev);
9507}
9508
Johannes Bergdfb89c52012-06-27 09:23:48 +02009509#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009510static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9511 struct cfg80211_registered_device *rdev)
9512{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009513 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009514 struct nlattr *nl_pats, *nl_pat;
9515 int i, pat_len;
9516
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009517 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009518 return 0;
9519
9520 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9521 if (!nl_pats)
9522 return -ENOBUFS;
9523
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009524 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009525 nl_pat = nla_nest_start(msg, i + 1);
9526 if (!nl_pat)
9527 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009528 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009529 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009530 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009531 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9532 wowlan->patterns[i].pattern) ||
9533 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009534 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009535 return -ENOBUFS;
9536 nla_nest_end(msg, nl_pat);
9537 }
9538 nla_nest_end(msg, nl_pats);
9539
9540 return 0;
9541}
9542
Johannes Berg2a0e0472013-01-23 22:57:40 +01009543static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9544 struct cfg80211_wowlan_tcp *tcp)
9545{
9546 struct nlattr *nl_tcp;
9547
9548 if (!tcp)
9549 return 0;
9550
9551 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9552 if (!nl_tcp)
9553 return -ENOBUFS;
9554
Jiri Benc930345e2015-03-29 16:59:25 +02009555 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9556 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009557 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9558 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9559 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9560 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9561 tcp->payload_len, tcp->payload) ||
9562 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9563 tcp->data_interval) ||
9564 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9565 tcp->wake_len, tcp->wake_data) ||
9566 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9567 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9568 return -ENOBUFS;
9569
9570 if (tcp->payload_seq.len &&
9571 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9572 sizeof(tcp->payload_seq), &tcp->payload_seq))
9573 return -ENOBUFS;
9574
9575 if (tcp->payload_tok.len &&
9576 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9577 sizeof(tcp->payload_tok) + tcp->tokens_size,
9578 &tcp->payload_tok))
9579 return -ENOBUFS;
9580
Johannes Berge248ad32013-05-16 10:24:28 +02009581 nla_nest_end(msg, nl_tcp);
9582
Johannes Berg2a0e0472013-01-23 22:57:40 +01009583 return 0;
9584}
9585
Luciano Coelho75453cc2015-01-09 14:06:37 +02009586static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9587 struct cfg80211_sched_scan_request *req)
9588{
Avraham Stern3b06d272015-10-12 09:51:34 +03009589 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009590 int i;
9591
9592 if (!req)
9593 return 0;
9594
9595 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9596 if (!nd)
9597 return -ENOBUFS;
9598
Avraham Stern3b06d272015-10-12 09:51:34 +03009599 if (req->n_scan_plans == 1 &&
9600 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9601 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009602 return -ENOBUFS;
9603
Luciano Coelho21fea562015-03-17 16:36:01 +02009604 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9605 return -ENOBUFS;
9606
Luciano Coelho75453cc2015-01-09 14:06:37 +02009607 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9608 if (!freqs)
9609 return -ENOBUFS;
9610
Johannes Berg53b18982016-09-14 09:59:21 +02009611 for (i = 0; i < req->n_channels; i++) {
9612 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9613 return -ENOBUFS;
9614 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009615
9616 nla_nest_end(msg, freqs);
9617
9618 if (req->n_match_sets) {
9619 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009620 if (!matches)
9621 return -ENOBUFS;
9622
Luciano Coelho75453cc2015-01-09 14:06:37 +02009623 for (i = 0; i < req->n_match_sets; i++) {
9624 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009625 if (!match)
9626 return -ENOBUFS;
9627
Johannes Berg53b18982016-09-14 09:59:21 +02009628 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9629 req->match_sets[i].ssid.ssid_len,
9630 req->match_sets[i].ssid.ssid))
9631 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009632 nla_nest_end(msg, match);
9633 }
9634 nla_nest_end(msg, matches);
9635 }
9636
Avraham Stern3b06d272015-10-12 09:51:34 +03009637 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9638 if (!scan_plans)
9639 return -ENOBUFS;
9640
9641 for (i = 0; i < req->n_scan_plans; i++) {
9642 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009643 if (!scan_plan)
9644 return -ENOBUFS;
9645
Avraham Stern3b06d272015-10-12 09:51:34 +03009646 if (!scan_plan ||
9647 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9648 req->scan_plans[i].interval) ||
9649 (req->scan_plans[i].iterations &&
9650 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9651 req->scan_plans[i].iterations)))
9652 return -ENOBUFS;
9653 nla_nest_end(msg, scan_plan);
9654 }
9655 nla_nest_end(msg, scan_plans);
9656
Luciano Coelho75453cc2015-01-09 14:06:37 +02009657 nla_nest_end(msg, nd);
9658
9659 return 0;
9660}
9661
Johannes Bergff1b6e62011-05-04 15:37:28 +02009662static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9663{
9664 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9665 struct sk_buff *msg;
9666 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009667 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009668
Johannes Berg964dc9e2013-06-03 17:25:34 +02009669 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009670 return -EOPNOTSUPP;
9671
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009672 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009673 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009674 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9675 rdev->wiphy.wowlan_config->tcp->payload_len +
9676 rdev->wiphy.wowlan_config->tcp->wake_len +
9677 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009678 }
9679
9680 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009681 if (!msg)
9682 return -ENOMEM;
9683
Eric W. Biederman15e47302012-09-07 20:12:54 +00009684 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009685 NL80211_CMD_GET_WOWLAN);
9686 if (!hdr)
9687 goto nla_put_failure;
9688
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009689 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009690 struct nlattr *nl_wowlan;
9691
9692 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9693 if (!nl_wowlan)
9694 goto nla_put_failure;
9695
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009696 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009697 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009698 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009699 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009700 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009701 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009702 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009703 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009704 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009705 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009706 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009707 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009708 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009709 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9710 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009711
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009712 if (nl80211_send_wowlan_patterns(msg, rdev))
9713 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009714
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009715 if (nl80211_send_wowlan_tcp(msg,
9716 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009717 goto nla_put_failure;
9718
Luciano Coelho75453cc2015-01-09 14:06:37 +02009719 if (nl80211_send_wowlan_nd(
9720 msg,
9721 rdev->wiphy.wowlan_config->nd_config))
9722 goto nla_put_failure;
9723
Johannes Bergff1b6e62011-05-04 15:37:28 +02009724 nla_nest_end(msg, nl_wowlan);
9725 }
9726
9727 genlmsg_end(msg, hdr);
9728 return genlmsg_reply(msg, info);
9729
9730nla_put_failure:
9731 nlmsg_free(msg);
9732 return -ENOBUFS;
9733}
9734
Johannes Berg2a0e0472013-01-23 22:57:40 +01009735static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9736 struct nlattr *attr,
9737 struct cfg80211_wowlan *trig)
9738{
9739 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9740 struct cfg80211_wowlan_tcp *cfg;
9741 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9742 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9743 u32 size;
9744 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9745 int err, port;
9746
Johannes Berg964dc9e2013-06-03 17:25:34 +02009747 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009748 return -EINVAL;
9749
9750 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9751 nla_data(attr), nla_len(attr),
9752 nl80211_wowlan_tcp_policy);
9753 if (err)
9754 return err;
9755
9756 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9757 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9758 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9759 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9760 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9761 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9762 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9763 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9764 return -EINVAL;
9765
9766 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009767 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009768 return -EINVAL;
9769
9770 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009771 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009772 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009773 return -EINVAL;
9774
9775 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009776 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009777 return -EINVAL;
9778
9779 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9780 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9781 return -EINVAL;
9782
9783 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9784 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9785
9786 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9787 tokens_size = tokln - sizeof(*tok);
9788
9789 if (!tok->len || tokens_size % tok->len)
9790 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009791 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009792 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009793 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009794 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009795 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009796 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009797 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009798 return -EINVAL;
9799 if (tok->offset + tok->len > data_size)
9800 return -EINVAL;
9801 }
9802
9803 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9804 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009805 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009806 return -EINVAL;
9807 if (seq->len == 0 || seq->len > 4)
9808 return -EINVAL;
9809 if (seq->len + seq->offset > data_size)
9810 return -EINVAL;
9811 }
9812
9813 size = sizeof(*cfg);
9814 size += data_size;
9815 size += wake_size + wake_mask_size;
9816 size += tokens_size;
9817
9818 cfg = kzalloc(size, GFP_KERNEL);
9819 if (!cfg)
9820 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009821 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9822 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009823 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9824 ETH_ALEN);
9825 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9826 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9827 else
9828 port = 0;
9829#ifdef CONFIG_INET
9830 /* allocate a socket and port for it and use it */
9831 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9832 IPPROTO_TCP, &cfg->sock, 1);
9833 if (err) {
9834 kfree(cfg);
9835 return err;
9836 }
9837 if (inet_csk_get_port(cfg->sock->sk, port)) {
9838 sock_release(cfg->sock);
9839 kfree(cfg);
9840 return -EADDRINUSE;
9841 }
9842 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9843#else
9844 if (!port) {
9845 kfree(cfg);
9846 return -EINVAL;
9847 }
9848 cfg->src_port = port;
9849#endif
9850
9851 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9852 cfg->payload_len = data_size;
9853 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9854 memcpy((void *)cfg->payload,
9855 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9856 data_size);
9857 if (seq)
9858 cfg->payload_seq = *seq;
9859 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9860 cfg->wake_len = wake_size;
9861 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9862 memcpy((void *)cfg->wake_data,
9863 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9864 wake_size);
9865 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9866 data_size + wake_size;
9867 memcpy((void *)cfg->wake_mask,
9868 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9869 wake_mask_size);
9870 if (tok) {
9871 cfg->tokens_size = tokens_size;
9872 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9873 }
9874
9875 trig->tcp = cfg;
9876
9877 return 0;
9878}
9879
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009880static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9881 const struct wiphy_wowlan_support *wowlan,
9882 struct nlattr *attr,
9883 struct cfg80211_wowlan *trig)
9884{
9885 struct nlattr **tb;
9886 int err;
9887
9888 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9889 if (!tb)
9890 return -ENOMEM;
9891
9892 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9893 err = -EOPNOTSUPP;
9894 goto out;
9895 }
9896
9897 err = nla_parse(tb, NL80211_ATTR_MAX,
9898 nla_data(attr), nla_len(attr),
9899 nl80211_policy);
9900 if (err)
9901 goto out;
9902
Johannes Bergad2b26a2014-06-12 21:39:05 +02009903 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009904 err = PTR_ERR_OR_ZERO(trig->nd_config);
9905 if (err)
9906 trig->nd_config = NULL;
9907
9908out:
9909 kfree(tb);
9910 return err;
9911}
9912
Johannes Bergff1b6e62011-05-04 15:37:28 +02009913static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9914{
9915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9916 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009917 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009918 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009919 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009920 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009921 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009922 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009923
Johannes Berg964dc9e2013-06-03 17:25:34 +02009924 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009925 return -EOPNOTSUPP;
9926
Johannes Bergae33bd82012-07-12 16:25:02 +02009927 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9928 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009929 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009930 goto set_wakeup;
9931 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009932
9933 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9934 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9935 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9936 nl80211_wowlan_policy);
9937 if (err)
9938 return err;
9939
9940 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9941 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9942 return -EINVAL;
9943 new_triggers.any = true;
9944 }
9945
9946 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9947 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9948 return -EINVAL;
9949 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009950 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009951 }
9952
9953 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9954 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9955 return -EINVAL;
9956 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009957 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009958 }
9959
Johannes Berg77dbbb12011-07-13 10:48:55 +02009960 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9961 return -EINVAL;
9962
9963 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9964 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9965 return -EINVAL;
9966 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009967 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009968 }
9969
9970 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9971 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9972 return -EINVAL;
9973 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009974 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009975 }
9976
9977 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9978 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9979 return -EINVAL;
9980 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009981 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009982 }
9983
9984 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9985 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9986 return -EINVAL;
9987 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009988 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009989 }
9990
Johannes Bergff1b6e62011-05-04 15:37:28 +02009991 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9992 struct nlattr *pat;
9993 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009994 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009995 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009996
Johannes Berg98fc4382015-03-01 09:10:13 +02009997 regular = true;
9998
Johannes Bergff1b6e62011-05-04 15:37:28 +02009999 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10000 rem)
10001 n_patterns++;
10002 if (n_patterns > wowlan->n_patterns)
10003 return -EINVAL;
10004
10005 new_triggers.patterns = kcalloc(n_patterns,
10006 sizeof(new_triggers.patterns[0]),
10007 GFP_KERNEL);
10008 if (!new_triggers.patterns)
10009 return -ENOMEM;
10010
10011 new_triggers.n_patterns = n_patterns;
10012 i = 0;
10013
10014 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10015 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010016 u8 *mask_pat;
10017
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010018 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10019 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010020 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010021 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10022 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010023 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010024 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010025 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010026 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010027 goto error;
10028 if (pat_len > wowlan->pattern_max_len ||
10029 pat_len < wowlan->pattern_min_len)
10030 goto error;
10031
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010032 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010033 pkt_offset = 0;
10034 else
10035 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010036 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010037 if (pkt_offset > wowlan->max_pkt_offset)
10038 goto error;
10039 new_triggers.patterns[i].pkt_offset = pkt_offset;
10040
Johannes Berg922bd802014-05-19 17:59:50 +020010041 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10042 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010043 err = -ENOMEM;
10044 goto error;
10045 }
Johannes Berg922bd802014-05-19 17:59:50 +020010046 new_triggers.patterns[i].mask = mask_pat;
10047 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010048 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010049 mask_pat += mask_len;
10050 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010051 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010052 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010053 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010054 pat_len);
10055 i++;
10056 }
10057 }
10058
Johannes Berg2a0e0472013-01-23 22:57:40 +010010059 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010060 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010061 err = nl80211_parse_wowlan_tcp(
10062 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10063 &new_triggers);
10064 if (err)
10065 goto error;
10066 }
10067
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010068 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010069 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010070 err = nl80211_parse_wowlan_nd(
10071 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10072 &new_triggers);
10073 if (err)
10074 goto error;
10075 }
10076
Johannes Berg98fc4382015-03-01 09:10:13 +020010077 /* The 'any' trigger means the device continues operating more or less
10078 * as in its normal operation mode and wakes up the host on most of the
10079 * normal interrupts (like packet RX, ...)
10080 * It therefore makes little sense to combine with the more constrained
10081 * wakeup trigger modes.
10082 */
10083 if (new_triggers.any && regular) {
10084 err = -EINVAL;
10085 goto error;
10086 }
10087
Johannes Bergae33bd82012-07-12 16:25:02 +020010088 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10089 if (!ntrig) {
10090 err = -ENOMEM;
10091 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010092 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010093 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010094 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010095
Johannes Bergae33bd82012-07-12 16:25:02 +020010096 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010097 if (rdev->ops->set_wakeup &&
10098 prev_enabled != !!rdev->wiphy.wowlan_config)
10099 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010100
Johannes Bergff1b6e62011-05-04 15:37:28 +020010101 return 0;
10102 error:
10103 for (i = 0; i < new_triggers.n_patterns; i++)
10104 kfree(new_triggers.patterns[i].mask);
10105 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010106 if (new_triggers.tcp && new_triggers.tcp->sock)
10107 sock_release(new_triggers.tcp->sock);
10108 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010109 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010110 return err;
10111}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010112#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010113
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010114static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10115 struct cfg80211_registered_device *rdev)
10116{
10117 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10118 int i, j, pat_len;
10119 struct cfg80211_coalesce_rules *rule;
10120
10121 if (!rdev->coalesce->n_rules)
10122 return 0;
10123
10124 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10125 if (!nl_rules)
10126 return -ENOBUFS;
10127
10128 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10129 nl_rule = nla_nest_start(msg, i + 1);
10130 if (!nl_rule)
10131 return -ENOBUFS;
10132
10133 rule = &rdev->coalesce->rules[i];
10134 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10135 rule->delay))
10136 return -ENOBUFS;
10137
10138 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10139 rule->condition))
10140 return -ENOBUFS;
10141
10142 nl_pats = nla_nest_start(msg,
10143 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10144 if (!nl_pats)
10145 return -ENOBUFS;
10146
10147 for (j = 0; j < rule->n_patterns; j++) {
10148 nl_pat = nla_nest_start(msg, j + 1);
10149 if (!nl_pat)
10150 return -ENOBUFS;
10151 pat_len = rule->patterns[j].pattern_len;
10152 if (nla_put(msg, NL80211_PKTPAT_MASK,
10153 DIV_ROUND_UP(pat_len, 8),
10154 rule->patterns[j].mask) ||
10155 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10156 rule->patterns[j].pattern) ||
10157 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10158 rule->patterns[j].pkt_offset))
10159 return -ENOBUFS;
10160 nla_nest_end(msg, nl_pat);
10161 }
10162 nla_nest_end(msg, nl_pats);
10163 nla_nest_end(msg, nl_rule);
10164 }
10165 nla_nest_end(msg, nl_rules);
10166
10167 return 0;
10168}
10169
10170static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10171{
10172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10173 struct sk_buff *msg;
10174 void *hdr;
10175
10176 if (!rdev->wiphy.coalesce)
10177 return -EOPNOTSUPP;
10178
10179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10180 if (!msg)
10181 return -ENOMEM;
10182
10183 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10184 NL80211_CMD_GET_COALESCE);
10185 if (!hdr)
10186 goto nla_put_failure;
10187
10188 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10189 goto nla_put_failure;
10190
10191 genlmsg_end(msg, hdr);
10192 return genlmsg_reply(msg, info);
10193
10194nla_put_failure:
10195 nlmsg_free(msg);
10196 return -ENOBUFS;
10197}
10198
10199void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10200{
10201 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10202 int i, j;
10203 struct cfg80211_coalesce_rules *rule;
10204
10205 if (!coalesce)
10206 return;
10207
10208 for (i = 0; i < coalesce->n_rules; i++) {
10209 rule = &coalesce->rules[i];
10210 for (j = 0; j < rule->n_patterns; j++)
10211 kfree(rule->patterns[j].mask);
10212 kfree(rule->patterns);
10213 }
10214 kfree(coalesce->rules);
10215 kfree(coalesce);
10216 rdev->coalesce = NULL;
10217}
10218
10219static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10220 struct nlattr *rule,
10221 struct cfg80211_coalesce_rules *new_rule)
10222{
10223 int err, i;
10224 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10225 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10226 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10227 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10228
10229 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
10230 nla_len(rule), nl80211_coalesce_policy);
10231 if (err)
10232 return err;
10233
10234 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10235 new_rule->delay =
10236 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10237 if (new_rule->delay > coalesce->max_delay)
10238 return -EINVAL;
10239
10240 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10241 new_rule->condition =
10242 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10243 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10244 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10245 return -EINVAL;
10246
10247 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10248 return -EINVAL;
10249
10250 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10251 rem)
10252 n_patterns++;
10253 if (n_patterns > coalesce->n_patterns)
10254 return -EINVAL;
10255
10256 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10257 GFP_KERNEL);
10258 if (!new_rule->patterns)
10259 return -ENOMEM;
10260
10261 new_rule->n_patterns = n_patterns;
10262 i = 0;
10263
10264 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10265 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010266 u8 *mask_pat;
10267
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010268 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
10269 nla_len(pat), NULL);
10270 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10271 !pat_tb[NL80211_PKTPAT_PATTERN])
10272 return -EINVAL;
10273 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10274 mask_len = DIV_ROUND_UP(pat_len, 8);
10275 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10276 return -EINVAL;
10277 if (pat_len > coalesce->pattern_max_len ||
10278 pat_len < coalesce->pattern_min_len)
10279 return -EINVAL;
10280
10281 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10282 pkt_offset = 0;
10283 else
10284 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10285 if (pkt_offset > coalesce->max_pkt_offset)
10286 return -EINVAL;
10287 new_rule->patterns[i].pkt_offset = pkt_offset;
10288
Johannes Berg922bd802014-05-19 17:59:50 +020010289 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10290 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010291 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010292
10293 new_rule->patterns[i].mask = mask_pat;
10294 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10295 mask_len);
10296
10297 mask_pat += mask_len;
10298 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010299 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010300 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10301 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010302 i++;
10303 }
10304
10305 return 0;
10306}
10307
10308static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10309{
10310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10311 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10312 struct cfg80211_coalesce new_coalesce = {};
10313 struct cfg80211_coalesce *n_coalesce;
10314 int err, rem_rule, n_rules = 0, i, j;
10315 struct nlattr *rule;
10316 struct cfg80211_coalesce_rules *tmp_rule;
10317
10318 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10319 return -EOPNOTSUPP;
10320
10321 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10322 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +030010323 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010324 return 0;
10325 }
10326
10327 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10328 rem_rule)
10329 n_rules++;
10330 if (n_rules > coalesce->n_rules)
10331 return -EINVAL;
10332
10333 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10334 GFP_KERNEL);
10335 if (!new_coalesce.rules)
10336 return -ENOMEM;
10337
10338 new_coalesce.n_rules = n_rules;
10339 i = 0;
10340
10341 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10342 rem_rule) {
10343 err = nl80211_parse_coalesce_rule(rdev, rule,
10344 &new_coalesce.rules[i]);
10345 if (err)
10346 goto error;
10347
10348 i++;
10349 }
10350
Ilan Peera1056b12015-10-22 22:27:46 +030010351 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010352 if (err)
10353 goto error;
10354
10355 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10356 if (!n_coalesce) {
10357 err = -ENOMEM;
10358 goto error;
10359 }
10360 cfg80211_rdev_free_coalesce(rdev);
10361 rdev->coalesce = n_coalesce;
10362
10363 return 0;
10364error:
10365 for (i = 0; i < new_coalesce.n_rules; i++) {
10366 tmp_rule = &new_coalesce.rules[i];
10367 for (j = 0; j < tmp_rule->n_patterns; j++)
10368 kfree(tmp_rule->patterns[j].mask);
10369 kfree(tmp_rule->patterns);
10370 }
10371 kfree(new_coalesce.rules);
10372
10373 return err;
10374}
10375
Johannes Berge5497d72011-07-05 16:35:40 +020010376static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10377{
10378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10379 struct net_device *dev = info->user_ptr[1];
10380 struct wireless_dev *wdev = dev->ieee80211_ptr;
10381 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10382 struct cfg80211_gtk_rekey_data rekey_data;
10383 int err;
10384
10385 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10386 return -EINVAL;
10387
10388 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
10389 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
10390 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
10391 nl80211_rekey_policy);
10392 if (err)
10393 return err;
10394
10395 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10396 return -ERANGE;
10397 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10398 return -ERANGE;
10399 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10400 return -ERANGE;
10401
Johannes Berg78f686c2014-09-10 22:28:06 +030010402 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10403 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10404 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010405
10406 wdev_lock(wdev);
10407 if (!wdev->current_bss) {
10408 err = -ENOTCONN;
10409 goto out;
10410 }
10411
10412 if (!rdev->ops->set_rekey_data) {
10413 err = -EOPNOTSUPP;
10414 goto out;
10415 }
10416
Hila Gonene35e4d22012-06-27 17:19:42 +030010417 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010418 out:
10419 wdev_unlock(wdev);
10420 return err;
10421}
10422
Johannes Berg28946da2011-11-04 11:18:12 +010010423static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10424 struct genl_info *info)
10425{
10426 struct net_device *dev = info->user_ptr[1];
10427 struct wireless_dev *wdev = dev->ieee80211_ptr;
10428
10429 if (wdev->iftype != NL80211_IFTYPE_AP &&
10430 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10431 return -EINVAL;
10432
Eric W. Biederman15e47302012-09-07 20:12:54 +000010433 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010434 return -EBUSY;
10435
Eric W. Biederman15e47302012-09-07 20:12:54 +000010436 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010437 return 0;
10438}
10439
Johannes Berg7f6cf312011-11-04 11:18:15 +010010440static int nl80211_probe_client(struct sk_buff *skb,
10441 struct genl_info *info)
10442{
10443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10444 struct net_device *dev = info->user_ptr[1];
10445 struct wireless_dev *wdev = dev->ieee80211_ptr;
10446 struct sk_buff *msg;
10447 void *hdr;
10448 const u8 *addr;
10449 u64 cookie;
10450 int err;
10451
10452 if (wdev->iftype != NL80211_IFTYPE_AP &&
10453 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10454 return -EOPNOTSUPP;
10455
10456 if (!info->attrs[NL80211_ATTR_MAC])
10457 return -EINVAL;
10458
10459 if (!rdev->ops->probe_client)
10460 return -EOPNOTSUPP;
10461
10462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10463 if (!msg)
10464 return -ENOMEM;
10465
Eric W. Biederman15e47302012-09-07 20:12:54 +000010466 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010467 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010468 if (!hdr) {
10469 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010470 goto free_msg;
10471 }
10472
10473 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10474
Hila Gonene35e4d22012-06-27 17:19:42 +030010475 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010476 if (err)
10477 goto free_msg;
10478
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010479 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10480 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010481 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010482
10483 genlmsg_end(msg, hdr);
10484
10485 return genlmsg_reply(msg, info);
10486
10487 nla_put_failure:
10488 err = -ENOBUFS;
10489 free_msg:
10490 nlmsg_free(msg);
10491 return err;
10492}
10493
Johannes Berg5e7602302011-11-04 11:18:17 +010010494static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10495{
10496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010497 struct cfg80211_beacon_registration *reg, *nreg;
10498 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010499
10500 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10501 return -EOPNOTSUPP;
10502
Ben Greear37c73b52012-10-26 14:49:25 -070010503 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10504 if (!nreg)
10505 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +010010506
Ben Greear37c73b52012-10-26 14:49:25 -070010507 /* First, check if already registered. */
10508 spin_lock_bh(&rdev->beacon_registrations_lock);
10509 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10510 if (reg->nlportid == info->snd_portid) {
10511 rv = -EALREADY;
10512 goto out_err;
10513 }
10514 }
10515 /* Add it to the list */
10516 nreg->nlportid = info->snd_portid;
10517 list_add(&nreg->list, &rdev->beacon_registrations);
10518
10519 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010520
10521 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010522out_err:
10523 spin_unlock_bh(&rdev->beacon_registrations_lock);
10524 kfree(nreg);
10525 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +010010526}
10527
Johannes Berg98104fde2012-06-16 00:19:54 +020010528static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10529{
10530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10531 struct wireless_dev *wdev = info->user_ptr[1];
10532 int err;
10533
10534 if (!rdev->ops->start_p2p_device)
10535 return -EOPNOTSUPP;
10536
10537 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10538 return -EOPNOTSUPP;
10539
10540 if (wdev->p2p_started)
10541 return 0;
10542
Luciano Coelhob6a55012014-02-27 11:07:21 +020010543 if (rfkill_blocked(rdev->rfkill))
10544 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010545
Johannes Bergeeb126e2012-10-23 15:16:50 +020010546 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010547 if (err)
10548 return err;
10549
10550 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010551 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010552
10553 return 0;
10554}
10555
10556static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10557{
10558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10559 struct wireless_dev *wdev = info->user_ptr[1];
10560
10561 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10562 return -EOPNOTSUPP;
10563
10564 if (!rdev->ops->stop_p2p_device)
10565 return -EOPNOTSUPP;
10566
Johannes Bergf9f47522013-03-19 15:04:07 +010010567 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010568
10569 return 0;
10570}
10571
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010572static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10573{
10574 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10575 struct wireless_dev *wdev = info->user_ptr[1];
10576 struct cfg80211_nan_conf conf = {};
10577 int err;
10578
10579 if (wdev->iftype != NL80211_IFTYPE_NAN)
10580 return -EOPNOTSUPP;
10581
10582 if (wdev->nan_started)
10583 return -EEXIST;
10584
10585 if (rfkill_blocked(rdev->rfkill))
10586 return -ERFKILL;
10587
10588 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10589 return -EINVAL;
10590
10591 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10592 return -EINVAL;
10593
10594 conf.master_pref =
10595 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10596 if (!conf.master_pref)
10597 return -EINVAL;
10598
10599 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10600
10601 err = rdev_start_nan(rdev, wdev, &conf);
10602 if (err)
10603 return err;
10604
10605 wdev->nan_started = true;
10606 rdev->opencount++;
10607
10608 return 0;
10609}
10610
10611static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10612{
10613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10614 struct wireless_dev *wdev = info->user_ptr[1];
10615
10616 if (wdev->iftype != NL80211_IFTYPE_NAN)
10617 return -EOPNOTSUPP;
10618
10619 cfg80211_stop_nan(rdev, wdev);
10620
10621 return 0;
10622}
10623
Ayala Bekera442b762016-09-20 17:31:15 +030010624static int validate_nan_filter(struct nlattr *filter_attr)
10625{
10626 struct nlattr *attr;
10627 int len = 0, n_entries = 0, rem;
10628
10629 nla_for_each_nested(attr, filter_attr, rem) {
10630 len += nla_len(attr);
10631 n_entries++;
10632 }
10633
10634 if (len >= U8_MAX)
10635 return -EINVAL;
10636
10637 return n_entries;
10638}
10639
10640static int handle_nan_filter(struct nlattr *attr_filter,
10641 struct cfg80211_nan_func *func,
10642 bool tx)
10643{
10644 struct nlattr *attr;
10645 int n_entries, rem, i;
10646 struct cfg80211_nan_func_filter *filter;
10647
10648 n_entries = validate_nan_filter(attr_filter);
10649 if (n_entries < 0)
10650 return n_entries;
10651
10652 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10653
10654 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10655 if (!filter)
10656 return -ENOMEM;
10657
10658 i = 0;
10659 nla_for_each_nested(attr, attr_filter, rem) {
10660 filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10661 GFP_KERNEL);
10662 filter[i].len = nla_len(attr);
10663 i++;
10664 }
10665 if (tx) {
10666 func->num_tx_filters = n_entries;
10667 func->tx_filters = filter;
10668 } else {
10669 func->num_rx_filters = n_entries;
10670 func->rx_filters = filter;
10671 }
10672
10673 return 0;
10674}
10675
10676static int nl80211_nan_add_func(struct sk_buff *skb,
10677 struct genl_info *info)
10678{
10679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10680 struct wireless_dev *wdev = info->user_ptr[1];
10681 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10682 struct cfg80211_nan_func *func;
10683 struct sk_buff *msg = NULL;
10684 void *hdr = NULL;
10685 int err = 0;
10686
10687 if (wdev->iftype != NL80211_IFTYPE_NAN)
10688 return -EOPNOTSUPP;
10689
10690 if (!wdev->nan_started)
10691 return -ENOTCONN;
10692
10693 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10694 return -EINVAL;
10695
10696 if (wdev->owner_nlportid &&
10697 wdev->owner_nlportid != info->snd_portid)
10698 return -ENOTCONN;
10699
10700 err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
10701 nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
10702 nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
10703 nl80211_nan_func_policy);
10704 if (err)
10705 return err;
10706
10707 func = kzalloc(sizeof(*func), GFP_KERNEL);
10708 if (!func)
10709 return -ENOMEM;
10710
10711 func->cookie = wdev->wiphy->cookie_counter++;
10712
10713 if (!tb[NL80211_NAN_FUNC_TYPE] ||
10714 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
10715 err = -EINVAL;
10716 goto out;
10717 }
10718
10719
10720 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
10721
10722 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
10723 err = -EINVAL;
10724 goto out;
10725 }
10726
10727 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
10728 sizeof(func->service_id));
10729
10730 func->close_range =
10731 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
10732
10733 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
10734 func->serv_spec_info_len =
10735 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
10736 func->serv_spec_info =
10737 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
10738 func->serv_spec_info_len,
10739 GFP_KERNEL);
10740 if (!func->serv_spec_info) {
10741 err = -ENOMEM;
10742 goto out;
10743 }
10744 }
10745
10746 if (tb[NL80211_NAN_FUNC_TTL])
10747 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
10748
10749 switch (func->type) {
10750 case NL80211_NAN_FUNC_PUBLISH:
10751 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
10752 err = -EINVAL;
10753 goto out;
10754 }
10755
10756 func->publish_type =
10757 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
10758 func->publish_bcast =
10759 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
10760
10761 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
10762 func->publish_bcast) {
10763 err = -EINVAL;
10764 goto out;
10765 }
10766 break;
10767 case NL80211_NAN_FUNC_SUBSCRIBE:
10768 func->subscribe_active =
10769 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
10770 break;
10771 case NL80211_NAN_FUNC_FOLLOW_UP:
10772 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
10773 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
10774 err = -EINVAL;
10775 goto out;
10776 }
10777
10778 func->followup_id =
10779 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
10780 func->followup_reqid =
10781 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
10782 memcpy(func->followup_dest.addr,
10783 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
10784 sizeof(func->followup_dest.addr));
10785 if (func->ttl) {
10786 err = -EINVAL;
10787 goto out;
10788 }
10789 break;
10790 default:
10791 err = -EINVAL;
10792 goto out;
10793 }
10794
10795 if (tb[NL80211_NAN_FUNC_SRF]) {
10796 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
10797
10798 err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
10799 nla_data(tb[NL80211_NAN_FUNC_SRF]),
10800 nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
10801 if (err)
10802 goto out;
10803
10804 func->srf_include =
10805 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
10806
10807 if (srf_tb[NL80211_NAN_SRF_BF]) {
10808 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
10809 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
10810 err = -EINVAL;
10811 goto out;
10812 }
10813
10814 func->srf_bf_len =
10815 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
10816 func->srf_bf =
10817 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
10818 func->srf_bf_len, GFP_KERNEL);
10819 if (!func->srf_bf) {
10820 err = -ENOMEM;
10821 goto out;
10822 }
10823
10824 func->srf_bf_idx =
10825 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
10826 } else {
10827 struct nlattr *attr, *mac_attr =
10828 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
10829 int n_entries, rem, i = 0;
10830
10831 if (!mac_attr) {
10832 err = -EINVAL;
10833 goto out;
10834 }
10835
10836 n_entries = validate_acl_mac_addrs(mac_attr);
10837 if (n_entries <= 0) {
10838 err = -EINVAL;
10839 goto out;
10840 }
10841
10842 func->srf_num_macs = n_entries;
10843 func->srf_macs =
10844 kzalloc(sizeof(*func->srf_macs) * n_entries,
10845 GFP_KERNEL);
10846 if (!func->srf_macs) {
10847 err = -ENOMEM;
10848 goto out;
10849 }
10850
10851 nla_for_each_nested(attr, mac_attr, rem)
10852 memcpy(func->srf_macs[i++].addr, nla_data(attr),
10853 sizeof(*func->srf_macs));
10854 }
10855 }
10856
10857 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
10858 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
10859 func, true);
10860 if (err)
10861 goto out;
10862 }
10863
10864 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
10865 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
10866 func, false);
10867 if (err)
10868 goto out;
10869 }
10870
10871 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10872 if (!msg) {
10873 err = -ENOMEM;
10874 goto out;
10875 }
10876
10877 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10878 NL80211_CMD_ADD_NAN_FUNCTION);
10879 /* This can't really happen - we just allocated 4KB */
10880 if (WARN_ON(!hdr)) {
10881 err = -ENOMEM;
10882 goto out;
10883 }
10884
10885 err = rdev_add_nan_func(rdev, wdev, func);
10886out:
10887 if (err < 0) {
10888 cfg80211_free_nan_func(func);
10889 nlmsg_free(msg);
10890 return err;
10891 }
10892
10893 /* propagate the instance id and cookie to userspace */
10894 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
10895 NL80211_ATTR_PAD))
10896 goto nla_put_failure;
10897
10898 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
10899 if (!func_attr)
10900 goto nla_put_failure;
10901
10902 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
10903 func->instance_id))
10904 goto nla_put_failure;
10905
10906 nla_nest_end(msg, func_attr);
10907
10908 genlmsg_end(msg, hdr);
10909 return genlmsg_reply(msg, info);
10910
10911nla_put_failure:
10912 nlmsg_free(msg);
10913 return -ENOBUFS;
10914}
10915
10916static int nl80211_nan_del_func(struct sk_buff *skb,
10917 struct genl_info *info)
10918{
10919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10920 struct wireless_dev *wdev = info->user_ptr[1];
10921 u64 cookie;
10922
10923 if (wdev->iftype != NL80211_IFTYPE_NAN)
10924 return -EOPNOTSUPP;
10925
10926 if (!wdev->nan_started)
10927 return -ENOTCONN;
10928
10929 if (!info->attrs[NL80211_ATTR_COOKIE])
10930 return -EINVAL;
10931
10932 if (wdev->owner_nlportid &&
10933 wdev->owner_nlportid != info->snd_portid)
10934 return -ENOTCONN;
10935
10936 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10937
10938 rdev_del_nan_func(rdev, wdev, cookie);
10939
10940 return 0;
10941}
10942
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030010943static int nl80211_nan_change_config(struct sk_buff *skb,
10944 struct genl_info *info)
10945{
10946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10947 struct wireless_dev *wdev = info->user_ptr[1];
10948 struct cfg80211_nan_conf conf = {};
10949 u32 changed = 0;
10950
10951 if (wdev->iftype != NL80211_IFTYPE_NAN)
10952 return -EOPNOTSUPP;
10953
10954 if (!wdev->nan_started)
10955 return -ENOTCONN;
10956
10957 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
10958 conf.master_pref =
10959 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10960 if (conf.master_pref <= 1 || conf.master_pref == 255)
10961 return -EINVAL;
10962
10963 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
10964 }
10965
10966 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
10967 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10968 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
10969 }
10970
10971 if (!changed)
10972 return -EINVAL;
10973
10974 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
10975}
10976
Ayala Beker50bcd312016-09-20 17:31:17 +030010977void cfg80211_nan_match(struct wireless_dev *wdev,
10978 struct cfg80211_nan_match_params *match, gfp_t gfp)
10979{
10980 struct wiphy *wiphy = wdev->wiphy;
10981 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
10982 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
10983 struct sk_buff *msg;
10984 void *hdr;
10985
10986 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
10987 return;
10988
10989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10990 if (!msg)
10991 return;
10992
10993 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
10994 if (!hdr) {
10995 nlmsg_free(msg);
10996 return;
10997 }
10998
10999 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11000 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11001 wdev->netdev->ifindex)) ||
11002 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11003 NL80211_ATTR_PAD))
11004 goto nla_put_failure;
11005
11006 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11007 NL80211_ATTR_PAD) ||
11008 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11009 goto nla_put_failure;
11010
11011 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11012 if (!match_attr)
11013 goto nla_put_failure;
11014
11015 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11016 if (!local_func_attr)
11017 goto nla_put_failure;
11018
11019 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11020 goto nla_put_failure;
11021
11022 nla_nest_end(msg, local_func_attr);
11023
11024 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11025 if (!peer_func_attr)
11026 goto nla_put_failure;
11027
11028 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11029 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11030 goto nla_put_failure;
11031
11032 if (match->info && match->info_len &&
11033 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11034 match->info))
11035 goto nla_put_failure;
11036
11037 nla_nest_end(msg, peer_func_attr);
11038 nla_nest_end(msg, match_attr);
11039 genlmsg_end(msg, hdr);
11040
11041 if (!wdev->owner_nlportid)
11042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11043 msg, 0, NL80211_MCGRP_NAN, gfp);
11044 else
11045 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11046 wdev->owner_nlportid);
11047
11048 return;
11049
11050nla_put_failure:
11051 nlmsg_free(msg);
11052}
11053EXPORT_SYMBOL(cfg80211_nan_match);
11054
Ayala Beker368e5a72016-09-20 17:31:18 +030011055void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11056 u8 inst_id,
11057 enum nl80211_nan_func_term_reason reason,
11058 u64 cookie, gfp_t gfp)
11059{
11060 struct wiphy *wiphy = wdev->wiphy;
11061 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11062 struct sk_buff *msg;
11063 struct nlattr *func_attr;
11064 void *hdr;
11065
11066 if (WARN_ON(!inst_id))
11067 return;
11068
11069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11070 if (!msg)
11071 return;
11072
11073 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11074 if (!hdr) {
11075 nlmsg_free(msg);
11076 return;
11077 }
11078
11079 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11080 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11081 wdev->netdev->ifindex)) ||
11082 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11083 NL80211_ATTR_PAD))
11084 goto nla_put_failure;
11085
11086 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11087 NL80211_ATTR_PAD))
11088 goto nla_put_failure;
11089
11090 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11091 if (!func_attr)
11092 goto nla_put_failure;
11093
11094 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11095 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11096 goto nla_put_failure;
11097
11098 nla_nest_end(msg, func_attr);
11099 genlmsg_end(msg, hdr);
11100
11101 if (!wdev->owner_nlportid)
11102 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11103 msg, 0, NL80211_MCGRP_NAN, gfp);
11104 else
11105 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11106 wdev->owner_nlportid);
11107
11108 return;
11109
11110nla_put_failure:
11111 nlmsg_free(msg);
11112}
11113EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11114
Johannes Berg3713b4e2013-02-14 16:19:38 +010011115static int nl80211_get_protocol_features(struct sk_buff *skb,
11116 struct genl_info *info)
11117{
11118 void *hdr;
11119 struct sk_buff *msg;
11120
11121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11122 if (!msg)
11123 return -ENOMEM;
11124
11125 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11126 NL80211_CMD_GET_PROTOCOL_FEATURES);
11127 if (!hdr)
11128 goto nla_put_failure;
11129
11130 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11131 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11132 goto nla_put_failure;
11133
11134 genlmsg_end(msg, hdr);
11135 return genlmsg_reply(msg, info);
11136
11137 nla_put_failure:
11138 kfree_skb(msg);
11139 return -ENOBUFS;
11140}
11141
Jouni Malinen355199e2013-02-27 17:14:27 +020011142static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11143{
11144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11145 struct cfg80211_update_ft_ies_params ft_params;
11146 struct net_device *dev = info->user_ptr[1];
11147
11148 if (!rdev->ops->update_ft_ies)
11149 return -EOPNOTSUPP;
11150
11151 if (!info->attrs[NL80211_ATTR_MDID] ||
11152 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11153 return -EINVAL;
11154
11155 memset(&ft_params, 0, sizeof(ft_params));
11156 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11157 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11158 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11159
11160 return rdev_update_ft_ies(rdev, dev, &ft_params);
11161}
11162
Arend van Spriel5de17982013-04-18 15:49:00 +020011163static int nl80211_crit_protocol_start(struct sk_buff *skb,
11164 struct genl_info *info)
11165{
11166 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11167 struct wireless_dev *wdev = info->user_ptr[1];
11168 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11169 u16 duration;
11170 int ret;
11171
11172 if (!rdev->ops->crit_proto_start)
11173 return -EOPNOTSUPP;
11174
11175 if (WARN_ON(!rdev->ops->crit_proto_stop))
11176 return -EINVAL;
11177
11178 if (rdev->crit_proto_nlportid)
11179 return -EBUSY;
11180
11181 /* determine protocol if provided */
11182 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11183 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11184
11185 if (proto >= NUM_NL80211_CRIT_PROTO)
11186 return -EINVAL;
11187
11188 /* timeout must be provided */
11189 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11190 return -EINVAL;
11191
11192 duration =
11193 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11194
11195 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11196 return -ERANGE;
11197
11198 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11199 if (!ret)
11200 rdev->crit_proto_nlportid = info->snd_portid;
11201
11202 return ret;
11203}
11204
11205static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11206 struct genl_info *info)
11207{
11208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11209 struct wireless_dev *wdev = info->user_ptr[1];
11210
11211 if (!rdev->ops->crit_proto_stop)
11212 return -EOPNOTSUPP;
11213
11214 if (rdev->crit_proto_nlportid) {
11215 rdev->crit_proto_nlportid = 0;
11216 rdev_crit_proto_stop(rdev, wdev);
11217 }
11218 return 0;
11219}
11220
Johannes Bergad7e7182013-11-13 13:37:47 +010011221static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11222{
11223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11224 struct wireless_dev *wdev =
11225 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11226 int i, err;
11227 u32 vid, subcmd;
11228
11229 if (!rdev->wiphy.vendor_commands)
11230 return -EOPNOTSUPP;
11231
11232 if (IS_ERR(wdev)) {
11233 err = PTR_ERR(wdev);
11234 if (err != -EINVAL)
11235 return err;
11236 wdev = NULL;
11237 } else if (wdev->wiphy != &rdev->wiphy) {
11238 return -EINVAL;
11239 }
11240
11241 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11242 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11243 return -EINVAL;
11244
11245 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11246 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11247 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11248 const struct wiphy_vendor_command *vcmd;
11249 void *data = NULL;
11250 int len = 0;
11251
11252 vcmd = &rdev->wiphy.vendor_commands[i];
11253
11254 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11255 continue;
11256
11257 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11258 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11259 if (!wdev)
11260 return -EINVAL;
11261 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11262 !wdev->netdev)
11263 return -EINVAL;
11264
11265 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11266 if (wdev->netdev &&
11267 !netif_running(wdev->netdev))
11268 return -ENETDOWN;
11269 if (!wdev->netdev && !wdev->p2p_started)
11270 return -ENETDOWN;
11271 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011272
11273 if (!vcmd->doit)
11274 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011275 } else {
11276 wdev = NULL;
11277 }
11278
11279 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11280 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11281 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11282 }
11283
11284 rdev->cur_cmd_info = info;
11285 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11286 data, len);
11287 rdev->cur_cmd_info = NULL;
11288 return err;
11289 }
11290
11291 return -EOPNOTSUPP;
11292}
11293
Johannes Berg7bdbe402015-08-15 22:39:49 +030011294static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11295 struct netlink_callback *cb,
11296 struct cfg80211_registered_device **rdev,
11297 struct wireless_dev **wdev)
11298{
11299 u32 vid, subcmd;
11300 unsigned int i;
11301 int vcmd_idx = -1;
11302 int err;
11303 void *data = NULL;
11304 unsigned int data_len = 0;
11305
Johannes Berg7bdbe402015-08-15 22:39:49 +030011306 if (cb->args[0]) {
11307 /* subtract the 1 again here */
11308 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11309 struct wireless_dev *tmp;
11310
Johannes Berg56769e72017-03-15 14:26:04 +010011311 if (!wiphy)
11312 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011313 *rdev = wiphy_to_rdev(wiphy);
11314 *wdev = NULL;
11315
11316 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011317 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011318 if (tmp->identifier == cb->args[1] - 1) {
11319 *wdev = tmp;
11320 break;
11321 }
11322 }
11323 }
11324
11325 /* keep rtnl locked in successful case */
11326 return 0;
11327 }
11328
11329 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
11330 nl80211_fam.attrbuf, nl80211_fam.maxattr,
11331 nl80211_policy);
11332 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011333 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011334
11335 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg56769e72017-03-15 14:26:04 +010011336 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
11337 return -EINVAL;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011338
11339 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
11340 nl80211_fam.attrbuf);
11341 if (IS_ERR(*wdev))
11342 *wdev = NULL;
11343
11344 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
11345 nl80211_fam.attrbuf);
Johannes Berg56769e72017-03-15 14:26:04 +010011346 if (IS_ERR(*rdev))
11347 return PTR_ERR(*rdev);
Johannes Berg7bdbe402015-08-15 22:39:49 +030011348
11349 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
11350 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11351
11352 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11353 const struct wiphy_vendor_command *vcmd;
11354
11355 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11356
11357 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11358 continue;
11359
Johannes Berg56769e72017-03-15 14:26:04 +010011360 if (!vcmd->dumpit)
11361 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011362
11363 vcmd_idx = i;
11364 break;
11365 }
11366
Johannes Berg56769e72017-03-15 14:26:04 +010011367 if (vcmd_idx < 0)
11368 return -EOPNOTSUPP;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011369
11370 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11371 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11372 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11373 }
11374
11375 /* 0 is the first index - add 1 to parse only once */
11376 cb->args[0] = (*rdev)->wiphy_idx + 1;
11377 /* add 1 to know if it was NULL */
11378 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11379 cb->args[2] = vcmd_idx;
11380 cb->args[3] = (unsigned long)data;
11381 cb->args[4] = data_len;
11382
11383 /* keep rtnl locked in successful case */
11384 return 0;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011385}
11386
11387static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11388 struct netlink_callback *cb)
11389{
11390 struct cfg80211_registered_device *rdev;
11391 struct wireless_dev *wdev;
11392 unsigned int vcmd_idx;
11393 const struct wiphy_vendor_command *vcmd;
11394 void *data;
11395 int data_len;
11396 int err;
11397 struct nlattr *vendor_data;
11398
Johannes Berg56769e72017-03-15 14:26:04 +010011399 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030011400 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11401 if (err)
Johannes Berg56769e72017-03-15 14:26:04 +010011402 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030011403
11404 vcmd_idx = cb->args[2];
11405 data = (void *)cb->args[3];
11406 data_len = cb->args[4];
11407 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11408
11409 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11410 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Berg56769e72017-03-15 14:26:04 +010011411 if (!wdev) {
11412 err = -EINVAL;
11413 goto out;
11414 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011415 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Berg56769e72017-03-15 14:26:04 +010011416 !wdev->netdev) {
11417 err = -EINVAL;
11418 goto out;
11419 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011420
11421 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
11422 if (wdev->netdev &&
Johannes Berg56769e72017-03-15 14:26:04 +010011423 !netif_running(wdev->netdev)) {
11424 err = -ENETDOWN;
11425 goto out;
11426 }
11427 if (!wdev->netdev && !wdev->p2p_started) {
11428 err = -ENETDOWN;
11429 goto out;
11430 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011431 }
11432 }
11433
11434 while (1) {
11435 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11436 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11437 NL80211_CMD_VENDOR);
11438 if (!hdr)
11439 break;
11440
11441 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011442 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11443 wdev_id(wdev),
11444 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011445 genlmsg_cancel(skb, hdr);
11446 break;
11447 }
11448
11449 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11450 if (!vendor_data) {
11451 genlmsg_cancel(skb, hdr);
11452 break;
11453 }
11454
11455 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11456 (unsigned long *)&cb->args[5]);
11457 nla_nest_end(skb, vendor_data);
11458
11459 if (err == -ENOBUFS || err == -ENOENT) {
11460 genlmsg_cancel(skb, hdr);
11461 break;
11462 } else if (err) {
11463 genlmsg_cancel(skb, hdr);
11464 goto out;
11465 }
11466
11467 genlmsg_end(skb, hdr);
11468 }
11469
11470 err = skb->len;
11471 out:
11472 rtnl_unlock();
11473 return err;
11474}
11475
Johannes Bergad7e7182013-11-13 13:37:47 +010011476struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11477 enum nl80211_commands cmd,
11478 enum nl80211_attrs attr,
11479 int approxlen)
11480{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011481 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011482
11483 if (WARN_ON(!rdev->cur_cmd_info))
11484 return NULL;
11485
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011486 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011487 rdev->cur_cmd_info->snd_portid,
11488 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011489 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011490}
11491EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11492
11493int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11494{
11495 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11496 void *hdr = ((void **)skb->cb)[1];
11497 struct nlattr *data = ((void **)skb->cb)[2];
11498
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011499 /* clear CB data for netlink core to own from now on */
11500 memset(skb->cb, 0, sizeof(skb->cb));
11501
Johannes Bergad7e7182013-11-13 13:37:47 +010011502 if (WARN_ON(!rdev->cur_cmd_info)) {
11503 kfree_skb(skb);
11504 return -EINVAL;
11505 }
11506
11507 nla_nest_end(skb, data);
11508 genlmsg_end(skb, hdr);
11509 return genlmsg_reply(skb, rdev->cur_cmd_info);
11510}
11511EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11512
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011513static int nl80211_set_qos_map(struct sk_buff *skb,
11514 struct genl_info *info)
11515{
11516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11517 struct cfg80211_qos_map *qos_map = NULL;
11518 struct net_device *dev = info->user_ptr[1];
11519 u8 *pos, len, num_des, des_len, des;
11520 int ret;
11521
11522 if (!rdev->ops->set_qos_map)
11523 return -EOPNOTSUPP;
11524
11525 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11526 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11527 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11528
11529 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11530 len > IEEE80211_QOS_MAP_LEN_MAX)
11531 return -EINVAL;
11532
11533 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11534 if (!qos_map)
11535 return -ENOMEM;
11536
11537 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11538 if (num_des) {
11539 des_len = num_des *
11540 sizeof(struct cfg80211_dscp_exception);
11541 memcpy(qos_map->dscp_exception, pos, des_len);
11542 qos_map->num_des = num_des;
11543 for (des = 0; des < num_des; des++) {
11544 if (qos_map->dscp_exception[des].up > 7) {
11545 kfree(qos_map);
11546 return -EINVAL;
11547 }
11548 }
11549 pos += des_len;
11550 }
11551 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11552 }
11553
11554 wdev_lock(dev->ieee80211_ptr);
11555 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11556 if (!ret)
11557 ret = rdev_set_qos_map(rdev, dev, qos_map);
11558 wdev_unlock(dev->ieee80211_ptr);
11559
11560 kfree(qos_map);
11561 return ret;
11562}
11563
Johannes Berg960d01a2014-09-09 22:55:35 +030011564static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11565{
11566 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11567 struct net_device *dev = info->user_ptr[1];
11568 struct wireless_dev *wdev = dev->ieee80211_ptr;
11569 const u8 *peer;
11570 u8 tsid, up;
11571 u16 admitted_time = 0;
11572 int err;
11573
Johannes Berg723e73a2014-10-22 09:25:06 +020011574 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011575 return -EOPNOTSUPP;
11576
11577 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11578 !info->attrs[NL80211_ATTR_USER_PRIO])
11579 return -EINVAL;
11580
11581 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11582 if (tsid >= IEEE80211_NUM_TIDS)
11583 return -EINVAL;
11584
11585 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11586 if (up >= IEEE80211_NUM_UPS)
11587 return -EINVAL;
11588
11589 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011590 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011591 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011592 * need more attributes for that (e.g. BA session requirement);
11593 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011594 */
11595 return -EINVAL;
11596 }
11597
11598 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11599
11600 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11601 admitted_time =
11602 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11603 if (!admitted_time)
11604 return -EINVAL;
11605 }
11606
11607 wdev_lock(wdev);
11608 switch (wdev->iftype) {
11609 case NL80211_IFTYPE_STATION:
11610 case NL80211_IFTYPE_P2P_CLIENT:
11611 if (wdev->current_bss)
11612 break;
11613 err = -ENOTCONN;
11614 goto out;
11615 default:
11616 err = -EOPNOTSUPP;
11617 goto out;
11618 }
11619
11620 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11621
11622 out:
11623 wdev_unlock(wdev);
11624 return err;
11625}
11626
11627static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11628{
11629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11630 struct net_device *dev = info->user_ptr[1];
11631 struct wireless_dev *wdev = dev->ieee80211_ptr;
11632 const u8 *peer;
11633 u8 tsid;
11634 int err;
11635
11636 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11637 return -EINVAL;
11638
11639 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11640 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11641
11642 wdev_lock(wdev);
11643 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11644 wdev_unlock(wdev);
11645
11646 return err;
11647}
11648
Arik Nemtsov1057d352014-11-19 12:54:26 +020011649static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11650 struct genl_info *info)
11651{
11652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11653 struct net_device *dev = info->user_ptr[1];
11654 struct wireless_dev *wdev = dev->ieee80211_ptr;
11655 struct cfg80211_chan_def chandef = {};
11656 const u8 *addr;
11657 u8 oper_class;
11658 int err;
11659
11660 if (!rdev->ops->tdls_channel_switch ||
11661 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11662 return -EOPNOTSUPP;
11663
11664 switch (dev->ieee80211_ptr->iftype) {
11665 case NL80211_IFTYPE_STATION:
11666 case NL80211_IFTYPE_P2P_CLIENT:
11667 break;
11668 default:
11669 return -EOPNOTSUPP;
11670 }
11671
11672 if (!info->attrs[NL80211_ATTR_MAC] ||
11673 !info->attrs[NL80211_ATTR_OPER_CLASS])
11674 return -EINVAL;
11675
11676 err = nl80211_parse_chandef(rdev, info, &chandef);
11677 if (err)
11678 return err;
11679
11680 /*
11681 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11682 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11683 * specification is not defined for them.
11684 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011685 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011686 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11687 chandef.width != NL80211_CHAN_WIDTH_20)
11688 return -EINVAL;
11689
11690 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011691 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11692 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011693 return -EINVAL;
11694
11695 /* don't allow switching to DFS channels */
11696 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11697 return -EINVAL;
11698
11699 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11700 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11701
11702 wdev_lock(wdev);
11703 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11704 wdev_unlock(wdev);
11705
11706 return err;
11707}
11708
11709static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11710 struct genl_info *info)
11711{
11712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11713 struct net_device *dev = info->user_ptr[1];
11714 struct wireless_dev *wdev = dev->ieee80211_ptr;
11715 const u8 *addr;
11716
11717 if (!rdev->ops->tdls_channel_switch ||
11718 !rdev->ops->tdls_cancel_channel_switch ||
11719 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11720 return -EOPNOTSUPP;
11721
11722 switch (dev->ieee80211_ptr->iftype) {
11723 case NL80211_IFTYPE_STATION:
11724 case NL80211_IFTYPE_P2P_CLIENT:
11725 break;
11726 default:
11727 return -EOPNOTSUPP;
11728 }
11729
11730 if (!info->attrs[NL80211_ATTR_MAC])
11731 return -EINVAL;
11732
11733 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11734
11735 wdev_lock(wdev);
11736 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11737 wdev_unlock(wdev);
11738
11739 return 0;
11740}
11741
Johannes Berg4c476992010-10-04 21:36:35 +020011742#define NL80211_FLAG_NEED_WIPHY 0x01
11743#define NL80211_FLAG_NEED_NETDEV 0x02
11744#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011745#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11746#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11747 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011748#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011749/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011750#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11751 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011752#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011753
Johannes Bergf84f7712013-11-14 17:14:45 +010011754static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011755 struct genl_info *info)
11756{
11757 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011758 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011759 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011760 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11761
11762 if (rtnl)
11763 rtnl_lock();
11764
11765 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011766 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011767 if (IS_ERR(rdev)) {
11768 if (rtnl)
11769 rtnl_unlock();
11770 return PTR_ERR(rdev);
11771 }
11772 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011773 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11774 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011775 ASSERT_RTNL();
11776
Johannes Berg89a54e42012-06-15 14:33:17 +020011777 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11778 info->attrs);
11779 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011780 if (rtnl)
11781 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011782 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011783 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011784
Johannes Berg89a54e42012-06-15 14:33:17 +020011785 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011786 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011787
Johannes Berg1bf614e2012-06-15 15:23:36 +020011788 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11789 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011790 if (rtnl)
11791 rtnl_unlock();
11792 return -EINVAL;
11793 }
11794
11795 info->user_ptr[1] = dev;
11796 } else {
11797 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011798 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011799
Johannes Berg1bf614e2012-06-15 15:23:36 +020011800 if (dev) {
11801 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11802 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011803 if (rtnl)
11804 rtnl_unlock();
11805 return -ENETDOWN;
11806 }
11807
11808 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020011809 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011810 if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
11811 !wdev->p2p_started) {
11812 if (rtnl)
11813 rtnl_unlock();
11814 return -ENETDOWN;
11815 }
11816 if (wdev->iftype == NL80211_IFTYPE_NAN &&
11817 !wdev->nan_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020011818 if (rtnl)
11819 rtnl_unlock();
11820 return -ENETDOWN;
11821 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020011822 }
11823
Johannes Berg4c476992010-10-04 21:36:35 +020011824 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011825 }
11826
11827 return 0;
11828}
11829
Johannes Bergf84f7712013-11-14 17:14:45 +010011830static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011831 struct genl_info *info)
11832{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011833 if (info->user_ptr[1]) {
11834 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11835 struct wireless_dev *wdev = info->user_ptr[1];
11836
11837 if (wdev->netdev)
11838 dev_put(wdev->netdev);
11839 } else {
11840 dev_put(info->user_ptr[1]);
11841 }
11842 }
Johannes Berg5393b912014-09-10 15:00:16 +030011843
Johannes Berg4c476992010-10-04 21:36:35 +020011844 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11845 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011846
11847 /* If needed, clear the netlink message payload from the SKB
11848 * as it might contain key data that shouldn't stick around on
11849 * the heap after the SKB is freed. The netlink message header
11850 * is still needed for further processing, so leave it intact.
11851 */
11852 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11853 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11854
11855 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11856 }
Johannes Berg4c476992010-10-04 21:36:35 +020011857}
11858
Johannes Berg4534de82013-11-14 17:14:46 +010011859static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011860 {
11861 .cmd = NL80211_CMD_GET_WIPHY,
11862 .doit = nl80211_get_wiphy,
11863 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011864 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011865 .policy = nl80211_policy,
11866 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011867 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11868 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011869 },
11870 {
11871 .cmd = NL80211_CMD_SET_WIPHY,
11872 .doit = nl80211_set_wiphy,
11873 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011874 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011875 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011876 },
11877 {
11878 .cmd = NL80211_CMD_GET_INTERFACE,
11879 .doit = nl80211_get_interface,
11880 .dumpit = nl80211_dump_interface,
11881 .policy = nl80211_policy,
11882 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011883 .internal_flags = NL80211_FLAG_NEED_WDEV |
11884 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011885 },
11886 {
11887 .cmd = NL80211_CMD_SET_INTERFACE,
11888 .doit = nl80211_set_interface,
11889 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011890 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011891 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11892 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011893 },
11894 {
11895 .cmd = NL80211_CMD_NEW_INTERFACE,
11896 .doit = nl80211_new_interface,
11897 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011898 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011899 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11900 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011901 },
11902 {
11903 .cmd = NL80211_CMD_DEL_INTERFACE,
11904 .doit = nl80211_del_interface,
11905 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011906 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011907 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011908 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011909 },
Johannes Berg41ade002007-12-19 02:03:29 +010011910 {
11911 .cmd = NL80211_CMD_GET_KEY,
11912 .doit = nl80211_get_key,
11913 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011914 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011916 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011917 },
11918 {
11919 .cmd = NL80211_CMD_SET_KEY,
11920 .doit = nl80211_set_key,
11921 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011922 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011924 NL80211_FLAG_NEED_RTNL |
11925 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011926 },
11927 {
11928 .cmd = NL80211_CMD_NEW_KEY,
11929 .doit = nl80211_new_key,
11930 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011931 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011932 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011933 NL80211_FLAG_NEED_RTNL |
11934 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011935 },
11936 {
11937 .cmd = NL80211_CMD_DEL_KEY,
11938 .doit = nl80211_del_key,
11939 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011940 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011942 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011943 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011944 {
11945 .cmd = NL80211_CMD_SET_BEACON,
11946 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011947 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011948 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011950 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011951 },
11952 {
Johannes Berg88600202012-02-13 15:17:18 +010011953 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011954 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011955 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011956 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011958 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011959 },
11960 {
Johannes Berg88600202012-02-13 15:17:18 +010011961 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011962 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011963 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011964 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011965 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011966 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011967 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011968 {
11969 .cmd = NL80211_CMD_GET_STATION,
11970 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011971 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011972 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011973 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11974 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011975 },
11976 {
11977 .cmd = NL80211_CMD_SET_STATION,
11978 .doit = nl80211_set_station,
11979 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011980 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011981 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011982 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011983 },
11984 {
11985 .cmd = NL80211_CMD_NEW_STATION,
11986 .doit = nl80211_new_station,
11987 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011988 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011990 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011991 },
11992 {
11993 .cmd = NL80211_CMD_DEL_STATION,
11994 .doit = nl80211_del_station,
11995 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011996 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011998 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011999 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012000 {
12001 .cmd = NL80211_CMD_GET_MPATH,
12002 .doit = nl80211_get_mpath,
12003 .dumpit = nl80211_dump_mpath,
12004 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012005 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012007 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012008 },
12009 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012010 .cmd = NL80211_CMD_GET_MPP,
12011 .doit = nl80211_get_mpp,
12012 .dumpit = nl80211_dump_mpp,
12013 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012014 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12016 NL80211_FLAG_NEED_RTNL,
12017 },
12018 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012019 .cmd = NL80211_CMD_SET_MPATH,
12020 .doit = nl80211_set_mpath,
12021 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012022 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012024 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012025 },
12026 {
12027 .cmd = NL80211_CMD_NEW_MPATH,
12028 .doit = nl80211_new_mpath,
12029 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012030 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012032 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012033 },
12034 {
12035 .cmd = NL80211_CMD_DEL_MPATH,
12036 .doit = nl80211_del_mpath,
12037 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012038 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012040 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012041 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012042 {
12043 .cmd = NL80211_CMD_SET_BSS,
12044 .doit = nl80211_set_bss,
12045 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012046 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012048 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012049 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012050 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012051 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012052 .doit = nl80211_get_reg_do,
12053 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012054 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012055 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012056 /* can be retrieved by unprivileged users */
12057 },
Johannes Bergb6863032015-10-15 09:25:18 +020012058#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012059 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012060 .cmd = NL80211_CMD_SET_REG,
12061 .doit = nl80211_set_reg,
12062 .policy = nl80211_policy,
12063 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012064 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012065 },
Johannes Bergb6863032015-10-15 09:25:18 +020012066#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012067 {
12068 .cmd = NL80211_CMD_REQ_SET_REG,
12069 .doit = nl80211_req_set_reg,
12070 .policy = nl80211_policy,
12071 .flags = GENL_ADMIN_PERM,
12072 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012073 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012074 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12075 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012076 .policy = nl80211_policy,
12077 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012078 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012079 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012080 },
12081 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012082 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12083 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012084 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012085 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012086 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012087 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012088 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012089 {
Johannes Berg2a519312009-02-10 21:25:55 +010012090 .cmd = NL80211_CMD_TRIGGER_SCAN,
12091 .doit = nl80211_trigger_scan,
12092 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012093 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012094 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012095 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012096 },
12097 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012098 .cmd = NL80211_CMD_ABORT_SCAN,
12099 .doit = nl80211_abort_scan,
12100 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012101 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012102 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12103 NL80211_FLAG_NEED_RTNL,
12104 },
12105 {
Johannes Berg2a519312009-02-10 21:25:55 +010012106 .cmd = NL80211_CMD_GET_SCAN,
12107 .policy = nl80211_policy,
12108 .dumpit = nl80211_dump_scan,
12109 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012110 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012111 .cmd = NL80211_CMD_START_SCHED_SCAN,
12112 .doit = nl80211_start_sched_scan,
12113 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012114 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012115 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12116 NL80211_FLAG_NEED_RTNL,
12117 },
12118 {
12119 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12120 .doit = nl80211_stop_sched_scan,
12121 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012122 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012123 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12124 NL80211_FLAG_NEED_RTNL,
12125 },
12126 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012127 .cmd = NL80211_CMD_AUTHENTICATE,
12128 .doit = nl80211_authenticate,
12129 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012130 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012131 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012132 NL80211_FLAG_NEED_RTNL |
12133 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012134 },
12135 {
12136 .cmd = NL80211_CMD_ASSOCIATE,
12137 .doit = nl80211_associate,
12138 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012139 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012141 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012142 },
12143 {
12144 .cmd = NL80211_CMD_DEAUTHENTICATE,
12145 .doit = nl80211_deauthenticate,
12146 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012147 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012149 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012150 },
12151 {
12152 .cmd = NL80211_CMD_DISASSOCIATE,
12153 .doit = nl80211_disassociate,
12154 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012155 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012157 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012158 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012159 {
12160 .cmd = NL80211_CMD_JOIN_IBSS,
12161 .doit = nl80211_join_ibss,
12162 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012163 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012165 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012166 },
12167 {
12168 .cmd = NL80211_CMD_LEAVE_IBSS,
12169 .doit = nl80211_leave_ibss,
12170 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012171 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012173 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012174 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012175#ifdef CONFIG_NL80211_TESTMODE
12176 {
12177 .cmd = NL80211_CMD_TESTMODE,
12178 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012179 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012180 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012181 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012182 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12183 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012184 },
12185#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012186 {
12187 .cmd = NL80211_CMD_CONNECT,
12188 .doit = nl80211_connect,
12189 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012190 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012192 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012193 },
12194 {
12195 .cmd = NL80211_CMD_DISCONNECT,
12196 .doit = nl80211_disconnect,
12197 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012198 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012200 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012201 },
Johannes Berg463d0182009-07-14 00:33:35 +020012202 {
12203 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12204 .doit = nl80211_wiphy_netns,
12205 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012206 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012207 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12208 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012209 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012210 {
12211 .cmd = NL80211_CMD_GET_SURVEY,
12212 .policy = nl80211_policy,
12213 .dumpit = nl80211_dump_survey,
12214 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012215 {
12216 .cmd = NL80211_CMD_SET_PMKSA,
12217 .doit = nl80211_setdel_pmksa,
12218 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012219 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012221 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012222 },
12223 {
12224 .cmd = NL80211_CMD_DEL_PMKSA,
12225 .doit = nl80211_setdel_pmksa,
12226 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012227 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012229 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012230 },
12231 {
12232 .cmd = NL80211_CMD_FLUSH_PMKSA,
12233 .doit = nl80211_flush_pmksa,
12234 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012235 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012237 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012238 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012239 {
12240 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12241 .doit = nl80211_remain_on_channel,
12242 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012243 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012244 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012245 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012246 },
12247 {
12248 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12249 .doit = nl80211_cancel_remain_on_channel,
12250 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012251 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012252 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012253 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012254 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012255 {
12256 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12257 .doit = nl80211_set_tx_bitrate_mask,
12258 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012259 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012260 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12261 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012262 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012263 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012264 .cmd = NL80211_CMD_REGISTER_FRAME,
12265 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012266 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012267 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012268 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012269 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012270 },
12271 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012272 .cmd = NL80211_CMD_FRAME,
12273 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012274 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012275 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012276 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012277 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012278 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012279 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012280 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12281 .doit = nl80211_tx_mgmt_cancel_wait,
12282 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012283 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012284 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012285 NL80211_FLAG_NEED_RTNL,
12286 },
12287 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012288 .cmd = NL80211_CMD_SET_POWER_SAVE,
12289 .doit = nl80211_set_power_save,
12290 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012291 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012292 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12293 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012294 },
12295 {
12296 .cmd = NL80211_CMD_GET_POWER_SAVE,
12297 .doit = nl80211_get_power_save,
12298 .policy = nl80211_policy,
12299 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012300 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12301 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012302 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012303 {
12304 .cmd = NL80211_CMD_SET_CQM,
12305 .doit = nl80211_set_cqm,
12306 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012307 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12309 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012310 },
Johannes Bergf444de02010-05-05 15:25:02 +020012311 {
12312 .cmd = NL80211_CMD_SET_CHANNEL,
12313 .doit = nl80211_set_channel,
12314 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012315 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012316 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12317 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012318 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012319 {
12320 .cmd = NL80211_CMD_SET_WDS_PEER,
12321 .doit = nl80211_set_wds_peer,
12322 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012323 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012324 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12325 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012326 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012327 {
12328 .cmd = NL80211_CMD_JOIN_MESH,
12329 .doit = nl80211_join_mesh,
12330 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012331 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12333 NL80211_FLAG_NEED_RTNL,
12334 },
12335 {
12336 .cmd = NL80211_CMD_LEAVE_MESH,
12337 .doit = nl80211_leave_mesh,
12338 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012339 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012340 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12341 NL80211_FLAG_NEED_RTNL,
12342 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012343 {
12344 .cmd = NL80211_CMD_JOIN_OCB,
12345 .doit = nl80211_join_ocb,
12346 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012347 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012348 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12349 NL80211_FLAG_NEED_RTNL,
12350 },
12351 {
12352 .cmd = NL80211_CMD_LEAVE_OCB,
12353 .doit = nl80211_leave_ocb,
12354 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012355 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12357 NL80211_FLAG_NEED_RTNL,
12358 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012359#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012360 {
12361 .cmd = NL80211_CMD_GET_WOWLAN,
12362 .doit = nl80211_get_wowlan,
12363 .policy = nl80211_policy,
12364 /* can be retrieved by unprivileged users */
12365 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12366 NL80211_FLAG_NEED_RTNL,
12367 },
12368 {
12369 .cmd = NL80211_CMD_SET_WOWLAN,
12370 .doit = nl80211_set_wowlan,
12371 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012372 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012373 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12374 NL80211_FLAG_NEED_RTNL,
12375 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012376#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012377 {
12378 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12379 .doit = nl80211_set_rekey_data,
12380 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012381 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012383 NL80211_FLAG_NEED_RTNL |
12384 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012385 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012386 {
12387 .cmd = NL80211_CMD_TDLS_MGMT,
12388 .doit = nl80211_tdls_mgmt,
12389 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012390 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012391 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12392 NL80211_FLAG_NEED_RTNL,
12393 },
12394 {
12395 .cmd = NL80211_CMD_TDLS_OPER,
12396 .doit = nl80211_tdls_oper,
12397 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012398 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012399 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12400 NL80211_FLAG_NEED_RTNL,
12401 },
Johannes Berg28946da2011-11-04 11:18:12 +010012402 {
12403 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12404 .doit = nl80211_register_unexpected_frame,
12405 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012406 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012407 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12408 NL80211_FLAG_NEED_RTNL,
12409 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012410 {
12411 .cmd = NL80211_CMD_PROBE_CLIENT,
12412 .doit = nl80211_probe_client,
12413 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012414 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012416 NL80211_FLAG_NEED_RTNL,
12417 },
Johannes Berg5e7602302011-11-04 11:18:17 +010012418 {
12419 .cmd = NL80211_CMD_REGISTER_BEACONS,
12420 .doit = nl80211_register_beacons,
12421 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012422 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e7602302011-11-04 11:18:17 +010012423 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12424 NL80211_FLAG_NEED_RTNL,
12425 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012426 {
12427 .cmd = NL80211_CMD_SET_NOACK_MAP,
12428 .doit = nl80211_set_noack_map,
12429 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012430 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012431 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12432 NL80211_FLAG_NEED_RTNL,
12433 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012434 {
12435 .cmd = NL80211_CMD_START_P2P_DEVICE,
12436 .doit = nl80211_start_p2p_device,
12437 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012438 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012439 .internal_flags = NL80211_FLAG_NEED_WDEV |
12440 NL80211_FLAG_NEED_RTNL,
12441 },
12442 {
12443 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12444 .doit = nl80211_stop_p2p_device,
12445 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012446 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012447 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12448 NL80211_FLAG_NEED_RTNL,
12449 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012450 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012451 .cmd = NL80211_CMD_START_NAN,
12452 .doit = nl80211_start_nan,
12453 .policy = nl80211_policy,
12454 .flags = GENL_ADMIN_PERM,
12455 .internal_flags = NL80211_FLAG_NEED_WDEV |
12456 NL80211_FLAG_NEED_RTNL,
12457 },
12458 {
12459 .cmd = NL80211_CMD_STOP_NAN,
12460 .doit = nl80211_stop_nan,
12461 .policy = nl80211_policy,
12462 .flags = GENL_ADMIN_PERM,
12463 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12464 NL80211_FLAG_NEED_RTNL,
12465 },
12466 {
Ayala Bekera442b762016-09-20 17:31:15 +030012467 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12468 .doit = nl80211_nan_add_func,
12469 .policy = nl80211_policy,
12470 .flags = GENL_ADMIN_PERM,
12471 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12472 NL80211_FLAG_NEED_RTNL,
12473 },
12474 {
12475 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12476 .doit = nl80211_nan_del_func,
12477 .policy = nl80211_policy,
12478 .flags = GENL_ADMIN_PERM,
12479 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12480 NL80211_FLAG_NEED_RTNL,
12481 },
12482 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012483 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12484 .doit = nl80211_nan_change_config,
12485 .policy = nl80211_policy,
12486 .flags = GENL_ADMIN_PERM,
12487 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12488 NL80211_FLAG_NEED_RTNL,
12489 },
12490 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012491 .cmd = NL80211_CMD_SET_MCAST_RATE,
12492 .doit = nl80211_set_mcast_rate,
12493 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012494 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012495 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12496 NL80211_FLAG_NEED_RTNL,
12497 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012498 {
12499 .cmd = NL80211_CMD_SET_MAC_ACL,
12500 .doit = nl80211_set_mac_acl,
12501 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012502 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012503 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12504 NL80211_FLAG_NEED_RTNL,
12505 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012506 {
12507 .cmd = NL80211_CMD_RADAR_DETECT,
12508 .doit = nl80211_start_radar_detection,
12509 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012510 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012511 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12512 NL80211_FLAG_NEED_RTNL,
12513 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012514 {
12515 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12516 .doit = nl80211_get_protocol_features,
12517 .policy = nl80211_policy,
12518 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012519 {
12520 .cmd = NL80211_CMD_UPDATE_FT_IES,
12521 .doit = nl80211_update_ft_ies,
12522 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012523 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012524 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12525 NL80211_FLAG_NEED_RTNL,
12526 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012527 {
12528 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12529 .doit = nl80211_crit_protocol_start,
12530 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012531 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012532 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12533 NL80211_FLAG_NEED_RTNL,
12534 },
12535 {
12536 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12537 .doit = nl80211_crit_protocol_stop,
12538 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012539 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012540 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12541 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012542 },
12543 {
12544 .cmd = NL80211_CMD_GET_COALESCE,
12545 .doit = nl80211_get_coalesce,
12546 .policy = nl80211_policy,
12547 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12548 NL80211_FLAG_NEED_RTNL,
12549 },
12550 {
12551 .cmd = NL80211_CMD_SET_COALESCE,
12552 .doit = nl80211_set_coalesce,
12553 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012554 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070012555 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12556 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012557 },
12558 {
12559 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12560 .doit = nl80211_channel_switch,
12561 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012562 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12564 NL80211_FLAG_NEED_RTNL,
12565 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012566 {
12567 .cmd = NL80211_CMD_VENDOR,
12568 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012569 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012570 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012571 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012572 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12573 NL80211_FLAG_NEED_RTNL,
12574 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012575 {
12576 .cmd = NL80211_CMD_SET_QOS_MAP,
12577 .doit = nl80211_set_qos_map,
12578 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012579 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012580 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12581 NL80211_FLAG_NEED_RTNL,
12582 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012583 {
12584 .cmd = NL80211_CMD_ADD_TX_TS,
12585 .doit = nl80211_add_tx_ts,
12586 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012587 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012588 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12589 NL80211_FLAG_NEED_RTNL,
12590 },
12591 {
12592 .cmd = NL80211_CMD_DEL_TX_TS,
12593 .doit = nl80211_del_tx_ts,
12594 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012595 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012596 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12597 NL80211_FLAG_NEED_RTNL,
12598 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012599 {
12600 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12601 .doit = nl80211_tdls_channel_switch,
12602 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012603 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012604 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12605 NL80211_FLAG_NEED_RTNL,
12606 },
12607 {
12608 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12609 .doit = nl80211_tdls_cancel_channel_switch,
12610 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012611 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012612 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12613 NL80211_FLAG_NEED_RTNL,
12614 },
Johannes Berg55682962007-09-20 13:09:35 -040012615};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012616
Johannes Berg55682962007-09-20 13:09:35 -040012617/* notification functions */
12618
Johannes Berg3bb20552014-05-26 13:52:25 +020012619void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12620 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012621{
12622 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012623 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012624
Johannes Berg3bb20552014-05-26 13:52:25 +020012625 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12626 cmd != NL80211_CMD_DEL_WIPHY);
12627
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012628 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012629 if (!msg)
12630 return;
12631
Johannes Berg3bb20552014-05-26 13:52:25 +020012632 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040012633 nlmsg_free(msg);
12634 return;
12635 }
12636
Johannes Berg68eb5502013-11-19 15:19:38 +010012637 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012638 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012639}
12640
Denis Kenzior896ff062016-08-03 16:58:33 -050012641void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
12642 struct wireless_dev *wdev,
12643 enum nl80211_commands cmd)
12644{
12645 struct sk_buff *msg;
12646
12647 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
12648 cmd != NL80211_CMD_DEL_INTERFACE);
12649
12650 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12651 if (!msg)
12652 return;
12653
12654 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
12655 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
12656 nlmsg_free(msg);
12657 return;
12658 }
12659
12660 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12661 NL80211_MCGRP_CONFIG, GFP_KERNEL);
12662}
12663
Johannes Berg362a4152009-05-24 16:43:15 +020012664static int nl80211_add_scan_req(struct sk_buff *msg,
12665 struct cfg80211_registered_device *rdev)
12666{
12667 struct cfg80211_scan_request *req = rdev->scan_req;
12668 struct nlattr *nest;
12669 int i;
12670
12671 if (WARN_ON(!req))
12672 return 0;
12673
12674 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
12675 if (!nest)
12676 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012677 for (i = 0; i < req->n_ssids; i++) {
12678 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
12679 goto nla_put_failure;
12680 }
Johannes Berg362a4152009-05-24 16:43:15 +020012681 nla_nest_end(msg, nest);
12682
12683 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
12684 if (!nest)
12685 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012686 for (i = 0; i < req->n_channels; i++) {
12687 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
12688 goto nla_put_failure;
12689 }
Johannes Berg362a4152009-05-24 16:43:15 +020012690 nla_nest_end(msg, nest);
12691
David S. Miller9360ffd2012-03-29 04:41:26 -040012692 if (req->ie &&
12693 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
12694 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020012695
Johannes Bergae917c92013-10-25 11:05:22 +020012696 if (req->flags &&
12697 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
12698 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070012699
Avraham Stern1d762502016-07-05 17:10:13 +030012700 if (req->info.scan_start_tsf &&
12701 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
12702 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
12703 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
12704 req->info.tsf_bssid)))
12705 goto nla_put_failure;
12706
Johannes Berg362a4152009-05-24 16:43:15 +020012707 return 0;
12708 nla_put_failure:
12709 return -ENOBUFS;
12710}
12711
Johannes Berga538e2d2009-06-16 19:56:42 +020012712static int nl80211_send_scan_msg(struct sk_buff *msg,
12713 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012714 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012715 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020012716 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010012717{
12718 void *hdr;
12719
Eric W. Biederman15e47302012-09-07 20:12:54 +000012720 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010012721 if (!hdr)
12722 return -1;
12723
David S. Miller9360ffd2012-03-29 04:41:26 -040012724 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020012725 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12726 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012727 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12728 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012729 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010012730
Johannes Berg362a4152009-05-24 16:43:15 +020012731 /* ignore errors and send incomplete event anyway */
12732 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010012733
Johannes Berg053c0952015-01-16 22:09:00 +010012734 genlmsg_end(msg, hdr);
12735 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010012736
12737 nla_put_failure:
12738 genlmsg_cancel(msg, hdr);
12739 return -EMSGSIZE;
12740}
12741
Luciano Coelho807f8a82011-05-11 17:09:35 +030012742static int
12743nl80211_send_sched_scan_msg(struct sk_buff *msg,
12744 struct cfg80211_registered_device *rdev,
12745 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012746 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030012747{
12748 void *hdr;
12749
Eric W. Biederman15e47302012-09-07 20:12:54 +000012750 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012751 if (!hdr)
12752 return -1;
12753
David S. Miller9360ffd2012-03-29 04:41:26 -040012754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12756 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012757
Johannes Berg053c0952015-01-16 22:09:00 +010012758 genlmsg_end(msg, hdr);
12759 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012760
12761 nla_put_failure:
12762 genlmsg_cancel(msg, hdr);
12763 return -EMSGSIZE;
12764}
12765
Johannes Berga538e2d2009-06-16 19:56:42 +020012766void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012767 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012768{
12769 struct sk_buff *msg;
12770
Thomas Graf58050fc2012-06-28 03:57:45 +000012771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012772 if (!msg)
12773 return;
12774
Johannes Bergfd014282012-06-18 19:17:03 +020012775 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012776 NL80211_CMD_TRIGGER_SCAN) < 0) {
12777 nlmsg_free(msg);
12778 return;
12779 }
12780
Johannes Berg68eb5502013-11-19 15:19:38 +010012781 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012782 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012783}
12784
Johannes Bergf9d15d12014-01-22 11:14:19 +020012785struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12786 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012787{
12788 struct sk_buff *msg;
12789
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012791 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012792 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012793
Johannes Bergfd014282012-06-18 19:17:03 +020012794 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012795 aborted ? NL80211_CMD_SCAN_ABORTED :
12796 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012797 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012798 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012799 }
12800
Johannes Bergf9d15d12014-01-22 11:14:19 +020012801 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012802}
12803
Johannes Bergf9d15d12014-01-22 11:14:19 +020012804void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12805 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012806{
Johannes Berg2a519312009-02-10 21:25:55 +010012807 if (!msg)
12808 return;
12809
Johannes Berg68eb5502013-11-19 15:19:38 +010012810 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012811 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012812}
12813
Luciano Coelho807f8a82011-05-11 17:09:35 +030012814void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12815 struct net_device *netdev)
12816{
12817 struct sk_buff *msg;
12818
12819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12820 if (!msg)
12821 return;
12822
12823 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12824 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12825 nlmsg_free(msg);
12826 return;
12827 }
12828
Johannes Berg68eb5502013-11-19 15:19:38 +010012829 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012830 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012831}
12832
12833void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12834 struct net_device *netdev, u32 cmd)
12835{
12836 struct sk_buff *msg;
12837
Thomas Graf58050fc2012-06-28 03:57:45 +000012838 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012839 if (!msg)
12840 return;
12841
12842 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12843 nlmsg_free(msg);
12844 return;
12845 }
12846
Johannes Berg68eb5502013-11-19 15:19:38 +010012847 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012848 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012849}
12850
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012851static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12852 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012853{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012854 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012855 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12856 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012857
David S. Miller9360ffd2012-03-29 04:41:26 -040012858 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12859 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12860 NL80211_REGDOM_TYPE_WORLD))
12861 goto nla_put_failure;
12862 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12863 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12864 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12865 goto nla_put_failure;
12866 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12867 request->intersect) {
12868 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12869 NL80211_REGDOM_TYPE_INTERSECTION))
12870 goto nla_put_failure;
12871 } else {
12872 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12873 NL80211_REGDOM_TYPE_COUNTRY) ||
12874 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12875 request->alpha2))
12876 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012877 }
12878
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012879 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12880 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12881
12882 if (wiphy &&
12883 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12884 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012885
12886 if (wiphy &&
12887 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12888 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12889 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012890 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012891
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012892 return true;
12893
12894nla_put_failure:
12895 return false;
12896}
12897
12898/*
12899 * This can happen on global regulatory changes or device specific settings
12900 * based on custom regulatory domains.
12901 */
12902void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12903 struct regulatory_request *request)
12904{
12905 struct sk_buff *msg;
12906 void *hdr;
12907
12908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12909 if (!msg)
12910 return;
12911
12912 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12913 if (!hdr) {
12914 nlmsg_free(msg);
12915 return;
12916 }
12917
12918 if (nl80211_reg_change_event_fill(msg, request) == false)
12919 goto nla_put_failure;
12920
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012921 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012922
Johannes Bergbc43b282009-07-25 10:54:13 +020012923 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012924 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012925 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012926 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012927
12928 return;
12929
12930nla_put_failure:
12931 genlmsg_cancel(msg, hdr);
12932 nlmsg_free(msg);
12933}
12934
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012935static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12936 struct net_device *netdev,
12937 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012938 enum nl80211_commands cmd, gfp_t gfp,
12939 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012940{
12941 struct sk_buff *msg;
12942 void *hdr;
12943
Johannes Berge6d6e342009-07-01 21:26:47 +020012944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012945 if (!msg)
12946 return;
12947
12948 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12949 if (!hdr) {
12950 nlmsg_free(msg);
12951 return;
12952 }
12953
David S. Miller9360ffd2012-03-29 04:41:26 -040012954 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12956 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12957 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012958
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012959 if (uapsd_queues >= 0) {
12960 struct nlattr *nla_wmm =
12961 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12962 if (!nla_wmm)
12963 goto nla_put_failure;
12964
12965 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12966 uapsd_queues))
12967 goto nla_put_failure;
12968
12969 nla_nest_end(msg, nla_wmm);
12970 }
12971
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012972 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012973
Johannes Berg68eb5502013-11-19 15:19:38 +010012974 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012975 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012976 return;
12977
12978 nla_put_failure:
12979 genlmsg_cancel(msg, hdr);
12980 nlmsg_free(msg);
12981}
12982
12983void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012984 struct net_device *netdev, const u8 *buf,
12985 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012986{
12987 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012988 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012989}
12990
12991void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12992 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012993 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012994{
Johannes Berge6d6e342009-07-01 21:26:47 +020012995 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012996 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012997}
12998
Jouni Malinen53b46b82009-03-27 20:53:56 +020012999void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013000 struct net_device *netdev, const u8 *buf,
13001 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013002{
13003 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013004 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013005}
13006
Jouni Malinen53b46b82009-03-27 20:53:56 +020013007void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13008 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013009 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013010{
13011 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013012 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013013}
13014
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013015void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13016 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013017{
Johannes Berg947add32013-02-22 22:05:20 +010013018 struct wireless_dev *wdev = dev->ieee80211_ptr;
13019 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013020 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013021 const struct ieee80211_mgmt *mgmt = (void *)buf;
13022 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013023
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013024 if (WARN_ON(len < 2))
13025 return;
13026
13027 if (ieee80211_is_deauth(mgmt->frame_control))
13028 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13029 else
13030 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13031
13032 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013033 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013034}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013035EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013036
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013037static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13038 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013039 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013040{
13041 struct sk_buff *msg;
13042 void *hdr;
13043
Johannes Berge6d6e342009-07-01 21:26:47 +020013044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013045 if (!msg)
13046 return;
13047
13048 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13049 if (!hdr) {
13050 nlmsg_free(msg);
13051 return;
13052 }
13053
David S. Miller9360ffd2012-03-29 04:41:26 -040013054 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13055 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13056 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13057 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13058 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013059
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013060 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013061
Johannes Berg68eb5502013-11-19 15:19:38 +010013062 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013063 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013064 return;
13065
13066 nla_put_failure:
13067 genlmsg_cancel(msg, hdr);
13068 nlmsg_free(msg);
13069}
13070
13071void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013072 struct net_device *netdev, const u8 *addr,
13073 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013074{
13075 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013076 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013077}
13078
13079void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013080 struct net_device *netdev, const u8 *addr,
13081 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013082{
Johannes Berge6d6e342009-07-01 21:26:47 +020013083 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13084 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013085}
13086
Samuel Ortizb23aa672009-07-01 21:26:54 +020013087void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13088 struct net_device *netdev, const u8 *bssid,
13089 const u8 *req_ie, size_t req_ie_len,
13090 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013091 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013092{
13093 struct sk_buff *msg;
13094 void *hdr;
13095
Thomas Graf58050fc2012-06-28 03:57:45 +000013096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013097 if (!msg)
13098 return;
13099
13100 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13101 if (!hdr) {
13102 nlmsg_free(msg);
13103 return;
13104 }
13105
David S. Miller9360ffd2012-03-29 04:41:26 -040013106 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13108 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013109 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13110 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13111 status) ||
13112 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013113 (req_ie &&
13114 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13115 (resp_ie &&
13116 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13117 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013118
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013119 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013120
Johannes Berg68eb5502013-11-19 15:19:38 +010013121 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013122 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013123 return;
13124
13125 nla_put_failure:
13126 genlmsg_cancel(msg, hdr);
13127 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013128}
13129
13130void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13131 struct net_device *netdev, const u8 *bssid,
13132 const u8 *req_ie, size_t req_ie_len,
13133 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
13134{
13135 struct sk_buff *msg;
13136 void *hdr;
13137
Thomas Graf58050fc2012-06-28 03:57:45 +000013138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013139 if (!msg)
13140 return;
13141
13142 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13143 if (!hdr) {
13144 nlmsg_free(msg);
13145 return;
13146 }
13147
David S. Miller9360ffd2012-03-29 04:41:26 -040013148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13150 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13151 (req_ie &&
13152 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13153 (resp_ie &&
13154 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13155 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013156
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013157 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013158
Johannes Berg68eb5502013-11-19 15:19:38 +010013159 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013160 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013161 return;
13162
13163 nla_put_failure:
13164 genlmsg_cancel(msg, hdr);
13165 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013166}
13167
13168void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13169 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020013170 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013171{
13172 struct sk_buff *msg;
13173 void *hdr;
13174
Thomas Graf58050fc2012-06-28 03:57:45 +000013175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013176 if (!msg)
13177 return;
13178
13179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13180 if (!hdr) {
13181 nlmsg_free(msg);
13182 return;
13183 }
13184
David S. Miller9360ffd2012-03-29 04:41:26 -040013185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13187 (from_ap && reason &&
13188 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13189 (from_ap &&
13190 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13191 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13192 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013193
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013194 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013195
Johannes Berg68eb5502013-11-19 15:19:38 +010013196 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013197 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013198 return;
13199
13200 nla_put_failure:
13201 genlmsg_cancel(msg, hdr);
13202 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013203}
13204
Johannes Berg04a773a2009-04-19 21:24:32 +020013205void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13206 struct net_device *netdev, const u8 *bssid,
13207 gfp_t gfp)
13208{
13209 struct sk_buff *msg;
13210 void *hdr;
13211
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013213 if (!msg)
13214 return;
13215
13216 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13217 if (!hdr) {
13218 nlmsg_free(msg);
13219 return;
13220 }
13221
David S. Miller9360ffd2012-03-29 04:41:26 -040013222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13223 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13224 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13225 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013226
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013227 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013228
Johannes Berg68eb5502013-11-19 15:19:38 +010013229 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013230 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013231 return;
13232
13233 nla_put_failure:
13234 genlmsg_cancel(msg, hdr);
13235 nlmsg_free(msg);
13236}
13237
Johannes Berg947add32013-02-22 22:05:20 +010013238void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13239 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013240{
Johannes Berg947add32013-02-22 22:05:20 +010013241 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013242 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013243 struct sk_buff *msg;
13244 void *hdr;
13245
Johannes Berg947add32013-02-22 22:05:20 +010013246 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13247 return;
13248
13249 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13250
Javier Cardonac93b5e72011-04-07 15:08:34 -070013251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13252 if (!msg)
13253 return;
13254
13255 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13256 if (!hdr) {
13257 nlmsg_free(msg);
13258 return;
13259 }
13260
David S. Miller9360ffd2012-03-29 04:41:26 -040013261 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013262 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13263 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013264 (ie_len && ie &&
13265 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13266 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013267
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013268 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013269
Johannes Berg68eb5502013-11-19 15:19:38 +010013270 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013271 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013272 return;
13273
13274 nla_put_failure:
13275 genlmsg_cancel(msg, hdr);
13276 nlmsg_free(msg);
13277}
Johannes Berg947add32013-02-22 22:05:20 +010013278EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013279
Jouni Malinena3b8b052009-03-27 21:59:49 +020013280void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13281 struct net_device *netdev, const u8 *addr,
13282 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013283 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013284{
13285 struct sk_buff *msg;
13286 void *hdr;
13287
Johannes Berge6d6e342009-07-01 21:26:47 +020013288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013289 if (!msg)
13290 return;
13291
13292 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13293 if (!hdr) {
13294 nlmsg_free(msg);
13295 return;
13296 }
13297
David S. Miller9360ffd2012-03-29 04:41:26 -040013298 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13299 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13300 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13301 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13302 (key_id != -1 &&
13303 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13304 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13305 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013306
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013307 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013308
Johannes Berg68eb5502013-11-19 15:19:38 +010013309 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013310 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013311 return;
13312
13313 nla_put_failure:
13314 genlmsg_cancel(msg, hdr);
13315 nlmsg_free(msg);
13316}
13317
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013318void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13319 struct ieee80211_channel *channel_before,
13320 struct ieee80211_channel *channel_after)
13321{
13322 struct sk_buff *msg;
13323 void *hdr;
13324 struct nlattr *nl_freq;
13325
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013327 if (!msg)
13328 return;
13329
13330 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13331 if (!hdr) {
13332 nlmsg_free(msg);
13333 return;
13334 }
13335
13336 /*
13337 * Since we are applying the beacon hint to a wiphy we know its
13338 * wiphy_idx is valid
13339 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13341 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013342
13343 /* Before */
13344 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13345 if (!nl_freq)
13346 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013347 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013348 goto nla_put_failure;
13349 nla_nest_end(msg, nl_freq);
13350
13351 /* After */
13352 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13353 if (!nl_freq)
13354 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013355 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013356 goto nla_put_failure;
13357 nla_nest_end(msg, nl_freq);
13358
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013359 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013360
Johannes Berg463d0182009-07-14 00:33:35 +020013361 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013362 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013363 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013364 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013365
13366 return;
13367
13368nla_put_failure:
13369 genlmsg_cancel(msg, hdr);
13370 nlmsg_free(msg);
13371}
13372
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013373static void nl80211_send_remain_on_chan_event(
13374 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013375 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013376 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013377 unsigned int duration, gfp_t gfp)
13378{
13379 struct sk_buff *msg;
13380 void *hdr;
13381
13382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13383 if (!msg)
13384 return;
13385
13386 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13387 if (!hdr) {
13388 nlmsg_free(msg);
13389 return;
13390 }
13391
David S. Miller9360ffd2012-03-29 04:41:26 -040013392 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013393 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13394 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013395 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13396 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013397 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013398 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13399 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013400 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13401 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013402 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013403
David S. Miller9360ffd2012-03-29 04:41:26 -040013404 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13405 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13406 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013407
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013408 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013409
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 Malinen9588bbd2009-12-23 13:15:41 +010013412 return;
13413
13414 nla_put_failure:
13415 genlmsg_cancel(msg, hdr);
13416 nlmsg_free(msg);
13417}
13418
Johannes Berg947add32013-02-22 22:05:20 +010013419void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13420 struct ieee80211_channel *chan,
13421 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013422{
Johannes Berg947add32013-02-22 22:05:20 +010013423 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013424 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013425
13426 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013427 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013428 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013429 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013430}
Johannes Berg947add32013-02-22 22:05:20 +010013431EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013432
Johannes Berg947add32013-02-22 22:05:20 +010013433void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13434 struct ieee80211_channel *chan,
13435 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013436{
Johannes Berg947add32013-02-22 22:05:20 +010013437 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013438 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013439
13440 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013441 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013442 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013443}
Johannes Berg947add32013-02-22 22:05:20 +010013444EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013445
Johannes Berg947add32013-02-22 22:05:20 +010013446void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13447 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013448{
Johannes Berg947add32013-02-22 22:05:20 +010013449 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013450 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013451 struct sk_buff *msg;
13452
Johannes Berg947add32013-02-22 22:05:20 +010013453 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13454
Thomas Graf58050fc2012-06-28 03:57:45 +000013455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013456 if (!msg)
13457 return;
13458
Johannes Bergcf5ead82014-11-14 17:14:00 +010013459 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013460 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013461 nlmsg_free(msg);
13462 return;
13463 }
13464
Johannes Berg68eb5502013-11-19 15:19:38 +010013465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013466 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013467}
Johannes Berg947add32013-02-22 22:05:20 +010013468EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013469
Johannes Bergcf5ead82014-11-14 17:14:00 +010013470void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13471 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013472{
Johannes Berg947add32013-02-22 22:05:20 +010013473 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013474 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013475 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013476 struct station_info empty_sinfo = {};
13477
13478 if (!sinfo)
13479 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013480
Johannes Berg947add32013-02-22 22:05:20 +010013481 trace_cfg80211_del_sta(dev, mac_addr);
13482
Thomas Graf58050fc2012-06-28 03:57:45 +000013483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013484 if (!msg)
13485 return;
13486
Johannes Bergcf5ead82014-11-14 17:14:00 +010013487 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013488 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013489 nlmsg_free(msg);
13490 return;
13491 }
13492
Johannes Berg68eb5502013-11-19 15:19:38 +010013493 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013494 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013495}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013496EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013497
Johannes Berg947add32013-02-22 22:05:20 +010013498void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13499 enum nl80211_connect_failed_reason reason,
13500 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013501{
Johannes Berg947add32013-02-22 22:05:20 +010013502 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013503 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013504 struct sk_buff *msg;
13505 void *hdr;
13506
13507 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13508 if (!msg)
13509 return;
13510
13511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13512 if (!hdr) {
13513 nlmsg_free(msg);
13514 return;
13515 }
13516
13517 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13518 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13519 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13520 goto nla_put_failure;
13521
13522 genlmsg_end(msg, hdr);
13523
Johannes Berg68eb5502013-11-19 15:19:38 +010013524 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013525 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013526 return;
13527
13528 nla_put_failure:
13529 genlmsg_cancel(msg, hdr);
13530 nlmsg_free(msg);
13531}
Johannes Berg947add32013-02-22 22:05:20 +010013532EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013533
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013534static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13535 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013536{
13537 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013538 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013539 struct sk_buff *msg;
13540 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013541 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013542
Eric W. Biederman15e47302012-09-07 20:12:54 +000013543 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013544 return false;
13545
13546 msg = nlmsg_new(100, gfp);
13547 if (!msg)
13548 return true;
13549
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013550 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013551 if (!hdr) {
13552 nlmsg_free(msg);
13553 return true;
13554 }
13555
David S. Miller9360ffd2012-03-29 04:41:26 -040013556 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13557 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13558 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13559 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013560
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013561 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013562 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013563 return true;
13564
13565 nla_put_failure:
13566 genlmsg_cancel(msg, hdr);
13567 nlmsg_free(msg);
13568 return true;
13569}
13570
Johannes Berg947add32013-02-22 22:05:20 +010013571bool cfg80211_rx_spurious_frame(struct net_device *dev,
13572 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013573{
Johannes Berg947add32013-02-22 22:05:20 +010013574 struct wireless_dev *wdev = dev->ieee80211_ptr;
13575 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013576
Johannes Berg947add32013-02-22 22:05:20 +010013577 trace_cfg80211_rx_spurious_frame(dev, addr);
13578
13579 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13580 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13581 trace_cfg80211_return_bool(false);
13582 return false;
13583 }
13584 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13585 addr, gfp);
13586 trace_cfg80211_return_bool(ret);
13587 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013588}
Johannes Berg947add32013-02-22 22:05:20 +010013589EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13590
13591bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13592 const u8 *addr, gfp_t gfp)
13593{
13594 struct wireless_dev *wdev = dev->ieee80211_ptr;
13595 bool ret;
13596
13597 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13598
13599 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13600 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13601 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13602 trace_cfg80211_return_bool(false);
13603 return false;
13604 }
13605 ret = __nl80211_unexpected_frame(dev,
13606 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13607 addr, gfp);
13608 trace_cfg80211_return_bool(ret);
13609 return ret;
13610}
13611EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013612
Johannes Berg2e161f72010-08-12 15:38:38 +020013613int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013614 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013615 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013616 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013617{
Johannes Berg71bbc992012-06-15 15:30:18 +020013618 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013619 struct sk_buff *msg;
13620 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020013621
13622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13623 if (!msg)
13624 return -ENOMEM;
13625
Johannes Berg2e161f72010-08-12 15:38:38 +020013626 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020013627 if (!hdr) {
13628 nlmsg_free(msg);
13629 return -ENOMEM;
13630 }
13631
David S. Miller9360ffd2012-03-29 04:41:26 -040013632 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013633 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13634 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013635 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13636 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013637 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
13638 (sig_dbm &&
13639 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013640 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
13641 (flags &&
13642 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013643 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013644
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013645 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013646
Eric W. Biederman15e47302012-09-07 20:12:54 +000013647 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020013648
13649 nla_put_failure:
13650 genlmsg_cancel(msg, hdr);
13651 nlmsg_free(msg);
13652 return -ENOBUFS;
13653}
13654
Johannes Berg947add32013-02-22 22:05:20 +010013655void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
13656 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013657{
Johannes Berg947add32013-02-22 22:05:20 +010013658 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013659 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020013660 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013661 struct sk_buff *msg;
13662 void *hdr;
13663
Johannes Berg947add32013-02-22 22:05:20 +010013664 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
13665
Jouni Malinen026331c2010-02-15 12:53:10 +020013666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13667 if (!msg)
13668 return;
13669
Johannes Berg2e161f72010-08-12 15:38:38 +020013670 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020013671 if (!hdr) {
13672 nlmsg_free(msg);
13673 return;
13674 }
13675
David S. Miller9360ffd2012-03-29 04:41:26 -040013676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013677 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13678 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013679 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13680 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013681 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013682 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13683 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013684 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
13685 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013686
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013687 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013688
Johannes Berg68eb5502013-11-19 15:19:38 +010013689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013690 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013691 return;
13692
13693 nla_put_failure:
13694 genlmsg_cancel(msg, hdr);
13695 nlmsg_free(msg);
13696}
Johannes Berg947add32013-02-22 22:05:20 +010013697EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020013698
Johannes Berg5b97f492014-11-26 12:37:43 +010013699static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
13700 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013701{
Johannes Berg947add32013-02-22 22:05:20 +010013702 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010013703 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13704 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13705 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013706
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013707 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010013708 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013709
Johannes Berg5b97f492014-11-26 12:37:43 +010013710 cb = (void **)msg->cb;
13711
13712 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
13713 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013714 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010013715 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013716 }
13717
David S. Miller9360ffd2012-03-29 04:41:26 -040013718 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013719 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040013720 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013721
Johannes Berg5b97f492014-11-26 12:37:43 +010013722 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013723 goto nla_put_failure;
13724
Johannes Berg5b97f492014-11-26 12:37:43 +010013725 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
13726 if (!cb[1])
13727 goto nla_put_failure;
13728
13729 cb[2] = rdev;
13730
13731 return msg;
13732 nla_put_failure:
13733 nlmsg_free(msg);
13734 return NULL;
13735}
13736
13737static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
13738{
13739 void **cb = (void **)msg->cb;
13740 struct cfg80211_registered_device *rdev = cb[2];
13741
13742 nla_nest_end(msg, cb[1]);
13743 genlmsg_end(msg, cb[0]);
13744
13745 memset(msg->cb, 0, sizeof(msg->cb));
13746
13747 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13748 NL80211_MCGRP_MLME, gfp);
13749}
13750
13751void cfg80211_cqm_rssi_notify(struct net_device *dev,
13752 enum nl80211_cqm_rssi_threshold_event rssi_event,
13753 gfp_t gfp)
13754{
13755 struct sk_buff *msg;
13756
13757 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
13758
Johannes Berg98f03342014-11-26 12:42:02 +010013759 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13760 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13761 return;
13762
Johannes Berg5b97f492014-11-26 12:37:43 +010013763 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13764 if (!msg)
13765 return;
13766
David S. Miller9360ffd2012-03-29 04:41:26 -040013767 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13768 rssi_event))
13769 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013770
Johannes Berg5b97f492014-11-26 12:37:43 +010013771 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013772
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013773 return;
13774
13775 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013776 nlmsg_free(msg);
13777}
Johannes Berg947add32013-02-22 22:05:20 +010013778EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013779
Johannes Berg5b97f492014-11-26 12:37:43 +010013780void cfg80211_cqm_txe_notify(struct net_device *dev,
13781 const u8 *peer, u32 num_packets,
13782 u32 rate, u32 intvl, gfp_t gfp)
13783{
13784 struct sk_buff *msg;
13785
13786 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13787 if (!msg)
13788 return;
13789
13790 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13791 goto nla_put_failure;
13792
13793 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13794 goto nla_put_failure;
13795
13796 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13797 goto nla_put_failure;
13798
13799 cfg80211_send_cqm(msg, gfp);
13800 return;
13801
13802 nla_put_failure:
13803 nlmsg_free(msg);
13804}
13805EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13806
13807void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13808 const u8 *peer, u32 num_packets, gfp_t gfp)
13809{
13810 struct sk_buff *msg;
13811
13812 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13813
13814 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13815 if (!msg)
13816 return;
13817
13818 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13819 goto nla_put_failure;
13820
13821 cfg80211_send_cqm(msg, gfp);
13822 return;
13823
13824 nla_put_failure:
13825 nlmsg_free(msg);
13826}
13827EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13828
Johannes Berg98f03342014-11-26 12:42:02 +010013829void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13830{
13831 struct sk_buff *msg;
13832
13833 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13834 if (!msg)
13835 return;
13836
13837 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13838 goto nla_put_failure;
13839
13840 cfg80211_send_cqm(msg, gfp);
13841 return;
13842
13843 nla_put_failure:
13844 nlmsg_free(msg);
13845}
13846EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13847
Johannes Berg947add32013-02-22 22:05:20 +010013848static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13849 struct net_device *netdev, const u8 *bssid,
13850 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013851{
13852 struct sk_buff *msg;
13853 struct nlattr *rekey_attr;
13854 void *hdr;
13855
Thomas Graf58050fc2012-06-28 03:57:45 +000013856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013857 if (!msg)
13858 return;
13859
13860 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13861 if (!hdr) {
13862 nlmsg_free(msg);
13863 return;
13864 }
13865
David S. Miller9360ffd2012-03-29 04:41:26 -040013866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13867 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13868 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13869 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013870
13871 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13872 if (!rekey_attr)
13873 goto nla_put_failure;
13874
David S. Miller9360ffd2012-03-29 04:41:26 -040013875 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13876 NL80211_REPLAY_CTR_LEN, replay_ctr))
13877 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013878
13879 nla_nest_end(msg, rekey_attr);
13880
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013881 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013882
Johannes Berg68eb5502013-11-19 15:19:38 +010013883 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013884 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013885 return;
13886
13887 nla_put_failure:
13888 genlmsg_cancel(msg, hdr);
13889 nlmsg_free(msg);
13890}
13891
Johannes Berg947add32013-02-22 22:05:20 +010013892void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13893 const u8 *replay_ctr, gfp_t gfp)
13894{
13895 struct wireless_dev *wdev = dev->ieee80211_ptr;
13896 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013897 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013898
13899 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13900 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13901}
13902EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13903
13904static void
13905nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13906 struct net_device *netdev, int index,
13907 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013908{
13909 struct sk_buff *msg;
13910 struct nlattr *attr;
13911 void *hdr;
13912
Thomas Graf58050fc2012-06-28 03:57:45 +000013913 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013914 if (!msg)
13915 return;
13916
13917 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13918 if (!hdr) {
13919 nlmsg_free(msg);
13920 return;
13921 }
13922
David S. Miller9360ffd2012-03-29 04:41:26 -040013923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13924 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13925 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013926
13927 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13928 if (!attr)
13929 goto nla_put_failure;
13930
David S. Miller9360ffd2012-03-29 04:41:26 -040013931 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13932 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13933 (preauth &&
13934 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13935 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013936
13937 nla_nest_end(msg, attr);
13938
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013939 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013940
Johannes Berg68eb5502013-11-19 15:19:38 +010013941 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013942 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013943 return;
13944
13945 nla_put_failure:
13946 genlmsg_cancel(msg, hdr);
13947 nlmsg_free(msg);
13948}
13949
Johannes Berg947add32013-02-22 22:05:20 +010013950void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13951 const u8 *bssid, bool preauth, gfp_t gfp)
13952{
13953 struct wireless_dev *wdev = dev->ieee80211_ptr;
13954 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013955 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013956
13957 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13958 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13959}
13960EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13961
13962static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13963 struct net_device *netdev,
13964 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013965 gfp_t gfp,
13966 enum nl80211_commands notif,
13967 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013968{
13969 struct sk_buff *msg;
13970 void *hdr;
13971
Thomas Graf58050fc2012-06-28 03:57:45 +000013972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013973 if (!msg)
13974 return;
13975
Luciano Coelhof8d75522014-11-07 14:31:35 +020013976 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013977 if (!hdr) {
13978 nlmsg_free(msg);
13979 return;
13980 }
13981
Johannes Berg683b6d32012-11-08 21:25:48 +010013982 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13983 goto nla_put_failure;
13984
13985 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013986 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013987
Luciano Coelhof8d75522014-11-07 14:31:35 +020013988 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13989 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13990 goto nla_put_failure;
13991
Thomas Pedersen53145262012-04-06 13:35:47 -070013992 genlmsg_end(msg, hdr);
13993
Johannes Berg68eb5502013-11-19 15:19:38 +010013994 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013995 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013996 return;
13997
13998 nla_put_failure:
13999 genlmsg_cancel(msg, hdr);
14000 nlmsg_free(msg);
14001}
14002
Johannes Berg947add32013-02-22 22:05:20 +010014003void cfg80211_ch_switch_notify(struct net_device *dev,
14004 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014005{
Johannes Berg947add32013-02-22 22:05:20 +010014006 struct wireless_dev *wdev = dev->ieee80211_ptr;
14007 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014008 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014009
Simon Wunderliche487eae2013-11-21 18:19:51 +010014010 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014011
Simon Wunderliche487eae2013-11-21 18:19:51 +010014012 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014013
Michal Kazior9e0e2962014-01-29 14:22:27 +010014014 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014015 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014016 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14017 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014018}
14019EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14020
Luciano Coelhof8d75522014-11-07 14:31:35 +020014021void cfg80211_ch_switch_started_notify(struct net_device *dev,
14022 struct cfg80211_chan_def *chandef,
14023 u8 count)
14024{
14025 struct wireless_dev *wdev = dev->ieee80211_ptr;
14026 struct wiphy *wiphy = wdev->wiphy;
14027 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14028
14029 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14030
14031 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14032 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14033}
14034EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14035
Thomas Pedersen84f10702012-07-12 16:17:33 -070014036void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014037nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014038 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014039 enum nl80211_radar_event event,
14040 struct net_device *netdev, gfp_t gfp)
14041{
14042 struct sk_buff *msg;
14043 void *hdr;
14044
14045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14046 if (!msg)
14047 return;
14048
14049 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14050 if (!hdr) {
14051 nlmsg_free(msg);
14052 return;
14053 }
14054
14055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14056 goto nla_put_failure;
14057
14058 /* NOP and radar events don't need a netdev parameter */
14059 if (netdev) {
14060 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14061
14062 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014063 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14064 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014065 goto nla_put_failure;
14066 }
14067
14068 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14069 goto nla_put_failure;
14070
14071 if (nl80211_send_chandef(msg, chandef))
14072 goto nla_put_failure;
14073
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014074 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014075
Johannes Berg68eb5502013-11-19 15:19:38 +010014076 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014077 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014078 return;
14079
14080 nla_put_failure:
14081 genlmsg_cancel(msg, hdr);
14082 nlmsg_free(msg);
14083}
14084
Johannes Berg7f6cf312011-11-04 11:18:15 +010014085void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14086 u64 cookie, bool acked, gfp_t gfp)
14087{
14088 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014089 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014090 struct sk_buff *msg;
14091 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014092
Beni Lev4ee3e062012-08-27 12:49:39 +030014093 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14094
Thomas Graf58050fc2012-06-28 03:57:45 +000014095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014096
Johannes Berg7f6cf312011-11-04 11:18:15 +010014097 if (!msg)
14098 return;
14099
14100 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14101 if (!hdr) {
14102 nlmsg_free(msg);
14103 return;
14104 }
14105
David S. Miller9360ffd2012-03-29 04:41:26 -040014106 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14108 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014109 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14110 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014111 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14112 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014113
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014114 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014115
Johannes Berg68eb5502013-11-19 15:19:38 +010014116 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014117 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014118 return;
14119
14120 nla_put_failure:
14121 genlmsg_cancel(msg, hdr);
14122 nlmsg_free(msg);
14123}
14124EXPORT_SYMBOL(cfg80211_probe_status);
14125
Johannes Berg5e7602302011-11-04 11:18:17 +010014126void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14127 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014128 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010014129{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014130 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010014131 struct sk_buff *msg;
14132 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014133 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010014134
Beni Lev4ee3e062012-08-27 12:49:39 +030014135 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14136
Ben Greear37c73b52012-10-26 14:49:25 -070014137 spin_lock_bh(&rdev->beacon_registrations_lock);
14138 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14139 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14140 if (!msg) {
14141 spin_unlock_bh(&rdev->beacon_registrations_lock);
14142 return;
14143 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014144
Ben Greear37c73b52012-10-26 14:49:25 -070014145 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14146 if (!hdr)
14147 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010014148
Ben Greear37c73b52012-10-26 14:49:25 -070014149 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14150 (freq &&
14151 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14152 (sig_dbm &&
14153 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14154 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14155 goto nla_put_failure;
14156
14157 genlmsg_end(msg, hdr);
14158
14159 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010014160 }
Ben Greear37c73b52012-10-26 14:49:25 -070014161 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010014162 return;
14163
14164 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014165 spin_unlock_bh(&rdev->beacon_registrations_lock);
14166 if (hdr)
14167 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010014168 nlmsg_free(msg);
14169}
14170EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14171
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014172#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014173static int cfg80211_net_detect_results(struct sk_buff *msg,
14174 struct cfg80211_wowlan_wakeup *wakeup)
14175{
14176 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14177 struct nlattr *nl_results, *nl_match, *nl_freqs;
14178 int i, j;
14179
14180 nl_results = nla_nest_start(
14181 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14182 if (!nl_results)
14183 return -EMSGSIZE;
14184
14185 for (i = 0; i < nd->n_matches; i++) {
14186 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14187
14188 nl_match = nla_nest_start(msg, i);
14189 if (!nl_match)
14190 break;
14191
14192 /* The SSID attribute is optional in nl80211, but for
14193 * simplicity reasons it's always present in the
14194 * cfg80211 structure. If a driver can't pass the
14195 * SSID, that needs to be changed. A zero length SSID
14196 * is still a valid SSID (wildcard), so it cannot be
14197 * used for this purpose.
14198 */
14199 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14200 match->ssid.ssid)) {
14201 nla_nest_cancel(msg, nl_match);
14202 goto out;
14203 }
14204
14205 if (match->n_channels) {
14206 nl_freqs = nla_nest_start(
14207 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14208 if (!nl_freqs) {
14209 nla_nest_cancel(msg, nl_match);
14210 goto out;
14211 }
14212
14213 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014214 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014215 nla_nest_cancel(msg, nl_freqs);
14216 nla_nest_cancel(msg, nl_match);
14217 goto out;
14218 }
14219 }
14220
14221 nla_nest_end(msg, nl_freqs);
14222 }
14223
14224 nla_nest_end(msg, nl_match);
14225 }
14226
14227out:
14228 nla_nest_end(msg, nl_results);
14229 return 0;
14230}
14231
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014232void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14233 struct cfg80211_wowlan_wakeup *wakeup,
14234 gfp_t gfp)
14235{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014236 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014237 struct sk_buff *msg;
14238 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014239 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014240
14241 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14242
14243 if (wakeup)
14244 size += wakeup->packet_present_len;
14245
14246 msg = nlmsg_new(size, gfp);
14247 if (!msg)
14248 return;
14249
14250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14251 if (!hdr)
14252 goto free_msg;
14253
14254 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014255 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14256 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014257 goto free_msg;
14258
14259 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14260 wdev->netdev->ifindex))
14261 goto free_msg;
14262
14263 if (wakeup) {
14264 struct nlattr *reasons;
14265
14266 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014267 if (!reasons)
14268 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014269
14270 if (wakeup->disconnect &&
14271 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14272 goto free_msg;
14273 if (wakeup->magic_pkt &&
14274 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14275 goto free_msg;
14276 if (wakeup->gtk_rekey_failure &&
14277 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14278 goto free_msg;
14279 if (wakeup->eap_identity_req &&
14280 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14281 goto free_msg;
14282 if (wakeup->four_way_handshake &&
14283 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14284 goto free_msg;
14285 if (wakeup->rfkill_release &&
14286 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14287 goto free_msg;
14288
14289 if (wakeup->pattern_idx >= 0 &&
14290 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14291 wakeup->pattern_idx))
14292 goto free_msg;
14293
Johannes Bergae917c92013-10-25 11:05:22 +020014294 if (wakeup->tcp_match &&
14295 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14296 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014297
Johannes Bergae917c92013-10-25 11:05:22 +020014298 if (wakeup->tcp_connlost &&
14299 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14300 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014301
Johannes Bergae917c92013-10-25 11:05:22 +020014302 if (wakeup->tcp_nomoretokens &&
14303 nla_put_flag(msg,
14304 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14305 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014306
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014307 if (wakeup->packet) {
14308 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14309 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14310
14311 if (!wakeup->packet_80211) {
14312 pkt_attr =
14313 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14314 len_attr =
14315 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14316 }
14317
14318 if (wakeup->packet_len &&
14319 nla_put_u32(msg, len_attr, wakeup->packet_len))
14320 goto free_msg;
14321
14322 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14323 wakeup->packet))
14324 goto free_msg;
14325 }
14326
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014327 if (wakeup->net_detect &&
14328 cfg80211_net_detect_results(msg, wakeup))
14329 goto free_msg;
14330
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014331 nla_nest_end(msg, reasons);
14332 }
14333
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014334 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014335
Johannes Berg68eb5502013-11-19 15:19:38 +010014336 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014337 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014338 return;
14339
14340 free_msg:
14341 nlmsg_free(msg);
14342}
14343EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14344#endif
14345
Jouni Malinen3475b092012-11-16 22:49:57 +020014346void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14347 enum nl80211_tdls_operation oper,
14348 u16 reason_code, gfp_t gfp)
14349{
14350 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014351 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014352 struct sk_buff *msg;
14353 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014354
14355 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14356 reason_code);
14357
14358 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14359 if (!msg)
14360 return;
14361
14362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14363 if (!hdr) {
14364 nlmsg_free(msg);
14365 return;
14366 }
14367
14368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14369 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14370 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14371 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14372 (reason_code > 0 &&
14373 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14374 goto nla_put_failure;
14375
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014376 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014377
Johannes Berg68eb5502013-11-19 15:19:38 +010014378 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014379 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014380 return;
14381
14382 nla_put_failure:
14383 genlmsg_cancel(msg, hdr);
14384 nlmsg_free(msg);
14385}
14386EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14387
Jouni Malinen026331c2010-02-15 12:53:10 +020014388static int nl80211_netlink_notify(struct notifier_block * nb,
14389 unsigned long state,
14390 void *_notify)
14391{
14392 struct netlink_notify *notify = _notify;
14393 struct cfg80211_registered_device *rdev;
14394 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014395 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014396
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014397 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014398 return NOTIFY_DONE;
14399
14400 rcu_read_lock();
14401
Johannes Berg5e7602302011-11-04 11:18:17 +010014402 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014403 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014404 struct cfg80211_sched_scan_request *sched_scan_req =
14405 rcu_dereference(rdev->sched_scan_req);
14406
14407 if (sched_scan_req && notify->portid &&
Johannes Berg0a28f532017-01-05 10:57:14 +010014408 sched_scan_req->owner_nlportid == notify->portid) {
14409 sched_scan_req->owner_nlportid = 0;
14410
14411 if (rdev->ops->sched_scan_stop &&
14412 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14413 schedule_work(&rdev->sched_scan_stop_wk);
14414 }
Johannes Berg78f22b62014-03-24 17:57:27 +010014415
Johannes Berg53873f12016-05-03 16:52:04 +030014416 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014417 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014418
Johannes Berg78f22b62014-03-24 17:57:27 +010014419 if (wdev->owner_nlportid == notify->portid)
14420 schedule_destroy_work = true;
14421 }
14422
Ben Greear37c73b52012-10-26 14:49:25 -070014423 spin_lock_bh(&rdev->beacon_registrations_lock);
14424 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14425 list) {
14426 if (reg->nlportid == notify->portid) {
14427 list_del(&reg->list);
14428 kfree(reg);
14429 break;
14430 }
14431 }
14432 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014433
14434 if (schedule_destroy_work) {
14435 struct cfg80211_iface_destroy *destroy;
14436
14437 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14438 if (destroy) {
14439 destroy->nlportid = notify->portid;
14440 spin_lock(&rdev->destroy_list_lock);
14441 list_add(&destroy->list, &rdev->destroy_list);
14442 spin_unlock(&rdev->destroy_list_lock);
14443 schedule_work(&rdev->destroy_work);
14444 }
14445 }
Johannes Berg5e7602302011-11-04 11:18:17 +010014446 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014447
14448 rcu_read_unlock();
14449
Ilan peer05050752015-03-04 00:32:06 -050014450 /*
14451 * It is possible that the user space process that is controlling the
14452 * indoor setting disappeared, so notify the regulatory core.
14453 */
14454 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014455 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014456}
14457
14458static struct notifier_block nl80211_netlink_notifier = {
14459 .notifier_call = nl80211_netlink_notify,
14460};
14461
Jouni Malinen355199e2013-02-27 17:14:27 +020014462void cfg80211_ft_event(struct net_device *netdev,
14463 struct cfg80211_ft_event_params *ft_event)
14464{
14465 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014467 struct sk_buff *msg;
14468 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014469
14470 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14471
14472 if (!ft_event->target_ap)
14473 return;
14474
14475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14476 if (!msg)
14477 return;
14478
14479 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014480 if (!hdr)
14481 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014482
Johannes Bergae917c92013-10-25 11:05:22 +020014483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14485 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14486 goto out;
14487
14488 if (ft_event->ies &&
14489 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14490 goto out;
14491 if (ft_event->ric_ies &&
14492 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14493 ft_event->ric_ies))
14494 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014495
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014496 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014497
Johannes Berg68eb5502013-11-19 15:19:38 +010014498 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014499 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014500 return;
14501 out:
14502 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014503}
14504EXPORT_SYMBOL(cfg80211_ft_event);
14505
Arend van Spriel5de17982013-04-18 15:49:00 +020014506void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14507{
14508 struct cfg80211_registered_device *rdev;
14509 struct sk_buff *msg;
14510 void *hdr;
14511 u32 nlportid;
14512
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014513 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014514 if (!rdev->crit_proto_nlportid)
14515 return;
14516
14517 nlportid = rdev->crit_proto_nlportid;
14518 rdev->crit_proto_nlportid = 0;
14519
14520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14521 if (!msg)
14522 return;
14523
14524 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14525 if (!hdr)
14526 goto nla_put_failure;
14527
14528 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014529 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14530 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014531 goto nla_put_failure;
14532
14533 genlmsg_end(msg, hdr);
14534
14535 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14536 return;
14537
14538 nla_put_failure:
14539 if (hdr)
14540 genlmsg_cancel(msg, hdr);
14541 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014542}
14543EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14544
Sameer Thalappilfaa4c4a2013-07-05 14:58:32 -070014545void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
14546{
14547 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14548 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
14549
14550 nl80211_send_mlme_event(rdev, netdev, NULL, 0,
14551 NL80211_CMD_STOP_AP, gfp, -1);
14552}
14553EXPORT_SYMBOL(cfg80211_ap_stopped);
14554
Johannes Berg348baf02014-01-24 14:06:29 +010014555void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14556{
14557 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014558 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014559 struct sk_buff *msg;
14560 void *hdr;
14561
14562 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14563 if (!msg)
14564 return;
14565
14566 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14567 if (!hdr)
14568 goto out;
14569
14570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14571 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014572 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14573 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014574 goto out;
14575
14576 genlmsg_end(msg, hdr);
14577
14578 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14579 NL80211_MCGRP_MLME, GFP_KERNEL);
14580 return;
14581 out:
14582 nlmsg_free(msg);
14583}
14584
Johannes Berg55682962007-09-20 13:09:35 -040014585/* initialisation/exit functions */
14586
14587int nl80211_init(void)
14588{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014589 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014590
Johannes Berg2a94fe42013-11-19 15:19:39 +010014591 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
14592 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040014593 if (err)
14594 return err;
14595
Jouni Malinen026331c2010-02-15 12:53:10 +020014596 err = netlink_register_notifier(&nl80211_netlink_notifier);
14597 if (err)
14598 goto err_out;
14599
Johannes Berg55682962007-09-20 13:09:35 -040014600 return 0;
14601 err_out:
14602 genl_unregister_family(&nl80211_fam);
14603 return err;
14604}
14605
14606void nl80211_exit(void)
14607{
Jouni Malinen026331c2010-02-15 12:53:10 +020014608 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014609 genl_unregister_family(&nl80211_fam);
14610}