blob: ff798620e929378f6f84025de315d0f52e2201df [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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-06-15 14:09:58 +0200178 else
179 tmp = NULL;
180
Johannes Berg7fee47782012-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 Malinen36aedc92008-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 Malinendc6382ce2009-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 Malinen11b6b5a2016-10-27 00:41:58 +0300360 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000361 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700362 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100363 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
364 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
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 },
Johannes Berg55682962007-09-20 13:09:35 -0400417};
418
Johannes Berge31b8212010-10-05 19:39:30 +0200419/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000420static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200421 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422 [NL80211_KEY_IDX] = { .type = NLA_U8 },
423 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200424 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200425 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
426 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200427 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100428 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
429};
430
431/* policy for the key default flags */
432static const struct nla_policy
433nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
434 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
435 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200436};
437
Johannes Bergf83ace32016-10-17 08:04:07 +0200438#ifdef CONFIG_PM
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};
Johannes Bergf83ace32016-10-17 08:04:07 +0200472#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200473
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700474/* policy for coalesce rule attributes */
475static const struct nla_policy
476nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
477 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
478 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
479 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
480};
481
Johannes Berge5497d72011-07-05 16:35:40 +0200482/* policy for GTK rekey offload attributes */
483static const struct nla_policy
484nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
485 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
486 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
487 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
488};
489
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300490static const struct nla_policy
491nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200492 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300493 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700494 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300495};
496
Avraham Stern3b06d272015-10-12 09:51:34 +0300497static const struct nla_policy
498nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
499 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
500 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
501};
502
Arend van Spriel38de03d2016-03-02 20:37:18 +0100503static const struct nla_policy
504nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
505 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
506 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
507 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
508 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
509 },
510};
511
Ayala Bekera442b762016-09-20 17:31:15 +0300512/* policy for NAN function attributes */
513static const struct nla_policy
514nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
515 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
516 [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY,
517 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
518 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
519 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
520 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
521 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
522 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
523 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
524 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
525 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
526 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
527 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
528 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
529 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
530 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
531 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
532 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
533};
534
535/* policy for Service Response Filter attributes */
536static const struct nla_policy
537nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
538 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
539 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
540 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
541 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
542 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
543};
544
Johannes Berg97990a02013-04-19 01:02:55 +0200545static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
546 struct netlink_callback *cb,
547 struct cfg80211_registered_device **rdev,
548 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100549{
Johannes Berg67748892010-10-04 21:14:06 +0200550 int err;
551
Johannes Berg67748892010-10-04 21:14:06 +0200552 rtnl_lock();
553
Johannes Berg97990a02013-04-19 01:02:55 +0200554 if (!cb->args[0]) {
555 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
556 nl80211_fam.attrbuf, nl80211_fam.maxattr,
557 nl80211_policy);
558 if (err)
559 goto out_unlock;
560
561 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
562 nl80211_fam.attrbuf);
563 if (IS_ERR(*wdev)) {
564 err = PTR_ERR(*wdev);
565 goto out_unlock;
566 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800567 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200568 /* 0 is the first index - add 1 to parse only once */
569 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200570 cb->args[1] = (*wdev)->identifier;
571 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200572 /* subtract the 1 again here */
573 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200574 struct wireless_dev *tmp;
575
576 if (!wiphy) {
577 err = -ENODEV;
578 goto out_unlock;
579 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800580 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200581 *wdev = NULL;
582
Johannes Berg53873f12016-05-03 16:52:04 +0300583 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200584 if (tmp->identifier == cb->args[1]) {
585 *wdev = tmp;
586 break;
587 }
588 }
Johannes Berg97990a02013-04-19 01:02:55 +0200589
590 if (!*wdev) {
591 err = -ENODEV;
592 goto out_unlock;
593 }
Johannes Berg67748892010-10-04 21:14:06 +0200594 }
595
Johannes Berg67748892010-10-04 21:14:06 +0200596 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200597 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200598 rtnl_unlock();
599 return err;
600}
601
Johannes Berg97990a02013-04-19 01:02:55 +0200602static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200603{
Johannes Berg67748892010-10-04 21:14:06 +0200604 rtnl_unlock();
605}
606
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100607/* IE validation */
608static bool is_valid_ie_attr(const struct nlattr *attr)
609{
610 const u8 *pos;
611 int len;
612
613 if (!attr)
614 return true;
615
616 pos = nla_data(attr);
617 len = nla_len(attr);
618
619 while (len) {
620 u8 elemlen;
621
622 if (len < 2)
623 return false;
624 len -= 2;
625
626 elemlen = pos[1];
627 if (elemlen > len)
628 return false;
629
630 len -= elemlen;
631 pos += 2 + elemlen;
632 }
633
634 return true;
635}
636
Johannes Berg55682962007-09-20 13:09:35 -0400637/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000638static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400639 int flags, u8 cmd)
640{
641 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000642 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400643}
644
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100646 struct ieee80211_channel *chan,
647 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400648{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200649 /* Some channels must be completely excluded from the
650 * list to protect old user-space tools from breaking
651 */
652 if (!large && chan->flags &
653 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
654 return 0;
655
David S. Miller9360ffd2012-03-29 04:41:26 -0400656 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
657 chan->center_freq))
658 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400659
David S. Miller9360ffd2012-03-29 04:41:26 -0400660 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
661 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
662 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200663 if (chan->flags & IEEE80211_CHAN_NO_IR) {
664 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
665 goto nla_put_failure;
666 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
667 goto nla_put_failure;
668 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100669 if (chan->flags & IEEE80211_CHAN_RADAR) {
670 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
671 goto nla_put_failure;
672 if (large) {
673 u32 time;
674
675 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
676
677 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
678 chan->dfs_state))
679 goto nla_put_failure;
680 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
681 time))
682 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100683 if (nla_put_u32(msg,
684 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
685 chan->dfs_cac_ms))
686 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100687 }
688 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400689
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100690 if (large) {
691 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
692 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
693 goto nla_put_failure;
694 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
695 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
696 goto nla_put_failure;
697 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
698 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
699 goto nla_put_failure;
700 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
701 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
702 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200703 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
704 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
705 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300706 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
707 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200708 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200709 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
710 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
711 goto nla_put_failure;
712 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
713 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
714 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100715 }
716
David S. Miller9360ffd2012-03-29 04:41:26 -0400717 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
718 DBM_TO_MBM(chan->max_power)))
719 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400720
721 return 0;
722
723 nla_put_failure:
724 return -ENOBUFS;
725}
726
Johannes Berg55682962007-09-20 13:09:35 -0400727/* netlink command implementations */
728
Johannes Bergb9454e82009-07-08 13:29:08 +0200729struct key_parse {
730 struct key_params p;
731 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200732 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200733 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100734 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200735};
736
737static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
738{
739 struct nlattr *tb[NL80211_KEY_MAX + 1];
740 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
741 nl80211_key_policy);
742 if (err)
743 return err;
744
745 k->def = !!tb[NL80211_KEY_DEFAULT];
746 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
747
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100748 if (k->def) {
749 k->def_uni = true;
750 k->def_multi = true;
751 }
752 if (k->defmgmt)
753 k->def_multi = true;
754
Johannes Bergb9454e82009-07-08 13:29:08 +0200755 if (tb[NL80211_KEY_IDX])
756 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
757
758 if (tb[NL80211_KEY_DATA]) {
759 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
760 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
761 }
762
763 if (tb[NL80211_KEY_SEQ]) {
764 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
765 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
766 }
767
768 if (tb[NL80211_KEY_CIPHER])
769 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
770
Johannes Berge31b8212010-10-05 19:39:30 +0200771 if (tb[NL80211_KEY_TYPE]) {
772 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
773 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
774 return -EINVAL;
775 }
776
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100777 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
778 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700779
Johannes Berg2da8f412012-01-20 13:52:37 +0100780 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
781 tb[NL80211_KEY_DEFAULT_TYPES],
782 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (err)
784 return err;
785
786 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
787 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
788 }
789
Johannes Bergb9454e82009-07-08 13:29:08 +0200790 return 0;
791}
792
793static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
794{
795 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
796 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
797 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
798 }
799
800 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
801 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
802 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
803 }
804
805 if (info->attrs[NL80211_ATTR_KEY_IDX])
806 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
807
808 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
809 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
810
811 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
812 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
813
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100814 if (k->def) {
815 k->def_uni = true;
816 k->def_multi = true;
817 }
818 if (k->defmgmt)
819 k->def_multi = true;
820
Johannes Berge31b8212010-10-05 19:39:30 +0200821 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
822 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
823 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
824 return -EINVAL;
825 }
826
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100827 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
828 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
829 int err = nla_parse_nested(
830 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
831 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
832 nl80211_key_default_policy);
833 if (err)
834 return err;
835
836 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
837 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
838 }
839
Johannes Bergb9454e82009-07-08 13:29:08 +0200840 return 0;
841}
842
843static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
844{
845 int err;
846
847 memset(k, 0, sizeof(*k));
848 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200849 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200850
851 if (info->attrs[NL80211_ATTR_KEY])
852 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
853 else
854 err = nl80211_parse_key_old(info, k);
855
856 if (err)
857 return err;
858
859 if (k->def && k->defmgmt)
860 return -EINVAL;
861
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100862 if (k->defmgmt) {
863 if (k->def_uni || !k->def_multi)
864 return -EINVAL;
865 }
866
Johannes Bergb9454e82009-07-08 13:29:08 +0200867 if (k->idx != -1) {
868 if (k->defmgmt) {
869 if (k->idx < 4 || k->idx > 5)
870 return -EINVAL;
871 } else if (k->def) {
872 if (k->idx < 0 || k->idx > 3)
873 return -EINVAL;
874 } else {
875 if (k->idx < 0 || k->idx > 5)
876 return -EINVAL;
877 }
878 }
879
880 return 0;
881}
882
Johannes Bergfffd0932009-07-08 14:22:54 +0200883static struct cfg80211_cached_keys *
884nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530885 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200886{
887 struct key_parse parse;
888 struct nlattr *key;
889 struct cfg80211_cached_keys *result;
890 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +0200891 bool have_key = false;
892
893 nla_for_each_nested(key, keys, rem) {
894 have_key = true;
895 break;
896 }
897
898 if (!have_key)
899 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200900
901 result = kzalloc(sizeof(*result), GFP_KERNEL);
902 if (!result)
903 return ERR_PTR(-ENOMEM);
904
905 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +0200906
907 nla_for_each_nested(key, keys, rem) {
908 memset(&parse, 0, sizeof(parse));
909 parse.idx = -1;
910
911 err = nl80211_parse_key_new(key, &parse);
912 if (err)
913 goto error;
914 err = -EINVAL;
915 if (!parse.p.key)
916 goto error;
Johannes Berg42ee2312016-09-13 15:51:03 +0200917 if (parse.idx < 0 || parse.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +0200918 goto error;
919 if (parse.def) {
920 if (def)
921 goto error;
922 def = 1;
923 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100924 if (!parse.def_uni || !parse.def_multi)
925 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200926 } else if (parse.defmgmt)
927 goto error;
928 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200929 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200930 if (err)
931 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +0200932 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
933 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
934 err = -EINVAL;
935 goto error;
936 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200937 result->params[parse.idx].cipher = parse.p.cipher;
938 result->params[parse.idx].key_len = parse.p.key_len;
939 result->params[parse.idx].key = result->data[parse.idx];
940 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530941
Johannes Berg386b1f22016-09-13 16:10:02 +0200942 /* must be WEP key if we got here */
943 if (no_ht)
944 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +0200945 }
946
Johannes Bergf1c1f172016-09-13 17:08:23 +0200947 if (result->def < 0) {
948 err = -EINVAL;
949 goto error;
950 }
951
Johannes Bergfffd0932009-07-08 14:22:54 +0200952 return result;
953 error:
954 kfree(result);
955 return ERR_PTR(err);
956}
957
958static int nl80211_key_allowed(struct wireless_dev *wdev)
959{
960 ASSERT_WDEV_LOCK(wdev);
961
Johannes Bergfffd0932009-07-08 14:22:54 +0200962 switch (wdev->iftype) {
963 case NL80211_IFTYPE_AP:
964 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200965 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700966 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200967 break;
968 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200969 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200970 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200971 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200972 return -ENOLINK;
973 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100974 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100975 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100976 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300977 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100978 case NL80211_IFTYPE_P2P_DEVICE:
979 case NL80211_IFTYPE_WDS:
980 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200981 return -EINVAL;
982 }
983
984 return 0;
985}
986
Jouni Malinen664834d2014-01-15 00:01:44 +0200987static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
988 struct nlattr *tb)
989{
990 struct ieee80211_channel *chan;
991
992 if (tb == NULL)
993 return NULL;
994 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
995 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
996 return NULL;
997 return chan;
998}
999
Johannes Berg7527a782011-05-13 10:58:57 +02001000static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1001{
1002 struct nlattr *nl_modes = nla_nest_start(msg, attr);
1003 int i;
1004
1005 if (!nl_modes)
1006 goto nla_put_failure;
1007
1008 i = 0;
1009 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001010 if ((ifmodes & 1) && nla_put_flag(msg, i))
1011 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001012 ifmodes >>= 1;
1013 i++;
1014 }
1015
1016 nla_nest_end(msg, nl_modes);
1017 return 0;
1018
1019nla_put_failure:
1020 return -ENOBUFS;
1021}
1022
1023static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001024 struct sk_buff *msg,
1025 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001026{
1027 struct nlattr *nl_combis;
1028 int i, j;
1029
1030 nl_combis = nla_nest_start(msg,
1031 NL80211_ATTR_INTERFACE_COMBINATIONS);
1032 if (!nl_combis)
1033 goto nla_put_failure;
1034
1035 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1036 const struct ieee80211_iface_combination *c;
1037 struct nlattr *nl_combi, *nl_limits;
1038
1039 c = &wiphy->iface_combinations[i];
1040
1041 nl_combi = nla_nest_start(msg, i + 1);
1042 if (!nl_combi)
1043 goto nla_put_failure;
1044
1045 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
1046 if (!nl_limits)
1047 goto nla_put_failure;
1048
1049 for (j = 0; j < c->n_limits; j++) {
1050 struct nlattr *nl_limit;
1051
1052 nl_limit = nla_nest_start(msg, j + 1);
1053 if (!nl_limit)
1054 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001055 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1056 c->limits[j].max))
1057 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001058 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1059 c->limits[j].types))
1060 goto nla_put_failure;
1061 nla_nest_end(msg, nl_limit);
1062 }
1063
1064 nla_nest_end(msg, nl_limits);
1065
David S. Miller9360ffd2012-03-29 04:41:26 -04001066 if (c->beacon_int_infra_match &&
1067 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1068 goto nla_put_failure;
1069 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1070 c->num_different_channels) ||
1071 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1072 c->max_interfaces))
1073 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001074 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001075 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1076 c->radar_detect_widths) ||
1077 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1078 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001079 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301080 if (c->beacon_int_min_gcd &&
1081 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1082 c->beacon_int_min_gcd))
1083 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001084
1085 nla_nest_end(msg, nl_combi);
1086 }
1087
1088 nla_nest_end(msg, nl_combis);
1089
1090 return 0;
1091nla_put_failure:
1092 return -ENOBUFS;
1093}
1094
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001096static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1097 struct sk_buff *msg)
1098{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001099 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001100 struct nlattr *nl_tcp;
1101
1102 if (!tcp)
1103 return 0;
1104
1105 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1106 if (!nl_tcp)
1107 return -ENOBUFS;
1108
1109 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1110 tcp->data_payload_max))
1111 return -ENOBUFS;
1112
1113 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1114 tcp->data_payload_max))
1115 return -ENOBUFS;
1116
1117 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1118 return -ENOBUFS;
1119
1120 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1121 sizeof(*tcp->tok), tcp->tok))
1122 return -ENOBUFS;
1123
1124 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1125 tcp->data_interval_max))
1126 return -ENOBUFS;
1127
1128 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1129 tcp->wake_payload_max))
1130 return -ENOBUFS;
1131
1132 nla_nest_end(msg, nl_tcp);
1133 return 0;
1134}
1135
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001137 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001138 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001139{
1140 struct nlattr *nl_wowlan;
1141
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001142 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 return 0;
1144
1145 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1146 if (!nl_wowlan)
1147 return -ENOBUFS;
1148
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001149 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001151 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001152 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001153 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001154 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001155 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001156 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001157 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001158 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001159 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001160 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001161 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001162 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001163 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001164 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1165 return -ENOBUFS;
1166
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001167 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001168 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001169 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1170 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1171 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1172 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 };
1174
1175 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1176 sizeof(pat), &pat))
1177 return -ENOBUFS;
1178 }
1179
Luciano Coelho75453cc2015-01-09 14:06:37 +02001180 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1181 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1182 rdev->wiphy.wowlan->max_nd_match_sets))
1183 return -ENOBUFS;
1184
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001185 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001186 return -ENOBUFS;
1187
Johannes Berg3713b4e2013-02-14 16:19:38 +01001188 nla_nest_end(msg, nl_wowlan);
1189
1190 return 0;
1191}
1192#endif
1193
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001194static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001195 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001196{
1197 struct nl80211_coalesce_rule_support rule;
1198
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001199 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001200 return 0;
1201
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001202 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1203 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1204 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1205 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1206 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1207 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001208
1209 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1210 return -ENOBUFS;
1211
1212 return 0;
1213}
1214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1216 struct ieee80211_supported_band *sband)
1217{
1218 struct nlattr *nl_rates, *nl_rate;
1219 struct ieee80211_rate *rate;
1220 int i;
1221
1222 /* add HT info */
1223 if (sband->ht_cap.ht_supported &&
1224 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1225 sizeof(sband->ht_cap.mcs),
1226 &sband->ht_cap.mcs) ||
1227 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1228 sband->ht_cap.cap) ||
1229 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1230 sband->ht_cap.ampdu_factor) ||
1231 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1232 sband->ht_cap.ampdu_density)))
1233 return -ENOBUFS;
1234
1235 /* add VHT info */
1236 if (sband->vht_cap.vht_supported &&
1237 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1238 sizeof(sband->vht_cap.vht_mcs),
1239 &sband->vht_cap.vht_mcs) ||
1240 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1241 sband->vht_cap.cap)))
1242 return -ENOBUFS;
1243
1244 /* add bitrates */
1245 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1246 if (!nl_rates)
1247 return -ENOBUFS;
1248
1249 for (i = 0; i < sband->n_bitrates; i++) {
1250 nl_rate = nla_nest_start(msg, i);
1251 if (!nl_rate)
1252 return -ENOBUFS;
1253
1254 rate = &sband->bitrates[i];
1255 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1256 rate->bitrate))
1257 return -ENOBUFS;
1258 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1259 nla_put_flag(msg,
1260 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1261 return -ENOBUFS;
1262
1263 nla_nest_end(msg, nl_rate);
1264 }
1265
1266 nla_nest_end(msg, nl_rates);
1267
1268 return 0;
1269}
1270
1271static int
1272nl80211_send_mgmt_stypes(struct sk_buff *msg,
1273 const struct ieee80211_txrx_stypes *mgmt_stypes)
1274{
1275 u16 stypes;
1276 struct nlattr *nl_ftypes, *nl_ifs;
1277 enum nl80211_iftype ift;
1278 int i;
1279
1280 if (!mgmt_stypes)
1281 return 0;
1282
1283 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1284 if (!nl_ifs)
1285 return -ENOBUFS;
1286
1287 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1288 nl_ftypes = nla_nest_start(msg, ift);
1289 if (!nl_ftypes)
1290 return -ENOBUFS;
1291 i = 0;
1292 stypes = mgmt_stypes[ift].tx;
1293 while (stypes) {
1294 if ((stypes & 1) &&
1295 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1296 (i << 4) | IEEE80211_FTYPE_MGMT))
1297 return -ENOBUFS;
1298 stypes >>= 1;
1299 i++;
1300 }
1301 nla_nest_end(msg, nl_ftypes);
1302 }
1303
1304 nla_nest_end(msg, nl_ifs);
1305
1306 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1307 if (!nl_ifs)
1308 return -ENOBUFS;
1309
1310 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1311 nl_ftypes = nla_nest_start(msg, ift);
1312 if (!nl_ftypes)
1313 return -ENOBUFS;
1314 i = 0;
1315 stypes = mgmt_stypes[ift].rx;
1316 while (stypes) {
1317 if ((stypes & 1) &&
1318 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1319 (i << 4) | IEEE80211_FTYPE_MGMT))
1320 return -ENOBUFS;
1321 stypes >>= 1;
1322 i++;
1323 }
1324 nla_nest_end(msg, nl_ftypes);
1325 }
1326 nla_nest_end(msg, nl_ifs);
1327
1328 return 0;
1329}
1330
Johannes Berg17948992016-10-26 11:42:04 +02001331#define CMD(op, n) \
1332 do { \
1333 if (rdev->ops->op) { \
1334 i++; \
1335 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1336 goto nla_put_failure; \
1337 } \
1338 } while (0)
1339
1340static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1341 struct sk_buff *msg)
1342{
1343 int i = 0;
1344
1345 /*
1346 * do *NOT* add anything into this function, new things need to be
1347 * advertised only to new versions of userspace that can deal with
1348 * the split (and they can't possibly care about new features...
1349 */
1350 CMD(add_virtual_intf, NEW_INTERFACE);
1351 CMD(change_virtual_intf, SET_INTERFACE);
1352 CMD(add_key, NEW_KEY);
1353 CMD(start_ap, START_AP);
1354 CMD(add_station, NEW_STATION);
1355 CMD(add_mpath, NEW_MPATH);
1356 CMD(update_mesh_config, SET_MESH_CONFIG);
1357 CMD(change_bss, SET_BSS);
1358 CMD(auth, AUTHENTICATE);
1359 CMD(assoc, ASSOCIATE);
1360 CMD(deauth, DEAUTHENTICATE);
1361 CMD(disassoc, DISASSOCIATE);
1362 CMD(join_ibss, JOIN_IBSS);
1363 CMD(join_mesh, JOIN_MESH);
1364 CMD(set_pmksa, SET_PMKSA);
1365 CMD(del_pmksa, DEL_PMKSA);
1366 CMD(flush_pmksa, FLUSH_PMKSA);
1367 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1368 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1369 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1370 CMD(mgmt_tx, FRAME);
1371 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1372 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1373 i++;
1374 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1375 goto nla_put_failure;
1376 }
1377 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1378 rdev->ops->join_mesh) {
1379 i++;
1380 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1381 goto nla_put_failure;
1382 }
1383 CMD(set_wds_peer, SET_WDS_PEER);
1384 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1385 CMD(tdls_mgmt, TDLS_MGMT);
1386 CMD(tdls_oper, TDLS_OPER);
1387 }
1388 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1389 CMD(sched_scan_start, START_SCHED_SCAN);
1390 CMD(probe_client, PROBE_CLIENT);
1391 CMD(set_noack_map, SET_NOACK_MAP);
1392 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1393 i++;
1394 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1395 goto nla_put_failure;
1396 }
1397 CMD(start_p2p_device, START_P2P_DEVICE);
1398 CMD(set_mcast_rate, SET_MCAST_RATE);
1399#ifdef CONFIG_NL80211_TESTMODE
1400 CMD(testmode_cmd, TESTMODE);
1401#endif
1402
1403 if (rdev->ops->connect || rdev->ops->auth) {
1404 i++;
1405 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1406 goto nla_put_failure;
1407 }
1408
1409 if (rdev->ops->disconnect || rdev->ops->deauth) {
1410 i++;
1411 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1412 goto nla_put_failure;
1413 }
1414
1415 return i;
1416 nla_put_failure:
1417 return -ENOBUFS;
1418}
1419
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420struct nl80211_dump_wiphy_state {
1421 s64 filter_wiphy;
1422 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301423 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001424 bool split;
1425};
1426
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001427static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001428 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001431{
1432 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001433 struct nlattr *nl_bands, *nl_band;
1434 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001435 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001436 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01001437 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001438 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001439 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001440 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001441 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001442
Johannes Berg3bb20552014-05-26 13:52:25 +02001443 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001444 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 return -ENOBUFS;
1446
Johannes Berg86e8cf92013-06-19 10:57:22 +02001447 if (WARN_ON(!state))
1448 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001449
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001453 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001455 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001456
Johannes Berg3bb20552014-05-26 13:52:25 +02001457 if (cmd != NL80211_CMD_NEW_WIPHY)
1458 goto finish;
1459
Johannes Berg86e8cf92013-06-19 10:57:22 +02001460 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 case 0:
1462 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001463 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001465 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001467 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001469 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001473 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001475 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001477 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001479 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001481 rdev->wiphy.max_match_sets) ||
1482 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1483 rdev->wiphy.max_sched_scan_plans) ||
1484 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1485 rdev->wiphy.max_sched_scan_plan_interval) ||
1486 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1487 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001488 goto nla_put_failure;
1489
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1492 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1495 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1498 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001499 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1501 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1504 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001505 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001507 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001508 state->split_start++;
1509 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 break;
1511 case 1:
1512 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1514 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001515 goto nla_put_failure;
1516
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001518 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001519 goto nla_put_failure;
1520
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001521 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1523 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001524
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001526 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001528 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001530
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001533 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001535
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001536 if ((rdev->wiphy.available_antennas_tx ||
1537 rdev->wiphy.available_antennas_rx) &&
1538 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 u32 tx_ant = 0, rx_ant = 0;
1540 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001541
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 if (!res) {
1544 if (nla_put_u32(msg,
1545 NL80211_ATTR_WIPHY_ANTENNA_TX,
1546 tx_ant) ||
1547 nla_put_u32(msg,
1548 NL80211_ATTR_WIPHY_ANTENNA_RX,
1549 rx_ant))
1550 goto nla_put_failure;
1551 }
Johannes Bergee688b002008-01-24 19:38:39 +01001552 }
1553
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557 case 2:
1558 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 state->split_start++;
1562 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 break;
1564 case 3:
1565 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1566 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001567 goto nla_put_failure;
1568
Johannes Berg86e8cf92013-06-19 10:57:22 +02001569 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001570 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 struct ieee80211_supported_band *sband;
1572
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001573 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574
1575 if (!sband)
1576 continue;
1577
1578 nl_band = nla_nest_start(msg, band);
1579 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001580 goto nla_put_failure;
1581
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 case 0:
1584 if (nl80211_send_band_rateinfo(msg, sband))
1585 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001586 state->chan_start++;
1587 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 break;
1589 default:
1590 /* add frequencies */
1591 nl_freqs = nla_nest_start(
1592 msg, NL80211_BAND_ATTR_FREQS);
1593 if (!nl_freqs)
1594 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001595
Johannes Berg86e8cf92013-06-19 10:57:22 +02001596 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 i < sband->n_channels;
1598 i++) {
1599 nl_freq = nla_nest_start(msg, i);
1600 if (!nl_freq)
1601 goto nla_put_failure;
1602
1603 chan = &sband->channels[i];
1604
Johannes Berg86e8cf92013-06-19 10:57:22 +02001605 if (nl80211_msg_put_channel(
1606 msg, chan,
1607 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 goto nla_put_failure;
1609
1610 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001611 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 break;
1613 }
1614 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001615 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 nla_nest_end(msg, nl_freqs);
1619 }
1620
1621 nla_nest_end(msg, nl_band);
1622
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 band--;
1627 break;
1628 }
Johannes Bergee688b002008-01-24 19:38:39 +01001629 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001631
Johannes Berg57fbcce2016-04-12 15:56:15 +02001632 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001633 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001636
Johannes Berg3713b4e2013-02-14 16:19:38 +01001637 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001638 if (state->band_start == 0 && state->chan_start == 0)
1639 state->split_start++;
1640 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001641 break;
1642 case 4:
1643 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1644 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001645 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646
Johannes Berg17948992016-10-26 11:42:04 +02001647 i = nl80211_add_commands_unsplit(rdev, msg);
1648 if (i < 0)
1649 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001650 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001651 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1652 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001654 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001655 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001656 if (rdev->wiphy.features &
1657 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001658 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001659 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001660#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001661
Johannes Berg3713b4e2013-02-14 16:19:38 +01001662 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001663 state->split_start++;
1664 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 break;
1666 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 if (rdev->ops->remain_on_channel &&
1668 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001669 nla_put_u32(msg,
1670 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001672 goto nla_put_failure;
1673
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001674 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001675 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1676 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001677
Johannes Berg3713b4e2013-02-14 16:19:38 +01001678 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1679 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001680 state->split_start++;
1681 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001682 break;
1683 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001684#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001685 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001687 state->split_start++;
1688 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689 break;
1690#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001691 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001692#endif
1693 case 7:
1694 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001695 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001696 goto nla_put_failure;
1697
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001698 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001700 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001701
Johannes Berg86e8cf92013-06-19 10:57:22 +02001702 state->split_start++;
1703 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 break;
1705 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001706 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001707 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001708 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 goto nla_put_failure;
1710
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001711 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001712 /*
1713 * We can only add the per-channel limit information if the
1714 * dump is split, otherwise it makes it too big. Therefore
1715 * only advertise it in that case.
1716 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001717 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001718 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1719 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 goto nla_put_failure;
1721
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001722 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001724 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1725 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001726 goto nla_put_failure;
1727
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001728 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1729 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001730 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001731 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001732 goto nla_put_failure;
1733
1734 /*
1735 * Any information below this point is only available to
1736 * applications that can deal with it being split. This
1737 * helps ensure that newly added capabilities don't break
1738 * older tools by overrunning their buffers.
1739 *
1740 * We still increment split_start so that in the split
1741 * case we'll continue with more data in the next round,
1742 * but break unconditionally so unsplit data stops here.
1743 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001745 break;
1746 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001747 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001748 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001749 rdev->wiphy.extended_capabilities_len,
1750 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001751 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001752 rdev->wiphy.extended_capabilities_len,
1753 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001754 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001755
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001756 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001757 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001758 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1759 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001760 goto nla_put_failure;
1761
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001762 state->split_start++;
1763 break;
1764 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001765 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001766 goto nla_put_failure;
1767
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001768 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001769 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1770 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1771 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001772
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001773 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001774 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001775 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001776 goto nla_put_failure;
1777
Johannes Bergad7e7182013-11-13 13:37:47 +01001778 state->split_start++;
1779 break;
1780 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001781 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001782 const struct nl80211_vendor_cmd_info *info;
1783 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001784
Johannes Berg567ffc32013-12-18 14:43:31 +01001785 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1786 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001787 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001788
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001789 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1790 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001791 if (nla_put(msg, i + 1, sizeof(*info), info))
1792 goto nla_put_failure;
1793 }
1794 nla_nest_end(msg, nested);
1795 }
1796
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001797 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001798 const struct nl80211_vendor_cmd_info *info;
1799 struct nlattr *nested;
1800
1801 nested = nla_nest_start(msg,
1802 NL80211_ATTR_VENDOR_EVENTS);
1803 if (!nested)
1804 goto nla_put_failure;
1805
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001806 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1807 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001808 if (nla_put(msg, i + 1, sizeof(*info), info))
1809 goto nla_put_failure;
1810 }
1811 nla_nest_end(msg, nested);
1812 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001813 state->split_start++;
1814 break;
1815 case 12:
1816 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1817 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1818 rdev->wiphy.max_num_csa_counters))
1819 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001820
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001821 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1822 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1823 goto nla_put_failure;
1824
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001825 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1826 sizeof(rdev->wiphy.ext_features),
1827 rdev->wiphy.ext_features))
1828 goto nla_put_failure;
1829
Arend van Spriel38de03d2016-03-02 20:37:18 +01001830 if (rdev->wiphy.bss_select_support) {
1831 struct nlattr *nested;
1832 u32 bss_select_support = rdev->wiphy.bss_select_support;
1833
1834 nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
1835 if (!nested)
1836 goto nla_put_failure;
1837
1838 i = 0;
1839 while (bss_select_support) {
1840 if ((bss_select_support & 1) &&
1841 nla_put_flag(msg, i))
1842 goto nla_put_failure;
1843 i++;
1844 bss_select_support >>= 1;
1845 }
1846 nla_nest_end(msg, nested);
1847 }
1848
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301849 state->split_start++;
1850 break;
1851 case 13:
1852 if (rdev->wiphy.num_iftype_ext_capab &&
1853 rdev->wiphy.iftype_ext_capab) {
1854 struct nlattr *nested_ext_capab, *nested;
1855
1856 nested = nla_nest_start(msg,
1857 NL80211_ATTR_IFTYPE_EXT_CAPA);
1858 if (!nested)
1859 goto nla_put_failure;
1860
1861 for (i = state->capa_start;
1862 i < rdev->wiphy.num_iftype_ext_capab; i++) {
1863 const struct wiphy_iftype_ext_capab *capab;
1864
1865 capab = &rdev->wiphy.iftype_ext_capab[i];
1866
1867 nested_ext_capab = nla_nest_start(msg, i);
1868 if (!nested_ext_capab ||
1869 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
1870 capab->iftype) ||
1871 nla_put(msg, NL80211_ATTR_EXT_CAPA,
1872 capab->extended_capabilities_len,
1873 capab->extended_capabilities) ||
1874 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1875 capab->extended_capabilities_len,
1876 capab->extended_capabilities_mask))
1877 goto nla_put_failure;
1878
1879 nla_nest_end(msg, nested_ext_capab);
1880 if (state->split)
1881 break;
1882 }
1883 nla_nest_end(msg, nested);
1884 if (i < rdev->wiphy.num_iftype_ext_capab) {
1885 state->capa_start = i + 1;
1886 break;
1887 }
1888 }
1889
Johannes Berg3713b4e2013-02-14 16:19:38 +01001890 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001891 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001892 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001893 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001894 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001895 genlmsg_end(msg, hdr);
1896 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001897
1898 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001899 genlmsg_cancel(msg, hdr);
1900 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001901}
1902
Johannes Berg86e8cf92013-06-19 10:57:22 +02001903static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1904 struct netlink_callback *cb,
1905 struct nl80211_dump_wiphy_state *state)
1906{
1907 struct nlattr **tb = nl80211_fam.attrbuf;
1908 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1909 tb, nl80211_fam.maxattr, nl80211_policy);
1910 /* ignore parse errors for backward compatibility */
1911 if (ret)
1912 return 0;
1913
1914 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1915 if (tb[NL80211_ATTR_WIPHY])
1916 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1917 if (tb[NL80211_ATTR_WDEV])
1918 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1919 if (tb[NL80211_ATTR_IFINDEX]) {
1920 struct net_device *netdev;
1921 struct cfg80211_registered_device *rdev;
1922 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1923
Ying Xue7f2b8562014-01-15 10:23:45 +08001924 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001925 if (!netdev)
1926 return -ENODEV;
1927 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001928 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001929 netdev->ieee80211_ptr->wiphy);
1930 state->filter_wiphy = rdev->wiphy_idx;
1931 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001932 }
1933
1934 return 0;
1935}
1936
Johannes Berg55682962007-09-20 13:09:35 -04001937static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1938{
Johannes Berg645e77d2013-03-01 14:03:49 +01001939 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001940 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001941 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001942
Johannes Berg5fe231e2013-05-08 21:45:15 +02001943 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001944 if (!state) {
1945 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001946 if (!state) {
1947 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001948 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001949 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001950 state->filter_wiphy = -1;
1951 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1952 if (ret) {
1953 kfree(state);
1954 rtnl_unlock();
1955 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001956 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001957 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001958 }
1959
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001960 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1961 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001962 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001963 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001964 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001965 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001966 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001967 continue;
1968 /* attempt to fit multiple wiphy data chunks into the skb */
1969 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001970 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1971 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001972 NETLINK_CB(cb->skb).portid,
1973 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001974 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001975 if (ret < 0) {
1976 /*
1977 * If sending the wiphy data didn't fit (ENOBUFS
1978 * or EMSGSIZE returned), this SKB is still
1979 * empty (so it's not too big because another
1980 * wiphy dataset is already in the skb) and
1981 * we've not tried to adjust the dump allocation
1982 * yet ... then adjust the alloc size to be
1983 * bigger, and return 1 but with the empty skb.
1984 * This results in an empty message being RX'ed
1985 * in userspace, but that is ignored.
1986 *
1987 * We can then retry with the larger buffer.
1988 */
1989 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001990 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001991 cb->min_dump_alloc < 4096) {
1992 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001993 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001994 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001995 return 1;
1996 }
1997 idx--;
1998 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001999 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002000 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002001 break;
Johannes Berg55682962007-09-20 13:09:35 -04002002 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002003 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002004
Johannes Berg86e8cf92013-06-19 10:57:22 +02002005 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002006
2007 return skb->len;
2008}
2009
Johannes Berg86e8cf92013-06-19 10:57:22 +02002010static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2011{
2012 kfree((void *)cb->args[0]);
2013 return 0;
2014}
2015
Johannes Berg55682962007-09-20 13:09:35 -04002016static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2017{
2018 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002020 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002021
Johannes Berg645e77d2013-03-01 14:03:49 +01002022 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002023 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002024 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002025
Johannes Berg3bb20552014-05-26 13:52:25 +02002026 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2027 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002028 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002029 nlmsg_free(msg);
2030 return -ENOBUFS;
2031 }
Johannes Berg55682962007-09-20 13:09:35 -04002032
Johannes Berg134e6372009-07-10 09:51:34 +00002033 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002034}
2035
Jouni Malinen31888482008-10-30 16:59:24 +02002036static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2037 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2038 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2039 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2040 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2041 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2042};
2043
2044static int parse_txq_params(struct nlattr *tb[],
2045 struct ieee80211_txq_params *txq_params)
2046{
Johannes Berga3304b02012-03-28 11:04:24 +02002047 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002048 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2049 !tb[NL80211_TXQ_ATTR_AIFS])
2050 return -EINVAL;
2051
Johannes Berga3304b02012-03-28 11:04:24 +02002052 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002053 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2054 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2055 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2056 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2057
Johannes Berga3304b02012-03-28 11:04:24 +02002058 if (txq_params->ac >= NL80211_NUM_ACS)
2059 return -EINVAL;
2060
Jouni Malinen31888482008-10-30 16:59:24 +02002061 return 0;
2062}
2063
Johannes Bergf444de02010-05-05 15:25:02 +02002064static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2065{
2066 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002067 * You can only set the channel explicitly for WDS interfaces,
2068 * all others have their channel managed via their respective
2069 * "establish a connection" command (connect, join, ...)
2070 *
2071 * For AP/GO and mesh mode, the channel can be set with the
2072 * channel userspace API, but is only stored and passed to the
2073 * low-level driver when the AP starts or the mesh is joined.
2074 * This is for backward compatibility, userspace can also give
2075 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002076 *
2077 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002078 * whatever else is going on, so they have their own special
2079 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002080 */
2081 return !wdev ||
2082 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002083 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002084 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2085 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002086}
2087
Johannes Berg683b6d32012-11-08 21:25:48 +01002088static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2089 struct genl_info *info,
2090 struct cfg80211_chan_def *chandef)
2091{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302092 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002093
2094 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
2095 return -EINVAL;
2096
2097 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
2098
2099 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002100 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2101 chandef->center_freq1 = control_freq;
2102 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002103
2104 /* Primary channel not allowed */
2105 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
2106 return -EINVAL;
2107
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002108 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
2109 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002110
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002111 chantype = nla_get_u32(
2112 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
2113
2114 switch (chantype) {
2115 case NL80211_CHAN_NO_HT:
2116 case NL80211_CHAN_HT20:
2117 case NL80211_CHAN_HT40PLUS:
2118 case NL80211_CHAN_HT40MINUS:
2119 cfg80211_chandef_create(chandef, chandef->chan,
2120 chantype);
2121 break;
2122 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01002123 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002124 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002125 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
2126 chandef->width =
2127 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2128 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
2129 chandef->center_freq1 =
2130 nla_get_u32(
2131 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
2132 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
2133 chandef->center_freq2 =
2134 nla_get_u32(
2135 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
2136 }
2137
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002138 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002139 return -EINVAL;
2140
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002141 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
2142 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002143 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002144
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002145 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2146 chandef->width == NL80211_CHAN_WIDTH_10) &&
2147 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
2148 return -EINVAL;
2149
Johannes Berg683b6d32012-11-08 21:25:48 +01002150 return 0;
2151}
2152
Johannes Bergf444de02010-05-05 15:25:02 +02002153static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002154 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002155 struct genl_info *info)
2156{
Johannes Berg683b6d32012-11-08 21:25:48 +01002157 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002158 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002159 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002160 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002161
Jouni Malinene16821b2014-04-28 11:22:08 +03002162 if (dev)
2163 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002164 if (!nl80211_can_set_dev_channel(wdev))
2165 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002166 if (wdev)
2167 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002168
Johannes Berg683b6d32012-11-08 21:25:48 +01002169 result = nl80211_parse_chandef(rdev, info, &chandef);
2170 if (result)
2171 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002172
Johannes Berge8c9bd52012-06-06 08:18:22 +02002173 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002174 case NL80211_IFTYPE_AP:
2175 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002176 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2177 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002178 result = -EINVAL;
2179 break;
2180 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002181 if (wdev->beacon_interval) {
2182 if (!dev || !rdev->ops->set_ap_chanwidth ||
2183 !(rdev->wiphy.features &
2184 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2185 result = -EBUSY;
2186 break;
2187 }
2188
2189 /* Only allow dynamic channel width changes */
2190 if (chandef.chan != wdev->preset_chandef.chan) {
2191 result = -EBUSY;
2192 break;
2193 }
2194 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2195 if (result)
2196 break;
2197 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002198 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002199 result = 0;
2200 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002201 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002202 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002203 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002204 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002205 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002206 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002207 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002208 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002209 }
Johannes Bergf444de02010-05-05 15:25:02 +02002210
2211 return result;
2212}
2213
2214static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2215{
Johannes Berg4c476992010-10-04 21:36:35 +02002216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2217 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002218
Jouni Malinene16821b2014-04-28 11:22:08 +03002219 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002220}
2221
Bill Jordane8347eb2010-10-01 13:54:28 -04002222static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2223{
Johannes Berg43b19952010-10-07 13:10:30 +02002224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2225 struct net_device *dev = info->user_ptr[1];
2226 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002227 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002228
2229 if (!info->attrs[NL80211_ATTR_MAC])
2230 return -EINVAL;
2231
Johannes Berg43b19952010-10-07 13:10:30 +02002232 if (netif_running(dev))
2233 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002234
Johannes Berg43b19952010-10-07 13:10:30 +02002235 if (!rdev->ops->set_wds_peer)
2236 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002237
Johannes Berg43b19952010-10-07 13:10:30 +02002238 if (wdev->iftype != NL80211_IFTYPE_WDS)
2239 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002240
2241 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002242 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002243}
2244
Johannes Berg55682962007-09-20 13:09:35 -04002245static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2246{
2247 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002248 struct net_device *netdev = NULL;
2249 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002250 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002251 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002252 u32 changed;
2253 u8 retry_short = 0, retry_long = 0;
2254 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002255 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002256
Johannes Berg5fe231e2013-05-08 21:45:15 +02002257 ASSERT_RTNL();
2258
Johannes Bergf444de02010-05-05 15:25:02 +02002259 /*
2260 * Try to find the wiphy and netdev. Normally this
2261 * function shouldn't need the netdev, but this is
2262 * done for backward compatibility -- previously
2263 * setting the channel was done per wiphy, but now
2264 * it is per netdev. Previous userland like hostapd
2265 * also passed a netdev to set_wiphy, so that it is
2266 * possible to let that go to the right netdev!
2267 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002268
Johannes Bergf444de02010-05-05 15:25:02 +02002269 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2270 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2271
Ying Xue7f2b8562014-01-15 10:23:45 +08002272 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002273 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002274 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002275 else
Johannes Bergf444de02010-05-05 15:25:02 +02002276 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002277 }
2278
Johannes Bergf444de02010-05-05 15:25:02 +02002279 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002280 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2281 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002282 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002283 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002284 wdev = NULL;
2285 netdev = NULL;
2286 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002287 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002288 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002289
2290 /*
2291 * end workaround code, by now the rdev is available
2292 * and locked, and wdev may or may not be NULL.
2293 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002294
2295 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002296 result = cfg80211_dev_rename(
2297 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002298
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002299 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002300 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002301
Jouni Malinen31888482008-10-30 16:59:24 +02002302 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2303 struct ieee80211_txq_params txq_params;
2304 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2305
Ying Xue7f2b8562014-01-15 10:23:45 +08002306 if (!rdev->ops->set_txq_params)
2307 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002308
Ying Xue7f2b8562014-01-15 10:23:45 +08002309 if (!netdev)
2310 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002311
Johannes Berg133a3ff2011-11-03 14:50:13 +01002312 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2314 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002315
Ying Xue7f2b8562014-01-15 10:23:45 +08002316 if (!netif_running(netdev))
2317 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002318
Jouni Malinen31888482008-10-30 16:59:24 +02002319 nla_for_each_nested(nl_txq_params,
2320 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2321 rem_txq_params) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02002322 result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX,
2323 nl_txq_params,
2324 txq_params_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01002325 if (result)
2326 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002327 result = parse_txq_params(tb, &txq_params);
2328 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002329 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002330
Hila Gonene35e4d22012-06-27 17:19:42 +03002331 result = rdev_set_txq_params(rdev, netdev,
2332 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002333 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002334 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002335 }
2336 }
2337
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002338 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002339 result = __nl80211_set_channel(
2340 rdev,
2341 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2342 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002343 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002344 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002345 }
2346
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002347 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002348 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002349 enum nl80211_tx_power_setting type;
2350 int idx, mbm = 0;
2351
Johannes Bergc8442112012-10-24 10:17:18 +02002352 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2353 txp_wdev = NULL;
2354
Ying Xue7f2b8562014-01-15 10:23:45 +08002355 if (!rdev->ops->set_tx_power)
2356 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002357
2358 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2359 type = nla_get_u32(info->attrs[idx]);
2360
2361 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002362 (type != NL80211_TX_POWER_AUTOMATIC))
2363 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002364
2365 if (type != NL80211_TX_POWER_AUTOMATIC) {
2366 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2367 mbm = nla_get_u32(info->attrs[idx]);
2368 }
2369
Johannes Bergc8442112012-10-24 10:17:18 +02002370 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002371 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002372 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002373 }
2374
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002375 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2376 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2377 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002378
Bruno Randolf7f531e02010-12-16 11:30:22 +09002379 if ((!rdev->wiphy.available_antennas_tx &&
2380 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002381 !rdev->ops->set_antenna)
2382 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002383
2384 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2385 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2386
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002387 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002388 * available antenna masks, except for the "all" mask */
2389 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002390 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2391 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002392
Bruno Randolf7f531e02010-12-16 11:30:22 +09002393 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2394 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002395
Hila Gonene35e4d22012-06-27 17:19:42 +03002396 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002397 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002398 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002399 }
2400
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002401 changed = 0;
2402
2403 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2404 retry_short = nla_get_u8(
2405 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002406 if (retry_short == 0)
2407 return -EINVAL;
2408
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002409 changed |= WIPHY_PARAM_RETRY_SHORT;
2410 }
2411
2412 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2413 retry_long = nla_get_u8(
2414 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002415 if (retry_long == 0)
2416 return -EINVAL;
2417
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002418 changed |= WIPHY_PARAM_RETRY_LONG;
2419 }
2420
2421 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2422 frag_threshold = nla_get_u32(
2423 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002424 if (frag_threshold < 256)
2425 return -EINVAL;
2426
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002427 if (frag_threshold != (u32) -1) {
2428 /*
2429 * Fragments (apart from the last one) are required to
2430 * have even length. Make the fragmentation code
2431 * simpler by stripping LSB should someone try to use
2432 * odd threshold value.
2433 */
2434 frag_threshold &= ~0x1;
2435 }
2436 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2437 }
2438
2439 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2440 rts_threshold = nla_get_u32(
2441 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2442 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2443 }
2444
Lukáš Turek81077e82009-12-21 22:50:47 +01002445 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002446 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2447 return -EINVAL;
2448
Lukáš Turek81077e82009-12-21 22:50:47 +01002449 coverage_class = nla_get_u8(
2450 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2451 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2452 }
2453
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002454 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2455 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2456 return -EOPNOTSUPP;
2457
2458 changed |= WIPHY_PARAM_DYN_ACK;
2459 }
2460
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002461 if (changed) {
2462 u8 old_retry_short, old_retry_long;
2463 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002464 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002465
Ying Xue7f2b8562014-01-15 10:23:45 +08002466 if (!rdev->ops->set_wiphy_params)
2467 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002468
2469 old_retry_short = rdev->wiphy.retry_short;
2470 old_retry_long = rdev->wiphy.retry_long;
2471 old_frag_threshold = rdev->wiphy.frag_threshold;
2472 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002473 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002474
2475 if (changed & WIPHY_PARAM_RETRY_SHORT)
2476 rdev->wiphy.retry_short = retry_short;
2477 if (changed & WIPHY_PARAM_RETRY_LONG)
2478 rdev->wiphy.retry_long = retry_long;
2479 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2480 rdev->wiphy.frag_threshold = frag_threshold;
2481 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2482 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002483 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2484 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002485
Hila Gonene35e4d22012-06-27 17:19:42 +03002486 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002487 if (result) {
2488 rdev->wiphy.retry_short = old_retry_short;
2489 rdev->wiphy.retry_long = old_retry_long;
2490 rdev->wiphy.frag_threshold = old_frag_threshold;
2491 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002492 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002493 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002494 }
2495 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002496 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002497}
2498
Johannes Berg71bbc992012-06-15 15:30:18 +02002499static inline u64 wdev_id(struct wireless_dev *wdev)
2500{
2501 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002502 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002503}
Johannes Berg55682962007-09-20 13:09:35 -04002504
Johannes Berg683b6d32012-11-08 21:25:48 +01002505static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002506 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002507{
Johannes Berg601555c2014-11-27 17:26:56 +01002508 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2509 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002510
Johannes Berg683b6d32012-11-08 21:25:48 +01002511 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2512 chandef->chan->center_freq))
2513 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002514 switch (chandef->width) {
2515 case NL80211_CHAN_WIDTH_20_NOHT:
2516 case NL80211_CHAN_WIDTH_20:
2517 case NL80211_CHAN_WIDTH_40:
2518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2519 cfg80211_get_chandef_type(chandef)))
2520 return -ENOBUFS;
2521 break;
2522 default:
2523 break;
2524 }
2525 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2526 return -ENOBUFS;
2527 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2528 return -ENOBUFS;
2529 if (chandef->center_freq2 &&
2530 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002531 return -ENOBUFS;
2532 return 0;
2533}
2534
Eric W. Biederman15e47302012-09-07 20:12:54 +00002535static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002536 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002537 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002538{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002539 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002540 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002541 void *hdr;
2542
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002543 if (removal)
2544 cmd = NL80211_CMD_DEL_INTERFACE;
2545
2546 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002547 if (!hdr)
2548 return -1;
2549
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002550 if (dev &&
2551 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002552 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002553 goto nla_put_failure;
2554
2555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2556 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02002557 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
2558 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002559 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002560 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2561 rdev->devlist_generation ^
2562 (cfg80211_rdev_list_generation << 2)))
2563 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002564
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002565 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002566 int ret;
2567 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002568
Johannes Berg683b6d32012-11-08 21:25:48 +01002569 ret = rdev_get_channel(rdev, wdev, &chandef);
2570 if (ret == 0) {
2571 if (nl80211_send_chandef(msg, &chandef))
2572 goto nla_put_failure;
2573 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002574 }
2575
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002576 if (rdev->ops->get_tx_power) {
2577 int dbm, ret;
2578
2579 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2580 if (ret == 0 &&
2581 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2582 DBM_TO_MBM(dbm)))
2583 goto nla_put_failure;
2584 }
2585
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002586 if (wdev->ssid_len) {
2587 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2588 goto nla_put_failure;
2589 }
2590
Johannes Berg053c0952015-01-16 22:09:00 +01002591 genlmsg_end(msg, hdr);
2592 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002593
2594 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002595 genlmsg_cancel(msg, hdr);
2596 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002597}
2598
2599static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2600{
2601 int wp_idx = 0;
2602 int if_idx = 0;
2603 int wp_start = cb->args[0];
2604 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002605 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002606 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002607 struct wireless_dev *wdev;
2608
Johannes Berg5fe231e2013-05-08 21:45:15 +02002609 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002610 if (!cb->args[2]) {
2611 struct nl80211_dump_wiphy_state state = {
2612 .filter_wiphy = -1,
2613 };
2614 int ret;
2615
2616 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
2617 if (ret)
2618 return ret;
2619
2620 filter_wiphy = state.filter_wiphy;
2621
2622 /*
2623 * if filtering, set cb->args[2] to +1 since 0 is the default
2624 * value needed to determine that parsing is necessary.
2625 */
2626 if (filter_wiphy >= 0)
2627 cb->args[2] = filter_wiphy + 1;
2628 else
2629 cb->args[2] = -1;
2630 } else if (cb->args[2] > 0) {
2631 filter_wiphy = cb->args[2] - 1;
2632 }
2633
Johannes Bergf5ea9122009-08-07 16:17:38 +02002634 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2635 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002636 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002637 if (wp_idx < wp_start) {
2638 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002639 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002640 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05002641
2642 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
2643 continue;
2644
Johannes Berg55682962007-09-20 13:09:35 -04002645 if_idx = 0;
2646
Johannes Berg53873f12016-05-03 16:52:04 +03002647 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002648 if (if_idx < if_start) {
2649 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002650 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002651 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002652 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002653 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002654 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002655 goto out;
2656 }
2657 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002658 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002659
2660 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002661 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002662 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002663 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002664
2665 cb->args[0] = wp_idx;
2666 cb->args[1] = if_idx;
2667
2668 return skb->len;
2669}
2670
2671static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2672{
2673 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002675 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002676
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002678 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002679 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002680
Eric W. Biederman15e47302012-09-07 20:12:54 +00002681 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002682 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002683 nlmsg_free(msg);
2684 return -ENOBUFS;
2685 }
Johannes Berg55682962007-09-20 13:09:35 -04002686
Johannes Berg134e6372009-07-10 09:51:34 +00002687 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002688}
2689
Michael Wu66f7ac52008-01-31 19:48:22 +01002690static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2691 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2692 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2693 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2694 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2695 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002696 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002697};
2698
2699static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2700{
2701 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2702 int flag;
2703
2704 *mntrflags = 0;
2705
2706 if (!nla)
2707 return -EINVAL;
2708
2709 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2710 nla, mntr_flags_policy))
2711 return -EINVAL;
2712
2713 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2714 if (flags[flag])
2715 *mntrflags |= (1<<flag);
2716
2717 return 0;
2718}
2719
Johannes Berg9bc383d2009-11-19 11:55:19 +01002720static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002721 struct net_device *netdev, u8 use_4addr,
2722 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002723{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002724 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002725 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002726 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002727 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002728 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002729
2730 switch (iftype) {
2731 case NL80211_IFTYPE_AP_VLAN:
2732 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2733 return 0;
2734 break;
2735 case NL80211_IFTYPE_STATION:
2736 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2737 return 0;
2738 break;
2739 default:
2740 break;
2741 }
2742
2743 return -EOPNOTSUPP;
2744}
2745
Johannes Berg55682962007-09-20 13:09:35 -04002746static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2747{
Johannes Berg4c476992010-10-04 21:36:35 +02002748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002749 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002750 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002751 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002752 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002753 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002754 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002755
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002756 memset(&params, 0, sizeof(params));
2757
Johannes Berg04a773a2009-04-19 21:24:32 +02002758 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002759
Johannes Berg723b0382008-09-16 20:22:09 +02002760 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002761 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002762 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002763 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002764 if (ntype > NL80211_IFTYPE_MAX)
2765 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002766 }
2767
Johannes Berg92ffe052008-09-16 20:39:36 +02002768 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002769 struct wireless_dev *wdev = dev->ieee80211_ptr;
2770
Johannes Berg4c476992010-10-04 21:36:35 +02002771 if (ntype != NL80211_IFTYPE_MESH_POINT)
2772 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002773 if (netif_running(dev))
2774 return -EBUSY;
2775
2776 wdev_lock(wdev);
2777 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2778 IEEE80211_MAX_MESH_ID_LEN);
2779 wdev->mesh_id_up_len =
2780 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2781 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2782 wdev->mesh_id_up_len);
2783 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002784 }
2785
Felix Fietkau8b787642009-11-10 18:53:10 +01002786 if (info->attrs[NL80211_ATTR_4ADDR]) {
2787 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2788 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002789 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002790 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002791 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002792 } else {
2793 params.use_4addr = -1;
2794 }
2795
Johannes Berg92ffe052008-09-16 20:39:36 +02002796 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002797 if (ntype != NL80211_IFTYPE_MONITOR)
2798 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002799 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2800 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002801 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002802 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002803
2804 flags = &_flags;
2805 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002806 }
Johannes Berg3b858752009-03-12 09:55:09 +01002807
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +03002808 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
2809 const u8 *mumimo_groups;
2810 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2811
2812 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2813 return -EOPNOTSUPP;
2814
2815 mumimo_groups =
2816 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
2817
2818 /* bits 0 and 63 are reserved and must be zero */
2819 if ((mumimo_groups[0] & BIT(7)) ||
2820 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
2821 return -EINVAL;
2822
2823 memcpy(params.vht_mumimo_groups, mumimo_groups,
2824 VHT_MUMIMO_GROUPS_DATA_LEN);
2825 change = true;
2826 }
2827
2828 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
2829 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
2830
2831 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
2832 return -EOPNOTSUPP;
2833
2834 nla_memcpy(params.macaddr,
2835 info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
2836 ETH_ALEN);
2837 change = true;
2838 }
2839
Luciano Coelho18003292013-08-29 13:26:57 +03002840 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002841 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2842 return -EOPNOTSUPP;
2843
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002844 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002845 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002846 else
2847 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002848
Johannes Berg9bc383d2009-11-19 11:55:19 +01002849 if (!err && params.use_4addr != -1)
2850 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2851
Johannes Berg55682962007-09-20 13:09:35 -04002852 return err;
2853}
2854
2855static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2856{
Johannes Berg4c476992010-10-04 21:36:35 +02002857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002858 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002859 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05002860 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002861 int err;
2862 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002863 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002864
Johannes Berg78f22b62014-03-24 17:57:27 +01002865 /* to avoid failing a new interface creation due to pending removal */
2866 cfg80211_destroy_ifaces(rdev);
2867
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002868 memset(&params, 0, sizeof(params));
2869
Johannes Berg55682962007-09-20 13:09:35 -04002870 if (!info->attrs[NL80211_ATTR_IFNAME])
2871 return -EINVAL;
2872
2873 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2874 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2875 if (type > NL80211_IFTYPE_MAX)
2876 return -EINVAL;
2877 }
2878
Johannes Berg79c97e92009-07-07 03:56:12 +02002879 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002880 !(rdev->wiphy.interface_modes & (1 << type)))
2881 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002882
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002883 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07002884 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2885 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002886 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2887 ETH_ALEN);
2888 if (!is_valid_ether_addr(params.macaddr))
2889 return -EADDRNOTAVAIL;
2890 }
2891
Johannes Berg9bc383d2009-11-19 11:55:19 +01002892 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002893 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002894 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002895 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002896 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002897 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002898
Michael Wu66f7ac52008-01-31 19:48:22 +01002899 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2900 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2901 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002902
Luciano Coelho18003292013-08-29 13:26:57 +03002903 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002904 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2905 return -EOPNOTSUPP;
2906
Johannes Berga18c7192015-02-24 10:56:42 +01002907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2908 if (!msg)
2909 return -ENOMEM;
2910
Hila Gonene35e4d22012-06-27 17:19:42 +03002911 wdev = rdev_add_virtual_intf(rdev,
2912 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002913 NET_NAME_USER, type, err ? NULL : &flags,
2914 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002915 if (WARN_ON(!wdev)) {
2916 nlmsg_free(msg);
2917 return -EPROTO;
2918 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002919 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002920 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002921 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002922
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002923 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002924 wdev->owner_nlportid = info->snd_portid;
2925
Johannes Berg98104fde2012-06-16 00:19:54 +02002926 switch (type) {
2927 case NL80211_IFTYPE_MESH_POINT:
2928 if (!info->attrs[NL80211_ATTR_MESH_ID])
2929 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002930 wdev_lock(wdev);
2931 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2932 IEEE80211_MAX_MESH_ID_LEN);
2933 wdev->mesh_id_up_len =
2934 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2935 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2936 wdev->mesh_id_up_len);
2937 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002938 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002939 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02002940 case NL80211_IFTYPE_P2P_DEVICE:
2941 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002942 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02002943 * through the netdev notifier and must be added here
2944 */
2945 mutex_init(&wdev->mtx);
2946 INIT_LIST_HEAD(&wdev->event_list);
2947 spin_lock_init(&wdev->event_lock);
2948 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2949 spin_lock_init(&wdev->mgmt_registrations_lock);
2950
Johannes Berg98104fde2012-06-16 00:19:54 +02002951 wdev->identifier = ++rdev->wdev_id;
Johannes Berg53873f12016-05-03 16:52:04 +03002952 list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
Johannes Berg98104fde2012-06-16 00:19:54 +02002953 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002954 break;
2955 default:
2956 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002957 }
2958
Eric W. Biederman15e47302012-09-07 20:12:54 +00002959 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002960 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002961 nlmsg_free(msg);
2962 return -ENOBUFS;
2963 }
2964
Denis Kenzior896ff062016-08-03 16:58:33 -05002965 /*
2966 * For wdevs which have no associated netdev object (e.g. of type
2967 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2968 * For all other types, the event will be generated from the
2969 * netdev notifier
2970 */
2971 if (!wdev->netdev)
2972 nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002973
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002974 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002975}
2976
2977static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2978{
Johannes Berg4c476992010-10-04 21:36:35 +02002979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002980 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002981
Johannes Berg4c476992010-10-04 21:36:35 +02002982 if (!rdev->ops->del_virtual_intf)
2983 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002984
Johannes Berg84efbb82012-06-16 00:00:26 +02002985 /*
2986 * If we remove a wireless device without a netdev then clear
2987 * user_ptr[1] so that nl80211_post_doit won't dereference it
2988 * to check if it needs to do dev_put(). Otherwise it crashes
2989 * since the wdev has been freed, unlike with a netdev where
2990 * we need the dev_put() for the netdev to really be freed.
2991 */
2992 if (!wdev->netdev)
2993 info->user_ptr[1] = NULL;
2994
Denis Kenzior7f8ed012016-08-03 16:58:35 -05002995 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002996}
2997
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002998static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2999{
3000 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3001 struct net_device *dev = info->user_ptr[1];
3002 u16 noack_map;
3003
3004 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3005 return -EINVAL;
3006
3007 if (!rdev->ops->set_noack_map)
3008 return -EOPNOTSUPP;
3009
3010 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3011
Hila Gonene35e4d22012-06-27 17:19:42 +03003012 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003013}
3014
Johannes Berg41ade002007-12-19 02:03:29 +01003015struct get_key_cookie {
3016 struct sk_buff *msg;
3017 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003018 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003019};
3020
3021static void get_key_callback(void *c, struct key_params *params)
3022{
Johannes Bergb9454e82009-07-08 13:29:08 +02003023 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003024 struct get_key_cookie *cookie = c;
3025
David S. Miller9360ffd2012-03-29 04:41:26 -04003026 if ((params->key &&
3027 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3028 params->key_len, params->key)) ||
3029 (params->seq &&
3030 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3031 params->seq_len, params->seq)) ||
3032 (params->cipher &&
3033 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3034 params->cipher)))
3035 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003036
Johannes Bergb9454e82009-07-08 13:29:08 +02003037 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
3038 if (!key)
3039 goto nla_put_failure;
3040
David S. Miller9360ffd2012-03-29 04:41:26 -04003041 if ((params->key &&
3042 nla_put(cookie->msg, NL80211_KEY_DATA,
3043 params->key_len, params->key)) ||
3044 (params->seq &&
3045 nla_put(cookie->msg, NL80211_KEY_SEQ,
3046 params->seq_len, params->seq)) ||
3047 (params->cipher &&
3048 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3049 params->cipher)))
3050 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003051
David S. Miller9360ffd2012-03-29 04:41:26 -04003052 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
3053 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003054
3055 nla_nest_end(cookie->msg, key);
3056
Johannes Berg41ade002007-12-19 02:03:29 +01003057 return;
3058 nla_put_failure:
3059 cookie->error = 1;
3060}
3061
3062static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3063{
Johannes Berg4c476992010-10-04 21:36:35 +02003064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003065 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003066 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003067 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003068 const u8 *mac_addr = NULL;
3069 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003070 struct get_key_cookie cookie = {
3071 .error = 0,
3072 };
3073 void *hdr;
3074 struct sk_buff *msg;
3075
3076 if (info->attrs[NL80211_ATTR_KEY_IDX])
3077 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
3078
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003079 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01003080 return -EINVAL;
3081
3082 if (info->attrs[NL80211_ATTR_MAC])
3083 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3084
Johannes Berge31b8212010-10-05 19:39:30 +02003085 pairwise = !!mac_addr;
3086 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3087 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003088
Johannes Berge31b8212010-10-05 19:39:30 +02003089 if (kt >= NUM_NL80211_KEYTYPES)
3090 return -EINVAL;
3091 if (kt != NL80211_KEYTYPE_GROUP &&
3092 kt != NL80211_KEYTYPE_PAIRWISE)
3093 return -EINVAL;
3094 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3095 }
3096
Johannes Berg4c476992010-10-04 21:36:35 +02003097 if (!rdev->ops->get_key)
3098 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003099
Johannes Berg0fa7b392015-01-23 11:10:12 +01003100 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3101 return -ENOENT;
3102
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003103 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003104 if (!msg)
3105 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003106
Eric W. Biederman15e47302012-09-07 20:12:54 +00003107 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003108 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003109 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003110 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003111
3112 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003113 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003114
David S. Miller9360ffd2012-03-29 04:41:26 -04003115 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3116 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3117 goto nla_put_failure;
3118 if (mac_addr &&
3119 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3120 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003121
Hila Gonene35e4d22012-06-27 17:19:42 +03003122 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3123 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003124
3125 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003126 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003127
3128 if (cookie.error)
3129 goto nla_put_failure;
3130
3131 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003132 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003133
3134 nla_put_failure:
3135 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003136 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003137 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003138 return err;
3139}
3140
3141static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3142{
Johannes Berg4c476992010-10-04 21:36:35 +02003143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003144 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003145 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003146 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003147
Johannes Bergb9454e82009-07-08 13:29:08 +02003148 err = nl80211_parse_key(info, &key);
3149 if (err)
3150 return err;
3151
3152 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003153 return -EINVAL;
3154
Johannes Bergb9454e82009-07-08 13:29:08 +02003155 /* only support setting default key */
3156 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01003157 return -EINVAL;
3158
Johannes Bergfffd0932009-07-08 14:22:54 +02003159 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003160
3161 if (key.def) {
3162 if (!rdev->ops->set_default_key) {
3163 err = -EOPNOTSUPP;
3164 goto out;
3165 }
3166
3167 err = nl80211_key_allowed(dev->ieee80211_ptr);
3168 if (err)
3169 goto out;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003172 key.def_uni, key.def_multi);
3173
3174 if (err)
3175 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003176
Johannes Berg3d23e342009-09-29 23:27:28 +02003177#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003178 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003179#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003180 } else {
3181 if (key.def_uni || !key.def_multi) {
3182 err = -EINVAL;
3183 goto out;
3184 }
3185
3186 if (!rdev->ops->set_default_mgmt_key) {
3187 err = -EOPNOTSUPP;
3188 goto out;
3189 }
3190
3191 err = nl80211_key_allowed(dev->ieee80211_ptr);
3192 if (err)
3193 goto out;
3194
Hila Gonene35e4d22012-06-27 17:19:42 +03003195 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003196 if (err)
3197 goto out;
3198
3199#ifdef CONFIG_CFG80211_WEXT
3200 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3201#endif
3202 }
3203
3204 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003205 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003206
Johannes Berg41ade002007-12-19 02:03:29 +01003207 return err;
3208}
3209
3210static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3211{
Johannes Berg4c476992010-10-04 21:36:35 +02003212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003213 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003214 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003215 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003216 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003217
Johannes Bergb9454e82009-07-08 13:29:08 +02003218 err = nl80211_parse_key(info, &key);
3219 if (err)
3220 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003221
Johannes Bergb9454e82009-07-08 13:29:08 +02003222 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003223 return -EINVAL;
3224
Johannes Berg41ade002007-12-19 02:03:29 +01003225 if (info->attrs[NL80211_ATTR_MAC])
3226 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3227
Johannes Berge31b8212010-10-05 19:39:30 +02003228 if (key.type == -1) {
3229 if (mac_addr)
3230 key.type = NL80211_KEYTYPE_PAIRWISE;
3231 else
3232 key.type = NL80211_KEYTYPE_GROUP;
3233 }
3234
3235 /* for now */
3236 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3237 key.type != NL80211_KEYTYPE_GROUP)
3238 return -EINVAL;
3239
Johannes Berg4c476992010-10-04 21:36:35 +02003240 if (!rdev->ops->add_key)
3241 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003242
Johannes Berge31b8212010-10-05 19:39:30 +02003243 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3244 key.type == NL80211_KEYTYPE_PAIRWISE,
3245 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003246 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003247
3248 wdev_lock(dev->ieee80211_ptr);
3249 err = nl80211_key_allowed(dev->ieee80211_ptr);
3250 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003251 err = rdev_add_key(rdev, dev, key.idx,
3252 key.type == NL80211_KEYTYPE_PAIRWISE,
3253 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003254 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003255
Johannes Berg41ade002007-12-19 02:03:29 +01003256 return err;
3257}
3258
3259static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3260{
Johannes Berg4c476992010-10-04 21:36:35 +02003261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003262 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003263 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003264 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003265 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003266
Johannes Bergb9454e82009-07-08 13:29:08 +02003267 err = nl80211_parse_key(info, &key);
3268 if (err)
3269 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003270
3271 if (info->attrs[NL80211_ATTR_MAC])
3272 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3273
Johannes Berge31b8212010-10-05 19:39:30 +02003274 if (key.type == -1) {
3275 if (mac_addr)
3276 key.type = NL80211_KEYTYPE_PAIRWISE;
3277 else
3278 key.type = NL80211_KEYTYPE_GROUP;
3279 }
3280
3281 /* for now */
3282 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3283 key.type != NL80211_KEYTYPE_GROUP)
3284 return -EINVAL;
3285
Johannes Berg4c476992010-10-04 21:36:35 +02003286 if (!rdev->ops->del_key)
3287 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003288
Johannes Bergfffd0932009-07-08 14:22:54 +02003289 wdev_lock(dev->ieee80211_ptr);
3290 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003291
Johannes Berg0fa7b392015-01-23 11:10:12 +01003292 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003293 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3294 err = -ENOENT;
3295
Johannes Bergfffd0932009-07-08 14:22:54 +02003296 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003297 err = rdev_del_key(rdev, dev, key.idx,
3298 key.type == NL80211_KEYTYPE_PAIRWISE,
3299 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003300
Johannes Berg3d23e342009-09-29 23:27:28 +02003301#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003302 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003303 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003304 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003305 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003306 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3307 }
3308#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003309 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003310
Johannes Berg41ade002007-12-19 02:03:29 +01003311 return err;
3312}
3313
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303314/* This function returns an error or the number of nested attributes */
3315static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3316{
3317 struct nlattr *attr;
3318 int n_entries = 0, tmp;
3319
3320 nla_for_each_nested(attr, nl_attr, tmp) {
3321 if (nla_len(attr) != ETH_ALEN)
3322 return -EINVAL;
3323
3324 n_entries++;
3325 }
3326
3327 return n_entries;
3328}
3329
3330/*
3331 * This function parses ACL information and allocates memory for ACL data.
3332 * On successful return, the calling function is responsible to free the
3333 * ACL buffer returned by this function.
3334 */
3335static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3336 struct genl_info *info)
3337{
3338 enum nl80211_acl_policy acl_policy;
3339 struct nlattr *attr;
3340 struct cfg80211_acl_data *acl;
3341 int i = 0, n_entries, tmp;
3342
3343 if (!wiphy->max_acl_mac_addrs)
3344 return ERR_PTR(-EOPNOTSUPP);
3345
3346 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3347 return ERR_PTR(-EINVAL);
3348
3349 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3350 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3351 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3352 return ERR_PTR(-EINVAL);
3353
3354 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3355 return ERR_PTR(-EINVAL);
3356
3357 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3358 if (n_entries < 0)
3359 return ERR_PTR(n_entries);
3360
3361 if (n_entries > wiphy->max_acl_mac_addrs)
3362 return ERR_PTR(-ENOTSUPP);
3363
3364 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3365 GFP_KERNEL);
3366 if (!acl)
3367 return ERR_PTR(-ENOMEM);
3368
3369 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3370 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3371 i++;
3372 }
3373
3374 acl->n_acl_entries = n_entries;
3375 acl->acl_policy = acl_policy;
3376
3377 return acl;
3378}
3379
3380static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3381{
3382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3383 struct net_device *dev = info->user_ptr[1];
3384 struct cfg80211_acl_data *acl;
3385 int err;
3386
3387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3388 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3389 return -EOPNOTSUPP;
3390
3391 if (!dev->ieee80211_ptr->beacon_interval)
3392 return -EINVAL;
3393
3394 acl = parse_acl_data(&rdev->wiphy, info);
3395 if (IS_ERR(acl))
3396 return PTR_ERR(acl);
3397
3398 err = rdev_set_mac_acl(rdev, dev, acl);
3399
3400 kfree(acl);
3401
3402 return err;
3403}
3404
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303405static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
3406 u8 *rates, u8 rates_len)
3407{
3408 u8 i;
3409 u32 mask = 0;
3410
3411 for (i = 0; i < rates_len; i++) {
3412 int rate = (rates[i] & 0x7f) * 5;
3413 int ridx;
3414
3415 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
3416 struct ieee80211_rate *srate =
3417 &sband->bitrates[ridx];
3418 if (rate == srate->bitrate) {
3419 mask |= 1 << ridx;
3420 break;
3421 }
3422 }
3423 if (ridx == sband->n_bitrates)
3424 return 0; /* rate not found */
3425 }
3426
3427 return mask;
3428}
3429
3430static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
3431 u8 *rates, u8 rates_len,
3432 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
3433{
3434 u8 i;
3435
3436 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
3437
3438 for (i = 0; i < rates_len; i++) {
3439 int ridx, rbit;
3440
3441 ridx = rates[i] / 8;
3442 rbit = BIT(rates[i] % 8);
3443
3444 /* check validity */
3445 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
3446 return false;
3447
3448 /* check availability */
3449 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
3450 mcs[ridx] |= rbit;
3451 else
3452 return false;
3453 }
3454
3455 return true;
3456}
3457
3458static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
3459{
3460 u16 mcs_mask = 0;
3461
3462 switch (vht_mcs_map) {
3463 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
3464 break;
3465 case IEEE80211_VHT_MCS_SUPPORT_0_7:
3466 mcs_mask = 0x00FF;
3467 break;
3468 case IEEE80211_VHT_MCS_SUPPORT_0_8:
3469 mcs_mask = 0x01FF;
3470 break;
3471 case IEEE80211_VHT_MCS_SUPPORT_0_9:
3472 mcs_mask = 0x03FF;
3473 break;
3474 default:
3475 break;
3476 }
3477
3478 return mcs_mask;
3479}
3480
3481static void vht_build_mcs_mask(u16 vht_mcs_map,
3482 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
3483{
3484 u8 nss;
3485
3486 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
3487 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
3488 vht_mcs_map >>= 2;
3489 }
3490}
3491
3492static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
3493 struct nl80211_txrate_vht *txrate,
3494 u16 mcs[NL80211_VHT_NSS_MAX])
3495{
3496 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3497 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
3498 u8 i;
3499
3500 if (!sband->vht_cap.vht_supported)
3501 return false;
3502
3503 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
3504
3505 /* Build vht_mcs_mask from VHT capabilities */
3506 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
3507
3508 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3509 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
3510 mcs[i] = txrate->mcs[i];
3511 else
3512 return false;
3513 }
3514
3515 return true;
3516}
3517
3518static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
3519 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
3520 .len = NL80211_MAX_SUPP_RATES },
3521 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
3522 .len = NL80211_MAX_SUPP_HT_RATES },
3523 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
3524 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
3525};
3526
3527static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
3528 struct cfg80211_bitrate_mask *mask)
3529{
3530 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
3531 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3532 int rem, i;
3533 struct nlattr *tx_rates;
3534 struct ieee80211_supported_band *sband;
3535 u16 vht_tx_mcs_map;
3536
3537 memset(mask, 0, sizeof(*mask));
3538 /* Default to all rates enabled */
3539 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3540 sband = rdev->wiphy.bands[i];
3541
3542 if (!sband)
3543 continue;
3544
3545 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
3546 memcpy(mask->control[i].ht_mcs,
3547 sband->ht_cap.mcs.rx_mask,
3548 sizeof(mask->control[i].ht_mcs));
3549
3550 if (!sband->vht_cap.vht_supported)
3551 continue;
3552
3553 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
3554 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
3555 }
3556
3557 /* if no rates are given set it back to the defaults */
3558 if (!info->attrs[NL80211_ATTR_TX_RATES])
3559 goto out;
3560
3561 /* The nested attribute uses enum nl80211_band as the index. This maps
3562 * directly to the enum nl80211_band values used in cfg80211.
3563 */
3564 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
3565 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
3566 enum nl80211_band band = nla_type(tx_rates);
3567 int err;
3568
3569 if (band < 0 || band >= NUM_NL80211_BANDS)
3570 return -EINVAL;
3571 sband = rdev->wiphy.bands[band];
3572 if (sband == NULL)
3573 return -EINVAL;
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02003574 err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates,
3575 nl80211_txattr_policy);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303576 if (err)
3577 return err;
3578 if (tb[NL80211_TXRATE_LEGACY]) {
3579 mask->control[band].legacy = rateset_to_mask(
3580 sband,
3581 nla_data(tb[NL80211_TXRATE_LEGACY]),
3582 nla_len(tb[NL80211_TXRATE_LEGACY]));
3583 if ((mask->control[band].legacy == 0) &&
3584 nla_len(tb[NL80211_TXRATE_LEGACY]))
3585 return -EINVAL;
3586 }
3587 if (tb[NL80211_TXRATE_HT]) {
3588 if (!ht_rateset_to_mask(
3589 sband,
3590 nla_data(tb[NL80211_TXRATE_HT]),
3591 nla_len(tb[NL80211_TXRATE_HT]),
3592 mask->control[band].ht_mcs))
3593 return -EINVAL;
3594 }
3595 if (tb[NL80211_TXRATE_VHT]) {
3596 if (!vht_set_mcs_mask(
3597 sband,
3598 nla_data(tb[NL80211_TXRATE_VHT]),
3599 mask->control[band].vht_mcs))
3600 return -EINVAL;
3601 }
3602 if (tb[NL80211_TXRATE_GI]) {
3603 mask->control[band].gi =
3604 nla_get_u8(tb[NL80211_TXRATE_GI]);
3605 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
3606 return -EINVAL;
3607 }
3608
3609 if (mask->control[band].legacy == 0) {
3610 /* don't allow empty legacy rates if HT or VHT
3611 * are not even supported.
3612 */
3613 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
3614 rdev->wiphy.bands[band]->vht_cap.vht_supported))
3615 return -EINVAL;
3616
3617 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3618 if (mask->control[band].ht_mcs[i])
3619 goto out;
3620
3621 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3622 if (mask->control[band].vht_mcs[i])
3623 goto out;
3624
3625 /* legacy and mcs rates may not be both empty */
3626 return -EINVAL;
3627 }
3628 }
3629
3630out:
3631 return 0;
3632}
3633
Johannes Berg8564e382016-09-19 09:44:44 +02003634static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
3635 enum nl80211_band band,
3636 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303637{
Johannes Berg8564e382016-09-19 09:44:44 +02003638 u32 count_ht, count_vht, i;
3639 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303640
3641 /* Allow only one rate */
3642 if (hweight32(rate) > 1)
3643 return -EINVAL;
3644
3645 count_ht = 0;
3646 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003647 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303648 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003649 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303650 count_ht++;
3651 if (count_ht > 1)
3652 return -EINVAL;
3653 }
3654 if (count_ht && rate)
3655 return -EINVAL;
3656 }
3657
3658 count_vht = 0;
3659 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02003660 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303661 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02003662 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303663 count_vht++;
3664 if (count_vht > 1)
3665 return -EINVAL;
3666 }
3667 if (count_vht && rate)
3668 return -EINVAL;
3669 }
3670
3671 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
3672 return -EINVAL;
3673
Johannes Berg8564e382016-09-19 09:44:44 +02003674 if (rate &&
3675 !wiphy_ext_feature_isset(&rdev->wiphy,
3676 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
3677 return -EINVAL;
3678 if (count_ht &&
3679 !wiphy_ext_feature_isset(&rdev->wiphy,
3680 NL80211_EXT_FEATURE_BEACON_RATE_HT))
3681 return -EINVAL;
3682 if (count_vht &&
3683 !wiphy_ext_feature_isset(&rdev->wiphy,
3684 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
3685 return -EINVAL;
3686
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303687 return 0;
3688}
3689
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003690static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003691 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003692{
Johannes Berg88600202012-02-13 15:17:18 +01003693 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003694
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003695 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3696 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3697 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3698 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003699 return -EINVAL;
3700
Johannes Berg88600202012-02-13 15:17:18 +01003701 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003702
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003703 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3704 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3705 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003706 if (!bcn->head_len)
3707 return -EINVAL;
3708 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003709 }
3710
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003711 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3712 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3713 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003714 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003715 }
3716
Johannes Berg4c476992010-10-04 21:36:35 +02003717 if (!haveinfo)
3718 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003719
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003720 if (attrs[NL80211_ATTR_IE]) {
3721 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3722 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003723 }
3724
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003725 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003726 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003727 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003728 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003729 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003730 }
3731
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003732 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003733 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003734 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003735 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003736 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003737 }
3738
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003739 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3740 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3741 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003742 }
3743
Johannes Berg88600202012-02-13 15:17:18 +01003744 return 0;
3745}
3746
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003747static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3748 struct cfg80211_ap_settings *params)
3749{
3750 struct wireless_dev *wdev;
3751 bool ret = false;
3752
Johannes Berg53873f12016-05-03 16:52:04 +03003753 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003754 if (wdev->iftype != NL80211_IFTYPE_AP &&
3755 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3756 continue;
3757
Johannes Berg683b6d32012-11-08 21:25:48 +01003758 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003759 continue;
3760
Johannes Berg683b6d32012-11-08 21:25:48 +01003761 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003762 ret = true;
3763 break;
3764 }
3765
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003766 return ret;
3767}
3768
Jouni Malinene39e5b52012-09-30 19:29:39 +03003769static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3770 enum nl80211_auth_type auth_type,
3771 enum nl80211_commands cmd)
3772{
3773 if (auth_type > NL80211_AUTHTYPE_MAX)
3774 return false;
3775
3776 switch (cmd) {
3777 case NL80211_CMD_AUTHENTICATE:
3778 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3779 auth_type == NL80211_AUTHTYPE_SAE)
3780 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003781 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3782 NL80211_EXT_FEATURE_FILS_STA) &&
3783 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3784 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3785 auth_type == NL80211_AUTHTYPE_FILS_PK))
3786 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003787 return true;
3788 case NL80211_CMD_CONNECT:
3789 case NL80211_CMD_START_AP:
3790 /* SAE not supported yet */
3791 if (auth_type == NL80211_AUTHTYPE_SAE)
3792 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03003793 /* FILS not supported yet */
3794 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
3795 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
3796 auth_type == NL80211_AUTHTYPE_FILS_PK)
3797 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03003798 return true;
3799 default:
3800 return false;
3801 }
3802}
3803
Johannes Berg88600202012-02-13 15:17:18 +01003804static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3805{
3806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3807 struct net_device *dev = info->user_ptr[1];
3808 struct wireless_dev *wdev = dev->ieee80211_ptr;
3809 struct cfg80211_ap_settings params;
3810 int err;
3811
3812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3813 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3814 return -EOPNOTSUPP;
3815
3816 if (!rdev->ops->start_ap)
3817 return -EOPNOTSUPP;
3818
3819 if (wdev->beacon_interval)
3820 return -EALREADY;
3821
3822 memset(&params, 0, sizeof(params));
3823
3824 /* these are required for START_AP */
3825 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3826 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3827 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3828 return -EINVAL;
3829
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003830 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003831 if (err)
3832 return err;
3833
3834 params.beacon_interval =
3835 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3836 params.dtim_period =
3837 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3838
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05303839 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
3840 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01003841 if (err)
3842 return err;
3843
3844 /*
3845 * In theory, some of these attributes should be required here
3846 * but since they were not used when the command was originally
3847 * added, keep them optional for old user space programs to let
3848 * them continue to work with drivers that do not need the
3849 * additional information -- drivers must check!
3850 */
3851 if (info->attrs[NL80211_ATTR_SSID]) {
3852 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3853 params.ssid_len =
3854 nla_len(info->attrs[NL80211_ATTR_SSID]);
3855 if (params.ssid_len == 0 ||
3856 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3857 return -EINVAL;
3858 }
3859
3860 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3861 params.hidden_ssid = nla_get_u32(
3862 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3863 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3864 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3865 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3866 return -EINVAL;
3867 }
3868
3869 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3870
3871 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3872 params.auth_type = nla_get_u32(
3873 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003874 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3875 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003876 return -EINVAL;
3877 } else
3878 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3879
3880 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3881 NL80211_MAX_NR_CIPHER_SUITES);
3882 if (err)
3883 return err;
3884
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303885 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3886 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3887 return -EOPNOTSUPP;
3888 params.inactivity_timeout = nla_get_u16(
3889 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3890 }
3891
Johannes Berg53cabad2012-11-14 15:17:28 +01003892 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3894 return -EINVAL;
3895 params.p2p_ctwindow =
3896 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3897 if (params.p2p_ctwindow > 127)
3898 return -EINVAL;
3899 if (params.p2p_ctwindow != 0 &&
3900 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3901 return -EINVAL;
3902 }
3903
3904 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3905 u8 tmp;
3906
3907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3908 return -EINVAL;
3909 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3910 if (tmp > 1)
3911 return -EINVAL;
3912 params.p2p_opp_ps = tmp;
3913 if (params.p2p_opp_ps != 0 &&
3914 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3915 return -EINVAL;
3916 }
3917
Johannes Bergaa430da2012-05-16 23:50:18 +02003918 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003919 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3920 if (err)
3921 return err;
3922 } else if (wdev->preset_chandef.chan) {
3923 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003924 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003925 return -EINVAL;
3926
Arik Nemtsov923b3522015-07-08 15:41:44 +03003927 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3928 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003929 return -EINVAL;
3930
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303931 if (info->attrs[NL80211_ATTR_TX_RATES]) {
3932 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
3933 if (err)
3934 return err;
3935
Johannes Berg8564e382016-09-19 09:44:44 +02003936 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
3937 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05303938 if (err)
3939 return err;
3940 }
3941
Eliad Peller18998c32014-09-10 14:07:34 +03003942 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3943 params.smps_mode =
3944 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3945 switch (params.smps_mode) {
3946 case NL80211_SMPS_OFF:
3947 break;
3948 case NL80211_SMPS_STATIC:
3949 if (!(rdev->wiphy.features &
3950 NL80211_FEATURE_STATIC_SMPS))
3951 return -EINVAL;
3952 break;
3953 case NL80211_SMPS_DYNAMIC:
3954 if (!(rdev->wiphy.features &
3955 NL80211_FEATURE_DYNAMIC_SMPS))
3956 return -EINVAL;
3957 break;
3958 default:
3959 return -EINVAL;
3960 }
3961 } else {
3962 params.smps_mode = NL80211_SMPS_OFF;
3963 }
3964
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05303965 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3966 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
3967 return -EOPNOTSUPP;
3968
Ola Olsson4baf6be2015-10-29 07:04:58 +01003969 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3970 params.acl = parse_acl_data(&rdev->wiphy, info);
3971 if (IS_ERR(params.acl))
3972 return PTR_ERR(params.acl);
3973 }
3974
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003975 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003976 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003977 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003978 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003979 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003980 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003981 wdev->ssid_len = params.ssid_len;
3982 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003983 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003984 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303985
3986 kfree(params.acl);
3987
Johannes Berg56d18932011-05-09 18:41:15 +02003988 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003989}
3990
Johannes Berg88600202012-02-13 15:17:18 +01003991static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3992{
3993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3994 struct net_device *dev = info->user_ptr[1];
3995 struct wireless_dev *wdev = dev->ieee80211_ptr;
3996 struct cfg80211_beacon_data params;
3997 int err;
3998
3999 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4000 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4001 return -EOPNOTSUPP;
4002
4003 if (!rdev->ops->change_beacon)
4004 return -EOPNOTSUPP;
4005
4006 if (!wdev->beacon_interval)
4007 return -EINVAL;
4008
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004009 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01004010 if (err)
4011 return err;
4012
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004013 wdev_lock(wdev);
4014 err = rdev_change_beacon(rdev, dev, &params);
4015 wdev_unlock(wdev);
4016
4017 return err;
Johannes Berg88600202012-02-13 15:17:18 +01004018}
4019
4020static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004021{
Johannes Berg4c476992010-10-04 21:36:35 +02004022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4023 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01004024
Ilan Peer7c8d5e02014-02-25 15:33:38 +02004025 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01004026}
4027
Johannes Berg5727ef12007-12-19 02:03:34 +01004028static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
4029 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
4030 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
4031 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03004032 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07004033 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01004034 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01004035};
4036
Johannes Bergeccb8e82009-05-11 21:57:56 +03004037static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004038 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03004039 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01004040{
4041 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03004042 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01004043 int flag;
4044
Johannes Bergeccb8e82009-05-11 21:57:56 +03004045 /*
4046 * Try parsing the new attribute first so userspace
4047 * can specify both for older kernels.
4048 */
4049 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
4050 if (nla) {
4051 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01004052
Johannes Bergeccb8e82009-05-11 21:57:56 +03004053 sta_flags = nla_data(nla);
4054 params->sta_flags_mask = sta_flags->mask;
4055 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004056 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03004057 if ((params->sta_flags_mask |
4058 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
4059 return -EINVAL;
4060 return 0;
4061 }
4062
4063 /* if present, parse the old attribute */
4064
4065 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01004066 if (!nla)
4067 return 0;
4068
4069 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
4070 nla, sta_flags_policy))
4071 return -EINVAL;
4072
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004073 /*
4074 * Only allow certain flags for interface types so that
4075 * other attributes are silently ignored. Remember that
4076 * this is backward compatibility code with old userspace
4077 * and shouldn't be hit in other cases anyway.
4078 */
4079 switch (iftype) {
4080 case NL80211_IFTYPE_AP:
4081 case NL80211_IFTYPE_AP_VLAN:
4082 case NL80211_IFTYPE_P2P_GO:
4083 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4084 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4085 BIT(NL80211_STA_FLAG_WME) |
4086 BIT(NL80211_STA_FLAG_MFP);
4087 break;
4088 case NL80211_IFTYPE_P2P_CLIENT:
4089 case NL80211_IFTYPE_STATION:
4090 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
4091 BIT(NL80211_STA_FLAG_TDLS_PEER);
4092 break;
4093 case NL80211_IFTYPE_MESH_POINT:
4094 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4095 BIT(NL80211_STA_FLAG_MFP) |
4096 BIT(NL80211_STA_FLAG_AUTHORIZED);
4097 default:
4098 return -EINVAL;
4099 }
Johannes Berg5727ef12007-12-19 02:03:34 +01004100
Johannes Berg3383b5a2012-05-10 20:14:43 +02004101 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
4102 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03004103 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01004104
Johannes Berg3383b5a2012-05-10 20:14:43 +02004105 /* no longer support new API additions in old API */
4106 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
4107 return -EINVAL;
4108 }
4109 }
4110
Johannes Berg5727ef12007-12-19 02:03:34 +01004111 return 0;
4112}
4113
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004114static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
4115 int attr)
4116{
4117 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004118 u32 bitrate;
4119 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01004120 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004121
4122 rate = nla_nest_start(msg, attr);
4123 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004124 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004125
4126 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4127 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03004128 /* report 16-bit bitrate only if we can */
4129 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004130 if (bitrate > 0 &&
4131 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
4132 return false;
4133 if (bitrate_compat > 0 &&
4134 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
4135 return false;
4136
Johannes Bergb51f3be2015-01-15 16:14:02 +01004137 switch (info->bw) {
4138 case RATE_INFO_BW_5:
4139 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
4140 break;
4141 case RATE_INFO_BW_10:
4142 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
4143 break;
4144 default:
4145 WARN_ON(1);
4146 /* fall through */
4147 case RATE_INFO_BW_20:
4148 rate_flg = 0;
4149 break;
4150 case RATE_INFO_BW_40:
4151 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
4152 break;
4153 case RATE_INFO_BW_80:
4154 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
4155 break;
4156 case RATE_INFO_BW_160:
4157 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
4158 break;
4159 }
4160
4161 if (rate_flg && nla_put_flag(msg, rate_flg))
4162 return false;
4163
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004164 if (info->flags & RATE_INFO_FLAGS_MCS) {
4165 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
4166 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004167 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4168 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4169 return false;
4170 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
4171 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
4172 return false;
4173 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
4174 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01004175 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
4176 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
4177 return false;
4178 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004179
4180 nla_nest_end(msg, rate);
4181 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004182}
4183
Felix Fietkau119363c2013-04-22 16:29:30 +02004184static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4185 int id)
4186{
4187 void *attr;
4188 int i = 0;
4189
4190 if (!mask)
4191 return true;
4192
4193 attr = nla_nest_start(msg, id);
4194 if (!attr)
4195 return false;
4196
4197 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4198 if (!(mask & BIT(i)))
4199 continue;
4200
4201 if (nla_put_u8(msg, i, signal[i]))
4202 return false;
4203 }
4204
4205 nla_nest_end(msg, attr);
4206
4207 return true;
4208}
4209
Johannes Bergcf5ead82014-11-14 17:14:00 +01004210static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
4211 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04004212 struct cfg80211_registered_device *rdev,
4213 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01004214 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004215{
4216 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07004217 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004218
Johannes Bergcf5ead82014-11-14 17:14:00 +01004219 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004220 if (!hdr)
4221 return -1;
4222
David S. Miller9360ffd2012-03-29 04:41:26 -04004223 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4224 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
4225 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
4226 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004227
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004228 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
4229 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004230 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004231
4232#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02004233 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Mohammed Shafi Shajakhan739960f2016-04-07 19:59:34 +05304234 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01004235 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4236 sinfo->memb)) \
4237 goto nla_put_failure; \
4238 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02004239#define PUT_SINFO_U64(attr, memb) do { \
4240 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4241 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4242 sinfo->memb, NL80211_STA_INFO_PAD)) \
4243 goto nla_put_failure; \
4244 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01004245
4246 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
4247 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
4248
4249 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
4250 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004251 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004252 (u32)sinfo->rx_bytes))
4253 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004254
4255 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
4256 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02004257 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4258 (u32)sinfo->tx_bytes))
4259 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004260
Johannes Bergd686b922016-04-26 09:54:11 +02004261 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
4262 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01004263 PUT_SINFO(LLID, llid, u16);
4264 PUT_SINFO(PLID, plid, u16);
4265 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02004266 PUT_SINFO_U64(RX_DURATION, rx_duration);
Johannes Berg319090b2014-11-17 14:08:11 +01004267
John W. Linville66266b32012-03-15 13:25:41 -04004268 switch (rdev->wiphy.signal_type) {
4269 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01004270 PUT_SINFO(SIGNAL, signal, u8);
4271 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04004272 break;
4273 default:
4274 break;
4275 }
Johannes Berg319090b2014-11-17 14:08:11 +01004276 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004277 if (!nl80211_put_signal(msg, sinfo->chains,
4278 sinfo->chain_signal,
4279 NL80211_STA_INFO_CHAIN_SIGNAL))
4280 goto nla_put_failure;
4281 }
Johannes Berg319090b2014-11-17 14:08:11 +01004282 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02004283 if (!nl80211_put_signal(msg, sinfo->chains,
4284 sinfo->chain_signal_avg,
4285 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4286 goto nla_put_failure;
4287 }
Johannes Berg319090b2014-11-17 14:08:11 +01004288 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004289 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4290 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01004291 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004292 }
Johannes Berg319090b2014-11-17 14:08:11 +01004293 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01004294 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
4295 NL80211_STA_INFO_RX_BITRATE))
4296 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01004297 }
Johannes Berg319090b2014-11-17 14:08:11 +01004298
4299 PUT_SINFO(RX_PACKETS, rx_packets, u32);
4300 PUT_SINFO(TX_PACKETS, tx_packets, u32);
4301 PUT_SINFO(TX_RETRIES, tx_retries, u32);
4302 PUT_SINFO(TX_FAILED, tx_failed, u32);
4303 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
4304 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
4305 PUT_SINFO(LOCAL_PM, local_pm, u32);
4306 PUT_SINFO(PEER_PM, peer_pm, u32);
4307 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
4308
4309 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07004310 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
4311 if (!bss_param)
4312 goto nla_put_failure;
4313
David S. Miller9360ffd2012-03-29 04:41:26 -04004314 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
4315 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
4316 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
4317 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
4318 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
4319 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
4320 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
4321 sinfo->bss_param.dtim_period) ||
4322 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
4323 sinfo->bss_param.beacon_interval))
4324 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07004325
4326 nla_nest_end(msg, bss_param);
4327 }
Johannes Berg319090b2014-11-17 14:08:11 +01004328 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004329 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
4330 sizeof(struct nl80211_sta_flag_update),
4331 &sinfo->sta_flags))
4332 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01004333
Johannes Bergd686b922016-04-26 09:54:11 +02004334 PUT_SINFO_U64(T_OFFSET, t_offset);
4335 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
4336 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01004337 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01004338
4339#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02004340#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004341
4342 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
4343 struct nlattr *tidsattr;
4344 int tid;
4345
4346 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
4347 if (!tidsattr)
4348 goto nla_put_failure;
4349
4350 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
4351 struct cfg80211_tid_stats *tidstats;
4352 struct nlattr *tidattr;
4353
4354 tidstats = &sinfo->pertid[tid];
4355
4356 if (!tidstats->filled)
4357 continue;
4358
4359 tidattr = nla_nest_start(msg, tid + 1);
4360 if (!tidattr)
4361 goto nla_put_failure;
4362
Johannes Bergd686b922016-04-26 09:54:11 +02004363#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01004364 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02004365 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4366 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01004367 goto nla_put_failure; \
4368 } while (0)
4369
Johannes Bergd686b922016-04-26 09:54:11 +02004370 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
4371 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
4372 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
4373 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01004374
Johannes Bergd686b922016-04-26 09:54:11 +02004375#undef PUT_TIDVAL_U64
Johannes Berg6de39802014-12-19 12:34:00 +01004376 nla_nest_end(msg, tidattr);
4377 }
4378
4379 nla_nest_end(msg, tidsattr);
4380 }
4381
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004382 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004383
Johannes Berg319090b2014-11-17 14:08:11 +01004384 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04004385 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
4386 sinfo->assoc_req_ies))
4387 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03004388
Johannes Berg053c0952015-01-16 22:09:00 +01004389 genlmsg_end(msg, hdr);
4390 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004391
4392 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004393 genlmsg_cancel(msg, hdr);
4394 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004395}
4396
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004398 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004399{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004401 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004402 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004403 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004404 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004405 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004406
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004407 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004408 if (err)
4409 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004410
Johannes Berg97990a02013-04-19 01:02:55 +02004411 if (!wdev->netdev) {
4412 err = -EINVAL;
4413 goto out_err;
4414 }
4415
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004416 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004417 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004418 goto out_err;
4419 }
4420
Johannes Bergbba95fe2008-07-29 13:22:51 +02004421 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03004422 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004423 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03004424 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004425 if (err == -ENOENT)
4426 break;
4427 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004428 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004429
Johannes Bergcf5ead82014-11-14 17:14:00 +01004430 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00004431 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004432 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004433 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004434 &sinfo) < 0)
4435 goto out;
4436
4437 sta_idx++;
4438 }
4439
Johannes Bergbba95fe2008-07-29 13:22:51 +02004440 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004441 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004443 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004444 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004445
4446 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004448
Johannes Berg5727ef12007-12-19 02:03:34 +01004449static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
4450{
Johannes Berg4c476992010-10-04 21:36:35 +02004451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4452 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004453 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004454 struct sk_buff *msg;
4455 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02004456 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004457
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004458 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004459
4460 if (!info->attrs[NL80211_ATTR_MAC])
4461 return -EINVAL;
4462
4463 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4464
Johannes Berg4c476992010-10-04 21:36:35 +02004465 if (!rdev->ops->get_station)
4466 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004467
Hila Gonene35e4d22012-06-27 17:19:42 +03004468 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004469 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004470 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004471
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004473 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004474 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004475
Johannes Bergcf5ead82014-11-14 17:14:00 +01004476 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
4477 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04004478 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02004479 nlmsg_free(msg);
4480 return -ENOBUFS;
4481 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01004482
Johannes Berg4c476992010-10-04 21:36:35 +02004483 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01004484}
4485
Johannes Berg77ee7c82013-02-15 00:48:33 +01004486int cfg80211_check_station_change(struct wiphy *wiphy,
4487 struct station_parameters *params,
4488 enum cfg80211_station_type statype)
4489{
Ayala Bekere4208422015-10-23 11:20:06 +03004490 if (params->listen_interval != -1 &&
4491 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004492 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03004493
Ayala Beker17b94242016-03-17 15:41:38 +02004494 if (params->support_p2p_ps != -1 &&
4495 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
4496 return -EINVAL;
4497
Arik Nemtsovc72e1142014-07-17 17:14:29 +03004498 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03004499 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
4500 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004501 return -EINVAL;
4502
4503 /* When you run into this, adjust the code below for the new flag */
4504 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4505
4506 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08004507 case CFG80211_STA_MESH_PEER_KERNEL:
4508 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004509 /*
4510 * No ignoring the TDLS flag here -- the userspace mesh
4511 * code doesn't have the bug of including TDLS in the
4512 * mask everywhere.
4513 */
4514 if (params->sta_flags_mask &
4515 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4516 BIT(NL80211_STA_FLAG_MFP) |
4517 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4518 return -EINVAL;
4519 break;
4520 case CFG80211_STA_TDLS_PEER_SETUP:
4521 case CFG80211_STA_TDLS_PEER_ACTIVE:
4522 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4523 return -EINVAL;
4524 /* ignore since it can't change */
4525 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4526 break;
4527 default:
4528 /* disallow mesh-specific things */
4529 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4530 return -EINVAL;
4531 if (params->local_pm)
4532 return -EINVAL;
4533 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4534 return -EINVAL;
4535 }
4536
4537 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4538 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4539 /* TDLS can't be set, ... */
4540 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4541 return -EINVAL;
4542 /*
4543 * ... but don't bother the driver with it. This works around
4544 * a hostapd/wpa_supplicant issue -- it always includes the
4545 * TLDS_PEER flag in the mask even for AP mode.
4546 */
4547 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4548 }
4549
Ayala Beker47edb112015-09-21 15:49:53 +03004550 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4551 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004552 /* reject other things that can't change */
4553 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4554 return -EINVAL;
4555 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4556 return -EINVAL;
4557 if (params->supported_rates)
4558 return -EINVAL;
4559 if (params->ext_capab || params->ht_capa || params->vht_capa)
4560 return -EINVAL;
4561 }
4562
Ayala Beker47edb112015-09-21 15:49:53 +03004563 if (statype != CFG80211_STA_AP_CLIENT &&
4564 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004565 if (params->vlan)
4566 return -EINVAL;
4567 }
4568
4569 switch (statype) {
4570 case CFG80211_STA_AP_MLME_CLIENT:
4571 /* Use this only for authorizing/unauthorizing a station */
4572 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4573 return -EOPNOTSUPP;
4574 break;
4575 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004576 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004577 /* accept only the listed bits */
4578 if (params->sta_flags_mask &
4579 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4580 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4581 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4582 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4583 BIT(NL80211_STA_FLAG_WME) |
4584 BIT(NL80211_STA_FLAG_MFP)))
4585 return -EINVAL;
4586
4587 /* but authenticated/associated only if driver handles it */
4588 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4589 params->sta_flags_mask &
4590 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4591 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4592 return -EINVAL;
4593 break;
4594 case CFG80211_STA_IBSS:
4595 case CFG80211_STA_AP_STA:
4596 /* reject any changes other than AUTHORIZED */
4597 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4598 return -EINVAL;
4599 break;
4600 case CFG80211_STA_TDLS_PEER_SETUP:
4601 /* reject any changes other than AUTHORIZED or WME */
4602 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4603 BIT(NL80211_STA_FLAG_WME)))
4604 return -EINVAL;
4605 /* force (at least) rates when authorizing */
4606 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4607 !params->supported_rates)
4608 return -EINVAL;
4609 break;
4610 case CFG80211_STA_TDLS_PEER_ACTIVE:
4611 /* reject any changes */
4612 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004613 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004614 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4615 return -EINVAL;
4616 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004617 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004618 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4619 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004620 return -EINVAL;
4621 break;
4622 }
4623
4624 return 0;
4625}
4626EXPORT_SYMBOL(cfg80211_check_station_change);
4627
Johannes Berg5727ef12007-12-19 02:03:34 +01004628/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004629 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004630 */
Johannes Berg80b99892011-11-18 16:23:01 +01004631static struct net_device *get_vlan(struct genl_info *info,
4632 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004633{
Johannes Berg463d0182009-07-14 00:33:35 +02004634 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004635 struct net_device *v;
4636 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004637
Johannes Berg80b99892011-11-18 16:23:01 +01004638 if (!vlanattr)
4639 return NULL;
4640
4641 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4642 if (!v)
4643 return ERR_PTR(-ENODEV);
4644
4645 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4646 ret = -EINVAL;
4647 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004648 }
Johannes Berg80b99892011-11-18 16:23:01 +01004649
Johannes Berg77ee7c82013-02-15 00:48:33 +01004650 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4651 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4652 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4653 ret = -EINVAL;
4654 goto error;
4655 }
4656
Johannes Berg80b99892011-11-18 16:23:01 +01004657 if (!netif_running(v)) {
4658 ret = -ENETDOWN;
4659 goto error;
4660 }
4661
4662 return v;
4663 error:
4664 dev_put(v);
4665 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004666}
4667
Johannes Berg94e860f2014-01-20 23:58:15 +01004668static const struct nla_policy
4669nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004670 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4671 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4672};
4673
Johannes Bergff276692013-02-15 00:09:01 +01004674static int nl80211_parse_sta_wme(struct genl_info *info,
4675 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004676{
Jouni Malinendf881292013-02-14 21:10:54 +02004677 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4678 struct nlattr *nla;
4679 int err;
4680
Jouni Malinendf881292013-02-14 21:10:54 +02004681 /* parse WME attributes if present */
4682 if (!info->attrs[NL80211_ATTR_STA_WME])
4683 return 0;
4684
4685 nla = info->attrs[NL80211_ATTR_STA_WME];
4686 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4687 nl80211_sta_wme_policy);
4688 if (err)
4689 return err;
4690
4691 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4692 params->uapsd_queues = nla_get_u8(
4693 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4694 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4695 return -EINVAL;
4696
4697 if (tb[NL80211_STA_WME_MAX_SP])
4698 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4699
4700 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4701 return -EINVAL;
4702
4703 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4704
4705 return 0;
4706}
4707
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304708static int nl80211_parse_sta_channel_info(struct genl_info *info,
4709 struct station_parameters *params)
4710{
4711 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4712 params->supported_channels =
4713 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4714 params->supported_channels_len =
4715 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4716 /*
4717 * Need to include at least one (first channel, number of
4718 * channels) tuple for each subband, and must have proper
4719 * tuples for the rest of the data as well.
4720 */
4721 if (params->supported_channels_len < 2)
4722 return -EINVAL;
4723 if (params->supported_channels_len % 2)
4724 return -EINVAL;
4725 }
4726
4727 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4728 params->supported_oper_classes =
4729 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4730 params->supported_oper_classes_len =
4731 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4732 /*
4733 * The value of the Length field of the Supported Operating
4734 * Classes element is between 2 and 253.
4735 */
4736 if (params->supported_oper_classes_len < 2 ||
4737 params->supported_oper_classes_len > 253)
4738 return -EINVAL;
4739 }
4740 return 0;
4741}
4742
Johannes Bergff276692013-02-15 00:09:01 +01004743static int nl80211_set_station_tdls(struct genl_info *info,
4744 struct station_parameters *params)
4745{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304746 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004747 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004748 if (info->attrs[NL80211_ATTR_PEER_AID])
4749 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004750 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4751 params->ht_capa =
4752 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4753 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4754 params->vht_capa =
4755 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4756
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304757 err = nl80211_parse_sta_channel_info(info, params);
4758 if (err)
4759 return err;
4760
Johannes Bergff276692013-02-15 00:09:01 +01004761 return nl80211_parse_sta_wme(info, params);
4762}
4763
Johannes Berg5727ef12007-12-19 02:03:34 +01004764static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4765{
Johannes Berg4c476992010-10-04 21:36:35 +02004766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004767 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004768 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004769 u8 *mac_addr;
4770 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004771
4772 memset(&params, 0, sizeof(params));
4773
Johannes Berg77ee7c82013-02-15 00:48:33 +01004774 if (!rdev->ops->change_station)
4775 return -EOPNOTSUPP;
4776
Ayala Bekere4208422015-10-23 11:20:06 +03004777 /*
4778 * AID and listen_interval properties can be set only for unassociated
4779 * station. Include these parameters here and will check them in
4780 * cfg80211_check_station_change().
4781 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004782 if (info->attrs[NL80211_ATTR_STA_AID])
4783 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004784
4785 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4786 params.listen_interval =
4787 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4788 else
4789 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004790
Ayala Beker17b94242016-03-17 15:41:38 +02004791 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4792 u8 tmp;
4793
4794 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4795 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4796 return -EINVAL;
4797
4798 params.support_p2p_ps = tmp;
4799 } else {
4800 params.support_p2p_ps = -1;
4801 }
4802
Johannes Berg5727ef12007-12-19 02:03:34 +01004803 if (!info->attrs[NL80211_ATTR_MAC])
4804 return -EINVAL;
4805
4806 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4807
4808 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4809 params.supported_rates =
4810 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4811 params.supported_rates_len =
4812 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4813 }
4814
Jouni Malinen9d62a982013-02-14 21:10:13 +02004815 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4816 params.capability =
4817 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4818 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4819 }
4820
4821 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4822 params.ext_capab =
4823 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4824 params.ext_capab_len =
4825 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4826 }
4827
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004828 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004829 return -EINVAL;
4830
Johannes Bergf8bacc22013-02-14 23:27:01 +01004831 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004832 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004833 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4834 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4835 return -EINVAL;
4836 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004837
Johannes Bergf8bacc22013-02-14 23:27:01 +01004838 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004839 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004840 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4841 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4842 return -EINVAL;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09004843 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
4844 params.peer_aid = nla_get_u16(
4845 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
4846 if (params.peer_aid > IEEE80211_MAX_AID)
4847 return -EINVAL;
4848 }
Johannes Bergf8bacc22013-02-14 23:27:01 +01004849 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4850 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004851
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004852 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4853 enum nl80211_mesh_power_mode pm = nla_get_u32(
4854 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4855
4856 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4857 pm > NL80211_MESH_POWER_MAX)
4858 return -EINVAL;
4859
4860 params.local_pm = pm;
4861 }
4862
Johannes Berg77ee7c82013-02-15 00:48:33 +01004863 /* Include parameters for TDLS peer (will check later) */
4864 err = nl80211_set_station_tdls(info, &params);
4865 if (err)
4866 return err;
4867
4868 params.vlan = get_vlan(info, rdev);
4869 if (IS_ERR(params.vlan))
4870 return PTR_ERR(params.vlan);
4871
Johannes Berga97f4422009-06-18 17:23:43 +02004872 switch (dev->ieee80211_ptr->iftype) {
4873 case NL80211_IFTYPE_AP:
4874 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004875 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004876 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004877 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004878 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004879 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004880 break;
4881 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004882 err = -EOPNOTSUPP;
4883 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004884 }
4885
Johannes Berg77ee7c82013-02-15 00:48:33 +01004886 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004887 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004888
Johannes Berg77ee7c82013-02-15 00:48:33 +01004889 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004890 if (params.vlan)
4891 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004892
Johannes Berg5727ef12007-12-19 02:03:34 +01004893 return err;
4894}
4895
4896static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4897{
Johannes Berg4c476992010-10-04 21:36:35 +02004898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004899 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004900 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004901 struct station_parameters params;
4902 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004903 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4904 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004905
4906 memset(&params, 0, sizeof(params));
4907
Johannes Berg984c3112013-02-14 23:43:25 +01004908 if (!rdev->ops->add_station)
4909 return -EOPNOTSUPP;
4910
Johannes Berg5727ef12007-12-19 02:03:34 +01004911 if (!info->attrs[NL80211_ATTR_MAC])
4912 return -EINVAL;
4913
Johannes Berg5727ef12007-12-19 02:03:34 +01004914 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4915 return -EINVAL;
4916
4917 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4918 return -EINVAL;
4919
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004920 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4921 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004922 return -EINVAL;
4923
Johannes Berg5727ef12007-12-19 02:03:34 +01004924 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4925 params.supported_rates =
4926 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4927 params.supported_rates_len =
4928 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4929 params.listen_interval =
4930 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004931
Ayala Beker17b94242016-03-17 15:41:38 +02004932 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
4933 u8 tmp;
4934
4935 tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
4936 if (tmp >= NUM_NL80211_P2P_PS_STATUS)
4937 return -EINVAL;
4938
4939 params.support_p2p_ps = tmp;
4940 } else {
4941 /*
4942 * if not specified, assume it's supported for P2P GO interface,
4943 * and is NOT supported for AP interface
4944 */
4945 params.support_p2p_ps =
4946 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
4947 }
4948
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004949 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004950 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004951 else
4952 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004953 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4954 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004955
Jouni Malinen9d62a982013-02-14 21:10:13 +02004956 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4957 params.capability =
4958 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4959 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4960 }
4961
4962 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4963 params.ext_capab =
4964 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4965 params.ext_capab_len =
4966 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4967 }
4968
Jouni Malinen36aedc92008-08-25 11:58:58 +03004969 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4970 params.ht_capa =
4971 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004972
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004973 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4974 params.vht_capa =
4975 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4976
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004977 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4978 params.opmode_notif_used = true;
4979 params.opmode_notif =
4980 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4981 }
4982
Johannes Bergf8bacc22013-02-14 23:27:01 +01004983 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004984 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004985 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4986 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4987 return -EINVAL;
4988 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004989
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304990 err = nl80211_parse_sta_channel_info(info, &params);
4991 if (err)
4992 return err;
4993
Johannes Bergff276692013-02-15 00:09:01 +01004994 err = nl80211_parse_sta_wme(info, &params);
4995 if (err)
4996 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004997
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004998 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004999 return -EINVAL;
5000
Johannes Berg496fcc22015-03-12 08:53:27 +02005001 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5002 * as userspace might just pass through the capabilities from the IEs
5003 * directly, rather than enforcing this restriction and returning an
5004 * error in this case.
5005 */
5006 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
5007 params.ht_capa = NULL;
5008 params.vht_capa = NULL;
5009 }
5010
Johannes Berg77ee7c82013-02-15 00:48:33 +01005011 /* When you run into this, adjust the code below for the new flag */
5012 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5013
Johannes Bergbdd90d52011-12-14 12:20:27 +01005014 switch (dev->ieee80211_ptr->iftype) {
5015 case NL80211_IFTYPE_AP:
5016 case NL80211_IFTYPE_AP_VLAN:
5017 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01005018 /* ignore WME attributes if iface/sta is not capable */
5019 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
5020 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
5021 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005022
Johannes Bergbdd90d52011-12-14 12:20:27 +01005023 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005024 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5025 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005026 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005027 /* but don't bother the driver with it */
5028 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03005029
Johannes Bergd582cff2012-10-26 17:53:44 +02005030 /* allow authenticated/associated only if driver handles it */
5031 if (!(rdev->wiphy.features &
5032 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01005033 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02005034 return -EINVAL;
5035
Johannes Bergbda95eb2015-11-26 16:26:13 +01005036 /* Older userspace, or userspace wanting to be compatible with
5037 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5038 * and assoc flags in the mask, but assumes the station will be
5039 * added as associated anyway since this was the required driver
5040 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5041 * introduced.
5042 * In order to not bother drivers with this quirk in the API
5043 * set the flags in both the mask and set for new stations in
5044 * this case.
5045 */
5046 if (!(params.sta_flags_mask & auth_assoc)) {
5047 params.sta_flags_mask |= auth_assoc;
5048 params.sta_flags_set |= auth_assoc;
5049 }
5050
Johannes Bergbdd90d52011-12-14 12:20:27 +01005051 /* must be last in here for error handling */
5052 params.vlan = get_vlan(info, rdev);
5053 if (IS_ERR(params.vlan))
5054 return PTR_ERR(params.vlan);
5055 break;
5056 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01005057 /* ignore uAPSD data */
5058 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5059
Johannes Bergd582cff2012-10-26 17:53:44 +02005060 /* associated is disallowed */
5061 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
5062 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005063 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03005064 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
5065 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02005066 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005067 break;
5068 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01005069 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01005070 /* ignore uAPSD data */
5071 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
5072
Johannes Berg77ee7c82013-02-15 00:48:33 +01005073 /* these are disallowed */
5074 if (params.sta_flags_mask &
5075 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
5076 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02005077 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01005078 /* Only TDLS peers can be added */
5079 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5080 return -EINVAL;
5081 /* Can only add if TDLS ... */
5082 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
5083 return -EOPNOTSUPP;
5084 /* ... with external setup is supported */
5085 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
5086 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005087 /*
5088 * Older wpa_supplicant versions always mark the TDLS peer
5089 * as authorized, but it shouldn't yet be.
5090 */
5091 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01005092 break;
5093 default:
5094 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03005095 }
5096
Johannes Bergbdd90d52011-12-14 12:20:27 +01005097 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01005098
Hila Gonene35e4d22012-06-27 17:19:42 +03005099 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005100
Johannes Berg5727ef12007-12-19 02:03:34 +01005101 if (params.vlan)
5102 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01005103 return err;
5104}
5105
5106static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
5107{
Johannes Berg4c476992010-10-04 21:36:35 +02005108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5109 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03005110 struct station_del_parameters params;
5111
5112 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01005113
5114 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03005115 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01005116
Johannes Berge80cf852009-05-11 14:43:13 +02005117 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02005118 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02005119 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02005120 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5121 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02005122
Johannes Berg4c476992010-10-04 21:36:35 +02005123 if (!rdev->ops->del_station)
5124 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01005125
Jouni Malinen98856862014-10-20 13:20:45 +03005126 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
5127 params.subtype =
5128 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
5129 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
5130 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
5131 return -EINVAL;
5132 } else {
5133 /* Default to Deauthentication frame */
5134 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
5135 }
5136
5137 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
5138 params.reason_code =
5139 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
5140 if (params.reason_code == 0)
5141 return -EINVAL; /* 0 is reserved */
5142 } else {
5143 /* Default to reason code 2 */
5144 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
5145 }
5146
Jouni Malinen89c771e2014-10-10 20:52:40 +03005147 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01005148}
5149
Eric W. Biederman15e47302012-09-07 20:12:54 +00005150static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005151 int flags, struct net_device *dev,
5152 u8 *dst, u8 *next_hop,
5153 struct mpath_info *pinfo)
5154{
5155 void *hdr;
5156 struct nlattr *pinfoattr;
5157
Henning Rogge1ef4c852014-11-04 16:14:58 +01005158 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005159 if (!hdr)
5160 return -1;
5161
David S. Miller9360ffd2012-03-29 04:41:26 -04005162 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5163 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
5164 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
5165 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
5166 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005167
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005168 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
5169 if (!pinfoattr)
5170 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005171 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
5172 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
5173 pinfo->frame_qlen))
5174 goto nla_put_failure;
5175 if (((pinfo->filled & MPATH_INFO_SN) &&
5176 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
5177 ((pinfo->filled & MPATH_INFO_METRIC) &&
5178 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
5179 pinfo->metric)) ||
5180 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
5181 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
5182 pinfo->exptime)) ||
5183 ((pinfo->filled & MPATH_INFO_FLAGS) &&
5184 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
5185 pinfo->flags)) ||
5186 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
5187 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
5188 pinfo->discovery_timeout)) ||
5189 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
5190 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
5191 pinfo->discovery_retries)))
5192 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005193
5194 nla_nest_end(msg, pinfoattr);
5195
Johannes Berg053c0952015-01-16 22:09:00 +01005196 genlmsg_end(msg, hdr);
5197 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005198
5199 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07005200 genlmsg_cancel(msg, hdr);
5201 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005202}
5203
5204static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005205 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005206{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005207 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005208 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005209 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005210 u8 dst[ETH_ALEN];
5211 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005212 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005213 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005214
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005215 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005216 if (err)
5217 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005218
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005219 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005220 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005221 goto out_err;
5222 }
5223
Johannes Berg97990a02013-04-19 01:02:55 +02005224 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005225 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02005226 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02005227 }
5228
Johannes Bergbba95fe2008-07-29 13:22:51 +02005229 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005230 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02005231 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005232 if (err == -ENOENT)
5233 break;
5234 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005235 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005236
Eric W. Biederman15e47302012-09-07 20:12:54 +00005237 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005238 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005239 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005240 &pinfo) < 0)
5241 goto out;
5242
5243 path_idx++;
5244 }
5245
Johannes Bergbba95fe2008-07-29 13:22:51 +02005246 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005247 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005248 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005249 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005250 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005251 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005252}
5253
5254static int nl80211_get_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];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005257 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02005258 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005259 struct mpath_info pinfo;
5260 struct sk_buff *msg;
5261 u8 *dst = NULL;
5262 u8 next_hop[ETH_ALEN];
5263
5264 memset(&pinfo, 0, sizeof(pinfo));
5265
5266 if (!info->attrs[NL80211_ATTR_MAC])
5267 return -EINVAL;
5268
5269 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5270
Johannes Berg4c476992010-10-04 21:36:35 +02005271 if (!rdev->ops->get_mpath)
5272 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005273
Johannes Berg4c476992010-10-04 21:36:35 +02005274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5275 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005276
Hila Gonene35e4d22012-06-27 17:19:42 +03005277 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005278 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005279 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005280
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005282 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02005283 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005284
Eric W. Biederman15e47302012-09-07 20:12:54 +00005285 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02005286 dev, dst, next_hop, &pinfo) < 0) {
5287 nlmsg_free(msg);
5288 return -ENOBUFS;
5289 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005290
Johannes Berg4c476992010-10-04 21:36:35 +02005291 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005292}
5293
5294static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
5295{
Johannes Berg4c476992010-10-04 21:36:35 +02005296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5297 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005298 u8 *dst = NULL;
5299 u8 *next_hop = NULL;
5300
5301 if (!info->attrs[NL80211_ATTR_MAC])
5302 return -EINVAL;
5303
5304 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5305 return -EINVAL;
5306
5307 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5308 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5309
Johannes Berg4c476992010-10-04 21:36:35 +02005310 if (!rdev->ops->change_mpath)
5311 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005312
Johannes Berg4c476992010-10-04 21:36:35 +02005313 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5314 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005315
Hila Gonene35e4d22012-06-27 17:19:42 +03005316 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005317}
Johannes Berg4c476992010-10-04 21:36:35 +02005318
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005319static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
5320{
Johannes Berg4c476992010-10-04 21:36:35 +02005321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5322 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005323 u8 *dst = NULL;
5324 u8 *next_hop = NULL;
5325
5326 if (!info->attrs[NL80211_ATTR_MAC])
5327 return -EINVAL;
5328
5329 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
5330 return -EINVAL;
5331
5332 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5333 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
5334
Johannes Berg4c476992010-10-04 21:36:35 +02005335 if (!rdev->ops->add_mpath)
5336 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005337
Johannes Berg4c476992010-10-04 21:36:35 +02005338 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5339 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005340
Hila Gonene35e4d22012-06-27 17:19:42 +03005341 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005342}
5343
5344static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
5345{
Johannes Berg4c476992010-10-04 21:36:35 +02005346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5347 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005348 u8 *dst = NULL;
5349
5350 if (info->attrs[NL80211_ATTR_MAC])
5351 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5352
Johannes Berg4c476992010-10-04 21:36:35 +02005353 if (!rdev->ops->del_mpath)
5354 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01005355
Hila Gonene35e4d22012-06-27 17:19:42 +03005356 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005357}
5358
Henning Rogge66be7d22014-09-12 08:58:49 +02005359static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
5360{
5361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5362 int err;
5363 struct net_device *dev = info->user_ptr[1];
5364 struct mpath_info pinfo;
5365 struct sk_buff *msg;
5366 u8 *dst = NULL;
5367 u8 mpp[ETH_ALEN];
5368
5369 memset(&pinfo, 0, sizeof(pinfo));
5370
5371 if (!info->attrs[NL80211_ATTR_MAC])
5372 return -EINVAL;
5373
5374 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
5375
5376 if (!rdev->ops->get_mpp)
5377 return -EOPNOTSUPP;
5378
5379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
5380 return -EOPNOTSUPP;
5381
5382 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
5383 if (err)
5384 return err;
5385
5386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5387 if (!msg)
5388 return -ENOMEM;
5389
5390 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
5391 dev, dst, mpp, &pinfo) < 0) {
5392 nlmsg_free(msg);
5393 return -ENOBUFS;
5394 }
5395
5396 return genlmsg_reply(msg, info);
5397}
5398
5399static int nl80211_dump_mpp(struct sk_buff *skb,
5400 struct netlink_callback *cb)
5401{
5402 struct mpath_info pinfo;
5403 struct cfg80211_registered_device *rdev;
5404 struct wireless_dev *wdev;
5405 u8 dst[ETH_ALEN];
5406 u8 mpp[ETH_ALEN];
5407 int path_idx = cb->args[2];
5408 int err;
5409
5410 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
5411 if (err)
5412 return err;
5413
5414 if (!rdev->ops->dump_mpp) {
5415 err = -EOPNOTSUPP;
5416 goto out_err;
5417 }
5418
5419 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
5420 err = -EOPNOTSUPP;
5421 goto out_err;
5422 }
5423
5424 while (1) {
5425 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
5426 mpp, &pinfo);
5427 if (err == -ENOENT)
5428 break;
5429 if (err)
5430 goto out_err;
5431
5432 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
5433 cb->nlh->nlmsg_seq, NLM_F_MULTI,
5434 wdev->netdev, dst, mpp,
5435 &pinfo) < 0)
5436 goto out;
5437
5438 path_idx++;
5439 }
5440
5441 out:
5442 cb->args[2] = path_idx;
5443 err = skb->len;
5444 out_err:
5445 nl80211_finish_wdev_dump(rdev);
5446 return err;
5447}
5448
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005449static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
5450{
Johannes Berg4c476992010-10-04 21:36:35 +02005451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5452 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005453 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005454 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005455 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005456
5457 memset(&params, 0, sizeof(params));
5458 /* default to not changing parameters */
5459 params.use_cts_prot = -1;
5460 params.use_short_preamble = -1;
5461 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005462 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01005463 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01005464 params.p2p_ctwindow = -1;
5465 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005466
5467 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
5468 params.use_cts_prot =
5469 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
5470 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
5471 params.use_short_preamble =
5472 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
5473 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
5474 params.use_short_slot_time =
5475 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02005476 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
5477 params.basic_rates =
5478 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5479 params.basic_rates_len =
5480 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
5481 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02005482 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
5483 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01005484 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
5485 params.ht_opmode =
5486 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005487
Johannes Berg53cabad2012-11-14 15:17:28 +01005488 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5489 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5490 return -EINVAL;
5491 params.p2p_ctwindow =
5492 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
5493 if (params.p2p_ctwindow < 0)
5494 return -EINVAL;
5495 if (params.p2p_ctwindow != 0 &&
5496 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5497 return -EINVAL;
5498 }
5499
5500 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5501 u8 tmp;
5502
5503 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5504 return -EINVAL;
5505 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
5506 if (tmp > 1)
5507 return -EINVAL;
5508 params.p2p_opp_ps = tmp;
5509 if (params.p2p_opp_ps &&
5510 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5511 return -EINVAL;
5512 }
5513
Johannes Berg4c476992010-10-04 21:36:35 +02005514 if (!rdev->ops->change_bss)
5515 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005516
Johannes Berg074ac8d2010-09-16 14:58:22 +02005517 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02005518 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5519 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005520
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005521 wdev_lock(wdev);
5522 err = rdev_change_bss(rdev, dev, &params);
5523 wdev_unlock(wdev);
5524
5525 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03005526}
5527
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005528static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
5529{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005530 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005531 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005532 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005533 u32 owner_nlportid;
5534
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005535 /*
5536 * You should only get this when cfg80211 hasn't yet initialized
5537 * completely when built-in to the kernel right between the time
5538 * window between nl80211_init() and regulatory_init(), if that is
5539 * even possible.
5540 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005541 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005542 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005543
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005544 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5545 user_reg_hint_type =
5546 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5547 else
5548 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5549
5550 switch (user_reg_hint_type) {
5551 case NL80211_USER_REG_HINT_USER:
5552 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005553 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5554 return -EINVAL;
5555
5556 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5557 return regulatory_hint_user(data, user_reg_hint_type);
5558 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005559 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5560 owner_nlportid = info->snd_portid;
5561 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5562 } else {
5563 owner_nlportid = 0;
5564 is_indoor = true;
5565 }
5566
5567 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005568 default:
5569 return -EINVAL;
5570 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005571}
5572
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005573static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005574 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005575{
Johannes Berg4c476992010-10-04 21:36:35 +02005576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005577 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005578 struct wireless_dev *wdev = dev->ieee80211_ptr;
5579 struct mesh_config cur_params;
5580 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005581 void *hdr;
5582 struct nlattr *pinfoattr;
5583 struct sk_buff *msg;
5584
Johannes Berg29cbe682010-12-03 09:20:44 +01005585 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5586 return -EOPNOTSUPP;
5587
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005588 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005589 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005590
Johannes Berg29cbe682010-12-03 09:20:44 +01005591 wdev_lock(wdev);
5592 /* If not connected, get default parameters */
5593 if (!wdev->mesh_id_len)
5594 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5595 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005596 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005597 wdev_unlock(wdev);
5598
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005599 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005600 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005601
5602 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005603 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005604 if (!msg)
5605 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005606 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005607 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005608 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005609 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005610 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005611 if (!pinfoattr)
5612 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005613 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5614 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5615 cur_params.dot11MeshRetryTimeout) ||
5616 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5617 cur_params.dot11MeshConfirmTimeout) ||
5618 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5619 cur_params.dot11MeshHoldingTimeout) ||
5620 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5621 cur_params.dot11MeshMaxPeerLinks) ||
5622 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5623 cur_params.dot11MeshMaxRetries) ||
5624 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5625 cur_params.dot11MeshTTL) ||
5626 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5627 cur_params.element_ttl) ||
5628 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5629 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005630 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5631 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005632 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5633 cur_params.dot11MeshHWMPmaxPREQretries) ||
5634 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5635 cur_params.path_refresh_time) ||
5636 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5637 cur_params.min_discovery_timeout) ||
5638 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5639 cur_params.dot11MeshHWMPactivePathTimeout) ||
5640 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5641 cur_params.dot11MeshHWMPpreqMinInterval) ||
5642 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5643 cur_params.dot11MeshHWMPperrMinInterval) ||
5644 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5645 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5646 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5647 cur_params.dot11MeshHWMPRootMode) ||
5648 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5649 cur_params.dot11MeshHWMPRannInterval) ||
5650 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5651 cur_params.dot11MeshGateAnnouncementProtocol) ||
5652 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5653 cur_params.dot11MeshForwarding) ||
5654 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005655 cur_params.rssi_threshold) ||
5656 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005657 cur_params.ht_opmode) ||
5658 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5659 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5660 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005661 cur_params.dot11MeshHWMProotInterval) ||
5662 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005663 cur_params.dot11MeshHWMPconfirmationInterval) ||
5664 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5665 cur_params.power_mode) ||
5666 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005667 cur_params.dot11MeshAwakeWindowDuration) ||
5668 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5669 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005670 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005671 nla_nest_end(msg, pinfoattr);
5672 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005673 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005674
Johannes Berg3b858752009-03-12 09:55:09 +01005675 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005676 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005677 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005678 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005679 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005680}
5681
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005682static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005683 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5684 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5685 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5686 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5687 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5688 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005689 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005690 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005691 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005692 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5693 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5694 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5695 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5696 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005697 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005698 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005699 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005700 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005701 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005702 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005703 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5704 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005705 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5706 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005707 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005708 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5709 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005710 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005711};
5712
Javier Cardonac80d5452010-12-16 17:37:49 -08005713static const struct nla_policy
5714 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005715 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005716 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5717 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005718 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005719 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005720 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005721 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005722 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005723 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005724};
5725
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005726static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
5727{
5728 u8 val = nla_get_u8(nla);
5729 if (val < min || val > max)
5730 return -EINVAL;
5731 *out = val;
5732 return 0;
5733}
5734
5735static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
5736{
5737 u8 val = nla_get_u8(nla);
5738 if (val < min || val > max)
5739 return -EINVAL;
5740 *out = val;
5741 return 0;
5742}
5743
5744static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
5745{
5746 u16 val = nla_get_u16(nla);
5747 if (val < min || val > max)
5748 return -EINVAL;
5749 *out = val;
5750 return 0;
5751}
5752
5753static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
5754{
5755 u32 val = nla_get_u32(nla);
5756 if (val < min || val > max)
5757 return -EINVAL;
5758 *out = val;
5759 return 0;
5760}
5761
5762static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
5763{
5764 s32 val = nla_get_s32(nla);
5765 if (val < min || val > max)
5766 return -EINVAL;
5767 *out = val;
5768 return 0;
5769}
5770
Johannes Bergff9a71a2016-08-11 14:59:53 +02005771static int nl80211_check_power_mode(const struct nlattr *nla,
5772 enum nl80211_mesh_power_mode min,
5773 enum nl80211_mesh_power_mode max,
5774 enum nl80211_mesh_power_mode *out)
5775{
5776 u32 val = nla_get_u32(nla);
5777 if (val < min || val > max)
5778 return -EINVAL;
5779 *out = val;
5780 return 0;
5781}
5782
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005783static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005784 struct mesh_config *cfg,
5785 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005786{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005787 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005788 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09005789 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005790
Marco Porschea54fba2013-01-07 16:04:48 +01005791#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5792do { \
5793 if (tb[attr]) { \
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005794 if (fn(tb[attr], min, max, &cfg->param)) \
Marco Porschea54fba2013-01-07 16:04:48 +01005795 return -EINVAL; \
Marco Porschea54fba2013-01-07 16:04:48 +01005796 mask |= (1 << (attr - 1)); \
5797 } \
5798} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005799
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005800 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005801 return -EINVAL;
5802 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005803 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005804 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005805 return -EINVAL;
5806
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005807 /* This makes sure that there aren't more than 32 mesh config
5808 * parameters (otherwise our bitfield scheme would not work.) */
5809 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5810
5811 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005813 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005814 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005815 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005816 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005817 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005819 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005820 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005822 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005823 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005825 mask, NL80211_MESHCONF_MAX_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005826 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005827 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005828 mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005830 mask, NL80211_MESHCONF_ELEMENT_TTL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005831 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005832 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005833 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005834 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005835 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5836 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005837 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005838 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005839 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005840 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005841 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005843 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005844 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005846 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005847 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005848 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5849 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005850 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005851 nl80211_check_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005852 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005853 1, 65535, mask,
5854 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005855 nl80211_check_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005856 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005857 1, 65535, mask,
5858 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005859 nl80211_check_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005861 dot11MeshHWMPnetDiameterTraversalTime,
5862 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005863 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005864 nl80211_check_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005865 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5866 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005867 nl80211_check_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005868 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5869 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005870 nl80211_check_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005871 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005872 dot11MeshGateAnnouncementProtocol, 0, 1,
5873 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005874 nl80211_check_bool);
Marco Porschea54fba2013-01-07 16:04:48 +01005875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005876 mask, NL80211_MESHCONF_FORWARDING,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005877 nl80211_check_bool);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005879 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005880 nl80211_check_s32);
Masashi Honma97572352016-08-03 10:07:44 +09005881 /*
5882 * Check HT operation mode based on
5883 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5884 */
5885 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
5886 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
5887
5888 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
5889 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
5890 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5891 return -EINVAL;
5892
5893 if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
5894 (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5895 return -EINVAL;
5896
5897 switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
5898 case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
5899 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
5900 if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
5901 return -EINVAL;
5902 break;
5903 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
5904 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
5905 if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
5906 return -EINVAL;
5907 break;
5908 }
5909 cfg->ht_opmode = ht_opmode;
5910 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005911 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005912 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005913 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005914 nl80211_check_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005916 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005917 nl80211_check_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005918 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005919 dot11MeshHWMPconfirmationInterval,
5920 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005921 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005922 nl80211_check_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5924 NL80211_MESH_POWER_ACTIVE,
5925 NL80211_MESH_POWER_MAX,
5926 mask, NL80211_MESHCONF_POWER_MODE,
Johannes Bergff9a71a2016-08-11 14:59:53 +02005927 nl80211_check_power_mode);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5929 0, 65535, mask,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005930 NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005932 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
Arnd Bergmannf151d9d2016-06-15 22:29:41 +02005933 nl80211_check_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005934 if (mask_out)
5935 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005936
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005937 return 0;
5938
5939#undef FILL_IN_MESH_PARAM_IF_SET
5940}
5941
Javier Cardonac80d5452010-12-16 17:37:49 -08005942static int nl80211_parse_mesh_setup(struct genl_info *info,
5943 struct mesh_setup *setup)
5944{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005946 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5947
5948 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5949 return -EINVAL;
5950 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5951 info->attrs[NL80211_ATTR_MESH_SETUP],
5952 nl80211_mesh_setup_params_policy))
5953 return -EINVAL;
5954
Javier Cardonad299a1f2012-03-31 11:31:33 -07005955 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5956 setup->sync_method =
5957 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5958 IEEE80211_SYNC_METHOD_VENDOR :
5959 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5960
Javier Cardonac80d5452010-12-16 17:37:49 -08005961 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5962 setup->path_sel_proto =
5963 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5964 IEEE80211_PATH_PROTOCOL_VENDOR :
5965 IEEE80211_PATH_PROTOCOL_HWMP;
5966
5967 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5968 setup->path_metric =
5969 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5970 IEEE80211_PATH_METRIC_VENDOR :
5971 IEEE80211_PATH_METRIC_AIRTIME;
5972
Javier Cardona581a8b02011-04-07 15:08:27 -07005973 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005974 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005975 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005976 if (!is_valid_ie_attr(ieattr))
5977 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005978 setup->ie = nla_data(ieattr);
5979 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005980 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005981 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5982 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5983 return -EINVAL;
5984 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005985 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5986 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005987 if (setup->is_secure)
5988 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005989
Colleen Twitty6e16d902013-05-08 11:45:59 -07005990 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5991 if (!setup->user_mpm)
5992 return -EINVAL;
5993 setup->auth_id =
5994 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5995 }
5996
Javier Cardonac80d5452010-12-16 17:37:49 -08005997 return 0;
5998}
5999
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006000static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006001 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006002{
6003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6004 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006005 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006006 struct mesh_config cfg;
6007 u32 mask;
6008 int err;
6009
Johannes Berg29cbe682010-12-03 09:20:44 +01006010 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6011 return -EOPNOTSUPP;
6012
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006013 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006014 return -EOPNOTSUPP;
6015
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006016 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006017 if (err)
6018 return err;
6019
Johannes Berg29cbe682010-12-03 09:20:44 +01006020 wdev_lock(wdev);
6021 if (!wdev->mesh_id_len)
6022 err = -ENOLINK;
6023
6024 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03006025 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01006026
6027 wdev_unlock(wdev);
6028
6029 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006030}
6031
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006032static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
6033 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006034{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006035 struct nlattr *nl_reg_rules;
6036 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006037
Johannes Berg458f4f92012-12-06 15:47:38 +01006038 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
6039 (regdom->dfs_region &&
6040 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006041 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01006042
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006043 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
6044 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006045 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006046
Johannes Berg458f4f92012-12-06 15:47:38 +01006047 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006048 struct nlattr *nl_reg_rule;
6049 const struct ieee80211_reg_rule *reg_rule;
6050 const struct ieee80211_freq_range *freq_range;
6051 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01006052 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006053
Johannes Berg458f4f92012-12-06 15:47:38 +01006054 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006055 freq_range = &reg_rule->freq_range;
6056 power_rule = &reg_rule->power_rule;
6057
6058 nl_reg_rule = nla_nest_start(msg, i);
6059 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006060 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006061
Janusz Dziedzic97524822014-01-30 09:52:20 +01006062 max_bandwidth_khz = freq_range->max_bandwidth_khz;
6063 if (!max_bandwidth_khz)
6064 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
6065 reg_rule);
6066
David S. Miller9360ffd2012-03-29 04:41:26 -04006067 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
6068 reg_rule->flags) ||
6069 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
6070 freq_range->start_freq_khz) ||
6071 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
6072 freq_range->end_freq_khz) ||
6073 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01006074 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006075 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
6076 power_rule->max_antenna_gain) ||
6077 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01006078 power_rule->max_eirp) ||
6079 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
6080 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006081 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006082
6083 nla_nest_end(msg, nl_reg_rule);
6084 }
6085
6086 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006087 return 0;
6088
6089nla_put_failure:
6090 return -EMSGSIZE;
6091}
6092
6093static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
6094{
6095 const struct ieee80211_regdomain *regdom = NULL;
6096 struct cfg80211_registered_device *rdev;
6097 struct wiphy *wiphy = NULL;
6098 struct sk_buff *msg;
6099 void *hdr;
6100
6101 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6102 if (!msg)
6103 return -ENOBUFS;
6104
6105 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
6106 NL80211_CMD_GET_REG);
6107 if (!hdr)
6108 goto put_failure;
6109
6110 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006111 bool self_managed;
6112
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006113 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
6114 if (IS_ERR(rdev)) {
6115 nlmsg_free(msg);
6116 return PTR_ERR(rdev);
6117 }
6118
6119 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006120 self_managed = wiphy->regulatory_flags &
6121 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006122 regdom = get_wiphy_regdom(wiphy);
6123
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006124 /* a self-managed-reg device must have a private regdom */
6125 if (WARN_ON(!regdom && self_managed)) {
6126 nlmsg_free(msg);
6127 return -EINVAL;
6128 }
6129
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006130 if (regdom &&
6131 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6132 goto nla_put_failure;
6133 }
6134
6135 if (!wiphy && reg_last_request_cell_base() &&
6136 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6137 NL80211_USER_REG_HINT_CELL_BASE))
6138 goto nla_put_failure;
6139
6140 rcu_read_lock();
6141
6142 if (!regdom)
6143 regdom = rcu_dereference(cfg80211_regdomain);
6144
6145 if (nl80211_put_regdom(regdom, msg))
6146 goto nla_put_failure_rcu;
6147
6148 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006149
6150 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006151 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006152
Johannes Berg458f4f92012-12-06 15:47:38 +01006153nla_put_failure_rcu:
6154 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006155nla_put_failure:
6156 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01006157put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04006158 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02006159 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08006160}
6161
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006162static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
6163 u32 seq, int flags, struct wiphy *wiphy,
6164 const struct ieee80211_regdomain *regdom)
6165{
6166 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
6167 NL80211_CMD_GET_REG);
6168
6169 if (!hdr)
6170 return -1;
6171
6172 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6173
6174 if (nl80211_put_regdom(regdom, msg))
6175 goto nla_put_failure;
6176
6177 if (!wiphy && reg_last_request_cell_base() &&
6178 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
6179 NL80211_USER_REG_HINT_CELL_BASE))
6180 goto nla_put_failure;
6181
6182 if (wiphy &&
6183 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
6184 goto nla_put_failure;
6185
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02006186 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
6187 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
6188 goto nla_put_failure;
6189
Johannes Berg053c0952015-01-16 22:09:00 +01006190 genlmsg_end(msg, hdr);
6191 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02006192
6193nla_put_failure:
6194 genlmsg_cancel(msg, hdr);
6195 return -EMSGSIZE;
6196}
6197
6198static int nl80211_get_reg_dump(struct sk_buff *skb,
6199 struct netlink_callback *cb)
6200{
6201 const struct ieee80211_regdomain *regdom = NULL;
6202 struct cfg80211_registered_device *rdev;
6203 int err, reg_idx, start = cb->args[2];
6204
6205 rtnl_lock();
6206
6207 if (cfg80211_regdomain && start == 0) {
6208 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6209 NLM_F_MULTI, NULL,
6210 rtnl_dereference(cfg80211_regdomain));
6211 if (err < 0)
6212 goto out_err;
6213 }
6214
6215 /* the global regdom is idx 0 */
6216 reg_idx = 1;
6217 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
6218 regdom = get_wiphy_regdom(&rdev->wiphy);
6219 if (!regdom)
6220 continue;
6221
6222 if (++reg_idx <= start)
6223 continue;
6224
6225 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
6226 NLM_F_MULTI, &rdev->wiphy, regdom);
6227 if (err < 0) {
6228 reg_idx--;
6229 break;
6230 }
6231 }
6232
6233 cb->args[2] = reg_idx;
6234 err = skb->len;
6235out_err:
6236 rtnl_unlock();
6237 return err;
6238}
6239
Johannes Bergb6863032015-10-15 09:25:18 +02006240#ifdef CONFIG_CFG80211_CRDA_SUPPORT
6241static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
6242 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
6243 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
6244 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
6245 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
6246 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
6247 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
6248 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
6249};
6250
6251static int parse_reg_rule(struct nlattr *tb[],
6252 struct ieee80211_reg_rule *reg_rule)
6253{
6254 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
6255 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
6256
6257 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
6258 return -EINVAL;
6259 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
6260 return -EINVAL;
6261 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
6262 return -EINVAL;
6263 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
6264 return -EINVAL;
6265 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
6266 return -EINVAL;
6267
6268 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
6269
6270 freq_range->start_freq_khz =
6271 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
6272 freq_range->end_freq_khz =
6273 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
6274 freq_range->max_bandwidth_khz =
6275 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
6276
6277 power_rule->max_eirp =
6278 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
6279
6280 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
6281 power_rule->max_antenna_gain =
6282 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
6283
6284 if (tb[NL80211_ATTR_DFS_CAC_TIME])
6285 reg_rule->dfs_cac_ms =
6286 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
6287
6288 return 0;
6289}
6290
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006291static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
6292{
6293 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
6294 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01006295 char *alpha2;
6296 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006297 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01006298 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01006299 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006300
6301 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6302 return -EINVAL;
6303
6304 if (!info->attrs[NL80211_ATTR_REG_RULES])
6305 return -EINVAL;
6306
6307 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6308
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006309 if (info->attrs[NL80211_ATTR_DFS_REGION])
6310 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
6311
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006312 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006313 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006314 num_rules++;
6315 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04006316 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006317 }
6318
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08006319 if (!reg_is_valid_request(alpha2))
6320 return -EINVAL;
6321
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006322 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01006323 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006324
6325 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01006326 if (!rd)
6327 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006328
6329 rd->n_reg_rules = num_rules;
6330 rd->alpha2[0] = alpha2[0];
6331 rd->alpha2[1] = alpha2[1];
6332
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07006333 /*
6334 * Disable DFS master mode if the DFS region was
6335 * not supported or known on this kernel.
6336 */
6337 if (reg_supported_dfs_region(dfs_region))
6338 rd->dfs_region = dfs_region;
6339
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006340 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01006341 rem_reg_rules) {
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006342 r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX,
6343 nl_reg_rule, reg_rule_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01006344 if (r)
6345 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006346 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
6347 if (r)
6348 goto bad_reg;
6349
6350 rule_idx++;
6351
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006352 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
6353 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006354 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006355 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006356 }
6357
Johannes Berg06627992016-06-09 10:40:09 +02006358 /* set_regdom takes ownership of rd */
6359 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02006360 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006361 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04006362 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006363}
Johannes Bergb6863032015-10-15 09:25:18 +02006364#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006365
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006366static int validate_scan_freqs(struct nlattr *freqs)
6367{
6368 struct nlattr *attr1, *attr2;
6369 int n_channels = 0, tmp1, tmp2;
6370
6371 nla_for_each_nested(attr1, freqs, tmp1) {
6372 n_channels++;
6373 /*
6374 * Some hardware has a limited channel list for
6375 * scanning, and it is pretty much nonsensical
6376 * to scan for a channel twice, so disallow that
6377 * and don't require drivers to check that the
6378 * channel list they get isn't longer than what
6379 * they can scan, as long as they can scan all
6380 * the channels they registered at once.
6381 */
6382 nla_for_each_nested(attr2, freqs, tmp2)
6383 if (attr1 != attr2 &&
6384 nla_get_u32(attr1) == nla_get_u32(attr2))
6385 return 0;
6386 }
6387
6388 return n_channels;
6389}
6390
Johannes Berg57fbcce2016-04-12 15:56:15 +02006391static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01006392{
Johannes Berg57fbcce2016-04-12 15:56:15 +02006393 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01006394}
6395
6396static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
6397 struct cfg80211_bss_selection *bss_select)
6398{
6399 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
6400 struct nlattr *nest;
6401 int err;
6402 bool found = false;
6403 int i;
6404
6405 /* only process one nested attribute */
6406 nest = nla_data(nla);
6407 if (!nla_ok(nest, nla_len(nest)))
6408 return -EINVAL;
6409
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006410 err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest,
6411 nl80211_bss_select_policy);
Arend van Spriel38de03d2016-03-02 20:37:18 +01006412 if (err)
6413 return err;
6414
6415 /* only one attribute may be given */
6416 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
6417 if (attr[i]) {
6418 if (found)
6419 return -EINVAL;
6420 found = true;
6421 }
6422 }
6423
6424 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
6425
6426 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
6427 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
6428
6429 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
6430 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
6431 bss_select->param.band_pref =
6432 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
6433 if (!is_band_valid(wiphy, bss_select->param.band_pref))
6434 return -EINVAL;
6435 }
6436
6437 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
6438 struct nl80211_bss_select_rssi_adjust *adj_param;
6439
6440 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
6441 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
6442 bss_select->param.adjust.band = adj_param->band;
6443 bss_select->param.adjust.delta = adj_param->delta;
6444 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
6445 return -EINVAL;
6446 }
6447
6448 /* user-space did not provide behaviour attribute */
6449 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
6450 return -EINVAL;
6451
6452 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
6453 return -EINVAL;
6454
6455 return 0;
6456}
6457
Johannes Bergad2b26a2014-06-12 21:39:05 +02006458static int nl80211_parse_random_mac(struct nlattr **attrs,
6459 u8 *mac_addr, u8 *mac_addr_mask)
6460{
6461 int i;
6462
6463 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08006464 eth_zero_addr(mac_addr);
6465 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02006466 mac_addr[0] = 0x2;
6467 mac_addr_mask[0] = 0x3;
6468
6469 return 0;
6470 }
6471
6472 /* need both or none */
6473 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
6474 return -EINVAL;
6475
6476 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
6477 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
6478
6479 /* don't allow or configure an mcast address */
6480 if (!is_multicast_ether_addr(mac_addr_mask) ||
6481 is_multicast_ether_addr(mac_addr))
6482 return -EINVAL;
6483
6484 /*
6485 * allow users to pass a MAC address that has bits set outside
6486 * of the mask, but don't bother drivers with having to deal
6487 * with such bits
6488 */
6489 for (i = 0; i < ETH_ALEN; i++)
6490 mac_addr[i] &= mac_addr_mask[i];
6491
6492 return 0;
6493}
6494
Johannes Berg2a519312009-02-10 21:25:55 +01006495static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
6496{
Johannes Berg4c476992010-10-04 21:36:35 +02006497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02006498 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01006499 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01006500 struct nlattr *attr;
6501 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006502 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006503 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01006504
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006505 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6506 return -EINVAL;
6507
Johannes Berg79c97e92009-07-07 03:56:12 +02006508 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01006509
Ayala Bekercb3b7d82016-09-20 17:31:13 +03006510 if (wdev->iftype == NL80211_IFTYPE_NAN)
6511 return -EOPNOTSUPP;
6512
Johannes Berg4c476992010-10-04 21:36:35 +02006513 if (!rdev->ops->scan)
6514 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01006515
Johannes Bergf9d15d12014-01-22 11:14:19 +02006516 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01006517 err = -EBUSY;
6518 goto unlock;
6519 }
Johannes Berg2a519312009-02-10 21:25:55 +01006520
6521 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02006522 n_channels = validate_scan_freqs(
6523 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01006524 if (!n_channels) {
6525 err = -EINVAL;
6526 goto unlock;
6527 }
Johannes Berg2a519312009-02-10 21:25:55 +01006528 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006529 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01006530 }
6531
6532 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
6533 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
6534 n_ssids++;
6535
Johannes Bergf9f47522013-03-19 15:04:07 +01006536 if (n_ssids > wiphy->max_scan_ssids) {
6537 err = -EINVAL;
6538 goto unlock;
6539 }
Johannes Berg2a519312009-02-10 21:25:55 +01006540
Jouni Malinen70692ad2009-02-16 19:39:13 +02006541 if (info->attrs[NL80211_ATTR_IE])
6542 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6543 else
6544 ie_len = 0;
6545
Johannes Bergf9f47522013-03-19 15:04:07 +01006546 if (ie_len > wiphy->max_scan_ie_len) {
6547 err = -EINVAL;
6548 goto unlock;
6549 }
Johannes Berg18a83652009-03-31 12:12:05 +02006550
Johannes Berg2a519312009-02-10 21:25:55 +01006551 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006552 + sizeof(*request->ssids) * n_ssids
6553 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02006554 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01006555 if (!request) {
6556 err = -ENOMEM;
6557 goto unlock;
6558 }
Johannes Berg2a519312009-02-10 21:25:55 +01006559
Johannes Berg2a519312009-02-10 21:25:55 +01006560 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02006561 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01006562 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02006563 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006564 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02006565 request->ie = (void *)(request->ssids + n_ssids);
6566 else
6567 request->ie = (void *)(request->channels + n_channels);
6568 }
Johannes Berg2a519312009-02-10 21:25:55 +01006569
Johannes Berg584991d2009-11-02 13:32:03 +01006570 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006571 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
6572 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01006573 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01006574 struct ieee80211_channel *chan;
6575
6576 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6577
6578 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01006579 err = -EINVAL;
6580 goto out_free;
6581 }
Johannes Berg584991d2009-11-02 13:32:03 +01006582
6583 /* ignore disabled channels */
6584 if (chan->flags & IEEE80211_CHAN_DISABLED)
6585 continue;
6586
6587 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006588 i++;
6589 }
6590 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006591 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02006592
Johannes Berg2a519312009-02-10 21:25:55 +01006593 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02006594 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01006595 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07006596
Johannes Berg2a519312009-02-10 21:25:55 +01006597 if (!wiphy->bands[band])
6598 continue;
6599 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01006600 struct ieee80211_channel *chan;
6601
6602 chan = &wiphy->bands[band]->channels[j];
6603
6604 if (chan->flags & IEEE80211_CHAN_DISABLED)
6605 continue;
6606
6607 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01006608 i++;
6609 }
6610 }
6611 }
6612
Johannes Berg584991d2009-11-02 13:32:03 +01006613 if (!i) {
6614 err = -EINVAL;
6615 goto out_free;
6616 }
6617
6618 request->n_channels = i;
6619
Johannes Berg2a519312009-02-10 21:25:55 +01006620 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006621 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01006622 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006623 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01006624 err = -EINVAL;
6625 goto out_free;
6626 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006627 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01006628 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01006629 i++;
6630 }
6631 }
6632
Jouni Malinen70692ad2009-02-16 19:39:13 +02006633 if (info->attrs[NL80211_ATTR_IE]) {
6634 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02006635 memcpy((void *)request->ie,
6636 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02006637 request->ie_len);
6638 }
6639
Johannes Berg57fbcce2016-04-12 15:56:15 +02006640 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02006641 if (wiphy->bands[i])
6642 request->rates[i] =
6643 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02006644
6645 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
6646 nla_for_each_nested(attr,
6647 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
6648 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02006649 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02006650
Johannes Berg57fbcce2016-04-12 15:56:15 +02006651 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02006652 err = -EINVAL;
6653 goto out_free;
6654 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01006655
6656 if (!wiphy->bands[band])
6657 continue;
6658
Johannes Berg34850ab2011-07-18 18:08:35 +02006659 err = ieee80211_get_ratemask(wiphy->bands[band],
6660 nla_data(attr),
6661 nla_len(attr),
6662 &request->rates[band]);
6663 if (err)
6664 goto out_free;
6665 }
6666 }
6667
Avraham Stern1d762502016-07-05 17:10:13 +03006668 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
6669 if (!wiphy_ext_feature_isset(wiphy,
6670 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
6671 err = -EOPNOTSUPP;
6672 goto out_free;
6673 }
6674
6675 request->duration =
6676 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
6677 request->duration_mandatory =
6678 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
6679 }
6680
Sam Leffler46856bb2012-10-11 21:03:32 -07006681 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006682 request->flags = nla_get_u32(
6683 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006684 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6685 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006686 err = -EOPNOTSUPP;
6687 goto out_free;
6688 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006689
6690 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6691 if (!(wiphy->features &
6692 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
6693 err = -EOPNOTSUPP;
6694 goto out_free;
6695 }
6696
6697 if (wdev->current_bss) {
6698 err = -EOPNOTSUPP;
6699 goto out_free;
6700 }
6701
6702 err = nl80211_parse_random_mac(info->attrs,
6703 request->mac_addr,
6704 request->mac_addr_mask);
6705 if (err)
6706 goto out_free;
6707 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006708 }
Sam Lefflered4737712012-10-11 21:03:31 -07006709
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05306710 request->no_cck =
6711 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
6712
Jouni Malinen818965d2016-02-26 22:12:47 +02006713 if (info->attrs[NL80211_ATTR_MAC])
6714 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
6715 ETH_ALEN);
6716 else
6717 eth_broadcast_addr(request->bssid);
6718
Johannes Bergfd014282012-06-18 19:17:03 +02006719 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006720 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006721 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006722
Johannes Berg79c97e92009-07-07 03:56:12 +02006723 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006724 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006725
Johannes Berg463d0182009-07-14 00:33:35 +02006726 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006727 nl80211_send_scan_start(rdev, wdev);
6728 if (wdev->netdev)
6729 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006730 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006731 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006732 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006733 kfree(request);
6734 }
Johannes Berg3b858752009-03-12 09:55:09 +01006735
Johannes Bergf9f47522013-03-19 15:04:07 +01006736 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006737 return err;
6738}
6739
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306740static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6741{
6742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6743 struct wireless_dev *wdev = info->user_ptr[1];
6744
6745 if (!rdev->ops->abort_scan)
6746 return -EOPNOTSUPP;
6747
6748 if (rdev->scan_msg)
6749 return 0;
6750
6751 if (!rdev->scan_req)
6752 return -ENOENT;
6753
6754 rdev_abort_scan(rdev, wdev);
6755 return 0;
6756}
6757
Avraham Stern3b06d272015-10-12 09:51:34 +03006758static int
6759nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6760 struct cfg80211_sched_scan_request *request,
6761 struct nlattr **attrs)
6762{
6763 int tmp, err, i = 0;
6764 struct nlattr *attr;
6765
6766 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6767 u32 interval;
6768
6769 /*
6770 * If scan plans are not specified,
6771 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6772 * case one scan plan will be set with the specified scan
6773 * interval and infinite number of iterations.
6774 */
6775 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6776 return -EINVAL;
6777
6778 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6779 if (!interval)
6780 return -EINVAL;
6781
6782 request->scan_plans[0].interval =
6783 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6784 if (!request->scan_plans[0].interval)
6785 return -EINVAL;
6786
6787 if (request->scan_plans[0].interval >
6788 wiphy->max_sched_scan_plan_interval)
6789 request->scan_plans[0].interval =
6790 wiphy->max_sched_scan_plan_interval;
6791
6792 return 0;
6793 }
6794
6795 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6796 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6797
6798 if (WARN_ON(i >= n_plans))
6799 return -EINVAL;
6800
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006801 err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6802 attr, nl80211_plan_policy);
Avraham Stern3b06d272015-10-12 09:51:34 +03006803 if (err)
6804 return err;
6805
6806 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6807 return -EINVAL;
6808
6809 request->scan_plans[i].interval =
6810 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6811 if (!request->scan_plans[i].interval ||
6812 request->scan_plans[i].interval >
6813 wiphy->max_sched_scan_plan_interval)
6814 return -EINVAL;
6815
6816 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6817 request->scan_plans[i].iterations =
6818 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6819 if (!request->scan_plans[i].iterations ||
6820 (request->scan_plans[i].iterations >
6821 wiphy->max_sched_scan_plan_iterations))
6822 return -EINVAL;
6823 } else if (i < n_plans - 1) {
6824 /*
6825 * All scan plans but the last one must specify
6826 * a finite number of iterations
6827 */
6828 return -EINVAL;
6829 }
6830
6831 i++;
6832 }
6833
6834 /*
6835 * The last scan plan must not specify the number of
6836 * iterations, it is supposed to run infinitely
6837 */
6838 if (request->scan_plans[n_plans - 1].iterations)
6839 return -EINVAL;
6840
6841 return 0;
6842}
6843
Luciano Coelho256da022014-11-10 16:13:46 +02006844static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006845nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006846 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006847{
6848 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006849 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006850 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02006851 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006852 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006853 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006854 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006855
Luciano Coelho256da022014-11-10 16:13:46 +02006856 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6857 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006858
Luciano Coelho256da022014-11-10 16:13:46 +02006859 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006860 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006861 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006862 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006863 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006864 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006865 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006866 }
6867
Luciano Coelho256da022014-11-10 16:13:46 +02006868 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6869 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006870 tmp)
6871 n_ssids++;
6872
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006873 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006874 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006875
Johannes Bergea73cbc2014-01-24 10:53:53 +01006876 /*
6877 * First, count the number of 'real' matchsets. Due to an issue with
6878 * the old implementation, matchsets containing only the RSSI attribute
6879 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6880 * RSSI for all matchsets, rather than their own matchset for reporting
6881 * all APs with a strong RSSI. This is needed to be compatible with
6882 * older userspace that treated a matchset with only the RSSI as the
6883 * global RSSI for all other matchsets - if there are other matchsets.
6884 */
Luciano Coelho256da022014-11-10 16:13:46 +02006885 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006886 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006887 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006888 tmp) {
6889 struct nlattr *rssi;
6890
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02006891 err = nla_parse_nested(tb,
6892 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6893 attr, nl80211_match_policy);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006894 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006895 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006896 /* add other standalone attributes here */
6897 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6898 n_match_sets++;
6899 continue;
6900 }
6901 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6902 if (rssi)
6903 default_match_rssi = nla_get_s32(rssi);
6904 }
6905 }
6906
6907 /* However, if there's no other matchset, add the RSSI one */
6908 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6909 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006910
6911 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006912 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006913
Luciano Coelho256da022014-11-10 16:13:46 +02006914 if (attrs[NL80211_ATTR_IE])
6915 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006916 else
6917 ie_len = 0;
6918
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006919 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006920 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006921
Avraham Stern3b06d272015-10-12 09:51:34 +03006922 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6923 /*
6924 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6925 * each scan plan already specifies its own interval
6926 */
6927 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6928 return ERR_PTR(-EINVAL);
6929
6930 nla_for_each_nested(attr,
6931 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6932 n_plans++;
6933 } else {
6934 /*
6935 * The scan interval attribute is kept for backward
6936 * compatibility. If no scan plans are specified and sched scan
6937 * interval is specified, one scan plan will be set with this
6938 * scan interval and infinite number of iterations.
6939 */
6940 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6941 return ERR_PTR(-EINVAL);
6942
6943 n_plans = 1;
6944 }
6945
6946 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6947 return ERR_PTR(-EINVAL);
6948
Luciano Coelho807f8a82011-05-11 17:09:35 +03006949 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006950 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006951 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006952 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006953 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006954 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006955 if (!request)
6956 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006957
6958 if (n_ssids)
6959 request->ssids = (void *)&request->channels[n_channels];
6960 request->n_ssids = n_ssids;
6961 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006962 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006963 request->ie = (void *)(request->ssids + n_ssids);
6964 else
6965 request->ie = (void *)(request->channels + n_channels);
6966 }
6967
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006968 if (n_match_sets) {
6969 if (request->ie)
6970 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006971 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006972 request->match_sets =
6973 (void *)(request->ssids + n_ssids);
6974 else
6975 request->match_sets =
6976 (void *)(request->channels + n_channels);
6977 }
6978 request->n_match_sets = n_match_sets;
6979
Avraham Stern3b06d272015-10-12 09:51:34 +03006980 if (n_match_sets)
6981 request->scan_plans = (void *)(request->match_sets +
6982 n_match_sets);
6983 else if (request->ie)
6984 request->scan_plans = (void *)(request->ie + ie_len);
6985 else if (n_ssids)
6986 request->scan_plans = (void *)(request->ssids + n_ssids);
6987 else
6988 request->scan_plans = (void *)(request->channels + n_channels);
6989
6990 request->n_scan_plans = n_plans;
6991
Luciano Coelho807f8a82011-05-11 17:09:35 +03006992 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006993 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006994 /* user specified, bail out if channel not found */
6995 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006996 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006997 tmp) {
6998 struct ieee80211_channel *chan;
6999
7000 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7001
7002 if (!chan) {
7003 err = -EINVAL;
7004 goto out_free;
7005 }
7006
7007 /* ignore disabled channels */
7008 if (chan->flags & IEEE80211_CHAN_DISABLED)
7009 continue;
7010
7011 request->channels[i] = chan;
7012 i++;
7013 }
7014 } else {
7015 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007016 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007017 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007018
Luciano Coelho807f8a82011-05-11 17:09:35 +03007019 if (!wiphy->bands[band])
7020 continue;
7021 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
7022 struct ieee80211_channel *chan;
7023
7024 chan = &wiphy->bands[band]->channels[j];
7025
7026 if (chan->flags & IEEE80211_CHAN_DISABLED)
7027 continue;
7028
7029 request->channels[i] = chan;
7030 i++;
7031 }
7032 }
7033 }
7034
7035 if (!i) {
7036 err = -EINVAL;
7037 goto out_free;
7038 }
7039
7040 request->n_channels = i;
7041
7042 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007043 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02007044 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03007045 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007046 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03007047 err = -EINVAL;
7048 goto out_free;
7049 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007050 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007051 memcpy(request->ssids[i].ssid, nla_data(attr),
7052 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03007053 i++;
7054 }
7055 }
7056
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007057 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02007058 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007059 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02007060 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007061 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07007062 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007063
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02007064 err = nla_parse_nested(tb,
7065 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
7066 attr, nl80211_match_policy);
Johannes Bergae811e22014-01-24 10:17:47 +01007067 if (err)
7068 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02007069 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007070 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01007071 if (WARN_ON(i >= n_match_sets)) {
7072 /* this indicates a programming error,
7073 * the loop above should have verified
7074 * things properly
7075 */
7076 err = -EINVAL;
7077 goto out_free;
7078 }
7079
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007080 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
7081 err = -EINVAL;
7082 goto out_free;
7083 }
7084 memcpy(request->match_sets[i].ssid.ssid,
7085 nla_data(ssid), nla_len(ssid));
7086 request->match_sets[i].ssid.ssid_len =
7087 nla_len(ssid);
Kirtika Ruchandani56ab3642016-05-29 19:54:10 -07007088 /* special attribute - old implementation w/a */
Johannes Bergea73cbc2014-01-24 10:53:53 +01007089 request->match_sets[i].rssi_thold =
7090 default_match_rssi;
7091 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
7092 if (rssi)
7093 request->match_sets[i].rssi_thold =
7094 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007095 }
7096 i++;
7097 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01007098
7099 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02007100 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01007101 request->match_sets[0].rssi_thold = default_match_rssi;
7102
7103 request->min_rssi_thold = INT_MAX;
7104 for (i = 0; i < n_match_sets; i++)
7105 request->min_rssi_thold =
7106 min(request->match_sets[i].rssi_thold,
7107 request->min_rssi_thold);
7108 } else {
7109 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03007110 }
7111
Johannes Berg9900e482014-02-04 21:01:25 +01007112 if (ie_len) {
7113 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007114 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02007115 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03007116 request->ie_len);
7117 }
7118
Luciano Coelho256da022014-11-10 16:13:46 +02007119 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07007120 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02007121 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02007122 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7123 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07007124 err = -EOPNOTSUPP;
7125 goto out_free;
7126 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02007127
7128 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7129 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
7130
7131 if (!wdev) /* must be net-detect */
7132 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7133
7134 if (!(wiphy->features & flg)) {
7135 err = -EOPNOTSUPP;
7136 goto out_free;
7137 }
7138
7139 if (wdev && wdev->current_bss) {
7140 err = -EOPNOTSUPP;
7141 goto out_free;
7142 }
7143
7144 err = nl80211_parse_random_mac(attrs, request->mac_addr,
7145 request->mac_addr_mask);
7146 if (err)
7147 goto out_free;
7148 }
Sam Leffler46856bb2012-10-11 21:03:32 -07007149 }
Sam Lefflered4737712012-10-11 21:03:31 -07007150
Luciano Coelho9c748932015-01-16 16:04:09 +02007151 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
7152 request->delay =
7153 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
7154
Avraham Stern3b06d272015-10-12 09:51:34 +03007155 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
7156 if (err)
7157 goto out_free;
7158
Sam Leffler15d60302012-10-11 21:03:34 -07007159 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007160
Luciano Coelho256da022014-11-10 16:13:46 +02007161 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03007162
7163out_free:
7164 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02007165 return ERR_PTR(err);
7166}
7167
7168static int nl80211_start_sched_scan(struct sk_buff *skb,
7169 struct genl_info *info)
7170{
7171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7172 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02007173 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007174 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02007175 int err;
7176
7177 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7178 !rdev->ops->sched_scan_start)
7179 return -EOPNOTSUPP;
7180
7181 if (rdev->sched_scan_req)
7182 return -EINPROGRESS;
7183
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007184 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
7185 info->attrs);
7186
7187 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007188 if (err)
7189 goto out_err;
7190
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007191 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007192 if (err)
7193 goto out_free;
7194
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007195 sched_scan_req->dev = dev;
7196 sched_scan_req->wiphy = &rdev->wiphy;
7197
Jukka Rissanen93a1e862014-12-15 13:25:39 +02007198 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
7199 sched_scan_req->owner_nlportid = info->snd_portid;
7200
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007201 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007202
7203 nl80211_send_sched_scan(rdev, dev,
7204 NL80211_CMD_START_SCHED_SCAN);
7205 return 0;
7206
7207out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02007208 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02007209out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03007210 return err;
7211}
7212
7213static int nl80211_stop_sched_scan(struct sk_buff *skb,
7214 struct genl_info *info)
7215{
7216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7217
7218 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
7219 !rdev->ops->sched_scan_stop)
7220 return -EOPNOTSUPP;
7221
Johannes Berg5fe231e2013-05-08 21:45:15 +02007222 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03007223}
7224
Simon Wunderlich04f39042013-02-08 18:16:19 +01007225static int nl80211_start_radar_detection(struct sk_buff *skb,
7226 struct genl_info *info)
7227{
7228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7229 struct net_device *dev = info->user_ptr[1];
7230 struct wireless_dev *wdev = dev->ieee80211_ptr;
7231 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007232 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007233 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007234 int err;
7235
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01007236 dfs_region = reg_get_dfs_region(wdev->wiphy);
7237 if (dfs_region == NL80211_DFS_UNSET)
7238 return -EINVAL;
7239
Simon Wunderlich04f39042013-02-08 18:16:19 +01007240 err = nl80211_parse_chandef(rdev, info, &chandef);
7241 if (err)
7242 return err;
7243
Simon Wunderlichff311bc2013-09-03 19:43:18 +02007244 if (netif_carrier_ok(dev))
7245 return -EBUSY;
7246
Simon Wunderlich04f39042013-02-08 18:16:19 +01007247 if (wdev->cac_started)
7248 return -EBUSY;
7249
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007250 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03007251 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007252 if (err < 0)
7253 return err;
7254
7255 if (err == 0)
7256 return -EINVAL;
7257
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01007258 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01007259 return -EINVAL;
7260
7261 if (!rdev->ops->start_radar_detection)
7262 return -EOPNOTSUPP;
7263
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007264 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
7265 if (WARN_ON(!cac_time_ms))
7266 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
7267
Ilan Peera1056b1b2015-10-22 22:27:46 +03007268 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01007269 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01007270 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007271 wdev->cac_started = true;
7272 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01007273 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01007274 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01007275 return err;
7276}
7277
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007278static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
7279{
7280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7281 struct net_device *dev = info->user_ptr[1];
7282 struct wireless_dev *wdev = dev->ieee80211_ptr;
7283 struct cfg80211_csa_settings params;
7284 /* csa_attrs is defined static to avoid waste of stack size - this
7285 * function is called under RTNL lock, so this should not be a problem.
7286 */
7287 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007288 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007289 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007290 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03007291 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007292
7293 if (!rdev->ops->channel_switch ||
7294 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
7295 return -EOPNOTSUPP;
7296
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007297 switch (dev->ieee80211_ptr->iftype) {
7298 case NL80211_IFTYPE_AP:
7299 case NL80211_IFTYPE_P2P_GO:
7300 need_new_beacon = true;
7301
7302 /* useless if AP is not running */
7303 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01007304 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007305 break;
7306 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007307 if (!wdev->ssid_len)
7308 return -ENOTCONN;
7309 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07007310 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01007311 if (!wdev->mesh_id_len)
7312 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007313 break;
7314 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007315 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007316 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007317
7318 memset(&params, 0, sizeof(params));
7319
7320 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7321 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
7322 return -EINVAL;
7323
7324 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02007325 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007326 return -EINVAL;
7327
Luciano Coelho252e07c2014-10-08 09:48:34 +03007328 /* Even though the attribute is u32, the specification says
7329 * u8, so let's make sure we don't overflow.
7330 */
7331 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
7332 if (cs_count > 255)
7333 return -EINVAL;
7334
7335 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007336
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007337 if (!need_new_beacon)
7338 goto skip_beacons;
7339
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007340 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
7341 if (err)
7342 return err;
7343
7344 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
7345 info->attrs[NL80211_ATTR_CSA_IES],
7346 nl80211_policy);
7347 if (err)
7348 return err;
7349
7350 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
7351 if (err)
7352 return err;
7353
7354 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
7355 return -EINVAL;
7356
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007357 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7358 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007359 return -EINVAL;
7360
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007361 params.n_counter_offsets_beacon = len / sizeof(u16);
7362 if (rdev->wiphy.max_num_csa_counters &&
7363 (params.n_counter_offsets_beacon >
7364 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007365 return -EINVAL;
7366
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007367 params.counter_offsets_beacon =
7368 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
7369
7370 /* sanity checks - counters should fit and be the same */
7371 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
7372 u16 offset = params.counter_offsets_beacon[i];
7373
7374 if (offset >= params.beacon_csa.tail_len)
7375 return -EINVAL;
7376
7377 if (params.beacon_csa.tail[offset] != params.count)
7378 return -EINVAL;
7379 }
7380
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007381 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007382 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7383 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007384 return -EINVAL;
7385
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007386 params.n_counter_offsets_presp = len / sizeof(u16);
7387 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02007388 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007389 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007390 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03007391
7392 params.counter_offsets_presp =
7393 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
7394
7395 /* sanity checks - counters should fit and be the same */
7396 for (i = 0; i < params.n_counter_offsets_presp; i++) {
7397 u16 offset = params.counter_offsets_presp[i];
7398
7399 if (offset >= params.beacon_csa.probe_resp_len)
7400 return -EINVAL;
7401
7402 if (params.beacon_csa.probe_resp[offset] !=
7403 params.count)
7404 return -EINVAL;
7405 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007406 }
7407
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02007408skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007409 err = nl80211_parse_chandef(rdev, info, &params.chandef);
7410 if (err)
7411 return err;
7412
Arik Nemtsov923b3522015-07-08 15:41:44 +03007413 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
7414 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007415 return -EINVAL;
7416
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007417 err = cfg80211_chandef_dfs_required(wdev->wiphy,
7418 &params.chandef,
7419 wdev->iftype);
7420 if (err < 0)
7421 return err;
7422
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02007423 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02007424 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007425
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007426 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
7427 params.block_tx = true;
7428
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007429 wdev_lock(wdev);
7430 err = rdev_channel_switch(rdev, dev, &params);
7431 wdev_unlock(wdev);
7432
7433 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02007434}
7435
Johannes Berg9720bb32011-06-21 09:45:33 +02007436static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
7437 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007438 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02007439 struct wireless_dev *wdev,
7440 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01007441{
Johannes Berg48ab9052009-07-10 18:42:31 +02007442 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01007443 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01007444 void *hdr;
7445 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02007446
7447 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007448
Eric W. Biederman15e47302012-09-07 20:12:54 +00007449 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01007450 NL80211_CMD_NEW_SCAN_RESULTS);
7451 if (!hdr)
7452 return -1;
7453
Johannes Berg9720bb32011-06-21 09:45:33 +02007454 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
7455
Johannes Berg97990a02013-04-19 01:02:55 +02007456 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
7457 goto nla_put_failure;
7458 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007459 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
7460 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007461 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
7462 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02007463 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007464
7465 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
7466 if (!bss)
7467 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007468 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01007469 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04007470 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01007471
7472 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02007473 /* indicate whether we have probe response data or not */
7474 if (rcu_access_pointer(res->proberesp_ies) &&
7475 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
7476 goto fail_unlock_rcu;
7477
7478 /* this pointer prefers to be pointed to probe response data
7479 * but is always valid
7480 */
Johannes Berg9caf0362012-11-29 01:25:20 +01007481 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01007482 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007483 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
7484 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007485 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01007486 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
7487 ies->len, ies->data))
7488 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007489 }
Johannes Berg0e227082014-08-12 20:34:30 +02007490
7491 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01007492 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02007493 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007494 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
7495 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01007496 goto fail_unlock_rcu;
7497 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
7498 ies->len, ies->data))
7499 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01007500 }
7501 rcu_read_unlock();
7502
David S. Miller9360ffd2012-03-29 04:41:26 -04007503 if (res->beacon_interval &&
7504 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
7505 goto nla_put_failure;
7506 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
7507 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02007508 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007509 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
7510 jiffies_to_msecs(jiffies - intbss->ts)))
7511 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007512
Avraham Stern1d762502016-07-05 17:10:13 +03007513 if (intbss->parent_tsf &&
7514 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
7515 intbss->parent_tsf, NL80211_BSS_PAD) ||
7516 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
7517 intbss->parent_bssid)))
7518 goto nla_put_failure;
7519
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007520 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007521 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
7522 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02007523 goto nla_put_failure;
7524
Johannes Berg77965c92009-02-18 18:45:06 +01007525 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01007526 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04007527 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
7528 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007529 break;
7530 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007531 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
7532 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01007533 break;
7534 default:
7535 break;
7536 }
7537
Johannes Berg48ab9052009-07-10 18:42:31 +02007538 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02007539 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02007540 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04007541 if (intbss == wdev->current_bss &&
7542 nla_put_u32(msg, NL80211_BSS_STATUS,
7543 NL80211_BSS_STATUS_ASSOCIATED))
7544 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007545 break;
7546 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04007547 if (intbss == wdev->current_bss &&
7548 nla_put_u32(msg, NL80211_BSS_STATUS,
7549 NL80211_BSS_STATUS_IBSS_JOINED))
7550 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02007551 break;
7552 default:
7553 break;
7554 }
7555
Johannes Berg2a519312009-02-10 21:25:55 +01007556 nla_nest_end(msg, bss);
7557
Johannes Berg053c0952015-01-16 22:09:00 +01007558 genlmsg_end(msg, hdr);
7559 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007560
Johannes Berg8cef2c92013-02-05 16:54:31 +01007561 fail_unlock_rcu:
7562 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01007563 nla_put_failure:
7564 genlmsg_cancel(msg, hdr);
7565 return -EMSGSIZE;
7566}
7567
Johannes Berg97990a02013-04-19 01:02:55 +02007568static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01007569{
Johannes Berg48ab9052009-07-10 18:42:31 +02007570 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01007571 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02007572 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007573 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007574 int err;
7575
Johannes Berg97990a02013-04-19 01:02:55 +02007576 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007577 if (err)
7578 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01007579
Johannes Berg48ab9052009-07-10 18:42:31 +02007580 wdev_lock(wdev);
7581 spin_lock_bh(&rdev->bss_lock);
7582 cfg80211_bss_expire(rdev);
7583
Johannes Berg9720bb32011-06-21 09:45:33 +02007584 cb->seq = rdev->bss_generation;
7585
Johannes Berg48ab9052009-07-10 18:42:31 +02007586 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01007587 if (++idx <= start)
7588 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02007589 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01007590 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02007591 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01007592 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02007593 break;
Johannes Berg2a519312009-02-10 21:25:55 +01007594 }
7595 }
7596
Johannes Berg48ab9052009-07-10 18:42:31 +02007597 spin_unlock_bh(&rdev->bss_lock);
7598 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007599
Johannes Berg97990a02013-04-19 01:02:55 +02007600 cb->args[2] = idx;
7601 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01007602
Johannes Berg67748892010-10-04 21:14:06 +02007603 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01007604}
7605
Eric W. Biederman15e47302012-09-07 20:12:54 +00007606static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007607 int flags, struct net_device *dev,
7608 bool allow_radio_stats,
7609 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01007610{
7611 void *hdr;
7612 struct nlattr *infoattr;
7613
Johannes Berg11f78ac2014-11-14 16:43:50 +01007614 /* skip radio stats if userspace didn't request them */
7615 if (!survey->channel && !allow_radio_stats)
7616 return 0;
7617
Eric W. Biederman15e47302012-09-07 20:12:54 +00007618 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01007619 NL80211_CMD_NEW_SURVEY_RESULTS);
7620 if (!hdr)
7621 return -ENOMEM;
7622
David S. Miller9360ffd2012-03-29 04:41:26 -04007623 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
7624 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007625
7626 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
7627 if (!infoattr)
7628 goto nla_put_failure;
7629
Johannes Berg11f78ac2014-11-14 16:43:50 +01007630 if (survey->channel &&
7631 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04007632 survey->channel->center_freq))
7633 goto nla_put_failure;
7634
7635 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
7636 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
7637 goto nla_put_failure;
7638 if ((survey->filled & SURVEY_INFO_IN_USE) &&
7639 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
7640 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007641 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007642 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
7643 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007644 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007645 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007646 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
7647 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007648 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007649 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007650 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
7651 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007652 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007653 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007654 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
7655 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007656 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01007657 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007658 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
7659 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04007660 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01007661 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02007662 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
7663 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01007664 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01007665
7666 nla_nest_end(msg, infoattr);
7667
Johannes Berg053c0952015-01-16 22:09:00 +01007668 genlmsg_end(msg, hdr);
7669 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01007670
7671 nla_put_failure:
7672 genlmsg_cancel(msg, hdr);
7673 return -EMSGSIZE;
7674}
7675
Johannes Berg11f78ac2014-11-14 16:43:50 +01007676static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01007677{
7678 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007679 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02007680 struct wireless_dev *wdev;
7681 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01007682 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01007683 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01007684
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007685 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02007686 if (res)
7687 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01007688
Johannes Berg11f78ac2014-11-14 16:43:50 +01007689 /* prepare_wdev_dump parsed the attributes */
7690 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
7691
Johannes Berg97990a02013-04-19 01:02:55 +02007692 if (!wdev->netdev) {
7693 res = -EINVAL;
7694 goto out_err;
7695 }
7696
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007697 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01007698 res = -EOPNOTSUPP;
7699 goto out_err;
7700 }
7701
7702 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007703 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01007704 if (res == -ENOENT)
7705 break;
7706 if (res)
7707 goto out_err;
7708
Johannes Berg11f78ac2014-11-14 16:43:50 +01007709 /* don't send disabled channels, but do send non-channel data */
7710 if (survey.channel &&
7711 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07007712 survey_idx++;
7713 continue;
7714 }
7715
Holger Schurig61fa7132009-11-11 12:25:40 +01007716 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00007717 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01007718 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01007719 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01007720 goto out;
7721 survey_idx++;
7722 }
7723
7724 out:
Johannes Berg97990a02013-04-19 01:02:55 +02007725 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01007726 res = skb->len;
7727 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08007728 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01007729 return res;
7730}
7731
Samuel Ortizb23aa672009-07-01 21:26:54 +02007732static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7733{
7734 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7735 NL80211_WPA_VERSION_2));
7736}
7737
Jouni Malinen636a5d32009-03-19 13:39:22 +02007738static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7739{
Johannes Berg4c476992010-10-04 21:36:35 +02007740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7741 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007742 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007743 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
7744 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007745 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007746 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007747 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007748
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007749 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7750 return -EINVAL;
7751
7752 if (!info->attrs[NL80211_ATTR_MAC])
7753 return -EINVAL;
7754
Jouni Malinen17780922009-03-27 20:52:47 +02007755 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7756 return -EINVAL;
7757
Johannes Berg19957bb2009-07-02 17:20:43 +02007758 if (!info->attrs[NL80211_ATTR_SSID])
7759 return -EINVAL;
7760
7761 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7762 return -EINVAL;
7763
Johannes Bergfffd0932009-07-08 14:22:54 +02007764 err = nl80211_parse_key(info, &key);
7765 if (err)
7766 return err;
7767
7768 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007769 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7770 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007771 if (!key.p.key || !key.p.key_len)
7772 return -EINVAL;
7773 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7774 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7775 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7776 key.p.key_len != WLAN_KEY_LEN_WEP104))
7777 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02007778 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02007779 return -EINVAL;
7780 } else {
7781 key.p.key_len = 0;
7782 key.p.key = NULL;
7783 }
7784
Johannes Bergafea0b72010-08-10 09:46:42 +02007785 if (key.idx >= 0) {
7786 int i;
7787 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007788
Johannes Bergafea0b72010-08-10 09:46:42 +02007789 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7790 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7791 ok = true;
7792 break;
7793 }
7794 }
Johannes Berg4c476992010-10-04 21:36:35 +02007795 if (!ok)
7796 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007797 }
7798
Johannes Berg4c476992010-10-04 21:36:35 +02007799 if (!rdev->ops->auth)
7800 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007801
Johannes Berg074ac8d2010-09-16 14:58:22 +02007802 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007803 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7804 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007805
Johannes Berg19957bb2009-07-02 17:20:43 +02007806 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007807 chan = nl80211_get_valid_chan(&rdev->wiphy,
7808 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7809 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007810 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007811
Johannes Berg19957bb2009-07-02 17:20:43 +02007812 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7813 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7814
7815 if (info->attrs[NL80211_ATTR_IE]) {
7816 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7817 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7818 }
7819
7820 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007821 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007822 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007823
Jouni Malinen63181062016-10-27 00:42:02 +03007824 if ((auth_type == NL80211_AUTHTYPE_SAE ||
7825 auth_type == NL80211_AUTHTYPE_FILS_SK ||
7826 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
7827 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007828 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03007829 return -EINVAL;
7830
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007831 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03007832 if (auth_type != NL80211_AUTHTYPE_SAE &&
7833 auth_type != NL80211_AUTHTYPE_FILS_SK &&
7834 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
7835 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007836 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007837 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
7838 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007839 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007840 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03007841 return -EINVAL;
7842 }
7843
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007844 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7845
Johannes Berg95de8172012-01-20 13:55:25 +01007846 /*
7847 * Since we no longer track auth state, ignore
7848 * requests to only change local state.
7849 */
7850 if (local_state_change)
7851 return 0;
7852
Johannes Berg91bf9b22013-05-15 17:44:01 +02007853 wdev_lock(dev->ieee80211_ptr);
7854 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7855 ssid, ssid_len, ie, ie_len,
7856 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03007857 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007858 wdev_unlock(dev->ieee80211_ptr);
7859 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007860}
7861
Johannes Bergc0692b82010-08-27 14:26:53 +03007862static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7863 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007864 struct cfg80211_crypto_settings *settings,
7865 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007866{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007867 memset(settings, 0, sizeof(*settings));
7868
Samuel Ortizb23aa672009-07-01 21:26:54 +02007869 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7870
Johannes Bergc0692b82010-08-27 14:26:53 +03007871 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7872 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007873
Johannes Bergc0692b82010-08-27 14:26:53 +03007874 proto = nla_get_u16(
7875 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7876 settings->control_port_ethertype = cpu_to_be16(proto);
7877 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7878 proto != ETH_P_PAE)
7879 return -EINVAL;
7880 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7881 settings->control_port_no_encrypt = true;
7882 } else
7883 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7884
Samuel Ortizb23aa672009-07-01 21:26:54 +02007885 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7886 void *data;
7887 int len, i;
7888
7889 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7890 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7891 settings->n_ciphers_pairwise = len / sizeof(u32);
7892
7893 if (len % sizeof(u32))
7894 return -EINVAL;
7895
Johannes Berg3dc27d22009-07-02 21:36:37 +02007896 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007897 return -EINVAL;
7898
7899 memcpy(settings->ciphers_pairwise, data, len);
7900
7901 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007902 if (!cfg80211_supported_cipher_suite(
7903 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007904 settings->ciphers_pairwise[i]))
7905 return -EINVAL;
7906 }
7907
7908 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7909 settings->cipher_group =
7910 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007911 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7912 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007913 return -EINVAL;
7914 }
7915
7916 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7917 settings->wpa_versions =
7918 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7919 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7920 return -EINVAL;
7921 }
7922
7923 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7924 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007925 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007926
7927 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7928 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7929 settings->n_akm_suites = len / sizeof(u32);
7930
7931 if (len % sizeof(u32))
7932 return -EINVAL;
7933
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007934 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7935 return -EINVAL;
7936
Samuel Ortizb23aa672009-07-01 21:26:54 +02007937 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007938 }
7939
7940 return 0;
7941}
7942
Jouni Malinen636a5d32009-03-19 13:39:22 +02007943static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7944{
Johannes Berg4c476992010-10-04 21:36:35 +02007945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7946 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007947 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007948 struct cfg80211_assoc_request req = {};
7949 const u8 *bssid, *ssid;
7950 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007951
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007952 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7953 return -EINVAL;
7954
7955 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007956 !info->attrs[NL80211_ATTR_SSID] ||
7957 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007958 return -EINVAL;
7959
Johannes Berg4c476992010-10-04 21:36:35 +02007960 if (!rdev->ops->assoc)
7961 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007962
Johannes Berg074ac8d2010-09-16 14:58:22 +02007963 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7965 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007966
Johannes Berg19957bb2009-07-02 17:20:43 +02007967 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007968
Jouni Malinen664834d2014-01-15 00:01:44 +02007969 chan = nl80211_get_valid_chan(&rdev->wiphy,
7970 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7971 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007972 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007973
Johannes Berg19957bb2009-07-02 17:20:43 +02007974 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7975 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007976
7977 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007978 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7979 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007980 }
7981
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007982 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007983 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007984 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007985 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007986 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007987 else if (mfp != NL80211_MFP_NO)
7988 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007989 }
7990
Johannes Berg3e5d7642009-07-07 14:37:26 +02007991 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007992 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007993
Ben Greear7e7c8922011-11-18 11:31:59 -08007994 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007995 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007996
7997 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007998 memcpy(&req.ht_capa_mask,
7999 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8000 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08008001
8002 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008003 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08008004 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008005 memcpy(&req.ht_capa,
8006 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8007 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08008008 }
8009
Johannes Bergee2aca32013-02-21 17:36:01 +01008010 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01008011 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01008012
8013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01008014 memcpy(&req.vht_capa_mask,
8015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8016 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01008017
8018 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01008019 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01008020 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01008021 memcpy(&req.vht_capa,
8022 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8023 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01008024 }
8025
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008026 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008027 if (!((rdev->wiphy.features &
8028 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8029 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8030 !wiphy_ext_feature_isset(&rdev->wiphy,
8031 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008032 return -EINVAL;
8033 req.flags |= ASSOC_REQ_USE_RRM;
8034 }
8035
Johannes Bergf62fab72013-02-21 20:09:09 +01008036 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008037 if (!err) {
8038 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01008039 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
8040 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02008041 wdev_unlock(dev->ieee80211_ptr);
8042 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008043
Jouni Malinen636a5d32009-03-19 13:39:22 +02008044 return err;
8045}
8046
8047static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
8048{
Johannes Berg4c476992010-10-04 21:36:35 +02008049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8050 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008051 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008052 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008053 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008054 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008055
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008056 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8057 return -EINVAL;
8058
8059 if (!info->attrs[NL80211_ATTR_MAC])
8060 return -EINVAL;
8061
8062 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8063 return -EINVAL;
8064
Johannes Berg4c476992010-10-04 21:36:35 +02008065 if (!rdev->ops->deauth)
8066 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008067
Johannes Berg074ac8d2010-09-16 14:58:22 +02008068 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008069 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8070 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008071
Johannes Berg19957bb2009-07-02 17:20:43 +02008072 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008073
Johannes Berg19957bb2009-07-02 17:20:43 +02008074 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8075 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008076 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008077 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008078 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008079
8080 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008081 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8082 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008083 }
8084
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008085 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8086
Johannes Berg91bf9b22013-05-15 17:44:01 +02008087 wdev_lock(dev->ieee80211_ptr);
8088 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
8089 local_state_change);
8090 wdev_unlock(dev->ieee80211_ptr);
8091 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008092}
8093
8094static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
8095{
Johannes Berg4c476992010-10-04 21:36:35 +02008096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8097 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02008098 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02008099 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02008100 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008101 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008102
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008103 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8104 return -EINVAL;
8105
8106 if (!info->attrs[NL80211_ATTR_MAC])
8107 return -EINVAL;
8108
8109 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8110 return -EINVAL;
8111
Johannes Berg4c476992010-10-04 21:36:35 +02008112 if (!rdev->ops->disassoc)
8113 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008114
Johannes Berg074ac8d2010-09-16 14:58:22 +02008115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008116 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8117 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02008118
Johannes Berg19957bb2009-07-02 17:20:43 +02008119 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008120
Johannes Berg19957bb2009-07-02 17:20:43 +02008121 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8122 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01008123 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02008124 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02008125 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02008126
8127 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02008128 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8129 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02008130 }
8131
Jouni Malinend5cdfac2010-04-04 09:37:19 +03008132 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
8133
Johannes Berg91bf9b22013-05-15 17:44:01 +02008134 wdev_lock(dev->ieee80211_ptr);
8135 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
8136 local_state_change);
8137 wdev_unlock(dev->ieee80211_ptr);
8138 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02008139}
8140
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008141static bool
8142nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02008143 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008144 int rateval)
8145{
8146 struct wiphy *wiphy = &rdev->wiphy;
8147 bool found = false;
8148 int band, i;
8149
Johannes Berg57fbcce2016-04-12 15:56:15 +02008150 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008151 struct ieee80211_supported_band *sband;
8152
8153 sband = wiphy->bands[band];
8154 if (!sband)
8155 continue;
8156
8157 for (i = 0; i < sband->n_bitrates; i++) {
8158 if (sband->bitrates[i].bitrate == rateval) {
8159 mcast_rate[band] = i + 1;
8160 found = true;
8161 break;
8162 }
8163 }
8164 }
8165
8166 return found;
8167}
8168
Johannes Berg04a773a2009-04-19 21:24:32 +02008169static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
8170{
Johannes Berg4c476992010-10-04 21:36:35 +02008171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8172 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008173 struct cfg80211_ibss_params ibss;
8174 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008175 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02008176 int err;
8177
Johannes Berg8e30bc52009-04-22 17:45:38 +02008178 memset(&ibss, 0, sizeof(ibss));
8179
Johannes Berg04a773a2009-04-19 21:24:32 +02008180 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8181 return -EINVAL;
8182
Johannes Berg683b6d32012-11-08 21:25:48 +01008183 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02008184 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8185 return -EINVAL;
8186
Johannes Berg8e30bc52009-04-22 17:45:38 +02008187 ibss.beacon_interval = 100;
8188
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308189 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02008190 ibss.beacon_interval =
8191 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308192
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05308193 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
8194 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05308195 if (err)
8196 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02008197
Johannes Berg4c476992010-10-04 21:36:35 +02008198 if (!rdev->ops->join_ibss)
8199 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008200
Johannes Berg4c476992010-10-04 21:36:35 +02008201 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8202 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008203
Johannes Berg79c97e92009-07-07 03:56:12 +02008204 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02008205
Johannes Berg39193492011-09-16 13:45:25 +02008206 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02008207 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02008208
8209 if (!is_valid_ether_addr(ibss.bssid))
8210 return -EINVAL;
8211 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008212 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8213 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8214
8215 if (info->attrs[NL80211_ATTR_IE]) {
8216 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8217 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8218 }
8219
Johannes Berg683b6d32012-11-08 21:25:48 +01008220 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
8221 if (err)
8222 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008223
Ilan Peer174e0cd2014-02-23 09:13:01 +02008224 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
8225 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01008226 return -EINVAL;
8227
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008228 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02008229 case NL80211_CHAN_WIDTH_5:
8230 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008231 case NL80211_CHAN_WIDTH_20_NOHT:
8232 break;
8233 case NL80211_CHAN_WIDTH_20:
8234 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01008235 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8236 return -EINVAL;
8237 break;
8238 case NL80211_CHAN_WIDTH_80:
8239 case NL80211_CHAN_WIDTH_80P80:
8240 case NL80211_CHAN_WIDTH_160:
8241 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
8242 return -EINVAL;
8243 if (!wiphy_ext_feature_isset(&rdev->wiphy,
8244 NL80211_EXT_FEATURE_VHT_IBSS))
8245 return -EINVAL;
8246 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008247 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008248 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02008249 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01008250
Johannes Berg04a773a2009-04-19 21:24:32 +02008251 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02008252 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02008253
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008254 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8255 u8 *rates =
8256 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8257 int n_rates =
8258 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8259 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01008260 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008261
Johannes Berg34850ab2011-07-18 18:08:35 +02008262 err = ieee80211_get_ratemask(sband, rates, n_rates,
8263 &ibss.basic_rates);
8264 if (err)
8265 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008266 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008267
Simon Wunderlich803768f2013-06-28 10:39:58 +02008268 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8269 memcpy(&ibss.ht_capa_mask,
8270 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8271 sizeof(ibss.ht_capa_mask));
8272
8273 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
8274 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8275 return -EINVAL;
8276 memcpy(&ibss.ht_capa,
8277 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8278 sizeof(ibss.ht_capa));
8279 }
8280
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01008281 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8282 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
8283 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8284 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03008285
Johannes Berg4c476992010-10-04 21:36:35 +02008286 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05308287 bool no_ht = false;
8288
Johannes Berg4c476992010-10-04 21:36:35 +02008289 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308290 info->attrs[NL80211_ATTR_KEYS],
8291 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02008292 if (IS_ERR(connkeys))
8293 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308294
Johannes Berg3d9d1d62012-11-08 23:14:50 +01008295 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
8296 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01008297 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05308298 return -EINVAL;
8299 }
Johannes Berg4c476992010-10-04 21:36:35 +02008300 }
Johannes Berg04a773a2009-04-19 21:24:32 +02008301
Antonio Quartulli267335d2012-01-31 20:25:47 +01008302 ibss.control_port =
8303 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
8304
Simon Wunderlich5336fa82013-10-07 18:41:05 +02008305 ibss.userspace_handles_dfs =
8306 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
8307
Johannes Berg4c476992010-10-04 21:36:35 +02008308 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008309 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008310 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02008311 return err;
8312}
8313
8314static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
8315{
Johannes Berg4c476992010-10-04 21:36:35 +02008316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8317 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02008318
Johannes Berg4c476992010-10-04 21:36:35 +02008319 if (!rdev->ops->leave_ibss)
8320 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008321
Johannes Berg4c476992010-10-04 21:36:35 +02008322 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
8323 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02008324
Johannes Berg4c476992010-10-04 21:36:35 +02008325 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02008326}
8327
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008328static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
8329{
8330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8331 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02008332 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008333 u32 nla_rate;
8334 int err;
8335
8336 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02008337 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
8338 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008339 return -EOPNOTSUPP;
8340
8341 if (!rdev->ops->set_mcast_rate)
8342 return -EOPNOTSUPP;
8343
8344 memset(mcast_rate, 0, sizeof(mcast_rate));
8345
8346 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
8347 return -EINVAL;
8348
8349 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
8350 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
8351 return -EINVAL;
8352
Ilan Peera1056b1b2015-10-22 22:27:46 +03008353 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008354
8355 return err;
8356}
8357
Johannes Bergad7e7182013-11-13 13:37:47 +01008358static struct sk_buff *
8359__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008360 struct wireless_dev *wdev, int approxlen,
8361 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01008362 enum nl80211_attrs attr,
8363 const struct nl80211_vendor_cmd_info *info,
8364 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01008365{
8366 struct sk_buff *skb;
8367 void *hdr;
8368 struct nlattr *data;
8369
8370 skb = nlmsg_new(approxlen + 100, gfp);
8371 if (!skb)
8372 return NULL;
8373
8374 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
8375 if (!hdr) {
8376 kfree_skb(skb);
8377 return NULL;
8378 }
8379
8380 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
8381 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01008382
8383 if (info) {
8384 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
8385 info->vendor_id))
8386 goto nla_put_failure;
8387 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
8388 info->subcmd))
8389 goto nla_put_failure;
8390 }
8391
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008392 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008393 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
8394 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008395 goto nla_put_failure;
8396 if (wdev->netdev &&
8397 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
8398 wdev->netdev->ifindex))
8399 goto nla_put_failure;
8400 }
8401
Johannes Bergad7e7182013-11-13 13:37:47 +01008402 data = nla_nest_start(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02008403 if (!data)
8404 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01008405
8406 ((void **)skb->cb)[0] = rdev;
8407 ((void **)skb->cb)[1] = hdr;
8408 ((void **)skb->cb)[2] = data;
8409
8410 return skb;
8411
8412 nla_put_failure:
8413 kfree_skb(skb);
8414 return NULL;
8415}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008416
Johannes Berge03ad6e2014-01-01 17:22:30 +01008417struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008418 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008419 enum nl80211_commands cmd,
8420 enum nl80211_attrs attr,
8421 int vendor_event_idx,
8422 int approxlen, gfp_t gfp)
8423{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08008424 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01008425 const struct nl80211_vendor_cmd_info *info;
8426
8427 switch (cmd) {
8428 case NL80211_CMD_TESTMODE:
8429 if (WARN_ON(vendor_event_idx != -1))
8430 return NULL;
8431 info = NULL;
8432 break;
8433 case NL80211_CMD_VENDOR:
8434 if (WARN_ON(vendor_event_idx < 0 ||
8435 vendor_event_idx >= wiphy->n_vendor_events))
8436 return NULL;
8437 info = &wiphy->vendor_events[vendor_event_idx];
8438 break;
8439 default:
8440 WARN_ON(1);
8441 return NULL;
8442 }
8443
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02008444 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01008445 cmd, attr, info, gfp);
8446}
8447EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
8448
8449void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
8450{
8451 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
8452 void *hdr = ((void **)skb->cb)[1];
8453 struct nlattr *data = ((void **)skb->cb)[2];
8454 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
8455
Johannes Bergbd8c78e2014-07-30 14:55:26 +02008456 /* clear CB data for netlink core to own from now on */
8457 memset(skb->cb, 0, sizeof(skb->cb));
8458
Johannes Berge03ad6e2014-01-01 17:22:30 +01008459 nla_nest_end(skb, data);
8460 genlmsg_end(skb, hdr);
8461
8462 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
8463 mcgrp = NL80211_MCGRP_VENDOR;
8464
8465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
8466 mcgrp, gfp);
8467}
8468EXPORT_SYMBOL(__cfg80211_send_event_skb);
8469
Johannes Bergaff89a92009-07-01 21:26:51 +02008470#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02008471static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
8472{
Johannes Berg4c476992010-10-04 21:36:35 +02008473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03008474 struct wireless_dev *wdev =
8475 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02008476 int err;
8477
David Spinadelfc73f112013-07-31 18:04:15 +03008478 if (!rdev->ops->testmode_cmd)
8479 return -EOPNOTSUPP;
8480
8481 if (IS_ERR(wdev)) {
8482 err = PTR_ERR(wdev);
8483 if (err != -EINVAL)
8484 return err;
8485 wdev = NULL;
8486 } else if (wdev->wiphy != &rdev->wiphy) {
8487 return -EINVAL;
8488 }
8489
Johannes Bergaff89a92009-07-01 21:26:51 +02008490 if (!info->attrs[NL80211_ATTR_TESTDATA])
8491 return -EINVAL;
8492
Johannes Bergad7e7182013-11-13 13:37:47 +01008493 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03008494 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02008495 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
8496 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01008497 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02008498
Johannes Bergaff89a92009-07-01 21:26:51 +02008499 return err;
8500}
8501
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008502static int nl80211_testmode_dump(struct sk_buff *skb,
8503 struct netlink_callback *cb)
8504{
Johannes Berg00918d32011-12-13 17:22:05 +01008505 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008506 int err;
8507 long phy_idx;
8508 void *data = NULL;
8509 int data_len = 0;
8510
Johannes Berg5fe231e2013-05-08 21:45:15 +02008511 rtnl_lock();
8512
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008513 if (cb->args[0]) {
8514 /*
8515 * 0 is a valid index, but not valid for args[0],
8516 * so we need to offset by 1.
8517 */
8518 phy_idx = cb->args[0] - 1;
8519 } else {
8520 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
8521 nl80211_fam.attrbuf, nl80211_fam.maxattr,
8522 nl80211_policy);
8523 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02008524 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008525
Johannes Berg2bd7e352012-06-15 14:23:16 +02008526 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
8527 nl80211_fam.attrbuf);
8528 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008529 err = PTR_ERR(rdev);
8530 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01008531 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02008532 phy_idx = rdev->wiphy_idx;
8533 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02008534
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008535 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
8536 cb->args[1] =
8537 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
8538 }
8539
8540 if (cb->args[1]) {
8541 data = nla_data((void *)cb->args[1]);
8542 data_len = nla_len((void *)cb->args[1]);
8543 }
8544
Johannes Berg00918d32011-12-13 17:22:05 +01008545 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
8546 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008547 err = -ENOENT;
8548 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008549 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008550
Johannes Berg00918d32011-12-13 17:22:05 +01008551 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008552 err = -EOPNOTSUPP;
8553 goto out_err;
8554 }
8555
8556 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00008557 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008558 cb->nlh->nlmsg_seq, NLM_F_MULTI,
8559 NL80211_CMD_TESTMODE);
8560 struct nlattr *tmdata;
8561
Dan Carpentercb35fba2013-08-14 14:50:01 +03008562 if (!hdr)
8563 break;
8564
David S. Miller9360ffd2012-03-29 04:41:26 -04008565 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008566 genlmsg_cancel(skb, hdr);
8567 break;
8568 }
8569
8570 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
8571 if (!tmdata) {
8572 genlmsg_cancel(skb, hdr);
8573 break;
8574 }
Hila Gonene35e4d22012-06-27 17:19:42 +03008575 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008576 nla_nest_end(skb, tmdata);
8577
8578 if (err == -ENOBUFS || err == -ENOENT) {
8579 genlmsg_cancel(skb, hdr);
8580 break;
8581 } else if (err) {
8582 genlmsg_cancel(skb, hdr);
8583 goto out_err;
8584 }
8585
8586 genlmsg_end(skb, hdr);
8587 }
8588
8589 err = skb->len;
8590 /* see above */
8591 cb->args[0] = phy_idx + 1;
8592 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02008593 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008594 return err;
8595}
Johannes Bergaff89a92009-07-01 21:26:51 +02008596#endif
8597
Samuel Ortizb23aa672009-07-01 21:26:54 +02008598static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
8599{
Johannes Berg4c476992010-10-04 21:36:35 +02008600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8601 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008602 struct cfg80211_connect_params connect;
8603 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02008604 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008605 int err;
8606
8607 memset(&connect, 0, sizeof(connect));
8608
8609 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8610 return -EINVAL;
8611
8612 if (!info->attrs[NL80211_ATTR_SSID] ||
8613 !nla_len(info->attrs[NL80211_ATTR_SSID]))
8614 return -EINVAL;
8615
8616 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
8617 connect.auth_type =
8618 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03008619 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
8620 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02008621 return -EINVAL;
8622 } else
8623 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
8624
8625 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
8626
Johannes Bergc0692b82010-08-27 14:26:53 +03008627 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02008628 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008629 if (err)
8630 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008631
Johannes Berg074ac8d2010-09-16 14:58:22 +02008632 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008633 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8634 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008635
Johannes Berg79c97e92009-07-07 03:56:12 +02008636 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008637
Bala Shanmugam4486ea92012-03-07 17:27:12 +05308638 connect.bg_scan_period = -1;
8639 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
8640 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
8641 connect.bg_scan_period =
8642 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
8643 }
8644
Samuel Ortizb23aa672009-07-01 21:26:54 +02008645 if (info->attrs[NL80211_ATTR_MAC])
8646 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02008647 else if (info->attrs[NL80211_ATTR_MAC_HINT])
8648 connect.bssid_hint =
8649 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008650 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
8651 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
8652
8653 if (info->attrs[NL80211_ATTR_IE]) {
8654 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8655 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8656 }
8657
Jouni Malinencee00a92013-01-15 17:15:57 +02008658 if (info->attrs[NL80211_ATTR_USE_MFP]) {
8659 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
8660 if (connect.mfp != NL80211_MFP_REQUIRED &&
8661 connect.mfp != NL80211_MFP_NO)
8662 return -EINVAL;
8663 } else {
8664 connect.mfp = NL80211_MFP_NO;
8665 }
8666
Jouni Malinenba6fbac2016-03-29 13:53:27 +03008667 if (info->attrs[NL80211_ATTR_PREV_BSSID])
8668 connect.prev_bssid =
8669 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
8670
Samuel Ortizb23aa672009-07-01 21:26:54 +02008671 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008672 connect.channel = nl80211_get_valid_chan(
8673 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
8674 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02008675 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02008676 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02008677 connect.channel_hint = nl80211_get_valid_chan(
8678 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
8679 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02008680 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008681 }
8682
Johannes Bergfffd0932009-07-08 14:22:54 +02008683 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
8684 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05308685 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02008686 if (IS_ERR(connkeys))
8687 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02008688 }
8689
Ben Greear7e7c8922011-11-18 11:31:59 -08008690 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
8691 connect.flags |= ASSOC_REQ_DISABLE_HT;
8692
8693 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
8694 memcpy(&connect.ht_capa_mask,
8695 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
8696 sizeof(connect.ht_capa_mask));
8697
8698 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008699 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008700 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08008701 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08008702 }
Ben Greear7e7c8922011-11-18 11:31:59 -08008703 memcpy(&connect.ht_capa,
8704 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
8705 sizeof(connect.ht_capa));
8706 }
8707
Johannes Bergee2aca32013-02-21 17:36:01 +01008708 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
8709 connect.flags |= ASSOC_REQ_DISABLE_VHT;
8710
8711 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
8712 memcpy(&connect.vht_capa_mask,
8713 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
8714 sizeof(connect.vht_capa_mask));
8715
8716 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
8717 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03008718 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01008719 return -EINVAL;
8720 }
8721 memcpy(&connect.vht_capa,
8722 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
8723 sizeof(connect.vht_capa));
8724 }
8725
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008726 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02008727 if (!((rdev->wiphy.features &
8728 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
8729 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
8730 !wiphy_ext_feature_isset(&rdev->wiphy,
8731 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01008732 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008733 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01008734 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03008735 connect.flags |= ASSOC_REQ_USE_RRM;
8736 }
8737
Lior David34d50512016-01-28 10:58:25 +02008738 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02008739 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +02008740 kzfree(connkeys);
8741 return -EOPNOTSUPP;
8742 }
8743
Arend van Spriel38de03d2016-03-02 20:37:18 +01008744 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
8745 /* bss selection makes no sense if bssid is set */
8746 if (connect.bssid) {
8747 kzfree(connkeys);
8748 return -EINVAL;
8749 }
8750
8751 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
8752 wiphy, &connect.bss_select);
8753 if (err) {
8754 kzfree(connkeys);
8755 return err;
8756 }
8757 }
8758
Johannes Berg83739b02013-05-15 17:44:01 +02008759 wdev_lock(dev->ieee80211_ptr);
Jouni Malinen4ce2bd92016-03-29 13:53:28 +03008760 err = cfg80211_connect(rdev, dev, &connect, connkeys,
8761 connect.prev_bssid);
Johannes Berg83739b02013-05-15 17:44:01 +02008762 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008763 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008764 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008765 return err;
8766}
8767
8768static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8769{
Johannes Berg4c476992010-10-04 21:36:35 +02008770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8771 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008772 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008773 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008774
8775 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8776 reason = WLAN_REASON_DEAUTH_LEAVING;
8777 else
8778 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8779
8780 if (reason == 0)
8781 return -EINVAL;
8782
Johannes Berg074ac8d2010-09-16 14:58:22 +02008783 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008784 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8785 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008786
Johannes Berg83739b02013-05-15 17:44:01 +02008787 wdev_lock(dev->ieee80211_ptr);
8788 ret = cfg80211_disconnect(rdev, dev, reason, true);
8789 wdev_unlock(dev->ieee80211_ptr);
8790 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008791}
8792
Johannes Berg463d0182009-07-14 00:33:35 +02008793static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8794{
Johannes Berg4c476992010-10-04 21:36:35 +02008795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008796 struct net *net;
8797 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008798
Vadim Kochan4b681c82015-01-12 16:34:05 +02008799 if (info->attrs[NL80211_ATTR_PID]) {
8800 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8801
8802 net = get_net_ns_by_pid(pid);
8803 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8804 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8805
8806 net = get_net_ns_by_fd(fd);
8807 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008808 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008809 }
Johannes Berg463d0182009-07-14 00:33:35 +02008810
Johannes Berg4c476992010-10-04 21:36:35 +02008811 if (IS_ERR(net))
8812 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008813
8814 err = 0;
8815
8816 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008817 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8818 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008819
Johannes Berg463d0182009-07-14 00:33:35 +02008820 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008821 return err;
8822}
8823
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008824static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8825{
Johannes Berg4c476992010-10-04 21:36:35 +02008826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008827 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8828 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008829 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008830 struct cfg80211_pmksa pmksa;
8831
8832 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8833
8834 if (!info->attrs[NL80211_ATTR_MAC])
8835 return -EINVAL;
8836
8837 if (!info->attrs[NL80211_ATTR_PMKID])
8838 return -EINVAL;
8839
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008840 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8841 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8842
Johannes Berg074ac8d2010-09-16 14:58:22 +02008843 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008844 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8845 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008846
8847 switch (info->genlhdr->cmd) {
8848 case NL80211_CMD_SET_PMKSA:
8849 rdev_ops = rdev->ops->set_pmksa;
8850 break;
8851 case NL80211_CMD_DEL_PMKSA:
8852 rdev_ops = rdev->ops->del_pmksa;
8853 break;
8854 default:
8855 WARN_ON(1);
8856 break;
8857 }
8858
Johannes Berg4c476992010-10-04 21:36:35 +02008859 if (!rdev_ops)
8860 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008861
Johannes Berg4c476992010-10-04 21:36:35 +02008862 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008863}
8864
8865static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8866{
Johannes Berg4c476992010-10-04 21:36:35 +02008867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8868 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008869
Johannes Berg074ac8d2010-09-16 14:58:22 +02008870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008871 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8872 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008873
Johannes Berg4c476992010-10-04 21:36:35 +02008874 if (!rdev->ops->flush_pmksa)
8875 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008876
Hila Gonene35e4d22012-06-27 17:19:42 +03008877 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008878}
8879
Arik Nemtsov109086c2011-09-28 14:12:50 +03008880static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8881{
8882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8883 struct net_device *dev = info->user_ptr[1];
8884 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308885 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008886 u16 status_code;
8887 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008888 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008889
8890 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8891 !rdev->ops->tdls_mgmt)
8892 return -EOPNOTSUPP;
8893
8894 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8895 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8896 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8897 !info->attrs[NL80211_ATTR_IE] ||
8898 !info->attrs[NL80211_ATTR_MAC])
8899 return -EINVAL;
8900
8901 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8902 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8903 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8904 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008905 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308906 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8907 peer_capability =
8908 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008909
Hila Gonene35e4d22012-06-27 17:19:42 +03008910 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308911 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008912 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008913 nla_data(info->attrs[NL80211_ATTR_IE]),
8914 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008915}
8916
8917static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8918{
8919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8920 struct net_device *dev = info->user_ptr[1];
8921 enum nl80211_tdls_operation operation;
8922 u8 *peer;
8923
8924 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8925 !rdev->ops->tdls_oper)
8926 return -EOPNOTSUPP;
8927
8928 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8929 !info->attrs[NL80211_ATTR_MAC])
8930 return -EINVAL;
8931
8932 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8933 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8934
Hila Gonene35e4d22012-06-27 17:19:42 +03008935 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008936}
8937
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008938static int nl80211_remain_on_channel(struct sk_buff *skb,
8939 struct genl_info *info)
8940{
Johannes Berg4c476992010-10-04 21:36:35 +02008941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008942 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008943 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008944 struct sk_buff *msg;
8945 void *hdr;
8946 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008947 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008948 int err;
8949
8950 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8951 !info->attrs[NL80211_ATTR_DURATION])
8952 return -EINVAL;
8953
8954 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8955
Johannes Berg7c4ef712011-11-18 15:33:48 +01008956 if (!rdev->ops->remain_on_channel ||
8957 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008958 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008959
Johannes Bergebf348f2012-06-01 12:50:54 +02008960 /*
8961 * We should be on that channel for at least a minimum amount of
8962 * time (10ms) but no longer than the driver supports.
8963 */
8964 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8965 duration > rdev->wiphy.max_remain_on_channel_duration)
8966 return -EINVAL;
8967
Johannes Berg683b6d32012-11-08 21:25:48 +01008968 err = nl80211_parse_chandef(rdev, info, &chandef);
8969 if (err)
8970 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008971
8972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008973 if (!msg)
8974 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008975
Eric W. Biederman15e47302012-09-07 20:12:54 +00008976 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008977 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008978 if (!hdr) {
8979 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008980 goto free_msg;
8981 }
8982
Johannes Berg683b6d32012-11-08 21:25:48 +01008983 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8984 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008985
8986 if (err)
8987 goto free_msg;
8988
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008989 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
8990 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04008991 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008992
8993 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008994
8995 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008996
8997 nla_put_failure:
8998 err = -ENOBUFS;
8999 free_msg:
9000 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009001 return err;
9002}
9003
9004static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
9005 struct genl_info *info)
9006{
Johannes Berg4c476992010-10-04 21:36:35 +02009007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009008 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009009 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009010
9011 if (!info->attrs[NL80211_ATTR_COOKIE])
9012 return -EINVAL;
9013
Johannes Berg4c476992010-10-04 21:36:35 +02009014 if (!rdev->ops->cancel_remain_on_channel)
9015 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009016
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009017 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9018
Hila Gonene35e4d22012-06-27 17:19:42 +03009019 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009020}
9021
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009022static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
9023 struct genl_info *info)
9024{
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009025 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009027 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309028 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009029
Johannes Berg4c476992010-10-04 21:36:35 +02009030 if (!rdev->ops->set_bitrate_mask)
9031 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009032
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05309033 err = nl80211_parse_tx_bitrate_mask(info, &mask);
9034 if (err)
9035 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +01009036
Hila Gonene35e4d22012-06-27 17:19:42 +03009037 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009038}
9039
Johannes Berg2e161f72010-08-12 15:38:38 +02009040static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009041{
Johannes Berg4c476992010-10-04 21:36:35 +02009042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009043 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02009044 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02009045
9046 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
9047 return -EINVAL;
9048
Johannes Berg2e161f72010-08-12 15:38:38 +02009049 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
9050 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02009051
Johannes Berg71bbc992012-06-15 15:30:18 +02009052 switch (wdev->iftype) {
9053 case NL80211_IFTYPE_STATION:
9054 case NL80211_IFTYPE_ADHOC:
9055 case NL80211_IFTYPE_P2P_CLIENT:
9056 case NL80211_IFTYPE_AP:
9057 case NL80211_IFTYPE_AP_VLAN:
9058 case NL80211_IFTYPE_MESH_POINT:
9059 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009060 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009061 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009062 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009063 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009064 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009065 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009066
9067 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02009068 if (!rdev->ops->mgmt_tx)
9069 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009070
Eric W. Biederman15e47302012-09-07 20:12:54 +00009071 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02009072 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
9073 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02009074}
9075
Johannes Berg2e161f72010-08-12 15:38:38 +02009076static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02009077{
Johannes Berg4c476992010-10-04 21:36:35 +02009078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009079 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01009080 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02009081 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01009082 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009083 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01009084 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009085 struct cfg80211_mgmt_tx_params params = {
9086 .dont_wait_for_ack =
9087 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
9088 };
Jouni Malinen026331c2010-02-15 12:53:10 +02009089
Johannes Berg683b6d32012-11-08 21:25:48 +01009090 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02009091 return -EINVAL;
9092
Johannes Berg4c476992010-10-04 21:36:35 +02009093 if (!rdev->ops->mgmt_tx)
9094 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02009095
Johannes Berg71bbc992012-06-15 15:30:18 +02009096 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02009097 case NL80211_IFTYPE_P2P_DEVICE:
9098 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9099 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02009100 case NL80211_IFTYPE_STATION:
9101 case NL80211_IFTYPE_ADHOC:
9102 case NL80211_IFTYPE_P2P_CLIENT:
9103 case NL80211_IFTYPE_AP:
9104 case NL80211_IFTYPE_AP_VLAN:
9105 case NL80211_IFTYPE_MESH_POINT:
9106 case NL80211_IFTYPE_P2P_GO:
9107 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009108 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009109 default:
Johannes Berg4c476992010-10-04 21:36:35 +02009110 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009111 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009112
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009113 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01009114 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009115 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009116 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02009117
9118 /*
9119 * We should wait on the channel for at least a minimum amount
9120 * of time (10ms) but no longer than the driver supports.
9121 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009122 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
9123 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02009124 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009125 }
9126
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009127 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009128
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009129 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01009130 return -EINVAL;
9131
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009132 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05309133
Antonio Quartulliea141b752013-06-11 14:20:03 +02009134 /* get the channel if any has been specified, otherwise pass NULL to
9135 * the driver. The latter will use the current one
9136 */
9137 chandef.chan = NULL;
9138 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
9139 err = nl80211_parse_chandef(rdev, info, &chandef);
9140 if (err)
9141 return err;
9142 }
9143
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009144 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02009145 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02009146
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03009147 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
9148 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
9149
9150 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
9151 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9152 int i;
9153
9154 if (len % sizeof(u16))
9155 return -EINVAL;
9156
9157 params.n_csa_offsets = len / sizeof(u16);
9158 params.csa_offsets =
9159 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
9160
9161 /* check that all the offsets fit the frame */
9162 for (i = 0; i < params.n_csa_offsets; i++) {
9163 if (params.csa_offsets[i] >= params.len)
9164 return -EINVAL;
9165 }
9166 }
9167
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009168 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01009169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9170 if (!msg)
9171 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02009172
Eric W. Biederman15e47302012-09-07 20:12:54 +00009173 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01009174 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009175 if (!hdr) {
9176 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01009177 goto free_msg;
9178 }
Jouni Malinen026331c2010-02-15 12:53:10 +02009179 }
Johannes Berge247bd902011-11-04 11:18:21 +01009180
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02009181 params.chan = chandef.chan;
9182 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02009183 if (err)
9184 goto free_msg;
9185
Johannes Berge247bd902011-11-04 11:18:21 +01009186 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009187 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
9188 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009189 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009190
Johannes Berge247bd902011-11-04 11:18:21 +01009191 genlmsg_end(msg, hdr);
9192 return genlmsg_reply(msg, info);
9193 }
9194
9195 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02009196
9197 nla_put_failure:
9198 err = -ENOBUFS;
9199 free_msg:
9200 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02009201 return err;
9202}
9203
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009204static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
9205{
9206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02009207 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009208 u64 cookie;
9209
9210 if (!info->attrs[NL80211_ATTR_COOKIE])
9211 return -EINVAL;
9212
9213 if (!rdev->ops->mgmt_tx_cancel_wait)
9214 return -EOPNOTSUPP;
9215
Johannes Berg71bbc992012-06-15 15:30:18 +02009216 switch (wdev->iftype) {
9217 case NL80211_IFTYPE_STATION:
9218 case NL80211_IFTYPE_ADHOC:
9219 case NL80211_IFTYPE_P2P_CLIENT:
9220 case NL80211_IFTYPE_AP:
9221 case NL80211_IFTYPE_AP_VLAN:
9222 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02009223 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02009224 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03009225 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +02009226 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009227 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02009228 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009229
9230 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
9231
Hila Gonene35e4d22012-06-27 17:19:42 +03009232 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009233}
9234
Kalle Valoffb9eb32010-02-17 17:58:10 +02009235static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
9236{
Johannes Berg4c476992010-10-04 21:36:35 +02009237 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009238 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009239 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009240 u8 ps_state;
9241 bool state;
9242 int err;
9243
Johannes Berg4c476992010-10-04 21:36:35 +02009244 if (!info->attrs[NL80211_ATTR_PS_STATE])
9245 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009246
9247 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
9248
Johannes Berg4c476992010-10-04 21:36:35 +02009249 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
9250 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009251
9252 wdev = dev->ieee80211_ptr;
9253
Johannes Berg4c476992010-10-04 21:36:35 +02009254 if (!rdev->ops->set_power_mgmt)
9255 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009256
9257 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
9258
9259 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02009260 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009261
Hila Gonene35e4d22012-06-27 17:19:42 +03009262 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02009263 if (!err)
9264 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009265 return err;
9266}
9267
9268static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
9269{
Johannes Berg4c476992010-10-04 21:36:35 +02009270 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009271 enum nl80211_ps_state ps_state;
9272 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009273 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02009274 struct sk_buff *msg;
9275 void *hdr;
9276 int err;
9277
Kalle Valoffb9eb32010-02-17 17:58:10 +02009278 wdev = dev->ieee80211_ptr;
9279
Johannes Berg4c476992010-10-04 21:36:35 +02009280 if (!rdev->ops->set_power_mgmt)
9281 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009282
9283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02009284 if (!msg)
9285 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009286
Eric W. Biederman15e47302012-09-07 20:12:54 +00009287 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009288 NL80211_CMD_GET_POWER_SAVE);
9289 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02009290 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009291 goto free_msg;
9292 }
9293
9294 if (wdev->ps)
9295 ps_state = NL80211_PS_ENABLED;
9296 else
9297 ps_state = NL80211_PS_DISABLED;
9298
David S. Miller9360ffd2012-03-29 04:41:26 -04009299 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
9300 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02009301
9302 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02009303 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009304
Johannes Berg4c476992010-10-04 21:36:35 +02009305 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009306 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02009307 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02009308 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02009309 return err;
9310}
9311
Johannes Berg94e860f2014-01-20 23:58:15 +01009312static const struct nla_policy
9313nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009314 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
9315 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
9316 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07009317 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
9318 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
9319 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009320};
9321
Thomas Pedersen84f10702012-07-12 16:17:33 -07009322static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01009323 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009324{
9325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07009326 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009327 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07009328
Johannes Bergd9d8b012012-11-26 12:51:52 +01009329 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07009330 return -EINVAL;
9331
Thomas Pedersen84f10702012-07-12 16:17:33 -07009332 if (!rdev->ops->set_cqm_txe_config)
9333 return -EOPNOTSUPP;
9334
9335 if (wdev->iftype != NL80211_IFTYPE_STATION &&
9336 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9337 return -EOPNOTSUPP;
9338
Hila Gonene35e4d22012-06-27 17:19:42 +03009339 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07009340}
9341
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009342static int nl80211_set_cqm_rssi(struct genl_info *info,
9343 s32 threshold, u32 hysteresis)
9344{
Johannes Berg4c476992010-10-04 21:36:35 +02009345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02009346 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009347 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009348
9349 if (threshold > 0)
9350 return -EINVAL;
9351
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009352 /* disabling - hysteresis should also be zero then */
9353 if (threshold == 0)
9354 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009355
Johannes Berg4c476992010-10-04 21:36:35 +02009356 if (!rdev->ops->set_cqm_rssi_config)
9357 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009358
Johannes Berg074ac8d2010-09-16 14:58:22 +02009359 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009360 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
9361 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009362
Hila Gonene35e4d22012-06-27 17:19:42 +03009363 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009364}
9365
9366static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
9367{
9368 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
9369 struct nlattr *cqm;
9370 int err;
9371
9372 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009373 if (!cqm)
9374 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009375
9376 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
9377 nl80211_attr_cqm_policy);
9378 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009379 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009380
9381 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
9382 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009383 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
9384 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009385
Johannes Berg1da5fcc2013-08-06 14:10:48 +02009386 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
9387 }
9388
9389 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
9390 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
9391 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
9392 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
9393 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
9394 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
9395
9396 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
9397 }
9398
9399 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009400}
9401
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01009402static int nl80211_join_ocb(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 ocb_setup setup = {};
9407 int err;
9408
9409 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9410 if (err)
9411 return err;
9412
9413 return cfg80211_join_ocb(rdev, dev, &setup);
9414}
9415
9416static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
9417{
9418 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9419 struct net_device *dev = info->user_ptr[1];
9420
9421 return cfg80211_leave_ocb(rdev, dev);
9422}
9423
Johannes Berg29cbe682010-12-03 09:20:44 +01009424static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
9425{
9426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9427 struct net_device *dev = info->user_ptr[1];
9428 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08009429 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01009430 int err;
9431
9432 /* start with default */
9433 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08009434 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01009435
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009436 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01009437 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009438 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01009439 if (err)
9440 return err;
9441 }
9442
9443 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
9444 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
9445 return -EINVAL;
9446
Javier Cardonac80d5452010-12-16 17:37:49 -08009447 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
9448 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
9449
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08009450 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9451 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
9452 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9453 return -EINVAL;
9454
Marco Porsch9bdbf042013-01-07 16:04:51 +01009455 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
9456 setup.beacon_interval =
9457 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309458
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309459 err = cfg80211_validate_beacon_int(rdev,
9460 NL80211_IFTYPE_MESH_POINT,
9461 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309462 if (err)
9463 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +01009464 }
9465
9466 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
9467 setup.dtim_period =
9468 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
9469 if (setup.dtim_period < 1 || setup.dtim_period > 100)
9470 return -EINVAL;
9471 }
9472
Javier Cardonac80d5452010-12-16 17:37:49 -08009473 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
9474 /* parse additional setup parameters if given */
9475 err = nl80211_parse_mesh_setup(info, &setup);
9476 if (err)
9477 return err;
9478 }
9479
Thomas Pedersend37bb182013-03-04 13:06:13 -08009480 if (setup.user_mpm)
9481 cfg.auto_open_plinks = false;
9482
Johannes Bergcc1d2802012-05-16 23:50:20 +02009483 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01009484 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
9485 if (err)
9486 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009487 } else {
9488 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01009489 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02009490 }
9491
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07009492 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9493 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9494 int n_rates =
9495 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9496 struct ieee80211_supported_band *sband;
9497
9498 if (!setup.chandef.chan)
9499 return -EINVAL;
9500
9501 sband = rdev->wiphy.bands[setup.chandef.chan->band];
9502
9503 err = ieee80211_get_ratemask(sband, rates, n_rates,
9504 &setup.basic_rates);
9505 if (err)
9506 return err;
9507 }
9508
Johannes Berg8564e382016-09-19 09:44:44 +02009509 if (info->attrs[NL80211_ATTR_TX_RATES]) {
9510 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
9511 if (err)
9512 return err;
9513
9514 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
9515 &setup.beacon_rate);
9516 if (err)
9517 return err;
9518 }
9519
Javier Cardonac80d5452010-12-16 17:37:49 -08009520 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01009521}
9522
9523static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
9524{
9525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9526 struct net_device *dev = info->user_ptr[1];
9527
9528 return cfg80211_leave_mesh(rdev, dev);
9529}
9530
Johannes Bergdfb89c52012-06-27 09:23:48 +02009531#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009532static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
9533 struct cfg80211_registered_device *rdev)
9534{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009535 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009536 struct nlattr *nl_pats, *nl_pat;
9537 int i, pat_len;
9538
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009539 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009540 return 0;
9541
9542 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
9543 if (!nl_pats)
9544 return -ENOBUFS;
9545
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009546 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009547 nl_pat = nla_nest_start(msg, i + 1);
9548 if (!nl_pat)
9549 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009550 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009551 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009552 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009553 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9554 wowlan->patterns[i].pattern) ||
9555 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009556 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009557 return -ENOBUFS;
9558 nla_nest_end(msg, nl_pat);
9559 }
9560 nla_nest_end(msg, nl_pats);
9561
9562 return 0;
9563}
9564
Johannes Berg2a0e0472013-01-23 22:57:40 +01009565static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9566 struct cfg80211_wowlan_tcp *tcp)
9567{
9568 struct nlattr *nl_tcp;
9569
9570 if (!tcp)
9571 return 0;
9572
9573 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9574 if (!nl_tcp)
9575 return -ENOBUFS;
9576
Jiri Benc930345e2015-03-29 16:59:25 +02009577 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9578 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009579 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9580 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9581 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9582 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9583 tcp->payload_len, tcp->payload) ||
9584 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9585 tcp->data_interval) ||
9586 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9587 tcp->wake_len, tcp->wake_data) ||
9588 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9589 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9590 return -ENOBUFS;
9591
9592 if (tcp->payload_seq.len &&
9593 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9594 sizeof(tcp->payload_seq), &tcp->payload_seq))
9595 return -ENOBUFS;
9596
9597 if (tcp->payload_tok.len &&
9598 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9599 sizeof(tcp->payload_tok) + tcp->tokens_size,
9600 &tcp->payload_tok))
9601 return -ENOBUFS;
9602
Johannes Berge248ad32013-05-16 10:24:28 +02009603 nla_nest_end(msg, nl_tcp);
9604
Johannes Berg2a0e0472013-01-23 22:57:40 +01009605 return 0;
9606}
9607
Luciano Coelho75453cc2015-01-09 14:06:37 +02009608static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9609 struct cfg80211_sched_scan_request *req)
9610{
Avraham Stern3b06d272015-10-12 09:51:34 +03009611 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009612 int i;
9613
9614 if (!req)
9615 return 0;
9616
9617 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9618 if (!nd)
9619 return -ENOBUFS;
9620
Avraham Stern3b06d272015-10-12 09:51:34 +03009621 if (req->n_scan_plans == 1 &&
9622 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9623 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009624 return -ENOBUFS;
9625
Luciano Coelho21fea562015-03-17 16:36:01 +02009626 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9627 return -ENOBUFS;
9628
Luciano Coelho75453cc2015-01-09 14:06:37 +02009629 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9630 if (!freqs)
9631 return -ENOBUFS;
9632
Johannes Berg53b18982016-09-14 09:59:21 +02009633 for (i = 0; i < req->n_channels; i++) {
9634 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9635 return -ENOBUFS;
9636 }
Luciano Coelho75453cc2015-01-09 14:06:37 +02009637
9638 nla_nest_end(msg, freqs);
9639
9640 if (req->n_match_sets) {
9641 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009642 if (!matches)
9643 return -ENOBUFS;
9644
Luciano Coelho75453cc2015-01-09 14:06:37 +02009645 for (i = 0; i < req->n_match_sets; i++) {
9646 match = nla_nest_start(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009647 if (!match)
9648 return -ENOBUFS;
9649
Johannes Berg53b18982016-09-14 09:59:21 +02009650 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9651 req->match_sets[i].ssid.ssid_len,
9652 req->match_sets[i].ssid.ssid))
9653 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009654 nla_nest_end(msg, match);
9655 }
9656 nla_nest_end(msg, matches);
9657 }
9658
Avraham Stern3b06d272015-10-12 09:51:34 +03009659 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9660 if (!scan_plans)
9661 return -ENOBUFS;
9662
9663 for (i = 0; i < req->n_scan_plans; i++) {
9664 scan_plan = nla_nest_start(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009665 if (!scan_plan)
9666 return -ENOBUFS;
9667
Avraham Stern3b06d272015-10-12 09:51:34 +03009668 if (!scan_plan ||
9669 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9670 req->scan_plans[i].interval) ||
9671 (req->scan_plans[i].iterations &&
9672 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9673 req->scan_plans[i].iterations)))
9674 return -ENOBUFS;
9675 nla_nest_end(msg, scan_plan);
9676 }
9677 nla_nest_end(msg, scan_plans);
9678
Luciano Coelho75453cc2015-01-09 14:06:37 +02009679 nla_nest_end(msg, nd);
9680
9681 return 0;
9682}
9683
Johannes Bergff1b6e62011-05-04 15:37:28 +02009684static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9685{
9686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9687 struct sk_buff *msg;
9688 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009689 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009690
Johannes Berg964dc9e2013-06-03 17:25:34 +02009691 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009692 return -EOPNOTSUPP;
9693
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009694 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009695 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009696 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9697 rdev->wiphy.wowlan_config->tcp->payload_len +
9698 rdev->wiphy.wowlan_config->tcp->wake_len +
9699 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009700 }
9701
9702 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009703 if (!msg)
9704 return -ENOMEM;
9705
Eric W. Biederman15e47302012-09-07 20:12:54 +00009706 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009707 NL80211_CMD_GET_WOWLAN);
9708 if (!hdr)
9709 goto nla_put_failure;
9710
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009711 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009712 struct nlattr *nl_wowlan;
9713
9714 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9715 if (!nl_wowlan)
9716 goto nla_put_failure;
9717
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009718 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009719 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009720 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009721 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009722 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009723 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009724 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009725 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009726 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009727 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009728 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009729 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009730 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009731 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9732 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009733
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009734 if (nl80211_send_wowlan_patterns(msg, rdev))
9735 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009736
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009737 if (nl80211_send_wowlan_tcp(msg,
9738 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009739 goto nla_put_failure;
9740
Luciano Coelho75453cc2015-01-09 14:06:37 +02009741 if (nl80211_send_wowlan_nd(
9742 msg,
9743 rdev->wiphy.wowlan_config->nd_config))
9744 goto nla_put_failure;
9745
Johannes Bergff1b6e62011-05-04 15:37:28 +02009746 nla_nest_end(msg, nl_wowlan);
9747 }
9748
9749 genlmsg_end(msg, hdr);
9750 return genlmsg_reply(msg, info);
9751
9752nla_put_failure:
9753 nlmsg_free(msg);
9754 return -ENOBUFS;
9755}
9756
Johannes Berg2a0e0472013-01-23 22:57:40 +01009757static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9758 struct nlattr *attr,
9759 struct cfg80211_wowlan *trig)
9760{
9761 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9762 struct cfg80211_wowlan_tcp *cfg;
9763 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9764 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9765 u32 size;
9766 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9767 int err, port;
9768
Johannes Berg964dc9e2013-06-03 17:25:34 +02009769 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009770 return -EINVAL;
9771
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009772 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr,
9773 nl80211_wowlan_tcp_policy);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009774 if (err)
9775 return err;
9776
9777 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9778 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9779 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9780 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9781 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9782 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9783 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9784 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9785 return -EINVAL;
9786
9787 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009788 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009789 return -EINVAL;
9790
9791 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009792 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009793 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009794 return -EINVAL;
9795
9796 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009797 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009798 return -EINVAL;
9799
9800 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9801 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9802 return -EINVAL;
9803
9804 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9805 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9806
9807 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9808 tokens_size = tokln - sizeof(*tok);
9809
9810 if (!tok->len || tokens_size % tok->len)
9811 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009812 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009813 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009814 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009815 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009816 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009817 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009818 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009819 return -EINVAL;
9820 if (tok->offset + tok->len > data_size)
9821 return -EINVAL;
9822 }
9823
9824 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9825 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009826 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009827 return -EINVAL;
9828 if (seq->len == 0 || seq->len > 4)
9829 return -EINVAL;
9830 if (seq->len + seq->offset > data_size)
9831 return -EINVAL;
9832 }
9833
9834 size = sizeof(*cfg);
9835 size += data_size;
9836 size += wake_size + wake_mask_size;
9837 size += tokens_size;
9838
9839 cfg = kzalloc(size, GFP_KERNEL);
9840 if (!cfg)
9841 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009842 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9843 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009844 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9845 ETH_ALEN);
9846 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9847 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9848 else
9849 port = 0;
9850#ifdef CONFIG_INET
9851 /* allocate a socket and port for it and use it */
9852 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9853 IPPROTO_TCP, &cfg->sock, 1);
9854 if (err) {
9855 kfree(cfg);
9856 return err;
9857 }
9858 if (inet_csk_get_port(cfg->sock->sk, port)) {
9859 sock_release(cfg->sock);
9860 kfree(cfg);
9861 return -EADDRINUSE;
9862 }
9863 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9864#else
9865 if (!port) {
9866 kfree(cfg);
9867 return -EINVAL;
9868 }
9869 cfg->src_port = port;
9870#endif
9871
9872 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9873 cfg->payload_len = data_size;
9874 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9875 memcpy((void *)cfg->payload,
9876 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9877 data_size);
9878 if (seq)
9879 cfg->payload_seq = *seq;
9880 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9881 cfg->wake_len = wake_size;
9882 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9883 memcpy((void *)cfg->wake_data,
9884 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9885 wake_size);
9886 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9887 data_size + wake_size;
9888 memcpy((void *)cfg->wake_mask,
9889 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9890 wake_mask_size);
9891 if (tok) {
9892 cfg->tokens_size = tokens_size;
9893 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9894 }
9895
9896 trig->tcp = cfg;
9897
9898 return 0;
9899}
9900
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009901static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9902 const struct wiphy_wowlan_support *wowlan,
9903 struct nlattr *attr,
9904 struct cfg80211_wowlan *trig)
9905{
9906 struct nlattr **tb;
9907 int err;
9908
9909 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9910 if (!tb)
9911 return -ENOMEM;
9912
9913 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9914 err = -EOPNOTSUPP;
9915 goto out;
9916 }
9917
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009918 err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009919 if (err)
9920 goto out;
9921
Johannes Bergad2b26a2014-06-12 21:39:05 +02009922 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009923 err = PTR_ERR_OR_ZERO(trig->nd_config);
9924 if (err)
9925 trig->nd_config = NULL;
9926
9927out:
9928 kfree(tb);
9929 return err;
9930}
9931
Johannes Bergff1b6e62011-05-04 15:37:28 +02009932static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9933{
9934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9935 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009936 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009937 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009938 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009939 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009940 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009941 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009942
Johannes Berg964dc9e2013-06-03 17:25:34 +02009943 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009944 return -EOPNOTSUPP;
9945
Johannes Bergae33bd82012-07-12 16:25:02 +02009946 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9947 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009948 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009949 goto set_wakeup;
9950 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009951
Johannes Bergbfe2c7b2016-10-26 14:42:21 +02009952 err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG,
9953 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
9954 nl80211_wowlan_policy);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009955 if (err)
9956 return err;
9957
9958 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9959 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9960 return -EINVAL;
9961 new_triggers.any = true;
9962 }
9963
9964 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9965 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9966 return -EINVAL;
9967 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009968 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009969 }
9970
9971 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9972 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9973 return -EINVAL;
9974 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009975 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009976 }
9977
Johannes Berg77dbbb12011-07-13 10:48:55 +02009978 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9979 return -EINVAL;
9980
9981 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9982 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9983 return -EINVAL;
9984 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009985 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009986 }
9987
9988 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9989 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9990 return -EINVAL;
9991 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009992 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009993 }
9994
9995 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9996 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9997 return -EINVAL;
9998 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009999 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010000 }
10001
10002 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
10003 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
10004 return -EINVAL;
10005 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020010006 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020010007 }
10008
Johannes Bergff1b6e62011-05-04 15:37:28 +020010009 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
10010 struct nlattr *pat;
10011 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010012 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010013 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020010014
Johannes Berg98fc4382015-03-01 09:10:13 +020010015 regular = true;
10016
Johannes Bergff1b6e62011-05-04 15:37:28 +020010017 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10018 rem)
10019 n_patterns++;
10020 if (n_patterns > wowlan->n_patterns)
10021 return -EINVAL;
10022
10023 new_triggers.patterns = kcalloc(n_patterns,
10024 sizeof(new_triggers.patterns[0]),
10025 GFP_KERNEL);
10026 if (!new_triggers.patterns)
10027 return -ENOMEM;
10028
10029 new_triggers.n_patterns = n_patterns;
10030 i = 0;
10031
10032 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
10033 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010034 u8 *mask_pat;
10035
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010036 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat,
10037 NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010038 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010039 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10040 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020010041 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010042 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010043 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010044 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020010045 goto error;
10046 if (pat_len > wowlan->pattern_max_len ||
10047 pat_len < wowlan->pattern_min_len)
10048 goto error;
10049
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010050 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010051 pkt_offset = 0;
10052 else
10053 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010054 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080010055 if (pkt_offset > wowlan->max_pkt_offset)
10056 goto error;
10057 new_triggers.patterns[i].pkt_offset = pkt_offset;
10058
Johannes Berg922bd802014-05-19 17:59:50 +020010059 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10060 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020010061 err = -ENOMEM;
10062 goto error;
10063 }
Johannes Berg922bd802014-05-19 17:59:50 +020010064 new_triggers.patterns[i].mask = mask_pat;
10065 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010066 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020010067 mask_pat += mask_len;
10068 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010069 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010070 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070010071 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020010072 pat_len);
10073 i++;
10074 }
10075 }
10076
Johannes Berg2a0e0472013-01-23 22:57:40 +010010077 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010078 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010010079 err = nl80211_parse_wowlan_tcp(
10080 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
10081 &new_triggers);
10082 if (err)
10083 goto error;
10084 }
10085
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010086 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020010087 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030010088 err = nl80211_parse_wowlan_nd(
10089 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
10090 &new_triggers);
10091 if (err)
10092 goto error;
10093 }
10094
Johannes Berg98fc4382015-03-01 09:10:13 +020010095 /* The 'any' trigger means the device continues operating more or less
10096 * as in its normal operation mode and wakes up the host on most of the
10097 * normal interrupts (like packet RX, ...)
10098 * It therefore makes little sense to combine with the more constrained
10099 * wakeup trigger modes.
10100 */
10101 if (new_triggers.any && regular) {
10102 err = -EINVAL;
10103 goto error;
10104 }
10105
Johannes Bergae33bd82012-07-12 16:25:02 +020010106 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
10107 if (!ntrig) {
10108 err = -ENOMEM;
10109 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010110 }
Johannes Bergae33bd82012-07-12 16:25:02 +020010111 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010112 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020010113
Johannes Bergae33bd82012-07-12 16:25:02 +020010114 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020010115 if (rdev->ops->set_wakeup &&
10116 prev_enabled != !!rdev->wiphy.wowlan_config)
10117 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020010118
Johannes Bergff1b6e62011-05-04 15:37:28 +020010119 return 0;
10120 error:
10121 for (i = 0; i < new_triggers.n_patterns; i++)
10122 kfree(new_triggers.patterns[i].mask);
10123 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010010124 if (new_triggers.tcp && new_triggers.tcp->sock)
10125 sock_release(new_triggers.tcp->sock);
10126 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010010127 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020010128 return err;
10129}
Johannes Bergdfb89c52012-06-27 09:23:48 +020010130#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020010131
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010132static int nl80211_send_coalesce_rules(struct sk_buff *msg,
10133 struct cfg80211_registered_device *rdev)
10134{
10135 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
10136 int i, j, pat_len;
10137 struct cfg80211_coalesce_rules *rule;
10138
10139 if (!rdev->coalesce->n_rules)
10140 return 0;
10141
10142 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
10143 if (!nl_rules)
10144 return -ENOBUFS;
10145
10146 for (i = 0; i < rdev->coalesce->n_rules; i++) {
10147 nl_rule = nla_nest_start(msg, i + 1);
10148 if (!nl_rule)
10149 return -ENOBUFS;
10150
10151 rule = &rdev->coalesce->rules[i];
10152 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
10153 rule->delay))
10154 return -ENOBUFS;
10155
10156 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
10157 rule->condition))
10158 return -ENOBUFS;
10159
10160 nl_pats = nla_nest_start(msg,
10161 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
10162 if (!nl_pats)
10163 return -ENOBUFS;
10164
10165 for (j = 0; j < rule->n_patterns; j++) {
10166 nl_pat = nla_nest_start(msg, j + 1);
10167 if (!nl_pat)
10168 return -ENOBUFS;
10169 pat_len = rule->patterns[j].pattern_len;
10170 if (nla_put(msg, NL80211_PKTPAT_MASK,
10171 DIV_ROUND_UP(pat_len, 8),
10172 rule->patterns[j].mask) ||
10173 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
10174 rule->patterns[j].pattern) ||
10175 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
10176 rule->patterns[j].pkt_offset))
10177 return -ENOBUFS;
10178 nla_nest_end(msg, nl_pat);
10179 }
10180 nla_nest_end(msg, nl_pats);
10181 nla_nest_end(msg, nl_rule);
10182 }
10183 nla_nest_end(msg, nl_rules);
10184
10185 return 0;
10186}
10187
10188static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
10189{
10190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10191 struct sk_buff *msg;
10192 void *hdr;
10193
10194 if (!rdev->wiphy.coalesce)
10195 return -EOPNOTSUPP;
10196
10197 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10198 if (!msg)
10199 return -ENOMEM;
10200
10201 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10202 NL80211_CMD_GET_COALESCE);
10203 if (!hdr)
10204 goto nla_put_failure;
10205
10206 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
10207 goto nla_put_failure;
10208
10209 genlmsg_end(msg, hdr);
10210 return genlmsg_reply(msg, info);
10211
10212nla_put_failure:
10213 nlmsg_free(msg);
10214 return -ENOBUFS;
10215}
10216
10217void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
10218{
10219 struct cfg80211_coalesce *coalesce = rdev->coalesce;
10220 int i, j;
10221 struct cfg80211_coalesce_rules *rule;
10222
10223 if (!coalesce)
10224 return;
10225
10226 for (i = 0; i < coalesce->n_rules; i++) {
10227 rule = &coalesce->rules[i];
10228 for (j = 0; j < rule->n_patterns; j++)
10229 kfree(rule->patterns[j].mask);
10230 kfree(rule->patterns);
10231 }
10232 kfree(coalesce->rules);
10233 kfree(coalesce);
10234 rdev->coalesce = NULL;
10235}
10236
10237static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
10238 struct nlattr *rule,
10239 struct cfg80211_coalesce_rules *new_rule)
10240{
10241 int err, i;
10242 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10243 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
10244 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
10245 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
10246
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010247 err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule,
10248 nl80211_coalesce_policy);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010249 if (err)
10250 return err;
10251
10252 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
10253 new_rule->delay =
10254 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
10255 if (new_rule->delay > coalesce->max_delay)
10256 return -EINVAL;
10257
10258 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
10259 new_rule->condition =
10260 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
10261 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
10262 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
10263 return -EINVAL;
10264
10265 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
10266 return -EINVAL;
10267
10268 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10269 rem)
10270 n_patterns++;
10271 if (n_patterns > coalesce->n_patterns)
10272 return -EINVAL;
10273
10274 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
10275 GFP_KERNEL);
10276 if (!new_rule->patterns)
10277 return -ENOMEM;
10278
10279 new_rule->n_patterns = n_patterns;
10280 i = 0;
10281
10282 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
10283 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020010284 u8 *mask_pat;
10285
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010286 nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010287 if (!pat_tb[NL80211_PKTPAT_MASK] ||
10288 !pat_tb[NL80211_PKTPAT_PATTERN])
10289 return -EINVAL;
10290 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
10291 mask_len = DIV_ROUND_UP(pat_len, 8);
10292 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
10293 return -EINVAL;
10294 if (pat_len > coalesce->pattern_max_len ||
10295 pat_len < coalesce->pattern_min_len)
10296 return -EINVAL;
10297
10298 if (!pat_tb[NL80211_PKTPAT_OFFSET])
10299 pkt_offset = 0;
10300 else
10301 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
10302 if (pkt_offset > coalesce->max_pkt_offset)
10303 return -EINVAL;
10304 new_rule->patterns[i].pkt_offset = pkt_offset;
10305
Johannes Berg922bd802014-05-19 17:59:50 +020010306 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
10307 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010308 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020010309
10310 new_rule->patterns[i].mask = mask_pat;
10311 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
10312 mask_len);
10313
10314 mask_pat += mask_len;
10315 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010316 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020010317 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
10318 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010319 i++;
10320 }
10321
10322 return 0;
10323}
10324
10325static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
10326{
10327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10328 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
10329 struct cfg80211_coalesce new_coalesce = {};
10330 struct cfg80211_coalesce *n_coalesce;
10331 int err, rem_rule, n_rules = 0, i, j;
10332 struct nlattr *rule;
10333 struct cfg80211_coalesce_rules *tmp_rule;
10334
10335 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
10336 return -EOPNOTSUPP;
10337
10338 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
10339 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030010340 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010341 return 0;
10342 }
10343
10344 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10345 rem_rule)
10346 n_rules++;
10347 if (n_rules > coalesce->n_rules)
10348 return -EINVAL;
10349
10350 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
10351 GFP_KERNEL);
10352 if (!new_coalesce.rules)
10353 return -ENOMEM;
10354
10355 new_coalesce.n_rules = n_rules;
10356 i = 0;
10357
10358 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
10359 rem_rule) {
10360 err = nl80211_parse_coalesce_rule(rdev, rule,
10361 &new_coalesce.rules[i]);
10362 if (err)
10363 goto error;
10364
10365 i++;
10366 }
10367
Ilan Peera1056b1b2015-10-22 22:27:46 +030010368 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010369 if (err)
10370 goto error;
10371
10372 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
10373 if (!n_coalesce) {
10374 err = -ENOMEM;
10375 goto error;
10376 }
10377 cfg80211_rdev_free_coalesce(rdev);
10378 rdev->coalesce = n_coalesce;
10379
10380 return 0;
10381error:
10382 for (i = 0; i < new_coalesce.n_rules; i++) {
10383 tmp_rule = &new_coalesce.rules[i];
10384 for (j = 0; j < tmp_rule->n_patterns; j++)
10385 kfree(tmp_rule->patterns[j].mask);
10386 kfree(tmp_rule->patterns);
10387 }
10388 kfree(new_coalesce.rules);
10389
10390 return err;
10391}
10392
Johannes Berge5497d72011-07-05 16:35:40 +020010393static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
10394{
10395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10396 struct net_device *dev = info->user_ptr[1];
10397 struct wireless_dev *wdev = dev->ieee80211_ptr;
10398 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
10399 struct cfg80211_gtk_rekey_data rekey_data;
10400 int err;
10401
10402 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
10403 return -EINVAL;
10404
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010405 err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA,
10406 info->attrs[NL80211_ATTR_REKEY_DATA],
10407 nl80211_rekey_policy);
Johannes Berge5497d72011-07-05 16:35:40 +020010408 if (err)
10409 return err;
10410
10411 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
10412 return -ERANGE;
10413 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
10414 return -ERANGE;
10415 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
10416 return -ERANGE;
10417
Johannes Berg78f686c2014-09-10 22:28:06 +030010418 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
10419 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
10420 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020010421
10422 wdev_lock(wdev);
10423 if (!wdev->current_bss) {
10424 err = -ENOTCONN;
10425 goto out;
10426 }
10427
10428 if (!rdev->ops->set_rekey_data) {
10429 err = -EOPNOTSUPP;
10430 goto out;
10431 }
10432
Hila Gonene35e4d22012-06-27 17:19:42 +030010433 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020010434 out:
10435 wdev_unlock(wdev);
10436 return err;
10437}
10438
Johannes Berg28946da2011-11-04 11:18:12 +010010439static int nl80211_register_unexpected_frame(struct sk_buff *skb,
10440 struct genl_info *info)
10441{
10442 struct net_device *dev = info->user_ptr[1];
10443 struct wireless_dev *wdev = dev->ieee80211_ptr;
10444
10445 if (wdev->iftype != NL80211_IFTYPE_AP &&
10446 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10447 return -EINVAL;
10448
Eric W. Biederman15e47302012-09-07 20:12:54 +000010449 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010450 return -EBUSY;
10451
Eric W. Biederman15e47302012-09-07 20:12:54 +000010452 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010010453 return 0;
10454}
10455
Johannes Berg7f6cf312011-11-04 11:18:15 +010010456static int nl80211_probe_client(struct sk_buff *skb,
10457 struct genl_info *info)
10458{
10459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10460 struct net_device *dev = info->user_ptr[1];
10461 struct wireless_dev *wdev = dev->ieee80211_ptr;
10462 struct sk_buff *msg;
10463 void *hdr;
10464 const u8 *addr;
10465 u64 cookie;
10466 int err;
10467
10468 if (wdev->iftype != NL80211_IFTYPE_AP &&
10469 wdev->iftype != NL80211_IFTYPE_P2P_GO)
10470 return -EOPNOTSUPP;
10471
10472 if (!info->attrs[NL80211_ATTR_MAC])
10473 return -EINVAL;
10474
10475 if (!rdev->ops->probe_client)
10476 return -EOPNOTSUPP;
10477
10478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10479 if (!msg)
10480 return -ENOMEM;
10481
Eric W. Biederman15e47302012-09-07 20:12:54 +000010482 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010010483 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010484 if (!hdr) {
10485 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010486 goto free_msg;
10487 }
10488
10489 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10490
Hila Gonene35e4d22012-06-27 17:19:42 +030010491 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010492 if (err)
10493 goto free_msg;
10494
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010495 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10496 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010497 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010498
10499 genlmsg_end(msg, hdr);
10500
10501 return genlmsg_reply(msg, info);
10502
10503 nla_put_failure:
10504 err = -ENOBUFS;
10505 free_msg:
10506 nlmsg_free(msg);
10507 return err;
10508}
10509
Johannes Berg5e760232011-11-04 11:18:17 +010010510static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
10511{
10512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070010513 struct cfg80211_beacon_registration *reg, *nreg;
10514 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010515
10516 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
10517 return -EOPNOTSUPP;
10518
Ben Greear37c73b52012-10-26 14:49:25 -070010519 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
10520 if (!nreg)
10521 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010010522
Ben Greear37c73b52012-10-26 14:49:25 -070010523 /* First, check if already registered. */
10524 spin_lock_bh(&rdev->beacon_registrations_lock);
10525 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10526 if (reg->nlportid == info->snd_portid) {
10527 rv = -EALREADY;
10528 goto out_err;
10529 }
10530 }
10531 /* Add it to the list */
10532 nreg->nlportid = info->snd_portid;
10533 list_add(&nreg->list, &rdev->beacon_registrations);
10534
10535 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010536
10537 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070010538out_err:
10539 spin_unlock_bh(&rdev->beacon_registrations_lock);
10540 kfree(nreg);
10541 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010010542}
10543
Johannes Berg98104fde2012-06-16 00:19:54 +020010544static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
10545{
10546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10547 struct wireless_dev *wdev = info->user_ptr[1];
10548 int err;
10549
10550 if (!rdev->ops->start_p2p_device)
10551 return -EOPNOTSUPP;
10552
10553 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10554 return -EOPNOTSUPP;
10555
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010556 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020010557 return 0;
10558
Luciano Coelhob6a55012014-02-27 11:07:21 +020010559 if (rfkill_blocked(rdev->rfkill))
10560 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020010561
Johannes Bergeeb126e2012-10-23 15:16:50 +020010562 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010563 if (err)
10564 return err;
10565
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010566 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020010567 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020010568
10569 return 0;
10570}
10571
10572static int nl80211_stop_p2p_device(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
10577 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10578 return -EOPNOTSUPP;
10579
10580 if (!rdev->ops->stop_p2p_device)
10581 return -EOPNOTSUPP;
10582
Johannes Bergf9f47522013-03-19 15:04:07 +010010583 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010584
10585 return 0;
10586}
10587
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010588static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
10589{
10590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10591 struct wireless_dev *wdev = info->user_ptr[1];
10592 struct cfg80211_nan_conf conf = {};
10593 int err;
10594
10595 if (wdev->iftype != NL80211_IFTYPE_NAN)
10596 return -EOPNOTSUPP;
10597
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010598 if (!wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010599 return -EEXIST;
10600
10601 if (rfkill_blocked(rdev->rfkill))
10602 return -ERFKILL;
10603
10604 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
10605 return -EINVAL;
10606
10607 if (!info->attrs[NL80211_ATTR_NAN_DUAL])
10608 return -EINVAL;
10609
10610 conf.master_pref =
10611 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10612 if (!conf.master_pref)
10613 return -EINVAL;
10614
10615 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10616
10617 err = rdev_start_nan(rdev, wdev, &conf);
10618 if (err)
10619 return err;
10620
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010621 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010622 rdev->opencount++;
10623
10624 return 0;
10625}
10626
10627static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
10628{
10629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10630 struct wireless_dev *wdev = info->user_ptr[1];
10631
10632 if (wdev->iftype != NL80211_IFTYPE_NAN)
10633 return -EOPNOTSUPP;
10634
10635 cfg80211_stop_nan(rdev, wdev);
10636
10637 return 0;
10638}
10639
Ayala Bekera442b762016-09-20 17:31:15 +030010640static int validate_nan_filter(struct nlattr *filter_attr)
10641{
10642 struct nlattr *attr;
10643 int len = 0, n_entries = 0, rem;
10644
10645 nla_for_each_nested(attr, filter_attr, rem) {
10646 len += nla_len(attr);
10647 n_entries++;
10648 }
10649
10650 if (len >= U8_MAX)
10651 return -EINVAL;
10652
10653 return n_entries;
10654}
10655
10656static int handle_nan_filter(struct nlattr *attr_filter,
10657 struct cfg80211_nan_func *func,
10658 bool tx)
10659{
10660 struct nlattr *attr;
10661 int n_entries, rem, i;
10662 struct cfg80211_nan_func_filter *filter;
10663
10664 n_entries = validate_nan_filter(attr_filter);
10665 if (n_entries < 0)
10666 return n_entries;
10667
10668 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
10669
10670 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
10671 if (!filter)
10672 return -ENOMEM;
10673
10674 i = 0;
10675 nla_for_each_nested(attr, attr_filter, rem) {
10676 filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
10677 GFP_KERNEL);
10678 filter[i].len = nla_len(attr);
10679 i++;
10680 }
10681 if (tx) {
10682 func->num_tx_filters = n_entries;
10683 func->tx_filters = filter;
10684 } else {
10685 func->num_rx_filters = n_entries;
10686 func->rx_filters = filter;
10687 }
10688
10689 return 0;
10690}
10691
10692static int nl80211_nan_add_func(struct sk_buff *skb,
10693 struct genl_info *info)
10694{
10695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10696 struct wireless_dev *wdev = info->user_ptr[1];
10697 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
10698 struct cfg80211_nan_func *func;
10699 struct sk_buff *msg = NULL;
10700 void *hdr = NULL;
10701 int err = 0;
10702
10703 if (wdev->iftype != NL80211_IFTYPE_NAN)
10704 return -EOPNOTSUPP;
10705
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010706 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030010707 return -ENOTCONN;
10708
10709 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
10710 return -EINVAL;
10711
10712 if (wdev->owner_nlportid &&
10713 wdev->owner_nlportid != info->snd_portid)
10714 return -ENOTCONN;
10715
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010716 err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX,
10717 info->attrs[NL80211_ATTR_NAN_FUNC],
10718 nl80211_nan_func_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010719 if (err)
10720 return err;
10721
10722 func = kzalloc(sizeof(*func), GFP_KERNEL);
10723 if (!func)
10724 return -ENOMEM;
10725
10726 func->cookie = wdev->wiphy->cookie_counter++;
10727
10728 if (!tb[NL80211_NAN_FUNC_TYPE] ||
10729 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
10730 err = -EINVAL;
10731 goto out;
10732 }
10733
10734
10735 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
10736
10737 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
10738 err = -EINVAL;
10739 goto out;
10740 }
10741
10742 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
10743 sizeof(func->service_id));
10744
10745 func->close_range =
10746 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
10747
10748 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
10749 func->serv_spec_info_len =
10750 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
10751 func->serv_spec_info =
10752 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
10753 func->serv_spec_info_len,
10754 GFP_KERNEL);
10755 if (!func->serv_spec_info) {
10756 err = -ENOMEM;
10757 goto out;
10758 }
10759 }
10760
10761 if (tb[NL80211_NAN_FUNC_TTL])
10762 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
10763
10764 switch (func->type) {
10765 case NL80211_NAN_FUNC_PUBLISH:
10766 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
10767 err = -EINVAL;
10768 goto out;
10769 }
10770
10771 func->publish_type =
10772 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
10773 func->publish_bcast =
10774 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
10775
10776 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
10777 func->publish_bcast) {
10778 err = -EINVAL;
10779 goto out;
10780 }
10781 break;
10782 case NL80211_NAN_FUNC_SUBSCRIBE:
10783 func->subscribe_active =
10784 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
10785 break;
10786 case NL80211_NAN_FUNC_FOLLOW_UP:
10787 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
10788 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) {
10789 err = -EINVAL;
10790 goto out;
10791 }
10792
10793 func->followup_id =
10794 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
10795 func->followup_reqid =
10796 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
10797 memcpy(func->followup_dest.addr,
10798 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
10799 sizeof(func->followup_dest.addr));
10800 if (func->ttl) {
10801 err = -EINVAL;
10802 goto out;
10803 }
10804 break;
10805 default:
10806 err = -EINVAL;
10807 goto out;
10808 }
10809
10810 if (tb[NL80211_NAN_FUNC_SRF]) {
10811 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
10812
Johannes Bergbfe2c7b2016-10-26 14:42:21 +020010813 err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
10814 tb[NL80211_NAN_FUNC_SRF],
10815 nl80211_nan_srf_policy);
Ayala Bekera442b762016-09-20 17:31:15 +030010816 if (err)
10817 goto out;
10818
10819 func->srf_include =
10820 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
10821
10822 if (srf_tb[NL80211_NAN_SRF_BF]) {
10823 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
10824 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
10825 err = -EINVAL;
10826 goto out;
10827 }
10828
10829 func->srf_bf_len =
10830 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
10831 func->srf_bf =
10832 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
10833 func->srf_bf_len, GFP_KERNEL);
10834 if (!func->srf_bf) {
10835 err = -ENOMEM;
10836 goto out;
10837 }
10838
10839 func->srf_bf_idx =
10840 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
10841 } else {
10842 struct nlattr *attr, *mac_attr =
10843 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
10844 int n_entries, rem, i = 0;
10845
10846 if (!mac_attr) {
10847 err = -EINVAL;
10848 goto out;
10849 }
10850
10851 n_entries = validate_acl_mac_addrs(mac_attr);
10852 if (n_entries <= 0) {
10853 err = -EINVAL;
10854 goto out;
10855 }
10856
10857 func->srf_num_macs = n_entries;
10858 func->srf_macs =
10859 kzalloc(sizeof(*func->srf_macs) * n_entries,
10860 GFP_KERNEL);
10861 if (!func->srf_macs) {
10862 err = -ENOMEM;
10863 goto out;
10864 }
10865
10866 nla_for_each_nested(attr, mac_attr, rem)
10867 memcpy(func->srf_macs[i++].addr, nla_data(attr),
10868 sizeof(*func->srf_macs));
10869 }
10870 }
10871
10872 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
10873 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
10874 func, true);
10875 if (err)
10876 goto out;
10877 }
10878
10879 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
10880 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
10881 func, false);
10882 if (err)
10883 goto out;
10884 }
10885
10886 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10887 if (!msg) {
10888 err = -ENOMEM;
10889 goto out;
10890 }
10891
10892 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10893 NL80211_CMD_ADD_NAN_FUNCTION);
10894 /* This can't really happen - we just allocated 4KB */
10895 if (WARN_ON(!hdr)) {
10896 err = -ENOMEM;
10897 goto out;
10898 }
10899
10900 err = rdev_add_nan_func(rdev, wdev, func);
10901out:
10902 if (err < 0) {
10903 cfg80211_free_nan_func(func);
10904 nlmsg_free(msg);
10905 return err;
10906 }
10907
10908 /* propagate the instance id and cookie to userspace */
10909 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
10910 NL80211_ATTR_PAD))
10911 goto nla_put_failure;
10912
10913 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
10914 if (!func_attr)
10915 goto nla_put_failure;
10916
10917 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
10918 func->instance_id))
10919 goto nla_put_failure;
10920
10921 nla_nest_end(msg, func_attr);
10922
10923 genlmsg_end(msg, hdr);
10924 return genlmsg_reply(msg, info);
10925
10926nla_put_failure:
10927 nlmsg_free(msg);
10928 return -ENOBUFS;
10929}
10930
10931static int nl80211_nan_del_func(struct sk_buff *skb,
10932 struct genl_info *info)
10933{
10934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10935 struct wireless_dev *wdev = info->user_ptr[1];
10936 u64 cookie;
10937
10938 if (wdev->iftype != NL80211_IFTYPE_NAN)
10939 return -EOPNOTSUPP;
10940
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010941 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030010942 return -ENOTCONN;
10943
10944 if (!info->attrs[NL80211_ATTR_COOKIE])
10945 return -EINVAL;
10946
10947 if (wdev->owner_nlportid &&
10948 wdev->owner_nlportid != info->snd_portid)
10949 return -ENOTCONN;
10950
10951 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10952
10953 rdev_del_nan_func(rdev, wdev, cookie);
10954
10955 return 0;
10956}
10957
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030010958static int nl80211_nan_change_config(struct sk_buff *skb,
10959 struct genl_info *info)
10960{
10961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10962 struct wireless_dev *wdev = info->user_ptr[1];
10963 struct cfg80211_nan_conf conf = {};
10964 u32 changed = 0;
10965
10966 if (wdev->iftype != NL80211_IFTYPE_NAN)
10967 return -EOPNOTSUPP;
10968
Arend Van Spriel73c7da32016-10-20 20:08:22 +010010969 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030010970 return -ENOTCONN;
10971
10972 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
10973 conf.master_pref =
10974 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
10975 if (conf.master_pref <= 1 || conf.master_pref == 255)
10976 return -EINVAL;
10977
10978 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
10979 }
10980
10981 if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
10982 conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
10983 changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
10984 }
10985
10986 if (!changed)
10987 return -EINVAL;
10988
10989 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
10990}
10991
Ayala Beker50bcd312016-09-20 17:31:17 +030010992void cfg80211_nan_match(struct wireless_dev *wdev,
10993 struct cfg80211_nan_match_params *match, gfp_t gfp)
10994{
10995 struct wiphy *wiphy = wdev->wiphy;
10996 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
10997 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
10998 struct sk_buff *msg;
10999 void *hdr;
11000
11001 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
11002 return;
11003
11004 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11005 if (!msg)
11006 return;
11007
11008 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
11009 if (!hdr) {
11010 nlmsg_free(msg);
11011 return;
11012 }
11013
11014 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11015 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11016 wdev->netdev->ifindex)) ||
11017 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11018 NL80211_ATTR_PAD))
11019 goto nla_put_failure;
11020
11021 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
11022 NL80211_ATTR_PAD) ||
11023 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
11024 goto nla_put_failure;
11025
11026 match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
11027 if (!match_attr)
11028 goto nla_put_failure;
11029
11030 local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
11031 if (!local_func_attr)
11032 goto nla_put_failure;
11033
11034 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
11035 goto nla_put_failure;
11036
11037 nla_nest_end(msg, local_func_attr);
11038
11039 peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
11040 if (!peer_func_attr)
11041 goto nla_put_failure;
11042
11043 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
11044 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
11045 goto nla_put_failure;
11046
11047 if (match->info && match->info_len &&
11048 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
11049 match->info))
11050 goto nla_put_failure;
11051
11052 nla_nest_end(msg, peer_func_attr);
11053 nla_nest_end(msg, match_attr);
11054 genlmsg_end(msg, hdr);
11055
11056 if (!wdev->owner_nlportid)
11057 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11058 msg, 0, NL80211_MCGRP_NAN, gfp);
11059 else
11060 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11061 wdev->owner_nlportid);
11062
11063 return;
11064
11065nla_put_failure:
11066 nlmsg_free(msg);
11067}
11068EXPORT_SYMBOL(cfg80211_nan_match);
11069
Ayala Beker368e5a72016-09-20 17:31:18 +030011070void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
11071 u8 inst_id,
11072 enum nl80211_nan_func_term_reason reason,
11073 u64 cookie, gfp_t gfp)
11074{
11075 struct wiphy *wiphy = wdev->wiphy;
11076 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11077 struct sk_buff *msg;
11078 struct nlattr *func_attr;
11079 void *hdr;
11080
11081 if (WARN_ON(!inst_id))
11082 return;
11083
11084 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11085 if (!msg)
11086 return;
11087
11088 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
11089 if (!hdr) {
11090 nlmsg_free(msg);
11091 return;
11092 }
11093
11094 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11095 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11096 wdev->netdev->ifindex)) ||
11097 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
11098 NL80211_ATTR_PAD))
11099 goto nla_put_failure;
11100
11101 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11102 NL80211_ATTR_PAD))
11103 goto nla_put_failure;
11104
11105 func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
11106 if (!func_attr)
11107 goto nla_put_failure;
11108
11109 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
11110 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
11111 goto nla_put_failure;
11112
11113 nla_nest_end(msg, func_attr);
11114 genlmsg_end(msg, hdr);
11115
11116 if (!wdev->owner_nlportid)
11117 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
11118 msg, 0, NL80211_MCGRP_NAN, gfp);
11119 else
11120 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
11121 wdev->owner_nlportid);
11122
11123 return;
11124
11125nla_put_failure:
11126 nlmsg_free(msg);
11127}
11128EXPORT_SYMBOL(cfg80211_nan_func_terminated);
11129
Johannes Berg3713b4e2013-02-14 16:19:38 +010011130static int nl80211_get_protocol_features(struct sk_buff *skb,
11131 struct genl_info *info)
11132{
11133 void *hdr;
11134 struct sk_buff *msg;
11135
11136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11137 if (!msg)
11138 return -ENOMEM;
11139
11140 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
11141 NL80211_CMD_GET_PROTOCOL_FEATURES);
11142 if (!hdr)
11143 goto nla_put_failure;
11144
11145 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
11146 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
11147 goto nla_put_failure;
11148
11149 genlmsg_end(msg, hdr);
11150 return genlmsg_reply(msg, info);
11151
11152 nla_put_failure:
11153 kfree_skb(msg);
11154 return -ENOBUFS;
11155}
11156
Jouni Malinen355199e2013-02-27 17:14:27 +020011157static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
11158{
11159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11160 struct cfg80211_update_ft_ies_params ft_params;
11161 struct net_device *dev = info->user_ptr[1];
11162
11163 if (!rdev->ops->update_ft_ies)
11164 return -EOPNOTSUPP;
11165
11166 if (!info->attrs[NL80211_ATTR_MDID] ||
11167 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
11168 return -EINVAL;
11169
11170 memset(&ft_params, 0, sizeof(ft_params));
11171 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
11172 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
11173 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
11174
11175 return rdev_update_ft_ies(rdev, dev, &ft_params);
11176}
11177
Arend van Spriel5de17982013-04-18 15:49:00 +020011178static int nl80211_crit_protocol_start(struct sk_buff *skb,
11179 struct genl_info *info)
11180{
11181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11182 struct wireless_dev *wdev = info->user_ptr[1];
11183 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
11184 u16 duration;
11185 int ret;
11186
11187 if (!rdev->ops->crit_proto_start)
11188 return -EOPNOTSUPP;
11189
11190 if (WARN_ON(!rdev->ops->crit_proto_stop))
11191 return -EINVAL;
11192
11193 if (rdev->crit_proto_nlportid)
11194 return -EBUSY;
11195
11196 /* determine protocol if provided */
11197 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
11198 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
11199
11200 if (proto >= NUM_NL80211_CRIT_PROTO)
11201 return -EINVAL;
11202
11203 /* timeout must be provided */
11204 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
11205 return -EINVAL;
11206
11207 duration =
11208 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
11209
11210 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
11211 return -ERANGE;
11212
11213 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
11214 if (!ret)
11215 rdev->crit_proto_nlportid = info->snd_portid;
11216
11217 return ret;
11218}
11219
11220static int nl80211_crit_protocol_stop(struct sk_buff *skb,
11221 struct genl_info *info)
11222{
11223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11224 struct wireless_dev *wdev = info->user_ptr[1];
11225
11226 if (!rdev->ops->crit_proto_stop)
11227 return -EOPNOTSUPP;
11228
11229 if (rdev->crit_proto_nlportid) {
11230 rdev->crit_proto_nlportid = 0;
11231 rdev_crit_proto_stop(rdev, wdev);
11232 }
11233 return 0;
11234}
11235
Johannes Bergad7e7182013-11-13 13:37:47 +010011236static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
11237{
11238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11239 struct wireless_dev *wdev =
11240 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
11241 int i, err;
11242 u32 vid, subcmd;
11243
11244 if (!rdev->wiphy.vendor_commands)
11245 return -EOPNOTSUPP;
11246
11247 if (IS_ERR(wdev)) {
11248 err = PTR_ERR(wdev);
11249 if (err != -EINVAL)
11250 return err;
11251 wdev = NULL;
11252 } else if (wdev->wiphy != &rdev->wiphy) {
11253 return -EINVAL;
11254 }
11255
11256 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
11257 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
11258 return -EINVAL;
11259
11260 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
11261 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
11262 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
11263 const struct wiphy_vendor_command *vcmd;
11264 void *data = NULL;
11265 int len = 0;
11266
11267 vcmd = &rdev->wiphy.vendor_commands[i];
11268
11269 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11270 continue;
11271
11272 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11273 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11274 if (!wdev)
11275 return -EINVAL;
11276 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11277 !wdev->netdev)
11278 return -EINVAL;
11279
11280 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011281 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010011282 return -ENETDOWN;
11283 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030011284
11285 if (!vcmd->doit)
11286 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010011287 } else {
11288 wdev = NULL;
11289 }
11290
11291 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
11292 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11293 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
11294 }
11295
11296 rdev->cur_cmd_info = info;
11297 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
11298 data, len);
11299 rdev->cur_cmd_info = NULL;
11300 return err;
11301 }
11302
11303 return -EOPNOTSUPP;
11304}
11305
Johannes Berg7bdbe402015-08-15 22:39:49 +030011306static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
11307 struct netlink_callback *cb,
11308 struct cfg80211_registered_device **rdev,
11309 struct wireless_dev **wdev)
11310{
11311 u32 vid, subcmd;
11312 unsigned int i;
11313 int vcmd_idx = -1;
11314 int err;
11315 void *data = NULL;
11316 unsigned int data_len = 0;
11317
11318 rtnl_lock();
11319
11320 if (cb->args[0]) {
11321 /* subtract the 1 again here */
11322 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
11323 struct wireless_dev *tmp;
11324
11325 if (!wiphy) {
11326 err = -ENODEV;
11327 goto out_unlock;
11328 }
11329 *rdev = wiphy_to_rdev(wiphy);
11330 *wdev = NULL;
11331
11332 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030011333 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011334 if (tmp->identifier == cb->args[1] - 1) {
11335 *wdev = tmp;
11336 break;
11337 }
11338 }
11339 }
11340
11341 /* keep rtnl locked in successful case */
11342 return 0;
11343 }
11344
11345 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
11346 nl80211_fam.attrbuf, nl80211_fam.maxattr,
11347 nl80211_policy);
11348 if (err)
11349 goto out_unlock;
11350
11351 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
11352 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
11353 err = -EINVAL;
11354 goto out_unlock;
11355 }
11356
11357 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
11358 nl80211_fam.attrbuf);
11359 if (IS_ERR(*wdev))
11360 *wdev = NULL;
11361
11362 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
11363 nl80211_fam.attrbuf);
11364 if (IS_ERR(*rdev)) {
11365 err = PTR_ERR(*rdev);
11366 goto out_unlock;
11367 }
11368
11369 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
11370 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
11371
11372 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
11373 const struct wiphy_vendor_command *vcmd;
11374
11375 vcmd = &(*rdev)->wiphy.vendor_commands[i];
11376
11377 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
11378 continue;
11379
11380 if (!vcmd->dumpit) {
11381 err = -EOPNOTSUPP;
11382 goto out_unlock;
11383 }
11384
11385 vcmd_idx = i;
11386 break;
11387 }
11388
11389 if (vcmd_idx < 0) {
11390 err = -EOPNOTSUPP;
11391 goto out_unlock;
11392 }
11393
11394 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
11395 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11396 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
11397 }
11398
11399 /* 0 is the first index - add 1 to parse only once */
11400 cb->args[0] = (*rdev)->wiphy_idx + 1;
11401 /* add 1 to know if it was NULL */
11402 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
11403 cb->args[2] = vcmd_idx;
11404 cb->args[3] = (unsigned long)data;
11405 cb->args[4] = data_len;
11406
11407 /* keep rtnl locked in successful case */
11408 return 0;
11409 out_unlock:
11410 rtnl_unlock();
11411 return err;
11412}
11413
11414static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
11415 struct netlink_callback *cb)
11416{
11417 struct cfg80211_registered_device *rdev;
11418 struct wireless_dev *wdev;
11419 unsigned int vcmd_idx;
11420 const struct wiphy_vendor_command *vcmd;
11421 void *data;
11422 int data_len;
11423 int err;
11424 struct nlattr *vendor_data;
11425
11426 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
11427 if (err)
11428 return err;
11429
11430 vcmd_idx = cb->args[2];
11431 data = (void *)cb->args[3];
11432 data_len = cb->args[4];
11433 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
11434
11435 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
11436 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
11437 if (!wdev)
11438 return -EINVAL;
11439 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
11440 !wdev->netdev)
11441 return -EINVAL;
11442
11443 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011444 if (!wdev_running(wdev))
Johannes Berg7bdbe402015-08-15 22:39:49 +030011445 return -ENETDOWN;
11446 }
11447 }
11448
11449 while (1) {
11450 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
11451 cb->nlh->nlmsg_seq, NLM_F_MULTI,
11452 NL80211_CMD_VENDOR);
11453 if (!hdr)
11454 break;
11455
11456 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011457 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
11458 wdev_id(wdev),
11459 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030011460 genlmsg_cancel(skb, hdr);
11461 break;
11462 }
11463
11464 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
11465 if (!vendor_data) {
11466 genlmsg_cancel(skb, hdr);
11467 break;
11468 }
11469
11470 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
11471 (unsigned long *)&cb->args[5]);
11472 nla_nest_end(skb, vendor_data);
11473
11474 if (err == -ENOBUFS || err == -ENOENT) {
11475 genlmsg_cancel(skb, hdr);
11476 break;
11477 } else if (err) {
11478 genlmsg_cancel(skb, hdr);
11479 goto out;
11480 }
11481
11482 genlmsg_end(skb, hdr);
11483 }
11484
11485 err = skb->len;
11486 out:
11487 rtnl_unlock();
11488 return err;
11489}
11490
Johannes Bergad7e7182013-11-13 13:37:47 +010011491struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
11492 enum nl80211_commands cmd,
11493 enum nl80211_attrs attr,
11494 int approxlen)
11495{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011496 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010011497
11498 if (WARN_ON(!rdev->cur_cmd_info))
11499 return NULL;
11500
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020011501 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010011502 rdev->cur_cmd_info->snd_portid,
11503 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010011504 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010011505}
11506EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
11507
11508int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
11509{
11510 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
11511 void *hdr = ((void **)skb->cb)[1];
11512 struct nlattr *data = ((void **)skb->cb)[2];
11513
Johannes Bergbd8c78e2014-07-30 14:55:26 +020011514 /* clear CB data for netlink core to own from now on */
11515 memset(skb->cb, 0, sizeof(skb->cb));
11516
Johannes Bergad7e7182013-11-13 13:37:47 +010011517 if (WARN_ON(!rdev->cur_cmd_info)) {
11518 kfree_skb(skb);
11519 return -EINVAL;
11520 }
11521
11522 nla_nest_end(skb, data);
11523 genlmsg_end(skb, hdr);
11524 return genlmsg_reply(skb, rdev->cur_cmd_info);
11525}
11526EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
11527
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011528static int nl80211_set_qos_map(struct sk_buff *skb,
11529 struct genl_info *info)
11530{
11531 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11532 struct cfg80211_qos_map *qos_map = NULL;
11533 struct net_device *dev = info->user_ptr[1];
11534 u8 *pos, len, num_des, des_len, des;
11535 int ret;
11536
11537 if (!rdev->ops->set_qos_map)
11538 return -EOPNOTSUPP;
11539
11540 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
11541 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
11542 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
11543
11544 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
11545 len > IEEE80211_QOS_MAP_LEN_MAX)
11546 return -EINVAL;
11547
11548 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
11549 if (!qos_map)
11550 return -ENOMEM;
11551
11552 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
11553 if (num_des) {
11554 des_len = num_des *
11555 sizeof(struct cfg80211_dscp_exception);
11556 memcpy(qos_map->dscp_exception, pos, des_len);
11557 qos_map->num_des = num_des;
11558 for (des = 0; des < num_des; des++) {
11559 if (qos_map->dscp_exception[des].up > 7) {
11560 kfree(qos_map);
11561 return -EINVAL;
11562 }
11563 }
11564 pos += des_len;
11565 }
11566 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
11567 }
11568
11569 wdev_lock(dev->ieee80211_ptr);
11570 ret = nl80211_key_allowed(dev->ieee80211_ptr);
11571 if (!ret)
11572 ret = rdev_set_qos_map(rdev, dev, qos_map);
11573 wdev_unlock(dev->ieee80211_ptr);
11574
11575 kfree(qos_map);
11576 return ret;
11577}
11578
Johannes Berg960d01a2014-09-09 22:55:35 +030011579static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
11580{
11581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11582 struct net_device *dev = info->user_ptr[1];
11583 struct wireless_dev *wdev = dev->ieee80211_ptr;
11584 const u8 *peer;
11585 u8 tsid, up;
11586 u16 admitted_time = 0;
11587 int err;
11588
Johannes Berg723e73a2014-10-22 09:25:06 +020011589 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030011590 return -EOPNOTSUPP;
11591
11592 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
11593 !info->attrs[NL80211_ATTR_USER_PRIO])
11594 return -EINVAL;
11595
11596 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11597 if (tsid >= IEEE80211_NUM_TIDS)
11598 return -EINVAL;
11599
11600 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
11601 if (up >= IEEE80211_NUM_UPS)
11602 return -EINVAL;
11603
11604 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020011605 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030011606 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020011607 * need more attributes for that (e.g. BA session requirement);
11608 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030011609 */
11610 return -EINVAL;
11611 }
11612
11613 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11614
11615 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
11616 admitted_time =
11617 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
11618 if (!admitted_time)
11619 return -EINVAL;
11620 }
11621
11622 wdev_lock(wdev);
11623 switch (wdev->iftype) {
11624 case NL80211_IFTYPE_STATION:
11625 case NL80211_IFTYPE_P2P_CLIENT:
11626 if (wdev->current_bss)
11627 break;
11628 err = -ENOTCONN;
11629 goto out;
11630 default:
11631 err = -EOPNOTSUPP;
11632 goto out;
11633 }
11634
11635 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
11636
11637 out:
11638 wdev_unlock(wdev);
11639 return err;
11640}
11641
11642static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
11643{
11644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11645 struct net_device *dev = info->user_ptr[1];
11646 struct wireless_dev *wdev = dev->ieee80211_ptr;
11647 const u8 *peer;
11648 u8 tsid;
11649 int err;
11650
11651 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
11652 return -EINVAL;
11653
11654 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
11655 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
11656
11657 wdev_lock(wdev);
11658 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
11659 wdev_unlock(wdev);
11660
11661 return err;
11662}
11663
Arik Nemtsov1057d352014-11-19 12:54:26 +020011664static int nl80211_tdls_channel_switch(struct sk_buff *skb,
11665 struct genl_info *info)
11666{
11667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11668 struct net_device *dev = info->user_ptr[1];
11669 struct wireless_dev *wdev = dev->ieee80211_ptr;
11670 struct cfg80211_chan_def chandef = {};
11671 const u8 *addr;
11672 u8 oper_class;
11673 int err;
11674
11675 if (!rdev->ops->tdls_channel_switch ||
11676 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11677 return -EOPNOTSUPP;
11678
11679 switch (dev->ieee80211_ptr->iftype) {
11680 case NL80211_IFTYPE_STATION:
11681 case NL80211_IFTYPE_P2P_CLIENT:
11682 break;
11683 default:
11684 return -EOPNOTSUPP;
11685 }
11686
11687 if (!info->attrs[NL80211_ATTR_MAC] ||
11688 !info->attrs[NL80211_ATTR_OPER_CLASS])
11689 return -EINVAL;
11690
11691 err = nl80211_parse_chandef(rdev, info, &chandef);
11692 if (err)
11693 return err;
11694
11695 /*
11696 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11697 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11698 * specification is not defined for them.
11699 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020011700 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020011701 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
11702 chandef.width != NL80211_CHAN_WIDTH_20)
11703 return -EINVAL;
11704
11705 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030011706 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
11707 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020011708 return -EINVAL;
11709
11710 /* don't allow switching to DFS channels */
11711 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
11712 return -EINVAL;
11713
11714 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11715 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
11716
11717 wdev_lock(wdev);
11718 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
11719 wdev_unlock(wdev);
11720
11721 return err;
11722}
11723
11724static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
11725 struct genl_info *info)
11726{
11727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11728 struct net_device *dev = info->user_ptr[1];
11729 struct wireless_dev *wdev = dev->ieee80211_ptr;
11730 const u8 *addr;
11731
11732 if (!rdev->ops->tdls_channel_switch ||
11733 !rdev->ops->tdls_cancel_channel_switch ||
11734 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
11735 return -EOPNOTSUPP;
11736
11737 switch (dev->ieee80211_ptr->iftype) {
11738 case NL80211_IFTYPE_STATION:
11739 case NL80211_IFTYPE_P2P_CLIENT:
11740 break;
11741 default:
11742 return -EOPNOTSUPP;
11743 }
11744
11745 if (!info->attrs[NL80211_ATTR_MAC])
11746 return -EINVAL;
11747
11748 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
11749
11750 wdev_lock(wdev);
11751 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
11752 wdev_unlock(wdev);
11753
11754 return 0;
11755}
11756
Johannes Berg4c476992010-10-04 21:36:35 +020011757#define NL80211_FLAG_NEED_WIPHY 0x01
11758#define NL80211_FLAG_NEED_NETDEV 0x02
11759#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020011760#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11761#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11762 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020011763#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020011764/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020011765#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11766 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030011767#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020011768
Johannes Bergf84f7712013-11-14 17:14:45 +010011769static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011770 struct genl_info *info)
11771{
11772 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020011773 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011774 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020011775 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
11776
11777 if (rtnl)
11778 rtnl_lock();
11779
11780 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020011781 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020011782 if (IS_ERR(rdev)) {
11783 if (rtnl)
11784 rtnl_unlock();
11785 return PTR_ERR(rdev);
11786 }
11787 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011788 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
11789 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020011790 ASSERT_RTNL();
11791
Johannes Berg89a54e42012-06-15 14:33:17 +020011792 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
11793 info->attrs);
11794 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020011795 if (rtnl)
11796 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020011797 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020011798 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011799
Johannes Berg89a54e42012-06-15 14:33:17 +020011800 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011801 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020011802
Johannes Berg1bf614e2012-06-15 15:23:36 +020011803 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
11804 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020011805 if (rtnl)
11806 rtnl_unlock();
11807 return -EINVAL;
11808 }
11809
11810 info->user_ptr[1] = dev;
11811 } else {
11812 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020011813 }
Johannes Berg89a54e42012-06-15 14:33:17 +020011814
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011815 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
11816 !wdev_running(wdev)) {
11817 if (rtnl)
11818 rtnl_unlock();
11819 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020011820 }
11821
Arend Van Spriel73c7da32016-10-20 20:08:22 +010011822 if (dev)
11823 dev_hold(dev);
11824
Johannes Berg4c476992010-10-04 21:36:35 +020011825 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011826 }
11827
11828 return 0;
11829}
11830
Johannes Bergf84f7712013-11-14 17:14:45 +010011831static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020011832 struct genl_info *info)
11833{
Johannes Berg1bf614e2012-06-15 15:23:36 +020011834 if (info->user_ptr[1]) {
11835 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
11836 struct wireless_dev *wdev = info->user_ptr[1];
11837
11838 if (wdev->netdev)
11839 dev_put(wdev->netdev);
11840 } else {
11841 dev_put(info->user_ptr[1]);
11842 }
11843 }
Johannes Berg5393b912014-09-10 15:00:16 +030011844
Johannes Berg4c476992010-10-04 21:36:35 +020011845 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
11846 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030011847
11848 /* If needed, clear the netlink message payload from the SKB
11849 * as it might contain key data that shouldn't stick around on
11850 * the heap after the SKB is freed. The netlink message header
11851 * is still needed for further processing, so leave it intact.
11852 */
11853 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
11854 struct nlmsghdr *nlh = nlmsg_hdr(skb);
11855
11856 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
11857 }
Johannes Berg4c476992010-10-04 21:36:35 +020011858}
11859
Johannes Berg4534de82013-11-14 17:14:46 +010011860static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040011861 {
11862 .cmd = NL80211_CMD_GET_WIPHY,
11863 .doit = nl80211_get_wiphy,
11864 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020011865 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040011866 .policy = nl80211_policy,
11867 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011868 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11869 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011870 },
11871 {
11872 .cmd = NL80211_CMD_SET_WIPHY,
11873 .doit = nl80211_set_wiphy,
11874 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011875 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011876 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011877 },
11878 {
11879 .cmd = NL80211_CMD_GET_INTERFACE,
11880 .doit = nl80211_get_interface,
11881 .dumpit = nl80211_dump_interface,
11882 .policy = nl80211_policy,
11883 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020011884 .internal_flags = NL80211_FLAG_NEED_WDEV |
11885 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011886 },
11887 {
11888 .cmd = NL80211_CMD_SET_INTERFACE,
11889 .doit = nl80211_set_interface,
11890 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011891 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011892 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11893 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011894 },
11895 {
11896 .cmd = NL80211_CMD_NEW_INTERFACE,
11897 .doit = nl80211_new_interface,
11898 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011899 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011900 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11901 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011902 },
11903 {
11904 .cmd = NL80211_CMD_DEL_INTERFACE,
11905 .doit = nl80211_del_interface,
11906 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011907 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020011908 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011909 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040011910 },
Johannes Berg41ade002007-12-19 02:03:29 +010011911 {
11912 .cmd = NL80211_CMD_GET_KEY,
11913 .doit = nl80211_get_key,
11914 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011915 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011917 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011918 },
11919 {
11920 .cmd = NL80211_CMD_SET_KEY,
11921 .doit = nl80211_set_key,
11922 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011923 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011925 NL80211_FLAG_NEED_RTNL |
11926 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011927 },
11928 {
11929 .cmd = NL80211_CMD_NEW_KEY,
11930 .doit = nl80211_new_key,
11931 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011932 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011934 NL80211_FLAG_NEED_RTNL |
11935 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010011936 },
11937 {
11938 .cmd = NL80211_CMD_DEL_KEY,
11939 .doit = nl80211_del_key,
11940 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011941 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011942 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011943 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010011944 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010011945 {
11946 .cmd = NL80211_CMD_SET_BEACON,
11947 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011948 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011949 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011951 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011952 },
11953 {
Johannes Berg88600202012-02-13 15:17:18 +010011954 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011955 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011956 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011957 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011958 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011959 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011960 },
11961 {
Johannes Berg88600202012-02-13 15:17:18 +010011962 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011963 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011964 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010011965 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011966 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011967 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010011968 },
Johannes Berg5727ef12007-12-19 02:03:34 +010011969 {
11970 .cmd = NL80211_CMD_GET_STATION,
11971 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010011972 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010011973 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020011974 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11975 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011976 },
11977 {
11978 .cmd = NL80211_CMD_SET_STATION,
11979 .doit = nl80211_set_station,
11980 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011981 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011982 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011983 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011984 },
11985 {
11986 .cmd = NL80211_CMD_NEW_STATION,
11987 .doit = nl80211_new_station,
11988 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011989 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011990 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011991 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010011992 },
11993 {
11994 .cmd = NL80211_CMD_DEL_STATION,
11995 .doit = nl80211_del_station,
11996 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020011997 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011998 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011999 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010012000 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012001 {
12002 .cmd = NL80211_CMD_GET_MPATH,
12003 .doit = nl80211_get_mpath,
12004 .dumpit = nl80211_dump_mpath,
12005 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012006 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012008 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012009 },
12010 {
Henning Rogge66be7d22014-09-12 08:58:49 +020012011 .cmd = NL80211_CMD_GET_MPP,
12012 .doit = nl80211_get_mpp,
12013 .dumpit = nl80211_dump_mpp,
12014 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012015 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020012016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12017 NL80211_FLAG_NEED_RTNL,
12018 },
12019 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012020 .cmd = NL80211_CMD_SET_MPATH,
12021 .doit = nl80211_set_mpath,
12022 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012023 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012025 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012026 },
12027 {
12028 .cmd = NL80211_CMD_NEW_MPATH,
12029 .doit = nl80211_new_mpath,
12030 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012031 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012033 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012034 },
12035 {
12036 .cmd = NL80211_CMD_DEL_MPATH,
12037 .doit = nl80211_del_mpath,
12038 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012039 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012041 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010012042 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012043 {
12044 .cmd = NL80211_CMD_SET_BSS,
12045 .doit = nl80211_set_bss,
12046 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012047 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012049 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030012050 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012051 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012052 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012053 .doit = nl80211_get_reg_do,
12054 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012055 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012056 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012057 /* can be retrieved by unprivileged users */
12058 },
Johannes Bergb6863032015-10-15 09:25:18 +020012059#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080012060 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012061 .cmd = NL80211_CMD_SET_REG,
12062 .doit = nl80211_set_reg,
12063 .policy = nl80211_policy,
12064 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020012065 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012066 },
Johannes Bergb6863032015-10-15 09:25:18 +020012067#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012068 {
12069 .cmd = NL80211_CMD_REQ_SET_REG,
12070 .doit = nl80211_req_set_reg,
12071 .policy = nl80211_policy,
12072 .flags = GENL_ADMIN_PERM,
12073 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012074 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012075 .cmd = NL80211_CMD_GET_MESH_CONFIG,
12076 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012077 .policy = nl80211_policy,
12078 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012080 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012081 },
12082 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080012083 .cmd = NL80211_CMD_SET_MESH_CONFIG,
12084 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012085 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012086 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012088 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070012089 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020012090 {
Johannes Berg2a519312009-02-10 21:25:55 +010012091 .cmd = NL80211_CMD_TRIGGER_SCAN,
12092 .doit = nl80211_trigger_scan,
12093 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012094 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020012095 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012096 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010012097 },
12098 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012099 .cmd = NL80211_CMD_ABORT_SCAN,
12100 .doit = nl80211_abort_scan,
12101 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012102 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053012103 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12104 NL80211_FLAG_NEED_RTNL,
12105 },
12106 {
Johannes Berg2a519312009-02-10 21:25:55 +010012107 .cmd = NL80211_CMD_GET_SCAN,
12108 .policy = nl80211_policy,
12109 .dumpit = nl80211_dump_scan,
12110 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020012111 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030012112 .cmd = NL80211_CMD_START_SCHED_SCAN,
12113 .doit = nl80211_start_sched_scan,
12114 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012115 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12117 NL80211_FLAG_NEED_RTNL,
12118 },
12119 {
12120 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
12121 .doit = nl80211_stop_sched_scan,
12122 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012123 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030012124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12125 NL80211_FLAG_NEED_RTNL,
12126 },
12127 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020012128 .cmd = NL80211_CMD_AUTHENTICATE,
12129 .doit = nl80211_authenticate,
12130 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012131 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012133 NL80211_FLAG_NEED_RTNL |
12134 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012135 },
12136 {
12137 .cmd = NL80211_CMD_ASSOCIATE,
12138 .doit = nl80211_associate,
12139 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012140 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012141 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012142 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012143 },
12144 {
12145 .cmd = NL80211_CMD_DEAUTHENTICATE,
12146 .doit = nl80211_deauthenticate,
12147 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012148 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012150 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012151 },
12152 {
12153 .cmd = NL80211_CMD_DISASSOCIATE,
12154 .doit = nl80211_disassociate,
12155 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012156 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012157 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012158 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020012159 },
Johannes Berg04a773a2009-04-19 21:24:32 +020012160 {
12161 .cmd = NL80211_CMD_JOIN_IBSS,
12162 .doit = nl80211_join_ibss,
12163 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012164 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012166 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012167 },
12168 {
12169 .cmd = NL80211_CMD_LEAVE_IBSS,
12170 .doit = nl80211_leave_ibss,
12171 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012172 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012173 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012174 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020012175 },
Johannes Bergaff89a92009-07-01 21:26:51 +020012176#ifdef CONFIG_NL80211_TESTMODE
12177 {
12178 .cmd = NL80211_CMD_TESTMODE,
12179 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070012180 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020012181 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012182 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012183 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12184 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020012185 },
12186#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020012187 {
12188 .cmd = NL80211_CMD_CONNECT,
12189 .doit = nl80211_connect,
12190 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012191 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012193 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012194 },
12195 {
12196 .cmd = NL80211_CMD_DISCONNECT,
12197 .doit = nl80211_disconnect,
12198 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012199 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020012200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012201 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020012202 },
Johannes Berg463d0182009-07-14 00:33:35 +020012203 {
12204 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
12205 .doit = nl80211_wiphy_netns,
12206 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012207 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012208 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12209 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020012210 },
Holger Schurig61fa7132009-11-11 12:25:40 +010012211 {
12212 .cmd = NL80211_CMD_GET_SURVEY,
12213 .policy = nl80211_policy,
12214 .dumpit = nl80211_dump_survey,
12215 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012216 {
12217 .cmd = NL80211_CMD_SET_PMKSA,
12218 .doit = nl80211_setdel_pmksa,
12219 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012220 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012222 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012223 },
12224 {
12225 .cmd = NL80211_CMD_DEL_PMKSA,
12226 .doit = nl80211_setdel_pmksa,
12227 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012228 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012230 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012231 },
12232 {
12233 .cmd = NL80211_CMD_FLUSH_PMKSA,
12234 .doit = nl80211_flush_pmksa,
12235 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012236 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012238 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010012239 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012240 {
12241 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
12242 .doit = nl80211_remain_on_channel,
12243 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012245 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012246 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012247 },
12248 {
12249 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
12250 .doit = nl80211_cancel_remain_on_channel,
12251 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012252 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012253 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012254 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012255 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012256 {
12257 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
12258 .doit = nl80211_set_tx_bitrate_mask,
12259 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012260 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012261 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12262 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020012263 },
Jouni Malinen026331c2010-02-15 12:53:10 +020012264 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012265 .cmd = NL80211_CMD_REGISTER_FRAME,
12266 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012267 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012268 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012269 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020012270 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012271 },
12272 {
Johannes Berg2e161f72010-08-12 15:38:38 +020012273 .cmd = NL80211_CMD_FRAME,
12274 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020012275 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012276 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012277 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020012278 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020012279 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020012280 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012281 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
12282 .doit = nl80211_tx_mgmt_cancel_wait,
12283 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012284 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020012285 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010012286 NL80211_FLAG_NEED_RTNL,
12287 },
12288 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020012289 .cmd = NL80211_CMD_SET_POWER_SAVE,
12290 .doit = nl80211_set_power_save,
12291 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012292 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012293 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12294 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012295 },
12296 {
12297 .cmd = NL80211_CMD_GET_POWER_SAVE,
12298 .doit = nl80211_get_power_save,
12299 .policy = nl80211_policy,
12300 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020012301 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12302 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020012303 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012304 {
12305 .cmd = NL80211_CMD_SET_CQM,
12306 .doit = nl80211_set_cqm,
12307 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012308 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012309 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12310 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012311 },
Johannes Bergf444de02010-05-05 15:25:02 +020012312 {
12313 .cmd = NL80211_CMD_SET_CHANNEL,
12314 .doit = nl80211_set_channel,
12315 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012316 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020012317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12318 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020012319 },
Bill Jordane8347eb2010-10-01 13:54:28 -040012320 {
12321 .cmd = NL80211_CMD_SET_WDS_PEER,
12322 .doit = nl80211_set_wds_peer,
12323 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012324 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020012325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12326 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040012327 },
Johannes Berg29cbe682010-12-03 09:20:44 +010012328 {
12329 .cmd = NL80211_CMD_JOIN_MESH,
12330 .doit = nl80211_join_mesh,
12331 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012332 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12334 NL80211_FLAG_NEED_RTNL,
12335 },
12336 {
12337 .cmd = NL80211_CMD_LEAVE_MESH,
12338 .doit = nl80211_leave_mesh,
12339 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010012341 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12342 NL80211_FLAG_NEED_RTNL,
12343 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012344 {
12345 .cmd = NL80211_CMD_JOIN_OCB,
12346 .doit = nl80211_join_ocb,
12347 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012348 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12350 NL80211_FLAG_NEED_RTNL,
12351 },
12352 {
12353 .cmd = NL80211_CMD_LEAVE_OCB,
12354 .doit = nl80211_leave_ocb,
12355 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012356 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010012357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12358 NL80211_FLAG_NEED_RTNL,
12359 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012360#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020012361 {
12362 .cmd = NL80211_CMD_GET_WOWLAN,
12363 .doit = nl80211_get_wowlan,
12364 .policy = nl80211_policy,
12365 /* can be retrieved by unprivileged users */
12366 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12367 NL80211_FLAG_NEED_RTNL,
12368 },
12369 {
12370 .cmd = NL80211_CMD_SET_WOWLAN,
12371 .doit = nl80211_set_wowlan,
12372 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012373 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020012374 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12375 NL80211_FLAG_NEED_RTNL,
12376 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020012377#endif
Johannes Berge5497d72011-07-05 16:35:40 +020012378 {
12379 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
12380 .doit = nl80211_set_rekey_data,
12381 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012382 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020012383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030012384 NL80211_FLAG_NEED_RTNL |
12385 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020012386 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030012387 {
12388 .cmd = NL80211_CMD_TDLS_MGMT,
12389 .doit = nl80211_tdls_mgmt,
12390 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012391 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12393 NL80211_FLAG_NEED_RTNL,
12394 },
12395 {
12396 .cmd = NL80211_CMD_TDLS_OPER,
12397 .doit = nl80211_tdls_oper,
12398 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012399 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030012400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12401 NL80211_FLAG_NEED_RTNL,
12402 },
Johannes Berg28946da2011-11-04 11:18:12 +010012403 {
12404 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
12405 .doit = nl80211_register_unexpected_frame,
12406 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012407 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010012408 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12409 NL80211_FLAG_NEED_RTNL,
12410 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010012411 {
12412 .cmd = NL80211_CMD_PROBE_CLIENT,
12413 .doit = nl80211_probe_client,
12414 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012415 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020012416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010012417 NL80211_FLAG_NEED_RTNL,
12418 },
Johannes Berg5e760232011-11-04 11:18:17 +010012419 {
12420 .cmd = NL80211_CMD_REGISTER_BEACONS,
12421 .doit = nl80211_register_beacons,
12422 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012423 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010012424 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12425 NL80211_FLAG_NEED_RTNL,
12426 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012427 {
12428 .cmd = NL80211_CMD_SET_NOACK_MAP,
12429 .doit = nl80211_set_noack_map,
12430 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012431 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010012432 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12433 NL80211_FLAG_NEED_RTNL,
12434 },
Johannes Berg98104fde2012-06-16 00:19:54 +020012435 {
12436 .cmd = NL80211_CMD_START_P2P_DEVICE,
12437 .doit = nl80211_start_p2p_device,
12438 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012439 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012440 .internal_flags = NL80211_FLAG_NEED_WDEV |
12441 NL80211_FLAG_NEED_RTNL,
12442 },
12443 {
12444 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
12445 .doit = nl80211_stop_p2p_device,
12446 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012447 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020012448 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12449 NL80211_FLAG_NEED_RTNL,
12450 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012451 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012452 .cmd = NL80211_CMD_START_NAN,
12453 .doit = nl80211_start_nan,
12454 .policy = nl80211_policy,
12455 .flags = GENL_ADMIN_PERM,
12456 .internal_flags = NL80211_FLAG_NEED_WDEV |
12457 NL80211_FLAG_NEED_RTNL,
12458 },
12459 {
12460 .cmd = NL80211_CMD_STOP_NAN,
12461 .doit = nl80211_stop_nan,
12462 .policy = nl80211_policy,
12463 .flags = GENL_ADMIN_PERM,
12464 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12465 NL80211_FLAG_NEED_RTNL,
12466 },
12467 {
Ayala Bekera442b762016-09-20 17:31:15 +030012468 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
12469 .doit = nl80211_nan_add_func,
12470 .policy = nl80211_policy,
12471 .flags = GENL_ADMIN_PERM,
12472 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12473 NL80211_FLAG_NEED_RTNL,
12474 },
12475 {
12476 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
12477 .doit = nl80211_nan_del_func,
12478 .policy = nl80211_policy,
12479 .flags = GENL_ADMIN_PERM,
12480 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12481 NL80211_FLAG_NEED_RTNL,
12482 },
12483 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012484 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
12485 .doit = nl80211_nan_change_config,
12486 .policy = nl80211_policy,
12487 .flags = GENL_ADMIN_PERM,
12488 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12489 NL80211_FLAG_NEED_RTNL,
12490 },
12491 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012492 .cmd = NL80211_CMD_SET_MCAST_RATE,
12493 .doit = nl80211_set_mcast_rate,
12494 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012495 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010012496 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12497 NL80211_FLAG_NEED_RTNL,
12498 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012499 {
12500 .cmd = NL80211_CMD_SET_MAC_ACL,
12501 .doit = nl80211_set_mac_acl,
12502 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012503 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053012504 .internal_flags = NL80211_FLAG_NEED_NETDEV |
12505 NL80211_FLAG_NEED_RTNL,
12506 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010012507 {
12508 .cmd = NL80211_CMD_RADAR_DETECT,
12509 .doit = nl80211_start_radar_detection,
12510 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012511 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12513 NL80211_FLAG_NEED_RTNL,
12514 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010012515 {
12516 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
12517 .doit = nl80211_get_protocol_features,
12518 .policy = nl80211_policy,
12519 },
Jouni Malinen355199e2013-02-27 17:14:27 +020012520 {
12521 .cmd = NL80211_CMD_UPDATE_FT_IES,
12522 .doit = nl80211_update_ft_ies,
12523 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012524 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020012525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12526 NL80211_FLAG_NEED_RTNL,
12527 },
Arend van Spriel5de17982013-04-18 15:49:00 +020012528 {
12529 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
12530 .doit = nl80211_crit_protocol_start,
12531 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012532 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012533 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12534 NL80211_FLAG_NEED_RTNL,
12535 },
12536 {
12537 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
12538 .doit = nl80211_crit_protocol_stop,
12539 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012540 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020012541 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
12542 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012543 },
12544 {
12545 .cmd = NL80211_CMD_GET_COALESCE,
12546 .doit = nl80211_get_coalesce,
12547 .policy = nl80211_policy,
12548 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12549 NL80211_FLAG_NEED_RTNL,
12550 },
12551 {
12552 .cmd = NL80211_CMD_SET_COALESCE,
12553 .doit = nl80211_set_coalesce,
12554 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012555 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012556 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12557 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012558 },
12559 {
12560 .cmd = NL80211_CMD_CHANNEL_SWITCH,
12561 .doit = nl80211_channel_switch,
12562 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012563 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020012564 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12565 NL80211_FLAG_NEED_RTNL,
12566 },
Johannes Bergad7e7182013-11-13 13:37:47 +010012567 {
12568 .cmd = NL80211_CMD_VENDOR,
12569 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030012570 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010012571 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012572 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010012573 .internal_flags = NL80211_FLAG_NEED_WIPHY |
12574 NL80211_FLAG_NEED_RTNL,
12575 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012576 {
12577 .cmd = NL80211_CMD_SET_QOS_MAP,
12578 .doit = nl80211_set_qos_map,
12579 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012580 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080012581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12582 NL80211_FLAG_NEED_RTNL,
12583 },
Johannes Berg960d01a2014-09-09 22:55:35 +030012584 {
12585 .cmd = NL80211_CMD_ADD_TX_TS,
12586 .doit = nl80211_add_tx_ts,
12587 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12590 NL80211_FLAG_NEED_RTNL,
12591 },
12592 {
12593 .cmd = NL80211_CMD_DEL_TX_TS,
12594 .doit = nl80211_del_tx_ts,
12595 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012596 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030012597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12598 NL80211_FLAG_NEED_RTNL,
12599 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020012600 {
12601 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
12602 .doit = nl80211_tdls_channel_switch,
12603 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012604 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12606 NL80211_FLAG_NEED_RTNL,
12607 },
12608 {
12609 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
12610 .doit = nl80211_tdls_cancel_channel_switch,
12611 .policy = nl80211_policy,
Martin Willi5617c6c2016-05-09 18:33:58 +020012612 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020012613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
12614 NL80211_FLAG_NEED_RTNL,
12615 },
Johannes Berg55682962007-09-20 13:09:35 -040012616};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012617
Johannes Berg55682962007-09-20 13:09:35 -040012618/* notification functions */
12619
Johannes Berg3bb20552014-05-26 13:52:25 +020012620void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
12621 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040012622{
12623 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020012624 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040012625
Johannes Berg3bb20552014-05-26 13:52:25 +020012626 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
12627 cmd != NL80211_CMD_DEL_WIPHY);
12628
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012630 if (!msg)
12631 return;
12632
Johannes Berg3bb20552014-05-26 13:52:25 +020012633 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040012634 nlmsg_free(msg);
12635 return;
12636 }
12637
Johannes Berg68eb5502013-11-19 15:19:38 +010012638 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012639 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040012640}
12641
Denis Kenzior896ff062016-08-03 16:58:33 -050012642void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
12643 struct wireless_dev *wdev,
12644 enum nl80211_commands cmd)
12645{
12646 struct sk_buff *msg;
12647
12648 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
12649 cmd != NL80211_CMD_DEL_INTERFACE);
12650
12651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12652 if (!msg)
12653 return;
12654
12655 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
12656 cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
12657 nlmsg_free(msg);
12658 return;
12659 }
12660
12661 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12662 NL80211_MCGRP_CONFIG, GFP_KERNEL);
12663}
12664
Johannes Berg362a4152009-05-24 16:43:15 +020012665static int nl80211_add_scan_req(struct sk_buff *msg,
12666 struct cfg80211_registered_device *rdev)
12667{
12668 struct cfg80211_scan_request *req = rdev->scan_req;
12669 struct nlattr *nest;
12670 int i;
12671
12672 if (WARN_ON(!req))
12673 return 0;
12674
12675 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
12676 if (!nest)
12677 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012678 for (i = 0; i < req->n_ssids; i++) {
12679 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
12680 goto nla_put_failure;
12681 }
Johannes Berg362a4152009-05-24 16:43:15 +020012682 nla_nest_end(msg, nest);
12683
12684 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
12685 if (!nest)
12686 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040012687 for (i = 0; i < req->n_channels; i++) {
12688 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
12689 goto nla_put_failure;
12690 }
Johannes Berg362a4152009-05-24 16:43:15 +020012691 nla_nest_end(msg, nest);
12692
David S. Miller9360ffd2012-03-29 04:41:26 -040012693 if (req->ie &&
12694 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
12695 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020012696
Johannes Bergae917c92013-10-25 11:05:22 +020012697 if (req->flags &&
12698 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
12699 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070012700
Avraham Stern1d762502016-07-05 17:10:13 +030012701 if (req->info.scan_start_tsf &&
12702 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
12703 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
12704 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
12705 req->info.tsf_bssid)))
12706 goto nla_put_failure;
12707
Johannes Berg362a4152009-05-24 16:43:15 +020012708 return 0;
12709 nla_put_failure:
12710 return -ENOBUFS;
12711}
12712
Johannes Berga538e2d2009-06-16 19:56:42 +020012713static int nl80211_send_scan_msg(struct sk_buff *msg,
12714 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012715 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012716 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020012717 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010012718{
12719 void *hdr;
12720
Eric W. Biederman15e47302012-09-07 20:12:54 +000012721 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010012722 if (!hdr)
12723 return -1;
12724
David S. Miller9360ffd2012-03-29 04:41:26 -040012725 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020012726 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12727 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012728 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12729 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012730 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010012731
Johannes Berg362a4152009-05-24 16:43:15 +020012732 /* ignore errors and send incomplete event anyway */
12733 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010012734
Johannes Berg053c0952015-01-16 22:09:00 +010012735 genlmsg_end(msg, hdr);
12736 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010012737
12738 nla_put_failure:
12739 genlmsg_cancel(msg, hdr);
12740 return -EMSGSIZE;
12741}
12742
Luciano Coelho807f8a82011-05-11 17:09:35 +030012743static int
12744nl80211_send_sched_scan_msg(struct sk_buff *msg,
12745 struct cfg80211_registered_device *rdev,
12746 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012747 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030012748{
12749 void *hdr;
12750
Eric W. Biederman15e47302012-09-07 20:12:54 +000012751 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012752 if (!hdr)
12753 return -1;
12754
David S. Miller9360ffd2012-03-29 04:41:26 -040012755 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12756 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12757 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012758
Johannes Berg053c0952015-01-16 22:09:00 +010012759 genlmsg_end(msg, hdr);
12760 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030012761
12762 nla_put_failure:
12763 genlmsg_cancel(msg, hdr);
12764 return -EMSGSIZE;
12765}
12766
Johannes Berga538e2d2009-06-16 19:56:42 +020012767void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020012768 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020012769{
12770 struct sk_buff *msg;
12771
Thomas Graf58050fc2012-06-28 03:57:45 +000012772 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012773 if (!msg)
12774 return;
12775
Johannes Bergfd014282012-06-18 19:17:03 +020012776 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020012777 NL80211_CMD_TRIGGER_SCAN) < 0) {
12778 nlmsg_free(msg);
12779 return;
12780 }
12781
Johannes Berg68eb5502013-11-19 15:19:38 +010012782 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012783 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020012784}
12785
Johannes Bergf9d15d12014-01-22 11:14:19 +020012786struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
12787 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010012788{
12789 struct sk_buff *msg;
12790
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012792 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020012793 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012794
Johannes Bergfd014282012-06-18 19:17:03 +020012795 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020012796 aborted ? NL80211_CMD_SCAN_ABORTED :
12797 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010012798 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020012799 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010012800 }
12801
Johannes Bergf9d15d12014-01-22 11:14:19 +020012802 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010012803}
12804
Johannes Bergf9d15d12014-01-22 11:14:19 +020012805void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
12806 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010012807{
Johannes Berg2a519312009-02-10 21:25:55 +010012808 if (!msg)
12809 return;
12810
Johannes Berg68eb5502013-11-19 15:19:38 +010012811 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012812 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010012813}
12814
Luciano Coelho807f8a82011-05-11 17:09:35 +030012815void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
12816 struct net_device *netdev)
12817{
12818 struct sk_buff *msg;
12819
12820 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12821 if (!msg)
12822 return;
12823
12824 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
12825 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
12826 nlmsg_free(msg);
12827 return;
12828 }
12829
Johannes Berg68eb5502013-11-19 15:19:38 +010012830 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012831 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012832}
12833
12834void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
12835 struct net_device *netdev, u32 cmd)
12836{
12837 struct sk_buff *msg;
12838
Thomas Graf58050fc2012-06-28 03:57:45 +000012839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012840 if (!msg)
12841 return;
12842
12843 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
12844 nlmsg_free(msg);
12845 return;
12846 }
12847
Johannes Berg68eb5502013-11-19 15:19:38 +010012848 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012849 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030012850}
12851
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012852static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
12853 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012854{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012855 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040012856 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
12857 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012858
David S. Miller9360ffd2012-03-29 04:41:26 -040012859 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
12860 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12861 NL80211_REGDOM_TYPE_WORLD))
12862 goto nla_put_failure;
12863 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
12864 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12865 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
12866 goto nla_put_failure;
12867 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
12868 request->intersect) {
12869 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12870 NL80211_REGDOM_TYPE_INTERSECTION))
12871 goto nla_put_failure;
12872 } else {
12873 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
12874 NL80211_REGDOM_TYPE_COUNTRY) ||
12875 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
12876 request->alpha2))
12877 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012878 }
12879
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012880 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
12881 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
12882
12883 if (wiphy &&
12884 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
12885 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020012886
12887 if (wiphy &&
12888 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
12889 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
12890 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020012891 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012892
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020012893 return true;
12894
12895nla_put_failure:
12896 return false;
12897}
12898
12899/*
12900 * This can happen on global regulatory changes or device specific settings
12901 * based on custom regulatory domains.
12902 */
12903void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
12904 struct regulatory_request *request)
12905{
12906 struct sk_buff *msg;
12907 void *hdr;
12908
12909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12910 if (!msg)
12911 return;
12912
12913 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
12914 if (!hdr) {
12915 nlmsg_free(msg);
12916 return;
12917 }
12918
12919 if (nl80211_reg_change_event_fill(msg, request) == false)
12920 goto nla_put_failure;
12921
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012922 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012923
Johannes Bergbc43b282009-07-25 10:54:13 +020012924 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012925 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012926 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020012927 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040012928
12929 return;
12930
12931nla_put_failure:
12932 genlmsg_cancel(msg, hdr);
12933 nlmsg_free(msg);
12934}
12935
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012936static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
12937 struct net_device *netdev,
12938 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012939 enum nl80211_commands cmd, gfp_t gfp,
12940 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012941{
12942 struct sk_buff *msg;
12943 void *hdr;
12944
Johannes Berge6d6e342009-07-01 21:26:47 +020012945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012946 if (!msg)
12947 return;
12948
12949 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12950 if (!hdr) {
12951 nlmsg_free(msg);
12952 return;
12953 }
12954
David S. Miller9360ffd2012-03-29 04:41:26 -040012955 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12957 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
12958 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012959
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012960 if (uapsd_queues >= 0) {
12961 struct nlattr *nla_wmm =
12962 nla_nest_start(msg, NL80211_ATTR_STA_WME);
12963 if (!nla_wmm)
12964 goto nla_put_failure;
12965
12966 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
12967 uapsd_queues))
12968 goto nla_put_failure;
12969
12970 nla_nest_end(msg, nla_wmm);
12971 }
12972
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012973 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012974
Johannes Berg68eb5502013-11-19 15:19:38 +010012975 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012976 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012977 return;
12978
12979 nla_put_failure:
12980 genlmsg_cancel(msg, hdr);
12981 nlmsg_free(msg);
12982}
12983
12984void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020012985 struct net_device *netdev, const u8 *buf,
12986 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012987{
12988 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012989 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012990}
12991
12992void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
12993 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012994 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012995{
Johannes Berge6d6e342009-07-01 21:26:47 +020012996 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030012997 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020012998}
12999
Jouni Malinen53b46b82009-03-27 20:53:56 +020013000void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013001 struct net_device *netdev, const u8 *buf,
13002 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013003{
13004 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013005 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013006}
13007
Jouni Malinen53b46b82009-03-27 20:53:56 +020013008void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
13009 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020013010 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013011{
13012 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013013 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020013014}
13015
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013016void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
13017 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020013018{
Johannes Berg947add32013-02-22 22:05:20 +010013019 struct wireless_dev *wdev = dev->ieee80211_ptr;
13020 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013021 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013022 const struct ieee80211_mgmt *mgmt = (void *)buf;
13023 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020013024
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013025 if (WARN_ON(len < 2))
13026 return;
13027
13028 if (ieee80211_is_deauth(mgmt->frame_control))
13029 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
13030 else
13031 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
13032
13033 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030013034 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013035}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020013036EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020013037
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040013038static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
13039 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020013040 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013041{
13042 struct sk_buff *msg;
13043 void *hdr;
13044
Johannes Berge6d6e342009-07-01 21:26:47 +020013045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013046 if (!msg)
13047 return;
13048
13049 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13050 if (!hdr) {
13051 nlmsg_free(msg);
13052 return;
13053 }
13054
David S. Miller9360ffd2012-03-29 04:41:26 -040013055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13057 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
13058 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13059 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030013060
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013061 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030013062
Johannes Berg68eb5502013-11-19 15:19:38 +010013063 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013064 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013065 return;
13066
13067 nla_put_failure:
13068 genlmsg_cancel(msg, hdr);
13069 nlmsg_free(msg);
13070}
13071
13072void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013073 struct net_device *netdev, const u8 *addr,
13074 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013075{
13076 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020013077 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013078}
13079
13080void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020013081 struct net_device *netdev, const u8 *addr,
13082 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030013083{
Johannes Berge6d6e342009-07-01 21:26:47 +020013084 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
13085 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030013086}
13087
Samuel Ortizb23aa672009-07-01 21:26:54 +020013088void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
13089 struct net_device *netdev, const u8 *bssid,
13090 const u8 *req_ie, size_t req_ie_len,
13091 const u8 *resp_ie, size_t resp_ie_len,
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013092 int status, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013093{
13094 struct sk_buff *msg;
13095 void *hdr;
13096
Thomas Graf58050fc2012-06-28 03:57:45 +000013097 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013098 if (!msg)
13099 return;
13100
13101 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
13102 if (!hdr) {
13103 nlmsg_free(msg);
13104 return;
13105 }
13106
David S. Miller9360ffd2012-03-29 04:41:26 -040013107 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13109 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030013110 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
13111 status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
13112 status) ||
13113 (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013114 (req_ie &&
13115 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13116 (resp_ie &&
13117 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13118 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013119
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013120 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013121
Johannes Berg68eb5502013-11-19 15:19:38 +010013122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013123 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013124 return;
13125
13126 nla_put_failure:
13127 genlmsg_cancel(msg, hdr);
13128 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013129}
13130
13131void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
13132 struct net_device *netdev, const u8 *bssid,
13133 const u8 *req_ie, size_t req_ie_len,
13134 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
13135{
13136 struct sk_buff *msg;
13137 void *hdr;
13138
Thomas Graf58050fc2012-06-28 03:57:45 +000013139 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013140 if (!msg)
13141 return;
13142
13143 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
13144 if (!hdr) {
13145 nlmsg_free(msg);
13146 return;
13147 }
13148
David S. Miller9360ffd2012-03-29 04:41:26 -040013149 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13150 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13151 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
13152 (req_ie &&
13153 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
13154 (resp_ie &&
13155 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
13156 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013157
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013158 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013159
Johannes Berg68eb5502013-11-19 15:19:38 +010013160 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013161 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013162 return;
13163
13164 nla_put_failure:
13165 genlmsg_cancel(msg, hdr);
13166 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013167}
13168
13169void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
13170 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020013171 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020013172{
13173 struct sk_buff *msg;
13174 void *hdr;
13175
Thomas Graf58050fc2012-06-28 03:57:45 +000013176 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013177 if (!msg)
13178 return;
13179
13180 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
13181 if (!hdr) {
13182 nlmsg_free(msg);
13183 return;
13184 }
13185
David S. Miller9360ffd2012-03-29 04:41:26 -040013186 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13187 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13188 (from_ap && reason &&
13189 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
13190 (from_ap &&
13191 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
13192 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
13193 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020013194
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013195 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013196
Johannes Berg68eb5502013-11-19 15:19:38 +010013197 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013198 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013199 return;
13200
13201 nla_put_failure:
13202 genlmsg_cancel(msg, hdr);
13203 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020013204}
13205
Johannes Berg04a773a2009-04-19 21:24:32 +020013206void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
13207 struct net_device *netdev, const u8 *bssid,
13208 gfp_t gfp)
13209{
13210 struct sk_buff *msg;
13211 void *hdr;
13212
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013214 if (!msg)
13215 return;
13216
13217 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
13218 if (!hdr) {
13219 nlmsg_free(msg);
13220 return;
13221 }
13222
David S. Miller9360ffd2012-03-29 04:41:26 -040013223 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13224 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13225 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13226 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020013227
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013228 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020013229
Johannes Berg68eb5502013-11-19 15:19:38 +010013230 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013231 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020013232 return;
13233
13234 nla_put_failure:
13235 genlmsg_cancel(msg, hdr);
13236 nlmsg_free(msg);
13237}
13238
Johannes Berg947add32013-02-22 22:05:20 +010013239void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
13240 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070013241{
Johannes Berg947add32013-02-22 22:05:20 +010013242 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013243 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013244 struct sk_buff *msg;
13245 void *hdr;
13246
Johannes Berg947add32013-02-22 22:05:20 +010013247 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
13248 return;
13249
13250 trace_cfg80211_notify_new_peer_candidate(dev, addr);
13251
Javier Cardonac93b5e72011-04-07 15:08:34 -070013252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13253 if (!msg)
13254 return;
13255
13256 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
13257 if (!hdr) {
13258 nlmsg_free(msg);
13259 return;
13260 }
13261
David S. Miller9360ffd2012-03-29 04:41:26 -040013262 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013263 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13264 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013265 (ie_len && ie &&
13266 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
13267 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070013268
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013269 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013270
Johannes Berg68eb5502013-11-19 15:19:38 +010013271 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013272 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013273 return;
13274
13275 nla_put_failure:
13276 genlmsg_cancel(msg, hdr);
13277 nlmsg_free(msg);
13278}
Johannes Berg947add32013-02-22 22:05:20 +010013279EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070013280
Jouni Malinena3b8b052009-03-27 21:59:49 +020013281void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
13282 struct net_device *netdev, const u8 *addr,
13283 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020013284 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020013285{
13286 struct sk_buff *msg;
13287 void *hdr;
13288
Johannes Berge6d6e342009-07-01 21:26:47 +020013289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013290 if (!msg)
13291 return;
13292
13293 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
13294 if (!hdr) {
13295 nlmsg_free(msg);
13296 return;
13297 }
13298
David S. Miller9360ffd2012-03-29 04:41:26 -040013299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13300 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13301 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
13302 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
13303 (key_id != -1 &&
13304 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
13305 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
13306 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020013307
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013308 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013309
Johannes Berg68eb5502013-11-19 15:19:38 +010013310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013311 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020013312 return;
13313
13314 nla_put_failure:
13315 genlmsg_cancel(msg, hdr);
13316 nlmsg_free(msg);
13317}
13318
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013319void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
13320 struct ieee80211_channel *channel_before,
13321 struct ieee80211_channel *channel_after)
13322{
13323 struct sk_buff *msg;
13324 void *hdr;
13325 struct nlattr *nl_freq;
13326
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070013327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013328 if (!msg)
13329 return;
13330
13331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
13332 if (!hdr) {
13333 nlmsg_free(msg);
13334 return;
13335 }
13336
13337 /*
13338 * Since we are applying the beacon hint to a wiphy we know its
13339 * wiphy_idx is valid
13340 */
David S. Miller9360ffd2012-03-29 04:41:26 -040013341 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
13342 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013343
13344 /* Before */
13345 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
13346 if (!nl_freq)
13347 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013348 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013349 goto nla_put_failure;
13350 nla_nest_end(msg, nl_freq);
13351
13352 /* After */
13353 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
13354 if (!nl_freq)
13355 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010013356 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013357 goto nla_put_failure;
13358 nla_nest_end(msg, nl_freq);
13359
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013360 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013361
Johannes Berg463d0182009-07-14 00:33:35 +020013362 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010013363 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013364 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020013365 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040013366
13367 return;
13368
13369nla_put_failure:
13370 genlmsg_cancel(msg, hdr);
13371 nlmsg_free(msg);
13372}
13373
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013374static void nl80211_send_remain_on_chan_event(
13375 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020013376 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013377 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013378 unsigned int duration, gfp_t gfp)
13379{
13380 struct sk_buff *msg;
13381 void *hdr;
13382
13383 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13384 if (!msg)
13385 return;
13386
13387 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
13388 if (!hdr) {
13389 nlmsg_free(msg);
13390 return;
13391 }
13392
David S. Miller9360ffd2012-03-29 04:41:26 -040013393 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013394 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13395 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013396 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13397 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013398 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010013399 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
13400 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013401 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13402 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040013403 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013404
David S. Miller9360ffd2012-03-29 04:41:26 -040013405 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
13406 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
13407 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013408
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013409 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013410
Johannes Berg68eb5502013-11-19 15:19:38 +010013411 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013412 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013413 return;
13414
13415 nla_put_failure:
13416 genlmsg_cancel(msg, hdr);
13417 nlmsg_free(msg);
13418}
13419
Johannes Berg947add32013-02-22 22:05:20 +010013420void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
13421 struct ieee80211_channel *chan,
13422 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013423{
Johannes Berg947add32013-02-22 22:05:20 +010013424 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013425 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013426
13427 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013428 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020013429 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010013430 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013431}
Johannes Berg947add32013-02-22 22:05:20 +010013432EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013433
Johannes Berg947add32013-02-22 22:05:20 +010013434void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
13435 struct ieee80211_channel *chan,
13436 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013437{
Johannes Berg947add32013-02-22 22:05:20 +010013438 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013440
13441 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013442 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010013443 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013444}
Johannes Berg947add32013-02-22 22:05:20 +010013445EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010013446
Johannes Berg947add32013-02-22 22:05:20 +010013447void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
13448 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010013449{
Johannes Berg947add32013-02-22 22:05:20 +010013450 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013451 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010013452 struct sk_buff *msg;
13453
Johannes Berg947add32013-02-22 22:05:20 +010013454 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
13455
Thomas Graf58050fc2012-06-28 03:57:45 +000013456 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013457 if (!msg)
13458 return;
13459
Johannes Bergcf5ead82014-11-14 17:14:00 +010013460 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040013461 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010013462 nlmsg_free(msg);
13463 return;
13464 }
13465
Johannes Berg68eb5502013-11-19 15:19:38 +010013466 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013467 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010013468}
Johannes Berg947add32013-02-22 22:05:20 +010013469EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010013470
Johannes Bergcf5ead82014-11-14 17:14:00 +010013471void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
13472 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020013473{
Johannes Berg947add32013-02-22 22:05:20 +010013474 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013475 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020013476 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010013477 struct station_info empty_sinfo = {};
13478
13479 if (!sinfo)
13480 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020013481
Johannes Berg947add32013-02-22 22:05:20 +010013482 trace_cfg80211_del_sta(dev, mac_addr);
13483
Thomas Graf58050fc2012-06-28 03:57:45 +000013484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013485 if (!msg)
13486 return;
13487
Johannes Bergcf5ead82014-11-14 17:14:00 +010013488 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010013489 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020013490 nlmsg_free(msg);
13491 return;
13492 }
13493
Johannes Berg68eb5502013-11-19 15:19:38 +010013494 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013495 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020013496}
Johannes Bergcf5ead82014-11-14 17:14:00 +010013497EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020013498
Johannes Berg947add32013-02-22 22:05:20 +010013499void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
13500 enum nl80211_connect_failed_reason reason,
13501 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013502{
Johannes Berg947add32013-02-22 22:05:20 +010013503 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013504 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013505 struct sk_buff *msg;
13506 void *hdr;
13507
13508 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
13509 if (!msg)
13510 return;
13511
13512 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
13513 if (!hdr) {
13514 nlmsg_free(msg);
13515 return;
13516 }
13517
13518 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13519 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
13520 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
13521 goto nla_put_failure;
13522
13523 genlmsg_end(msg, hdr);
13524
Johannes Berg68eb5502013-11-19 15:19:38 +010013525 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013526 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013527 return;
13528
13529 nla_put_failure:
13530 genlmsg_cancel(msg, hdr);
13531 nlmsg_free(msg);
13532}
Johannes Berg947add32013-02-22 22:05:20 +010013533EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053013534
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013535static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
13536 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010013537{
13538 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010013540 struct sk_buff *msg;
13541 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000013542 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013543
Eric W. Biederman15e47302012-09-07 20:12:54 +000013544 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010013545 return false;
13546
13547 msg = nlmsg_new(100, gfp);
13548 if (!msg)
13549 return true;
13550
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013551 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010013552 if (!hdr) {
13553 nlmsg_free(msg);
13554 return true;
13555 }
13556
David S. Miller9360ffd2012-03-29 04:41:26 -040013557 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13558 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13559 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
13560 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010013561
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013562 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000013563 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010013564 return true;
13565
13566 nla_put_failure:
13567 genlmsg_cancel(msg, hdr);
13568 nlmsg_free(msg);
13569 return true;
13570}
13571
Johannes Berg947add32013-02-22 22:05:20 +010013572bool cfg80211_rx_spurious_frame(struct net_device *dev,
13573 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013574{
Johannes Berg947add32013-02-22 22:05:20 +010013575 struct wireless_dev *wdev = dev->ieee80211_ptr;
13576 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013577
Johannes Berg947add32013-02-22 22:05:20 +010013578 trace_cfg80211_rx_spurious_frame(dev, addr);
13579
13580 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13581 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
13582 trace_cfg80211_return_bool(false);
13583 return false;
13584 }
13585 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
13586 addr, gfp);
13587 trace_cfg80211_return_bool(ret);
13588 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013589}
Johannes Berg947add32013-02-22 22:05:20 +010013590EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
13591
13592bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
13593 const u8 *addr, gfp_t gfp)
13594{
13595 struct wireless_dev *wdev = dev->ieee80211_ptr;
13596 bool ret;
13597
13598 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
13599
13600 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
13601 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
13602 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
13603 trace_cfg80211_return_bool(false);
13604 return false;
13605 }
13606 ret = __nl80211_unexpected_frame(dev,
13607 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
13608 addr, gfp);
13609 trace_cfg80211_return_bool(ret);
13610 return ret;
13611}
13612EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010013613
Johannes Berg2e161f72010-08-12 15:38:38 +020013614int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000013615 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010013616 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013617 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013618{
Johannes Berg71bbc992012-06-15 15:30:18 +020013619 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013620 struct sk_buff *msg;
13621 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020013622
13623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13624 if (!msg)
13625 return -ENOMEM;
13626
Johannes Berg2e161f72010-08-12 15:38:38 +020013627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020013628 if (!hdr) {
13629 nlmsg_free(msg);
13630 return -ENOMEM;
13631 }
13632
David S. Miller9360ffd2012-03-29 04:41:26 -040013633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013634 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13635 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013636 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13637 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013638 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
13639 (sig_dbm &&
13640 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030013641 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
13642 (flags &&
13643 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040013644 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013645
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013646 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013647
Eric W. Biederman15e47302012-09-07 20:12:54 +000013648 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020013649
13650 nla_put_failure:
13651 genlmsg_cancel(msg, hdr);
13652 nlmsg_free(msg);
13653 return -ENOBUFS;
13654}
13655
Johannes Berg947add32013-02-22 22:05:20 +010013656void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
13657 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020013658{
Johannes Berg947add32013-02-22 22:05:20 +010013659 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013660 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020013661 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020013662 struct sk_buff *msg;
13663 void *hdr;
13664
Johannes Berg947add32013-02-22 22:05:20 +010013665 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
13666
Jouni Malinen026331c2010-02-15 12:53:10 +020013667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13668 if (!msg)
13669 return;
13670
Johannes Berg2e161f72010-08-12 15:38:38 +020013671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020013672 if (!hdr) {
13673 nlmsg_free(msg);
13674 return;
13675 }
13676
David S. Miller9360ffd2012-03-29 04:41:26 -040013677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020013678 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13679 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013680 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13681 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013682 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013683 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13684 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040013685 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
13686 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020013687
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013688 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020013689
Johannes Berg68eb5502013-11-19 15:19:38 +010013690 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013691 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020013692 return;
13693
13694 nla_put_failure:
13695 genlmsg_cancel(msg, hdr);
13696 nlmsg_free(msg);
13697}
Johannes Berg947add32013-02-22 22:05:20 +010013698EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020013699
Johannes Berg5b97f492014-11-26 12:37:43 +010013700static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
13701 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013702{
Johannes Berg947add32013-02-22 22:05:20 +010013703 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010013704 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
13705 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13706 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013707
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013708 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010013709 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013710
Johannes Berg5b97f492014-11-26 12:37:43 +010013711 cb = (void **)msg->cb;
13712
13713 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
13714 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013715 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010013716 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013717 }
13718
David S. Miller9360ffd2012-03-29 04:41:26 -040013719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010013720 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040013721 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013722
Johannes Berg5b97f492014-11-26 12:37:43 +010013723 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013724 goto nla_put_failure;
13725
Johannes Berg5b97f492014-11-26 12:37:43 +010013726 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
13727 if (!cb[1])
13728 goto nla_put_failure;
13729
13730 cb[2] = rdev;
13731
13732 return msg;
13733 nla_put_failure:
13734 nlmsg_free(msg);
13735 return NULL;
13736}
13737
13738static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
13739{
13740 void **cb = (void **)msg->cb;
13741 struct cfg80211_registered_device *rdev = cb[2];
13742
13743 nla_nest_end(msg, cb[1]);
13744 genlmsg_end(msg, cb[0]);
13745
13746 memset(msg->cb, 0, sizeof(msg->cb));
13747
13748 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
13749 NL80211_MCGRP_MLME, gfp);
13750}
13751
13752void cfg80211_cqm_rssi_notify(struct net_device *dev,
13753 enum nl80211_cqm_rssi_threshold_event rssi_event,
13754 gfp_t gfp)
13755{
13756 struct sk_buff *msg;
13757
13758 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
13759
Johannes Berg98f03342014-11-26 12:42:02 +010013760 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
13761 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
13762 return;
13763
Johannes Berg5b97f492014-11-26 12:37:43 +010013764 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13765 if (!msg)
13766 return;
13767
David S. Miller9360ffd2012-03-29 04:41:26 -040013768 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
13769 rssi_event))
13770 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013771
Johannes Berg5b97f492014-11-26 12:37:43 +010013772 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013773
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013774 return;
13775
13776 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013777 nlmsg_free(msg);
13778}
Johannes Berg947add32013-02-22 22:05:20 +010013779EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020013780
Johannes Berg5b97f492014-11-26 12:37:43 +010013781void cfg80211_cqm_txe_notify(struct net_device *dev,
13782 const u8 *peer, u32 num_packets,
13783 u32 rate, u32 intvl, gfp_t gfp)
13784{
13785 struct sk_buff *msg;
13786
13787 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13788 if (!msg)
13789 return;
13790
13791 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
13792 goto nla_put_failure;
13793
13794 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
13795 goto nla_put_failure;
13796
13797 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
13798 goto nla_put_failure;
13799
13800 cfg80211_send_cqm(msg, gfp);
13801 return;
13802
13803 nla_put_failure:
13804 nlmsg_free(msg);
13805}
13806EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
13807
13808void cfg80211_cqm_pktloss_notify(struct net_device *dev,
13809 const u8 *peer, u32 num_packets, gfp_t gfp)
13810{
13811 struct sk_buff *msg;
13812
13813 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
13814
13815 msg = cfg80211_prepare_cqm(dev, peer, gfp);
13816 if (!msg)
13817 return;
13818
13819 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
13820 goto nla_put_failure;
13821
13822 cfg80211_send_cqm(msg, gfp);
13823 return;
13824
13825 nla_put_failure:
13826 nlmsg_free(msg);
13827}
13828EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
13829
Johannes Berg98f03342014-11-26 12:42:02 +010013830void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
13831{
13832 struct sk_buff *msg;
13833
13834 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
13835 if (!msg)
13836 return;
13837
13838 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
13839 goto nla_put_failure;
13840
13841 cfg80211_send_cqm(msg, gfp);
13842 return;
13843
13844 nla_put_failure:
13845 nlmsg_free(msg);
13846}
13847EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
13848
Johannes Berg947add32013-02-22 22:05:20 +010013849static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
13850 struct net_device *netdev, const u8 *bssid,
13851 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020013852{
13853 struct sk_buff *msg;
13854 struct nlattr *rekey_attr;
13855 void *hdr;
13856
Thomas Graf58050fc2012-06-28 03:57:45 +000013857 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013858 if (!msg)
13859 return;
13860
13861 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
13862 if (!hdr) {
13863 nlmsg_free(msg);
13864 return;
13865 }
13866
David S. Miller9360ffd2012-03-29 04:41:26 -040013867 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13868 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13869 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
13870 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013871
13872 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
13873 if (!rekey_attr)
13874 goto nla_put_failure;
13875
David S. Miller9360ffd2012-03-29 04:41:26 -040013876 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
13877 NL80211_REPLAY_CTR_LEN, replay_ctr))
13878 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020013879
13880 nla_nest_end(msg, rekey_attr);
13881
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013882 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020013883
Johannes Berg68eb5502013-11-19 15:19:38 +010013884 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013885 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020013886 return;
13887
13888 nla_put_failure:
13889 genlmsg_cancel(msg, hdr);
13890 nlmsg_free(msg);
13891}
13892
Johannes Berg947add32013-02-22 22:05:20 +010013893void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
13894 const u8 *replay_ctr, gfp_t gfp)
13895{
13896 struct wireless_dev *wdev = dev->ieee80211_ptr;
13897 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013898 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013899
13900 trace_cfg80211_gtk_rekey_notify(dev, bssid);
13901 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
13902}
13903EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
13904
13905static void
13906nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
13907 struct net_device *netdev, int index,
13908 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013909{
13910 struct sk_buff *msg;
13911 struct nlattr *attr;
13912 void *hdr;
13913
Thomas Graf58050fc2012-06-28 03:57:45 +000013914 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013915 if (!msg)
13916 return;
13917
13918 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
13919 if (!hdr) {
13920 nlmsg_free(msg);
13921 return;
13922 }
13923
David S. Miller9360ffd2012-03-29 04:41:26 -040013924 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13925 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13926 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013927
13928 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
13929 if (!attr)
13930 goto nla_put_failure;
13931
David S. Miller9360ffd2012-03-29 04:41:26 -040013932 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
13933 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
13934 (preauth &&
13935 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
13936 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013937
13938 nla_nest_end(msg, attr);
13939
Johannes Berg3b7b72e2011-10-22 19:05:51 +020013940 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013941
Johannes Berg68eb5502013-11-19 15:19:38 +010013942 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013943 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030013944 return;
13945
13946 nla_put_failure:
13947 genlmsg_cancel(msg, hdr);
13948 nlmsg_free(msg);
13949}
13950
Johannes Berg947add32013-02-22 22:05:20 +010013951void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
13952 const u8 *bssid, bool preauth, gfp_t gfp)
13953{
13954 struct wireless_dev *wdev = dev->ieee80211_ptr;
13955 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013956 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010013957
13958 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
13959 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
13960}
13961EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
13962
13963static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
13964 struct net_device *netdev,
13965 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020013966 gfp_t gfp,
13967 enum nl80211_commands notif,
13968 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070013969{
13970 struct sk_buff *msg;
13971 void *hdr;
13972
Thomas Graf58050fc2012-06-28 03:57:45 +000013973 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013974 if (!msg)
13975 return;
13976
Luciano Coelhof8d75522014-11-07 14:31:35 +020013977 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070013978 if (!hdr) {
13979 nlmsg_free(msg);
13980 return;
13981 }
13982
Johannes Berg683b6d32012-11-08 21:25:48 +010013983 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
13984 goto nla_put_failure;
13985
13986 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040013987 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070013988
Luciano Coelhof8d75522014-11-07 14:31:35 +020013989 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
13990 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
13991 goto nla_put_failure;
13992
Thomas Pedersen53145262012-04-06 13:35:47 -070013993 genlmsg_end(msg, hdr);
13994
Johannes Berg68eb5502013-11-19 15:19:38 +010013995 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013996 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070013997 return;
13998
13999 nla_put_failure:
14000 genlmsg_cancel(msg, hdr);
14001 nlmsg_free(msg);
14002}
14003
Johannes Berg947add32013-02-22 22:05:20 +010014004void cfg80211_ch_switch_notify(struct net_device *dev,
14005 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070014006{
Johannes Berg947add32013-02-22 22:05:20 +010014007 struct wireless_dev *wdev = dev->ieee80211_ptr;
14008 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014009 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010014010
Simon Wunderliche487eae2013-11-21 18:19:51 +010014011 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010014012
Simon Wunderliche487eae2013-11-21 18:19:51 +010014013 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010014014
Michal Kazior9e0e2962014-01-29 14:22:27 +010014015 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010014016 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020014017 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14018 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010014019}
14020EXPORT_SYMBOL(cfg80211_ch_switch_notify);
14021
Luciano Coelhof8d75522014-11-07 14:31:35 +020014022void cfg80211_ch_switch_started_notify(struct net_device *dev,
14023 struct cfg80211_chan_def *chandef,
14024 u8 count)
14025{
14026 struct wireless_dev *wdev = dev->ieee80211_ptr;
14027 struct wiphy *wiphy = wdev->wiphy;
14028 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
14029
14030 trace_cfg80211_ch_switch_started_notify(dev, chandef);
14031
14032 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
14033 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
14034}
14035EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
14036
Thomas Pedersen84f10702012-07-12 16:17:33 -070014037void
Simon Wunderlich04f39042013-02-08 18:16:19 +010014038nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010014039 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014040 enum nl80211_radar_event event,
14041 struct net_device *netdev, gfp_t gfp)
14042{
14043 struct sk_buff *msg;
14044 void *hdr;
14045
14046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14047 if (!msg)
14048 return;
14049
14050 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
14051 if (!hdr) {
14052 nlmsg_free(msg);
14053 return;
14054 }
14055
14056 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
14057 goto nla_put_failure;
14058
14059 /* NOP and radar events don't need a netdev parameter */
14060 if (netdev) {
14061 struct wireless_dev *wdev = netdev->ieee80211_ptr;
14062
14063 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014064 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14065 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010014066 goto nla_put_failure;
14067 }
14068
14069 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
14070 goto nla_put_failure;
14071
14072 if (nl80211_send_chandef(msg, chandef))
14073 goto nla_put_failure;
14074
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014075 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014076
Johannes Berg68eb5502013-11-19 15:19:38 +010014077 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014078 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010014079 return;
14080
14081 nla_put_failure:
14082 genlmsg_cancel(msg, hdr);
14083 nlmsg_free(msg);
14084}
14085
Johannes Berg7f6cf312011-11-04 11:18:15 +010014086void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
14087 u64 cookie, bool acked, gfp_t gfp)
14088{
14089 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014090 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014091 struct sk_buff *msg;
14092 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014093
Beni Lev4ee3e062012-08-27 12:49:39 +030014094 trace_cfg80211_probe_status(dev, addr, cookie, acked);
14095
Thomas Graf58050fc2012-06-28 03:57:45 +000014096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030014097
Johannes Berg7f6cf312011-11-04 11:18:15 +010014098 if (!msg)
14099 return;
14100
14101 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
14102 if (!hdr) {
14103 nlmsg_free(msg);
14104 return;
14105 }
14106
David S. Miller9360ffd2012-03-29 04:41:26 -040014107 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14109 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014110 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
14111 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040014112 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
14113 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010014114
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014115 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014116
Johannes Berg68eb5502013-11-19 15:19:38 +010014117 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014118 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010014119 return;
14120
14121 nla_put_failure:
14122 genlmsg_cancel(msg, hdr);
14123 nlmsg_free(msg);
14124}
14125EXPORT_SYMBOL(cfg80211_probe_status);
14126
Johannes Berg5e760232011-11-04 11:18:17 +010014127void cfg80211_report_obss_beacon(struct wiphy *wiphy,
14128 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070014129 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010014130{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014131 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010014132 struct sk_buff *msg;
14133 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070014134 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010014135
Beni Lev4ee3e062012-08-27 12:49:39 +030014136 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
14137
Ben Greear37c73b52012-10-26 14:49:25 -070014138 spin_lock_bh(&rdev->beacon_registrations_lock);
14139 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
14140 msg = nlmsg_new(len + 100, GFP_ATOMIC);
14141 if (!msg) {
14142 spin_unlock_bh(&rdev->beacon_registrations_lock);
14143 return;
14144 }
Johannes Berg5e760232011-11-04 11:18:17 +010014145
Ben Greear37c73b52012-10-26 14:49:25 -070014146 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
14147 if (!hdr)
14148 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010014149
Ben Greear37c73b52012-10-26 14:49:25 -070014150 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14151 (freq &&
14152 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
14153 (sig_dbm &&
14154 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
14155 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
14156 goto nla_put_failure;
14157
14158 genlmsg_end(msg, hdr);
14159
14160 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010014161 }
Ben Greear37c73b52012-10-26 14:49:25 -070014162 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010014163 return;
14164
14165 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070014166 spin_unlock_bh(&rdev->beacon_registrations_lock);
14167 if (hdr)
14168 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010014169 nlmsg_free(msg);
14170}
14171EXPORT_SYMBOL(cfg80211_report_obss_beacon);
14172
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014173#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014174static int cfg80211_net_detect_results(struct sk_buff *msg,
14175 struct cfg80211_wowlan_wakeup *wakeup)
14176{
14177 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
14178 struct nlattr *nl_results, *nl_match, *nl_freqs;
14179 int i, j;
14180
14181 nl_results = nla_nest_start(
14182 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
14183 if (!nl_results)
14184 return -EMSGSIZE;
14185
14186 for (i = 0; i < nd->n_matches; i++) {
14187 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
14188
14189 nl_match = nla_nest_start(msg, i);
14190 if (!nl_match)
14191 break;
14192
14193 /* The SSID attribute is optional in nl80211, but for
14194 * simplicity reasons it's always present in the
14195 * cfg80211 structure. If a driver can't pass the
14196 * SSID, that needs to be changed. A zero length SSID
14197 * is still a valid SSID (wildcard), so it cannot be
14198 * used for this purpose.
14199 */
14200 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
14201 match->ssid.ssid)) {
14202 nla_nest_cancel(msg, nl_match);
14203 goto out;
14204 }
14205
14206 if (match->n_channels) {
14207 nl_freqs = nla_nest_start(
14208 msg, NL80211_ATTR_SCAN_FREQUENCIES);
14209 if (!nl_freqs) {
14210 nla_nest_cancel(msg, nl_match);
14211 goto out;
14212 }
14213
14214 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020014215 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014216 nla_nest_cancel(msg, nl_freqs);
14217 nla_nest_cancel(msg, nl_match);
14218 goto out;
14219 }
14220 }
14221
14222 nla_nest_end(msg, nl_freqs);
14223 }
14224
14225 nla_nest_end(msg, nl_match);
14226 }
14227
14228out:
14229 nla_nest_end(msg, nl_results);
14230 return 0;
14231}
14232
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014233void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
14234 struct cfg80211_wowlan_wakeup *wakeup,
14235 gfp_t gfp)
14236{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014237 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014238 struct sk_buff *msg;
14239 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014240 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014241
14242 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
14243
14244 if (wakeup)
14245 size += wakeup->packet_present_len;
14246
14247 msg = nlmsg_new(size, gfp);
14248 if (!msg)
14249 return;
14250
14251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
14252 if (!hdr)
14253 goto free_msg;
14254
14255 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014256 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14257 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014258 goto free_msg;
14259
14260 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
14261 wdev->netdev->ifindex))
14262 goto free_msg;
14263
14264 if (wakeup) {
14265 struct nlattr *reasons;
14266
14267 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020014268 if (!reasons)
14269 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014270
14271 if (wakeup->disconnect &&
14272 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
14273 goto free_msg;
14274 if (wakeup->magic_pkt &&
14275 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
14276 goto free_msg;
14277 if (wakeup->gtk_rekey_failure &&
14278 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
14279 goto free_msg;
14280 if (wakeup->eap_identity_req &&
14281 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
14282 goto free_msg;
14283 if (wakeup->four_way_handshake &&
14284 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
14285 goto free_msg;
14286 if (wakeup->rfkill_release &&
14287 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
14288 goto free_msg;
14289
14290 if (wakeup->pattern_idx >= 0 &&
14291 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
14292 wakeup->pattern_idx))
14293 goto free_msg;
14294
Johannes Bergae917c92013-10-25 11:05:22 +020014295 if (wakeup->tcp_match &&
14296 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
14297 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014298
Johannes Bergae917c92013-10-25 11:05:22 +020014299 if (wakeup->tcp_connlost &&
14300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
14301 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014302
Johannes Bergae917c92013-10-25 11:05:22 +020014303 if (wakeup->tcp_nomoretokens &&
14304 nla_put_flag(msg,
14305 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
14306 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010014307
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014308 if (wakeup->packet) {
14309 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
14310 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
14311
14312 if (!wakeup->packet_80211) {
14313 pkt_attr =
14314 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
14315 len_attr =
14316 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
14317 }
14318
14319 if (wakeup->packet_len &&
14320 nla_put_u32(msg, len_attr, wakeup->packet_len))
14321 goto free_msg;
14322
14323 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
14324 wakeup->packet))
14325 goto free_msg;
14326 }
14327
Luciano Coelho8cd4d452014-09-17 11:55:28 +030014328 if (wakeup->net_detect &&
14329 cfg80211_net_detect_results(msg, wakeup))
14330 goto free_msg;
14331
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014332 nla_nest_end(msg, reasons);
14333 }
14334
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014335 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014336
Johannes Berg68eb5502013-11-19 15:19:38 +010014337 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014338 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010014339 return;
14340
14341 free_msg:
14342 nlmsg_free(msg);
14343}
14344EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
14345#endif
14346
Jouni Malinen3475b092012-11-16 22:49:57 +020014347void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
14348 enum nl80211_tdls_operation oper,
14349 u16 reason_code, gfp_t gfp)
14350{
14351 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014352 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020014353 struct sk_buff *msg;
14354 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020014355
14356 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
14357 reason_code);
14358
14359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14360 if (!msg)
14361 return;
14362
14363 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
14364 if (!hdr) {
14365 nlmsg_free(msg);
14366 return;
14367 }
14368
14369 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14370 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
14371 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
14372 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
14373 (reason_code > 0 &&
14374 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
14375 goto nla_put_failure;
14376
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014377 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020014378
Johannes Berg68eb5502013-11-19 15:19:38 +010014379 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014380 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020014381 return;
14382
14383 nla_put_failure:
14384 genlmsg_cancel(msg, hdr);
14385 nlmsg_free(msg);
14386}
14387EXPORT_SYMBOL(cfg80211_tdls_oper_request);
14388
Jouni Malinen026331c2010-02-15 12:53:10 +020014389static int nl80211_netlink_notify(struct notifier_block * nb,
14390 unsigned long state,
14391 void *_notify)
14392{
14393 struct netlink_notify *notify = _notify;
14394 struct cfg80211_registered_device *rdev;
14395 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070014396 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020014397
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030014398 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020014399 return NOTIFY_DONE;
14400
14401 rcu_read_lock();
14402
Johannes Berg5e760232011-11-04 11:18:17 +010014403 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010014404 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014405 bool schedule_scan_stop = false;
14406 struct cfg80211_sched_scan_request *sched_scan_req =
14407 rcu_dereference(rdev->sched_scan_req);
14408
14409 if (sched_scan_req && notify->portid &&
14410 sched_scan_req->owner_nlportid == notify->portid)
14411 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010014412
Johannes Berg53873f12016-05-03 16:52:04 +030014413 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000014414 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070014415
Johannes Berg78f22b62014-03-24 17:57:27 +010014416 if (wdev->owner_nlportid == notify->portid)
14417 schedule_destroy_work = true;
14418 }
14419
Ben Greear37c73b52012-10-26 14:49:25 -070014420 spin_lock_bh(&rdev->beacon_registrations_lock);
14421 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
14422 list) {
14423 if (reg->nlportid == notify->portid) {
14424 list_del(&reg->list);
14425 kfree(reg);
14426 break;
14427 }
14428 }
14429 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010014430
14431 if (schedule_destroy_work) {
14432 struct cfg80211_iface_destroy *destroy;
14433
14434 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
14435 if (destroy) {
14436 destroy->nlportid = notify->portid;
14437 spin_lock(&rdev->destroy_list_lock);
14438 list_add(&destroy->list, &rdev->destroy_list);
14439 spin_unlock(&rdev->destroy_list_lock);
14440 schedule_work(&rdev->destroy_work);
14441 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020014442 } else if (schedule_scan_stop) {
14443 sched_scan_req->owner_nlportid = 0;
14444
14445 if (rdev->ops->sched_scan_stop &&
14446 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
14447 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010014448 }
Johannes Berg5e760232011-11-04 11:18:17 +010014449 }
Jouni Malinen026331c2010-02-15 12:53:10 +020014450
14451 rcu_read_unlock();
14452
Ilan peer05050752015-03-04 00:32:06 -050014453 /*
14454 * It is possible that the user space process that is controlling the
14455 * indoor setting disappeared, so notify the regulatory core.
14456 */
14457 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080014458 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020014459}
14460
14461static struct notifier_block nl80211_netlink_notifier = {
14462 .notifier_call = nl80211_netlink_notify,
14463};
14464
Jouni Malinen355199e2013-02-27 17:14:27 +020014465void cfg80211_ft_event(struct net_device *netdev,
14466 struct cfg80211_ft_event_params *ft_event)
14467{
14468 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014469 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020014470 struct sk_buff *msg;
14471 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020014472
14473 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
14474
14475 if (!ft_event->target_ap)
14476 return;
14477
14478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14479 if (!msg)
14480 return;
14481
14482 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020014483 if (!hdr)
14484 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014485
Johannes Bergae917c92013-10-25 11:05:22 +020014486 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
14488 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
14489 goto out;
14490
14491 if (ft_event->ies &&
14492 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
14493 goto out;
14494 if (ft_event->ric_ies &&
14495 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
14496 ft_event->ric_ies))
14497 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020014498
Johannes Berg9c90a9f2013-06-04 12:46:03 +020014499 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020014500
Johannes Berg68eb5502013-11-19 15:19:38 +010014501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010014502 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020014503 return;
14504 out:
14505 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020014506}
14507EXPORT_SYMBOL(cfg80211_ft_event);
14508
Arend van Spriel5de17982013-04-18 15:49:00 +020014509void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
14510{
14511 struct cfg80211_registered_device *rdev;
14512 struct sk_buff *msg;
14513 void *hdr;
14514 u32 nlportid;
14515
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014516 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020014517 if (!rdev->crit_proto_nlportid)
14518 return;
14519
14520 nlportid = rdev->crit_proto_nlportid;
14521 rdev->crit_proto_nlportid = 0;
14522
14523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
14524 if (!msg)
14525 return;
14526
14527 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
14528 if (!hdr)
14529 goto nla_put_failure;
14530
14531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014532 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14533 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020014534 goto nla_put_failure;
14535
14536 genlmsg_end(msg, hdr);
14537
14538 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
14539 return;
14540
14541 nla_put_failure:
14542 if (hdr)
14543 genlmsg_cancel(msg, hdr);
14544 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020014545}
14546EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
14547
Johannes Berg348baf02014-01-24 14:06:29 +010014548void nl80211_send_ap_stopped(struct wireless_dev *wdev)
14549{
14550 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014551 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010014552 struct sk_buff *msg;
14553 void *hdr;
14554
14555 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14556 if (!msg)
14557 return;
14558
14559 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
14560 if (!hdr)
14561 goto out;
14562
14563 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
14564 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020014565 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
14566 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010014567 goto out;
14568
14569 genlmsg_end(msg, hdr);
14570
14571 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
14572 NL80211_MCGRP_MLME, GFP_KERNEL);
14573 return;
14574 out:
14575 nlmsg_free(msg);
14576}
14577
Johannes Berg55682962007-09-20 13:09:35 -040014578/* initialisation/exit functions */
14579
14580int nl80211_init(void)
14581{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000014582 int err;
Johannes Berg55682962007-09-20 13:09:35 -040014583
Johannes Berg2a94fe42013-11-19 15:19:39 +010014584 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
14585 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040014586 if (err)
14587 return err;
14588
Jouni Malinen026331c2010-02-15 12:53:10 +020014589 err = netlink_register_notifier(&nl80211_netlink_notifier);
14590 if (err)
14591 goto err_out;
14592
Johannes Berg55682962007-09-20 13:09:35 -040014593 return 0;
14594 err_out:
14595 genl_unregister_family(&nl80211_fam);
14596 return err;
14597}
14598
14599void nl80211_exit(void)
14600{
Jouni Malinen026331c2010-02-15 12:53:10 +020014601 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040014602 genl_unregister_family(&nl80211_fam);
14603}